Returning composite variables from a MatlabPoolJob.
Show older comments
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.
Answers (1)
Konrad Malkowski
on 18 Apr 2011
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 Comments
LittleJohn Little
on 19 Apr 2011
Konrad Malkowski
on 20 Apr 2011
Hi Sumedh,
The solution above gets the matrices on both workers and puts them into a cell array on the client. So you get both matrices back.
MATLAB PCT does not allow for nesting of parfor and spmd. So the inner spmd in your function will just run sequentially on a worker, on the distributed data provided to it by the outer spmd.
LittleJohn Little
on 21 Apr 2011
Konrad Malkowski
on 21 Apr 2011
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.
Categories
Find more on Parallel Computing Fundamentals in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!