I have a question regarding the use of ParallelDo
. I tried to parallelize the following code involving four nested Do
loops by using ParallelDo
to make it as fast as possible. For that I already tried parallelizing the outermost loop, but its slower than the original code without ParallelDo
. Would you please help me with this?
t = 2;
ip = 0;
ar = ConstantArray[0, {t (t + 2), t (t + 2)}];
f[n_, m_, v_, u_] := KroneckerDelta[n, v] KroneckerDelta[m, u];
SetSharedVariable[ar, ip];
ParallelDo[Do[i = ip + n + m + 1; jp = 0;
Do[Do[j = jp + u + v + 1; ar[[i, j]] = f[n, m, v, u], {u, -v, v}];
jp = jp + 2 v + 1, {v, t}], {m, -n, n}]; ip = i, {n, t}];//AbsoluteTiming
Actually, this is a simple example of what I am trying to do, to figure out why the above code doesn't work so that I can apply it to my more complex problem.
Compile
. Also, I really suspect that having all the sub kernels write to a shared array is not the way to go. $\endgroup$Table
may be a better choice. $\endgroup$