3

Appending to a list in parallel works:

b = {};
SetSharedVariable[b]
WaitAll[Table[ParallelSubmit[{p}, AppendTo[b, 1]], {p, 3}]];
(* b is now {1,1,1} *)

But stuffing a Bag in parallel doesn't:

b = Internal`Bag[];
SetSharedVariable[b]
ParallelDo[Internal`StuffBag[b, 1], {3}]
Internal`BagPart[b, All]
(* b is now {} *)

What am I doing wrong?

M.R.
  • 31,425
  • 8
  • 90
  • 281
  • 1
    Related: https://mathematica.stackexchange.com/questions/84534/reap-sow-with-parallelize-bad-performance-why and its linked Q&As. – Michael E2 Jan 27 '20 at 22:01

0 Answers0