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?
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