User`s guide

9 GPU Computing
9-6
parallel.gpu.RandStream
These functions perform in the same way as rng and RandStream in MATLAB, but
with certain limitations on the GPU. For more information on the use and limits of these
functions, type
help parallel.gpu.rng
help parallel.gpu.RandStream
The GPU uses the combined multiplicative recursive generator by default to create
uniform random values, and uses inversion for creating normal values. This is not the
default stream in a client MATLAB session on the CPU, but is the equivalent of
RandStream('CombRecursive','NormalTransform','Inversion');
However, a MATLAB worker session has the same default stream as its GPU, even if it is
a worker in a local cluster on the same machine. That is, a MATLAB client and workers
do not have the same default stream.
In most cases, it does not matter that the default random stream on the GPU is not the
same as the default stream in MATLAB on the CPU. But if you need to reproduce the
same stream on both GPU and CPU, you can set the CPU random stream accordingly,
and use the same seed to set both streams:
seed=0; n=4;
cpu_stream = RandStream('CombRecursive','Seed',seed,'NormalTransform','Inversion');
RandStream.setGlobalStream(cpu_stream);
gpu_stream = parallel.gpu.RandStream('CombRecursive','Seed',seed);
parallel.gpu.RandStream.setGlobalStream(gpu_stream);
r = rand(n); % On CPU
R = rand(n,'gpuArray'); % On GPU
OK = isequal(r,R)
1
There are three supported random generators on the GPU. The combined multiplicative
recursive generator (MRG32K3A) is the default because it is a popular and reliable
industry standard generator for parallel computing. You can choose the GPU random
generator with any of the following commands:
parallel.gpu.RandStream('combRecursive')
parallel.gpu.RandStream('Philox4x32-10')
parallel.gpu.RandStream('Threefry4x64-20')