# How to simultaneously monitoring parallel computations in different Kernels?

I have a question about monitoring parallel processes. Let's suppose that I am running the following code with 5 active Kernels.

ParallelDo[For[i = 1, i <= 5, i++, Print[i]], {k, 1, 5, 1}]


Every kernel will pick a number from 1 to 5 of the ParallelDo loop command and will execute the internal loop For individually. How can I monitor with a ProgressIndicator bar every single Kernel evaluation status simultaneously?

• Are you looking for something different than Parallel Kernel Status? Mar 5 '16 at 1:47
• Yes, I was looking for a way to monitor the evolution of the parameter "i" in the "For" cycle, independently for every Kernel. At the moment I am doing it by using the "Print" command, the problem is that it prints a new line every time, while I would like some kind of a monitor that auto-update himself without printing a new line every time. Looking on other questions I found that is exactly what "ProgressIndicator" does, but I am not able to use it the way I wanted. Do you have any suggestion on how to do so? Thanks. Mar 5 '16 at 5:44
• You should have a look at this: mathematica.stackexchange.com/a/1562/21606 Mar 5 '16 at 10:05
• Thanks! Exactly what I was looking for Mar 5 '16 at 19:17

Basically, one sets up a list - currentStep - which holds the current value of the iterators on every kernel (or some combination that gives the desired output) and is printed temporarily as a Dynamic construct. By this, one avoids huge amounts of Print cells in the notebook that need to be deleted afterwards.
Mainly, the correct assignment in the body needs to be like currentStep[[$KernelID /. kernels]] = i where i is the iterator. For the example given in the OP (where the iterator of the inner For loop needs to be monitored) we can proceed like this: kernels = ParallelTable[$KernelID -> i, {i, $KernelCount}]; currentStep = ConstantArray[0, Length@kernels]; SetSharedVariable[kernels, currentStep]; PrintTemporary["Current computation on each kernel:"]; PrintTemporary@Dynamic[currentStep//Column]; ParallelDo[For[i = 1, i <= 5, i++, Pause[.25]; currentStep[[$KernelID/.kernels]] = "Kernel: " <> ToString[\$KernelID] <> " -> i=" <> ToString[i]], {k, 1, 20, 1}]