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.
3 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266320-parfor-spmd-with-random-numbers#comment_339812
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266320-parfor-spmd-with-random-numbers#comment_339812
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266320-parfor-spmd-with-random-numbers#comment_339951
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266320-parfor-spmd-with-random-numbers#comment_339951
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266320-parfor-spmd-with-random-numbers#comment_340016
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266320-parfor-spmd-with-random-numbers#comment_340016
Sign in to comment.