I was trying to carry out the following calculations:
j = 0; SetSharedVariable[j];
resultlist1 = ParallelTable[j++; GaussianPotential[fieldlist[[ind2]], theta1, vz, v2, matrixsize, DisorderRangeRatio -> 0], {ind2, 1, num}];
At the same time, I am monitoring the progress by executing
Dynamic[Refresh[TableForm[{"ind1=", ind1, "ind2=", ind2, "j=", j}], UpdateInterval -> 1]]
There are two strange things:
(1) The behavior of j. The second command just quickly updates j from 1 to num, and stops there. I was expecting that the second command updates j each time it carries out a new calculation. How can I correct this?
(2) ParallelTable actually takes more time than Table. In contrast, when I execute the example in the official document,
Table[PrimeQ[x], {x, 10^1000, 10^1000 + 5000}]; // AbsoluteTiming
ParallelTable[PrimeQ[x], {x, 10^1000, 10^1000 + 5000}]; // AbsoluteTiming
The parallel version does save much time (5.87s vs 3.40s). What could be the reason for ParallelTable to be slower? Does it matter that the function GaussianPotential comes from a separate package I wrote?
AbsoluteTiming
will show you the correct results just if you have initiated the kernels preliminary or in case when you runParallelTable
at second time.. $\endgroup$