I have a code to generate a table with a computationally very expensive function f[x,y]. I run the code on a cloud server, that is, from the command line without graphical output. I found a way to print to the terminal the parameters x and y before a cell is computed. However, unfortunately, I now see that my code got stuck computing one of many cells and just by knowing which cells were started I don't know which of those have actually finished successfully (and, in particular, which ones have not).

Here is my code so far:

tab = Block[{counter},
    Print[{counter, (arg[[1]]), 10^21 (arg[[2]])}];
    {arg[[1]], arg[[2]], f[arg[[1]], arg[[2]]]}, {arg, 
     Tuples[{Range[0, 2, 0.1], Range[0, 4, 0.1]}]}, 
    Method -> "FinestGrained"]];

I assume that there is no way for me to recover the already computed cells. But at least I want to be smarter next time and print some information once the cell finished computing. I am aware that I could add this command at the end of the function f. But is there also a way to include this kind of progress indicator in the ParallelTable body?


I found the solution to this issue myself: Storing the result temporarily in a variable, then printing the message, and then setting the array element to the value of the variable:

f[x_, y_] := Block[{}, Pause[2]; Return[x + y]];
tab = Block[{counter = 0, result},
    Print[{counter, arg[[1]], arg[[2]]}];
    {arg[[1]], arg[[2]], result = f[arg[[1]], arg[[2]]]; 
     Print["done with ", {counter, arg[[1]], arg[[2]], result}]; 
     result}, {arg, Tuples[{Range[0, 2, 1], Range[0, 4, 1]}]}, 
    Method -> "FinestGrained"]];

Your Answer

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

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