1
$\begingroup$

Consider a code like

S0; (*initial list*)
S1=f[S0]; ""; Clear[S0];
S2=g[S1]; ""; Clear[S1];
S3=f[S2]; ""; Clear[S2];
S4=f[S3]; ""; Clear[S3];
S5=f[S4]; ""; Clear[S4];
S6=g[S5]; ""; Clear[S5];
S7=f[S6]; ""; Clear[S6];
S8=f[S7]; ""; Clear[S7];

where there is a considerable usage of RAM memory and processing in each evaluation of the functions. I have two questions. The first question is whether there is any difference between

S0; (*initial list*)
Parallelize[S1=f[S0]; ""; Clear[S0];]
Parallelize[S2=g[S1]; ""; Clear[S1];]
Parallelize[S3=f[S2]; ""; Clear[S2];]
Parallelize[S4=f[S3]; ""; Clear[S3];]
Parallelize[S5=f[S4]; ""; Clear[S4];]
Parallelize[S6=g[S5]; ""; Clear[S5];]
Parallelize[S7=f[S6]; ""; Clear[S6];]
Parallelize[S8=f[S7]; ""; Clear[S7];]

and

S0; (*initial list*)
Parallelize[S1=f[S0]; ""; Clear[S0];
S2=g[S1]; ""; Clear[S1];
S3=f[S2]; ""; Clear[S2];
S4=f[S3]; ""; Clear[S3];
S5=f[S4]; ""; Clear[S4];
S6=g[S5]; ""; Clear[S5];
S7=f[S6]; ""; Clear[S6];
S8=f[S7]; ""; Clear[S7];]

The second question is whether, maybe within this list, Parallelize is the best option for the code to try run in parallel in a supercomputer.

$\endgroup$
3
  • $\begingroup$ Seems like your outermost code structure is a fold. You could reformulate it with Fold[] but because of the sequential dependency this wouldn't offer much opportunities for parallelization. So the only possible gain for parallelization can probably only happen inside your f/g calls. Which means there's probably not much difference between a big Parallelize or many small ones in your example. If you give a bit more details how your f/g function looks like it might be easier to say how this can be optimized. I would start with the Fold refactoring. $\endgroup$ Oct 9, 2017 at 13:57
  • $\begingroup$ This eliminates the need for intermediate results and Clear (otherwise use FoldList if you want those). Also two more things. The ""; in your code currently does nothing, is there a reason why you write it like this? And traditionally, capitalized definitions are used for function definitions. Using them for variables can lead to problems when the name collides with internal functions (like N). $\endgroup$ Oct 9, 2017 at 14:01
  • $\begingroup$ @ThiesHeidecke The answer mathematica.stackexchange.com/a/157156/52401 explains why using "";Actually the repetition in the OP are automatically made with a Module (and then it doesn't makes difference to use ""; Clear[?]). My first question is just whether there is any different to Parallelize evaluations individually or pieces of code. $\endgroup$
    – Filburt
    Oct 9, 2017 at 14:36

0

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.

Browse other questions tagged or ask your own question.