Parfor/spmd with random numbers

조회 수: 1 (최근 30일)
JohnDapper
JohnDapper 2016년 2월 2일
댓글: Walter Roberson 2024년 11월 18일
In my code I want to run a function on each worker in parallel. The function is mexified C++ and (simply put) returns an image consisting of pixels with random intensity. Something like this:
parfor i = 1 : numiters
output(:,i) = myFn()
end
The trouble is that each output(:,i) is identical! Running the functions serially, like so:
for i = 1 : numiters
output(:,i) = myFn()
end
there are no troubles. Each output(:,i) is different. I thought that each worker is initialized with a random seed -- but I guess not. It seems that they are all initialized to the same seed. Any tips on how to overcome this issue?
Many thanks.
  댓글 수: 4
Brendan Hamm
Brendan Hamm 2016년 2월 3일
Cleve Moler had a nice blog post a while back about Parallel Random Number Generators.
Walter Roberson
Walter Roberson 2024년 11월 18일

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by