# Monitoring progress of long calculations

I've came upon a few methods of how to display "processing" information while Mathematica is running. But, from what I've understood, this only works in between lines of codes. Is it possible to display a "how far is something being processed"-information during a line of code?

For example, I wish to Map a function g over a very large list, for example:

Map[ g , Sort[Apply[Join, Table[Range[1000000], {1000}]]] ],


which will take quite some time. Now, because the list consists of 1000 times every number between 1 and 1000000, could it be possible do display (as a temporary display), which number is being processed?

I have thought of using Print and changing the function being mapped to

Map[ (Print[#]; g[#]) &, Sort[Apply[Join, Table[Range[1000000], {1000}]]] ],


but I was wondering if there was any "faster" method, which wouldn't print out every number of the list, but for example every 1000th number. I have thought about If before Print, but I think this method would take too much extra time.

• See this Q&A for some ideas. Commented Oct 31, 2013 at 10:25
• Thanks for the link, I like these ideas! Commented Oct 31, 2013 at 14:04

Or you can use something like this:

Monitor[
Table[Length@FactorInteger[2^n - 1], {n, 50, 500, 50}],
Grid[{{Text[Style["Integer Factorization :", Darker[Blue, 0.66]]],
ProgressIndicator[n, {50, 500}]},
{Text[Style["Factoring 2^n-1 with n : ", Darker[Blue, 0.66]]], n}},
Alignment -> Left, Dividers -> Center]]


Sorry for not using your computation, since it did not make sense to me, which is my fault. That's why I've chosen another, just to display my approach.

A simple way to do it would be to partition the big list into chunks, and map over each chunk in turn, monitoring the progress of that outer loop.

data = Range[10^6];
chunks = Partition[data, 1000];
result = Flatten[Table[g /@ chunks[[i]], {i, Length[chunks]}]] ~Monitor~ i;

Short[result]
(* {g[1], g[2], g[3], g[4], <<999992>>, g[999997], g[999998], g[999999], g[1000000]} *)

• Thanks! What do you mean by Length[pd]? Should this be Length[chunks]? Commented Oct 31, 2013 at 13:28
• @Gabriel, yes it should. Sorry, I changed the symbol name to make it clearer but missed one! Commented Oct 31, 2013 at 14:29

Provided you can put your intermediate results or progress indicator into a common scope with a ScheduledTask you can monitor proceedings as follows...

Module[{x = 0, monitor},
(* Create a monitoring ScheduledTask *)

(*SomeBigCalculation*)
Do[x++, {10^9}];

(*Kill the monitor when not required.*)

• Or you could simply write Dynamic@x. Commented Oct 31, 2013 at 14:52
• You can specify the update speed with Dynamic[Refresh[x, UpdateInterval -> int]], otherwise "Dynamic[expr] evaluates expr whenever it needs its value and it determines that any type of value of symbols on which it depends might have changed." (from the docs), which might mean low time granularity. Commented Oct 31, 2013 at 16:50
• But of course a ScheduledTask is very useful, did not mean to devalue your answer, I use it a lot! Commented Oct 31, 2013 at 16:51