2
$\begingroup$

Some time ago David published an implementation of a simple monitor for ParallelTable which dynamically displays current values of the iterator for all parallel kernels. However this implementation has significant drawback: if one kernel "freezes" while others have finished their work, this monitor will still display all the kernels as running and there is no straightaway way to decide at which value of the iterator the freezing occurred.

How to create a monitor for ParallelTable that will display only values of the iterator which currently are under evaluation? Ideally the value of the iterator should be shown along with the number of the parallel kernel where it is evaluating (I mean not $KernelID but the number shown as CellLabel like "(kernel 3)" when something is printed from a parallel kernel)? Timings for different values of the iterator may differ by orders of magnitude. A toy example:

ParallelTable[Pause[RandomVariate[ExponentialDistribution[1/2]]], {i, 50}]
$\endgroup$
2
$\begingroup$

This what I normally use:

status = ParallelEvaluate["idle"];
SetSharedVariable[status];
Monitor[
 ParallelTable[
  status[[$KernelID]] = {$KernelID,i,DateString[]};
  Pause[RandomVariate[ExponentialDistribution[1/2]]];
  out=RandomReal[]; (* long calculation *)
  status[[$KernelID]] = {$KernelID,"idle",DateString[]};
  out
  ,
  {i,50}
 ]
 ,
 status//TableForm
]

The downside is that the underlying assumption is that kernels are numbered 1 through something. This will fail if during you session you end up restarting kernels, etc.

This can be overcome with a bit of tweaking:

kernels = ParallelEvaluate[$KernelID];
SetSharedFunction[status];
Monitor[
 ParallelTable[
  status[$KernelID] = {$KernelID,i,DateString[]};
  Pause[RandomVariate[ExponentialDistribution[1/2]]];
  out=RandomReal[]; (* long calculation *)
  status[$KernelID] = {$KernelID,"idle",DateString[]};
  out
  ,
  {i,50}
 ]
 ,
 status/@kernels//TableForm
]
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.