Returning composite variables from a MatlabPoolJob.

5 views (last 30 days)
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
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
LittleJohn Little on 21 Apr 2011
Hi,
When I make the changes you suggested and run the code; I find that res is a 1X1 cell which again contains a 1X1 cell which contains the one matrix generated by rand.
As for the nested spmds, the manual says that i can nest spmds if the inner spmd is encapsulated in a function. Also, in this forum (http://www.mathworks.com/matlabcentral/answers/3986-nested-smpd-instructions), It says that nested spmds is possible if there are enough workers available. Correct me if I missed something.
Thanks again!
Konrad Malkowski
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.

Sign in to comment.

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!