User`s guide

Control Random Number Streams
6-41
Rg =
-0.0108 -0.7577 -0.8159 0.4742
Worker CPU and Worker GPU
Code running on a worker’s CPU uses the same generator to create random numbers as
code running on a worker’s GPU, but they do not share the same stream. You can use
a common seed to generate the same sequence of numbers, as shown in this example,
where each worker creates the same sequence on GPU and CPU, but different from the
sequence on the other worker.
p = parpool(2);
spmd
sc = RandStream('CombRecursive','Seed',labindex);
RandStream.setGlobalStream(sc);
Rc = rand(1,4)
sg = parallel.gpu.RandStream('CombRecursive','Seed',labindex);
parallel.gpu.RandStream.setGlobalStream(sg);
Rg = rand(1,4,'gpuArray')
end
delete(p)
For normally distributed random numbers from randn, by default a worker CPU
uses a NormalTransform setting of Ziggurat while a worker GPU uses a setting of
Inversion. You can set them both to use Inversion if you need the same sequence
from CPU and GPU.