I wrote a finite element program which assembles small matrices into a huge sparse matrix. It is multithreaded (using std::thread
). Depending on the number of threads, each thread is in charge of computing some amount of small matrices and writing the result into the sparse matrix. Thread 1 writes to indexes (0,0)
up to (i-1, i-1)
for example, thread 2 writes to indexes from (i, i)
to (2*i -1, 2*i -1)
and so on, where i
is precalculated depending on the number of threads used.
I would like to do the same with std::for_each
and std::execution::par
. However, I read I cannot choose the number of threads used. Is there any way I could tell std::for_each
where to write the results, that is, the precise location (i, j)
of the sparse matrix?