3
$\begingroup$

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?

$\endgroup$
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.