Reproducible random number sequence with parfor
Mostrar comentarios más antiguos
I would like to produce a reproducible random number sequence with parfor. I do not want to create a new random stream for each worker, but supply the workers with distinct and deterministic segments of a global random stream. I tried using instructions on this page (<http://www.mathworks.com/help/stats/reproducibility-in-parallel-statistical-computations.html)>, but it did not work for me.
if true
s = RandStream('mlfg6331_64');
options = statset('UseParallel',true,'Streams',s,'UseSubstreams',true);
agent = zeros(3,2);
parfor ind = 1:indn
agent(ind,:) = [randi(10), randi(10)];
end
agent
end
I can use the following code to achieve my goal, but that is not efficient, and I fear creating correlations between the parfor index and random numbers generated.
if true
agent = zeros(3,2);
parfor ind = 1:indn
rng(ind);
agent(ind,:) = [randi(10), randi(10)];
end
agent
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Resampling Techniques en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!