3
$\begingroup$

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.

$\endgroup$
1
  • 2
    $\begingroup$ 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}} }] ]? $\endgroup$
    – Kuba
    May 16, 2018 at 19:07

1 Answer 1

2
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Thanks for both suggestions. I'm away from my computer iuntil morning now, but will report back. $\endgroup$ May 16, 2018 at 19:14
  • $\begingroup$ Both of these work. I can only tick the one that's proposed as an answer, though. Much appreciated. $\endgroup$ May 17, 2018 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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