function setGpuGlobalRandStream(args, callback)
%setGpuGlobalRandStream Gateway for GPU random state initialization
%   Cluster code calls setGpuGlobalRandStream(args) to specify how
%   the default GPU random stream should be built.
%   GPU code calls setGpuGlobalRandStream([], @someFcn) to register a
%   callback to be invoked immediately (if "args" have been set), and
%   each subsequent time "args" is set.

% Copyright 2020 The MathWorks, Inc.

persistent ARGS CALLBACK
mlock; % Defend against cluster code calling "clear('functions')"

% Store any state if supplied
if nargin >= 1 && ~isempty(args)
    ARGS = args;
end
if nargin >= 2 && ~isempty(callback)
    CALLBACK = callback;
end

% ARGS and CALLBACK both available - invoke CALLBACK.
if ~isempty(ARGS) && ~isempty(CALLBACK)
    CALLBACK(ARGS{:});
end
end
