I'm pretty sure I'm controlling correctly the Random Number Generator when analyzing my data in my PC. Yet when I put the script to run in another server I get back different results. And the reason I think my code is correct is because I have total reproducability within a machine. Same results in same machines, always! Different results when using the server...
I've read the documentation regarding parfor really thoroughly, and what I'm doing is to assign a specific Substream number in each iteration, according to the iteration number and not the worker id.
Even when trying to create a pool with the same number of workers (4) in the 8core machine, I still get different results...
Here is the basic code used, without the irrelevant details.
myCluster = parcluster('local'); myCluster.NumWorkers = 4;
saveProfile(myCluster); parcluster('local')
parpool('local', 4)
spmd
rng(0,'combRecursive');
end
parfor iter = 1:10
stream = RandStream.getGlobalStream();
stream.Substream = (iter);
...
...
end
Are you sure that this is unique to parfor and running code in parallel? In general, MATLAB isn't guaranteed to give bit-for-bit identical answers on different operating systems because of different optimizations that the system and 3rd party libraries use across OSes. Moreover, if the two systems have different processor architectures, it's even less likely you'll get bit-for-bit identical answers because there will be different optimizations for the instruction sets of each processor.