MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Parallelize and Array access

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126663] Parallelize and Array access
  • From: John <glossner at gmail.com>
  • Date: Wed, 30 May 2012 04:07:38 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

The code below works fine in serial execution. Since results[i][j] is
not valid outside the Parallelize statement, what is the best way to
code this in Mathematica? I've searched this forum, Mathematica help,
and tried many alternatives to no avail. Thanks for any ideas.

AddSub[a_, b_] :=
  Module[{p, s},
   p = a + b;
   s = a - b;
   Return[{p, s}]
   ];

numElements = 5;
Parallelize[
  a = Range[numElements];
  b = Range[numElements];
  Do[
   result[i][j] = AddSub[a[[i]], b[[j]]];
   , {i, 1, numElements}, {j, 1, numElements}
   ];
  ];

anotherVariable = result;

Do[Print["anotherVariable[", x, "][", y, "] = ",
   anotherVariable[x][y]], {x, 1, numElements}, {y, 1, numElements}];




  • Prev by Date: Re: Sqrt of complex number
  • Next by Date: Re: Print TraditionalForm
  • Previous by thread: Re: Simplify and then discretize a set of equations with derivatives and integrals
  • Next by thread: I can not find all the contexts through the command "Contexts[]".