I have a very large sparse array, and the computation of individual matrix elements is fairly expensive. The Matrix is Hermitian and traceless, so I would like to construct only the sub-diagonal elements explicitly.
A sketch of my attempt:
M = SparseArray[{}, {imax, imax}];
SetSharedVariable[M];
ParallelDo[
If[j < i, M[[i, j]] = f[i, j]],
{i, 1, imax}, {j, 1, imax}];
My understanding is that setting M as a shared variable this way is very expensive. Is there a good way to parallelize this process?
Note: I have seen examples where people calculate dense matrices by constructing the submatrices on separate kernels, but for my matrix the computation time of a submatrix is difficult to estimate so trying to distribute the computation time manually is difficult.
SparseArray[ids -> vals]
, whereids = {{i1,j1},{i2,j2},...}
is a list of indexes andvals
is a list of correcpoding values. You can calulatevals
withParallelTable
. Moreover, adding elements to existingSparseArray
takes sensible amount of time. $\endgroup$