I managed to get the below code working for Array as I wish to track array building for 2d arrays.

The code inside the array elements is reasonably expensive, so my preference is to build the array in parallel.

Sadly, I'm running into the problem that making the step towards parallel array buildings for this example is not trivial. Simply setting SetSharedVariable or using Parallelize (or ParallelArray) does not seem to do the trick, which is usually enough to get it working.

How would I go about parallelising the code below? I only need an overall progress bar between 0 and 100%, nothing fancy that would for example track individual kernels on their current job.


SetAttributes[safeMonitor, HoldAll];
safeMonitor[index_, startIndex_, endIndex_, label_, 
    code_] /; $Notebooks := 
   Row[{ProgressIndicator[index, {startIndex, endIndex}], index}, 
safeMonitor[index_, startIndex_, endIndex_, label_, code_] := code;

dim = 1000;
g = (i = Divide[100 (dim (#1 - 1) + #2), dim^2.];
    f) &;
Block[{i = 1},
 safeMonitor[i, 1, 100, "", Array[g, {dim, dim}]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.