4
$\begingroup$

I have some heavy computations in Mathematica that use parallelization. The CPU consumption is ~80-90%. I use ProgressIndicator to trace the progress of the computation. During the calculations, when scrolling the notebook, everything is fine until I reach the evaluating cell (where the only dynamic content is this progress bar). Then, the notebook freezes for some significant amount of time - 20-30 seconds (the computation is ongoing, though).

This is the template of the code.

Monitor[Table[
   FinalBlock[list[[l]]], {l, 1, Length[list], 
    1}], Row[{ProgressIndicator[l, {1, Length[list]}], "i = ", l, 
    "/", Length[list], 
    " m = ", list[[l]]}, " "]];

What may be a reason for this, and how can it be fixed?

P.S. Mathematica 13.1/13.2@Windows 11.

$\endgroup$
4
  • $\begingroup$ What does FinalBlock do? $\endgroup$ Feb 7 at 2:26
  • $\begingroup$ @DanielLichtblau : it performs some compiled and parallelized code. $\endgroup$ Feb 7 at 8:48
  • $\begingroup$ Does it perhaps do large-scale numeric linear algebra? $\endgroup$ Feb 7 at 9:08
  • $\begingroup$ @DanielLichtblau : yes, it is some routine doing different manipulations with elements of tables. $\endgroup$ Feb 7 at 9:11

1 Answer 1

6
$\begingroup$

So here is my guess, based on information provided and on past experience. Which is to say, I'm describing a scenario I have often encountered that looks like but might not actually be your situation.

You are making calls that go into library code such as MKL for Lapack/BLAS. You scroll to the place with the dynamic content. You get a freeze. If this much is correct then read on.

First thing to be aware of is that some library code is not interruptible. This included Lapack and the underlying BLAS that it calls. Next is that to handle the dynamic updating, the front end UI needs to get information from the running kernel (where the computation is taking place).

The front end uses a dedicated link to get this information. In order to support the behavior required of Monitor this is of necessity a preemptive call. Which means the user interface needs to get information back from the kernel, off that same link, before it can update the dynamic content. Until it can do so, it is not able to do further processing. This needed information can only be passed along by the kernel at what I will call "check for interruption" points in the implementation code.

In much of the Mathematica kernel these points are abundant and there is no issue with supporting preemptive calls. External library code is often not instrumented with such points however. The upshot is that code that exercises long calls to external libraries will unresponsive to front-end queries until emerging from the library code.

Some of this is explained in the section "Slow Evaluations inside Dynamic" inside the tutorial Introduction to Dynamic. Monitor uses Dynamic and, for reasons noted above, has to update synchronously.

$\endgroup$
1
  • $\begingroup$ Thanks! It sounds reasonable. $\endgroup$ Feb 7 at 21:08

Your Answer

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

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