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
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
2016-6-28
You want a parallel.pool.Constant. https://www.mathworks.com/help/distcomp/parallel.pool.constant.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!