0

I want to modify a vector in a Table function, such as

vec = {0, 0, 0, 0};
Table[vec[[i]] = i, {i, 1, 4}];
vec
// output {1,2,3,4}

however, when I use ParallelTable function to speed up the progress, it fails to work.

vec = {0, 0, 0, 0};
ParallelTable[vec[[i]] = i, {i, 1, 4}];
vec
// output {0,0,0,0}

How can I fix it?

cmc
  • 741
  • 1
  • 6
  • 13
  • This can't be fixed without a significant performance degradation (SetSharedVariable) because Mathematica uses distributed memory parallelism. Restructure your algorithms so no global data needs to be written. – Szabolcs Nov 25 '18 at 19:26
  • @Szabolcs Can you point to a more elaborated discussion of these points? Thanks. – Alan Nov 26 '18 at 00:16
  • 1
    @Alan https://mathematica.stackexchange.com/a/138911/12 – Szabolcs Nov 26 '18 at 07:53

0 Answers0