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.
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 yourf
/g
calls. Which means there's probably not much difference between a bigParallelize
or many small ones in your example. If you give a bit more details how yourf
/g
function looks like it might be easier to say how this can be optimized. I would start with theFold
refactoring. $\endgroup$Clear
(otherwise useFoldList
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 (likeN
). $\endgroup$"";
Actually the repetition in the OP are automatically made with aModule
(and then it doesn't makes difference to use""; Clear[?]
). My first question is just whether there is any different toParallelize
evaluations individually or pieces of code. $\endgroup$