User guide
12-5
Theproblemwiththeaboveexampleisthatimplicitineachcalltorndnisawriteto
thesameglobalstate.Notethatrndn,rndGamandrnduallsharethesameglobal
state.Soreplacingoneoftheabovecallstorndnwithacalltornduwouldstillresult
inanillegalprogram.Tosolvethisproblem,eithermovethecalltorndnabovethe
firstThreadBegin,likethis:
x = rndn(500, 1);
x2 = rndn(500, 1);
ThreadBegin;
y = myFunction(x);
ThreadEnd;
ThreadBegin;
y2 = myFunction(x2);
ThreadEnd;
ThreadJoin;
Orpassinandreturnthestatevector:
seed1 = 723193;
seed2 = 94493;
ThreadBegin;
{ x1, state1 } = rndn(500, 1, seed1);
y1 = myFunction(x1);
ThreadEnd;
ThreadBegin;
{ x2, state2 } = rndn(500,1,seed2);
y2 = myFunction(x2);
ThreadEnd;
ThreadJoin;
12.3 Parallel Random Number Generation
Random Number
Generation
Random Number
Generation










