3

I have a table that takes a long time to calculate because f[x] is quite a complicated function:

Table[f[x], {m, 50, 1000, 50}, {x, 0, 50}]

It would be great to have a progress bar to give some idea of how long the evaluation will take to complete. Ideally, I would also like a counter stating which values of m and x are currently being assessed.

This thread offers a simple progress bar:

Monitor[
 Table[Pause[0.1]; Prime[i], {i, 100}],
  Row[{ProgressIndicator[i, {1, 100}], i}, " "]
]

But I can't figure out how to adapt this for a multi-row table with two variables, or how to produce a counter that tells me what values of m and x are currently being evaluated.

I'd be very grateful for any solutions.

Richard Burke-Ward
  • 2,231
  • 6
  • 12
  • 2
    Monitor[ Table[Pause[0.01]; Prime[m x], {m, 50, 1000, 50}, {x, 1, 50}], Grid[{ {"Total progress:", ProgressIndicator[Dynamic[m/1000]]}, {"Current row progress:", ProgressIndicator[Dynamic[x/50]]}, {"{m, x}=", {Dynamic@m, Dynamic@x}} }] ]? – Kuba May 16 '18 at 19:07

1 Answers1

2

How about a simple method such as this. You can easily adjust as needed. It hard to guess how long it will take each step. This assumes each step takes same amount of time. This is how ProgressIndicator works.

ClearAll[n, m, p];
f[n_] := FactorInteger[2^n - 1];

nRows = 10;
nCols = 20;
total = nRows*nCols;
p = 0;

Grid[{
  {Row[{"row ", Dynamic@m, " column ", Dynamic@n}]},
  {ProgressIndicator[Dynamic[p], {1, total}]}
  }]

Do[
 Do[
  p += 1;
  f[p],
  {m, 1, nRows}
  ],
 {n, 1, nCols}
 ]

now

enter image description here

Nasser
  • 143,286
  • 11
  • 154
  • 359