Returning composite variables from a MatlabPoolJob.
2 次查看(过去 30 天)
显示 更早的评论
I am trying to run a matlabpool on a cluster. Inside the job, i am using a spmd construct for my code. The code executes fine but I am not able return the composite output variable back to the client. Could someone tell me how to return the composite variable?
My code:
sched=findResource('scheduler','configuration','local');
destroy(sched.Jobs);
j1=createMatlabPoolJob('configuration','local','MaximumNumberOfWorkers',2,'MinimumNumberOfWorkers',2);
set(j1,'fileDependencies',{'try1.m'});
createTask(j1,@try1,0,{2});
submit(j1);
waitForState(j1,'finished');
res=getAllOutputArguments(j1);
try1.c
function op=try1(ip)
spmd
op=rand(ip);
end;
Thanks in advance.
0 个评论
回答(1 个)
Konrad Malkowski
2011-4-18
Hi,
First of you need to change the line with createTask, and tell MATLAB that you expect a single output from the try1 function:
createTask(j1,@try1,1,{2});
Second, the composite value is really just a reference to a value stored on a different machine. When using composites, values are never transfered between processes (machines). If a process containing a value dies, the corresponding composite value will also disappear.
To output the contents of op back to the client you will need to modify your try function as follows:
function op=try1(ip)
spmd
op=rand(ip);
end;
op = {op{:}};
end
or
function output=try1(ip)
spmd
op=rand(ip);
end;
for i = 1:numel(op)
output{i} = op{i}
end
4 个评论
Konrad Malkowski
2011-4-21
The reason for a 1x1 composite is that you are submitting a MATLABPOOLJOB and requesting only two workers. This is interpreted by local scheduler as 1 worker to act as client (to execute the code outside of spmd), and 1 worker to act as the MATLAB lab (to execute the code inside of spmd). If you want to have two MATLAB labs execute the SPMD you need to request three workers. In general with MATLABPOOLJOB you need to request N+1 workers, where N is the number of workers that you want to work in parallel on your problem.
Regarding the second question. Yes you can nest SPMD inside of the SPMD (when the nested SPMD is inside of a function). However, the internal SPMD will not get any additional workers. Think of it this way. Anything inside of SPMD is already working on a worker. Workers cannot act as "client MATLABs", so a nested SPMD is "ignored" and executes sequentially.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Parallel Server 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!