3
$\begingroup$

I noticed something changed, I am not sure when this started, if it is with 12.0 or 11.3.

I like to use Print inside either Do or Table for debugging. I have all prints send to console which I have open to see how far the computation has gone so far.

  CurrentValue[$FrontEnd, {"PrintAction"}] = {"PrintToConsole"}

When the number of iterations is large, the front end do not show the print statements at all in the console, until after the loop finished. which defeats the purpose of the prints since I want to see the them as the loop is running.

It is either the console is not scrolling automatically, or the messages are buffered there but not flushed.

What is the correct way to make the Print show up immediately? I found that adding a Pause[0.1] after each print makes it display the print at each iteration. A smaller value of Pause that 0.1 did not work as well.

But this means the loop now takes longer time.

Here is a MWE I was using now.

ClearAll[x,y,t,n,m]
L=20;
H=30;
c=3/10;
f1[x_]:=Piecewise[{{1,48/100 L<= x<= 52/100 L},{0,True}}];
f2[y_]:=Piecewise[{{1,48/100 H<= y<= 52/100 H},{0,True}}];
numberOfTerms=200;
res[n_,m_]=N@Integrate[f1[x]*f2[y]*Sin[(n Pi)/L x]*Sin[(m Pi)/H y],{x,0,L},{y,0,H}];

And now the loop.

Be careful. Before running this loop below, make sure to save all your work. As the front end can lock up until the loop is completed, which can take many long minutes. So if you do not want to wait, you might not be able to stop the evaluation.

Anm = Table[Print["n=", n, ", m=", m]; (*Pause[.1];*) 
   Evaluate[res[n, m]], {n, 1, numberOfTerms}, {m, 1, numberOfTerms}];

Now, as the above is running, looking at the console, shows that nothing is being printed, until the loop is completed, then all the messages will show at once.

Using 12.0 on windows 10 with 64 GB RAM.

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.