Is there a way to provide a variable to a worker of a parpool?

14 次查看(过去 30 天)
Hi,
Is there a way to provide a variable, or a set of variables to a particular worker and/or all workers of a parpool from the parent script that's generated the parpool?
What i'm looking for is something like this
*Some processing to calculate a number of variables.
ParallelPool = parpool(16);
*Pass the variables and their values just created to a particular worker and/or all workers
pctRunOnAll ParallelScript
Thanks
  1 个评论
Brendan Hamm
Brendan Hamm 2016-6-28
It sounds like what you want to do is use a Composite array.
% Create Random Data
A = rand(1);
B = rand(2);
% Open pool
parpool('local',2) % gcp('nocreate') % <-second option if you have pool open
% Create a Composite variable and assign its elements.
C = Composite(2);
C{1} = A;
C{2} = B;
spmd
disp(C) % display results
end
As you can see when I refer to C I get a different answer from each worker.

请先登录,再进行评论。

回答(1 个)

Sean de Wolski
Sean de Wolski 2016-6-28

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by