I’m building a large ParallelTable, and would like to maintain some sense of how the computation is going. For a non parallel table the following code does a great job:
counter = 1;
Timing[
Monitor[
Table[
counter++
, {n, 10^6}];
, ProgressIndicator[counter, {0, 10^6}]
]
]
with the result {0.943512, Null}. For the parallel case, however, it’s necessary to make the counter shared between the kernels:
counter = 1;
SetSharedVariable[counter];
Timing[
Monitor[
ParallelTable[
counter++
, {n, 10^4}];
, ProgressIndicator[counter, {0, 10^4}]
]
]
with the result {6.33388, Null}. Since the value of counter needs to be passed back and forth between the kernels at every update, the performance hit is beyond severe. Any ideas for how to get some sense of how the computation is going? Perhaps letting each kernel have its own value for counter and summing them at intervals? Perhaps some way of determining what elements of the table have already been farmed out to the kernels?
You nearly gave the answer yourself, when you said “Perhaps letting each kernel have its own value for counter and summing them at intervals?”.
Try something like this:
Note that it takes longer than your first single-CPU case only because it actually does something in the loop.
You can change the test AbsoluteTime[] – last > 1 to something more frequent like AbsoluteTime[] – last > 0.1.