SimEvents: Parallel Simulations produce same results for each MatLab worker
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I am trying to run the following:
function means = basic_parallel_test()
modelname = 'G_G_1_5';
reps = 10;
means = ones(10,1);
parfor j = 1 : reps
load_system(strcat(modelname,'.slx'));
se_randomizeseeds(modelname);
simout = sim(modelname);
y = simout.get('ct')
means(j,1) = mean(y.signals.values(:,1))
bdclose(modelname);
end;
end
No errors are reported. So far so good...
But the result is:
ans =
28.3941
30.0470
29.8563
27.9616
30.0470
29.8563
27.9616
27.9957
28.3941
27.9957
Every value is there twice. So it seems since I had 2 matlabworkers, both accessed the same instance of simout. Sice I defined that variable in the parfor-loop I thought it would only be visible inside the loop.
How could I do this right?
Thanks Daniel
0 Commenti
Risposta accettata
Edric Ellis
il 28 Set 2012
The reason for the duplicate results is that your call to 'se_randomizeseeds' is using the system clock to set up the random number generators. So, because the workers are in sync, they're both getting the same value. You can get around this by explicitly passing a 'GlobalSeed' option to 'se_randomizeseeds'. Here's one way to do that, where we're using a combination of the current time:
parfor j = 1 : reps
seed = mod(floor((j/reps) * now * 8640000),2^31-1);
se_randomizeseeds(modelname, 'GlobalSeed', seed);
...
end
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Discrete-Event Simulation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!