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 で Parallel Computing Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!