I am trying to parallelize my script. Here is a MWE of how I have done it:


container = {};

fun[x_] := 2*x;
container = ParallelTable[{i, fun[i]}, {i, 1, 3}];

I am unsure if this is done correctly. There are mainly two things I am concerned about when using ParallelTable:

  1. Is it necessary to parallelize the expression to be looped, i.e. fun?
  2. Is it necessary to make the container with the ParallelTable-results a shared variable?
  • 1
    $\begingroup$ 1. I believe in the most recent versions not necessary 2. No, don't do it as you did. This is only necessary for variables that you want to have shared during the parallel calculations. $\endgroup$ Jun 3 '13 at 21:29
  • 1
    $\begingroup$ @SjoerdC.deVries Adding to 1. From the documentation: "The default value is DistributedContexts:>$DistributedContexts with $DistributedContexts:=$Context, which distributes definitions of all symbols in the current context, but does not distribute definitions of symbols from packages." So you are right! $\endgroup$
    – sebhofer
    Jun 4 '13 at 9:22

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.