Wolfram Research

Function Repository Resource:

DynamicMap

Source Notebook

Map functions over lists while showing dynamic progress

Contributed by: Michael Sollami

ResourceFunction["DynamicMap"][f,list]

maps function f over the given list, while showing a progress indicator.

Details and Options

ResourceFunction["DynamicMap"] displays dynamic updates on the progress of the mapping in a panel:
ResourceFunction["DynamicMap"] works on associations as well as lists.
The panel displays the following details:
Item current index being processed
Size current size of resulting object
Time approximation of remaining time
Kernels number of parallel kernels being used
If a computation is aborted, either by pressing the Abort button in the panel or by aborting the kernel normally, ResourceFunction["DynamicMap"] will return a list containing all the of work that was already finished, along with a report of the index of the element on which ResourceFunction["DynamicMap"] was aborted.
ResourceFunction["DynamicMap"] supports the Boolean option "Parallel" (which is False by default). If set to True, it will attempt to launch parallel subkernels and proceed with the computation.

Examples

Basic Examples

DynamicMap displays a panel of mapping progress:

In[1]:=
ResourceFunction["DynamicMap"][Pause[#] &, Range@10]

Use DynamicMap to monitor a long computation and optionally abort it:

In[2]:=
a = Association[(# -> (2^# - 1)) & /@ Range[1000, 1002]];
x = ResourceFunction["DynamicMap"][FactorInteger, Range[4^5, 8^7]];

Apply DynamicMap to an association:

In[3]:=
ResourceFunction["DynamicMap"][#^2 &, AssociationThread[Range[20] -> Range[20]], "Parallel" -> False]
Out[3]=

Scope

Partial results

Click the abort button in the panel to stop the computation, but return partially completed work:

In[4]:=
ResourceFunction["DynamicMap"][Pause, Range[10], "Parallel" -> False]
Out[4]=

Options

Parallel

To do the work in parallel, DynamicMap will launch kernels as needed:

In[5]:=
pfunc[x_] := (Pause[2]; x^3)
res = ResourceFunction["DynamicMap"][pfunc, Range[24], "Parallel" -> True] // AbsoluteTiming
Out[6]=

If you abort the computation while using the Parallel option, partial results are returned as a list of rules mapping indices to values:

In[7]:=
pfunc[x_] := (Pause[1]; If[x > 7, Abort[]]; x^3)
ResourceFunction["DynamicMap"][pfunc, Range[10], "Parallel" -> True] // AbsoluteTiming
Out[7]=

When using the Parallel option, you can specify the minimum number of kernels used:

In[8]:=
pfunc[x_] := (Pause[2]; x^3)
ResourceFunction["DynamicMap"][pfunc, AssociationThread[Range[24] -> Range[24]], "Parallel" -> 2] // AbsoluteTiming
Out[8]=
In[9]:=
ResourceFunction["DynamicMap"][pfunc, AssociationThread[Range[24] -> Range[24]], "Parallel" -> 6] // AbsoluteTiming
Out[9]=

Possible Issues

Time estimates require a few seconds to measure and are only first-order approximations:

In[10]:=
a = Range[100, 400];
Short@ResourceFunction["DynamicMap"][FactorInteger[2^# - 1] &, a]
Out[7]=

Resource History

Related Resources

Author Notes

V1—Initial version

V2—Added "Parallel" option

License Information