#include #include #include #include #include #include template typename std::enable_if::value, void>::type randomInit(MA& A) { using ElementType = typename MA::ElementType; using Index = typename MA::Index; std::random_device random; std::mt19937 mt(random()); std::uniform_real_distribution uniform(-100,100); hpc::matvec::apply(A, [&](ElementType& val, Index i, Index j) -> void { val = uniform(mt); }); } int main() { using namespace hpc::matvec; GeMatrix A(51, 7); unsigned int nof_threads = std::thread::hardware_concurrency(); std::vector threads(nof_threads); unsigned int job_size = A.numRows / nof_threads; unsigned int remainder = A.numRows % nof_threads; GeMatrix::Index start = 0; for (int index = 0; index < nof_threads; ++index) { GeMatrix::Index num_rows = job_size; if (index < remainder) ++num_rows; auto A_ = A(start, 0, num_rows, A.numCols); threads[index] = std::thread([=]() mutable { randomInit(A_); }); start += num_rows; } for (int index = 0; index < nof_threads; ++index) { threads[index].join(); } /* print a small block of each of the initialized matrices */ print(A, "A"); }