Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

LaunchKernels[2];

container = {};
SetSharedVariable[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?
share|improve this question
1  
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. –  Sjoerd C. de Vries Jun 3 '13 at 21:29
1  
@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! –  sebhofer Jun 4 '13 at 9:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.