How to execute multiple spmd blocks in parallel?
이전 댓글 표시
Hello everyone,
I encountered a problem with the Matlab Parallel Computing functionalities, for which I could not find a solution in the Forum or Documentation.
I have a function, say "my_parallel_function" within which I use an spmd block to execute code in parallel. In the real case I also make use of the labSend/labReceive functionalities.
function [ ] = my_parallel_function( N_R, parameter )
spmd(N_R)
disp( [ 'Hello from lab ' num2str(labindex) ': P=' num2str(parameter) ] );
end
end
Now I want to execute this function in parallel, for different values of "parameter". My first attempt was to create a job object with independent tasks and let each task evaluate the function:
N_T = 2; % number of tasks
N_R = 3; % number of "realizations" which each tasks is supposed to run in parallel
c = parcluster;
j = createJob( c, 'Name', 'my_job');
parameter = 1;
t1 = createTask( j, @my_parallel_function, 0, { N_R, parameter }, 'CaptureDiary', true );
parameter = 2;
t2 = createTask( j, @my_parallel_function, 0, { N_R, parameter }, 'CaptureDiary', true );
submit(j);
However, this fails with the follwing error: "Could not create an SPMD block to match the requested size: 3. The parallel pool size is: 0."
So, I figured out the problem is that within a task (which is apparently always associated with 1 worker) a parallel pool cannot be created.
I also tried to work with "batch" but the same problem occurs.
Is there a way to associate multiple workers with the execution of a task which itself uses spmd?
As far as I understand, nesting of spmd and/or parfor is also not possible.
Any help is very much appreciated.
Thanks, Jan
답변 (1개)
Edric Ellis
2018년 3월 22일
You have already discovered batch, which I believe does everything you need. The alternative is to use createCommunicatingJob, which has two variants. The 'Pool' type is basically the same as the batch invocation you've discovered. The 'SPMD' type is appropriate when you essentially want to run a single spmd block. In that case, you simply specify the task function to be the body of the spmd block. In other words, given
function myOuterFunction()
spmd
mySpmdBody();
end
end
j = batch(@myOuterFunction, 0, {}, 'Pool', 3);
is pretty much equivalent to:
j = createCommunicatingJob('Type', 'spmd', 'NumWorkersRange', 3);
t = createTask(j, @mySpmdBody, 0, {});
submit(j);
The main difference here is that the createCommunicatingJob variant uses only 3 workers rather than 4 for the batch variant, since it doesn't need a separate worker to manage running the spmd block.
카테고리
도움말 센터 및 File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!