User`s guide
Control Random Number Streams
6-39
For identical results, you can set the client and worker to use the same generator and
seed. Here the file randScript2.m contains the following code:
s = RandStream('CombRecursive','Seed',1);
RandStream.setGlobalStream(s);
R = rand(1,4);
Now, run the new script in the client and on a worker:
randScript2; % In client
R
R =
0.4957 0.2243 0.2073 0.6823
j = batch(c,'randScript2'); % On worker
wait(j); load(j);
R
R =
0.4957 0.2243 0.2073 0.6823
Client and GPU
By default MATLAB clients use different random generators than code running on
a GPU. GPUs are more like workers in this regard, and use the Combined Multiple
Recursive generator ('CombRecursive' or 'mrg32k3a') unless otherwise specified.
This example shows a default generation of random numbers comparing CPU and GPU
in a fresh session.
Rc = rand(1,4)
Rc =
0.8147 0.9058 0.1270 0.9134
Rg = rand(1,4,'gpuArray')
Rg =
0.7270 0.4522 0.9387 0.2360
Be aware that the GPU supports only three generators ('CombRecursive',
'Philox4x32-10', and 'Threefry4x64-20'). The following table lists the algorithms
for these generators and their properties.