Function Repository Resource:

ParallelMapProgress

Source Notebook

A version of ParallelMap with incremental progress display

Contributed by: Roman E. Maeder

ResourceFunction["ParallelMapProgress"][f,expr]

evaluates ParallelMap[f,expr] and displays incremental progress information, including an estimated time to completion.

Details and Options

ResourceFunction["ParallelMapProgress"] takes the same options as ParallelMap, with the following changes:
DistributedContexts$DistributedContextsspecifies which symbols appearing in expr have their definitions automatically distributed to all available kernels before the computation
Method"FinestGrained"specifies the parallelization method to use
The default of the Method option is "FinestGrained", which gives the most accurate progress information.
The "Results" line shows the number of results received, the number of evaluations submitted and the granularity, i.e. the size of each evaluation. With Method"FinestGrained", the size of the evaluations is 1.
The "Kernels" line shows the number of busy kernels.
The progress indicator contains a stop button, which will stop submitting new evaluations and wait for all pending ones to finish. For a less graceful but quicker way to stop, abort the calculation.

Examples

Basic Examples (2) 

Find Mersenne primes:

In[1]:=
res = ResourceFunction["ParallelMapProgress"][PrimeQ[2^# - 1] &, Range[9601, 12000]];

Perform a series of calculations with large integers:

In[2]:=
res = ResourceFunction[
   "ParallelMapProgress"][{#, Total[FactorInteger[10^60 + #][[All, 2]]]} &, Range[1000], Method -> "ItemsPerEvaluation" -> 4];

Scope (2) 

The stop button will gracefully terminate the computation without aborting the kernels:

In[3]:=
res = ResourceFunction[
   "ParallelMapProgress"][{#, Total[FactorInteger[10^60 + #][[All, 2]]]} &, Range[1000], Method -> "ItemsPerEvaluation" -> 4];

For immediate termination, abort the computation:

In[4]:=
res = ResourceFunction[
   "ParallelMapProgress"][{#, Total[FactorInteger[10^60 + #][[All, 2]]]} &, Range[1000], Method -> "ItemsPerEvaluation" -> 4];
Out[4]=

Options (2) 

DistributedContexts (2) 

By default, definitions in the current context are distributed automatically:

In[5]:=
remote[x_] := {$KernelID, x^3}
In[6]:=
ResourceFunction["ParallelMapProgress"][remote, {1, 2, 3, 4}]
Out[6]=

Do not distribute any definitions of functions. In this case, the definition of local is applied only after the results are returned to the local kernel:

In[7]:=
local[x_] := {$KernelID, x^2}
In[8]:=
ResourceFunction["ParallelMapProgress"][local, {1, 2, 3, 4}, DistributedContexts -> None]
Out[8]=

Possible Issues (1) 

If the larger computations are near the end of the input list, timing estimates will be inaccurate:

In[9]:=
ResourceFunction["ParallelMapProgress"][
 Timing[Inverse[RandomReal[{-1, 1}, {#, #}]]; #] &, 2^Range[13]]
Out[9]=

Publisher

Roman Maeder

Version History

  • 1.0.0 – 03 August 2021

Related Resources

License Information