# How to monitor the progress of building a ParallelArray?

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.

ClearAll["Global*"];

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

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