1
$\begingroup$

If I use the following code the Array arr still contains zeros.

arr= Array[0 &, 10];

ParallelTable[

  arr[[i]] = 1,

  {i, 1, 10}

  ];

arr
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

What is here the problem?

I know I can use:

arr= Array[1 &, 10];

But in my case I have a complex calculation which's results should be saved inside of ParallelTable environment into an array.

I am programming with Mathematica 10.3.1.0 on Windows 10 Professional 64 Bit and have an i7-4940-MX 3,1 GHz processor (4 cores).

$\endgroup$
0

1 Answer 1

3
$\begingroup$

You have to set arr as a shared variable first, using SetSharedVariable,

SetSharedVariable[arr];
arr = Array[0 &, 10];
ParallelTable[Set[arr[[i]], 1], {i, 1, 10}];
arr
(* {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} *)
$\endgroup$
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.