Matlab Spmd Termination

335 Views Asked by At

I'm implementing a simulated annealing algorithm in matlab using spmd. I will compare different implentation types. One of them is asynchronous paralellism. 12 workers will run the code. if one of them meets the criteria(error<0.01) code will stop the search. Is there any command to do that? If I use labBroadcast or labsend/labreceive it will be synchronus.

2

There are 2 best solutions below

0
On BEST ANSWER

I would start all 12 Processes using jobs. You can check if one of the already completed jobs matches your criteria, then cancel the other jobs.

http://www.mathworks.com/help/distcomp/cancel.html http://www.mathworks.com/help/distcomp/create-simple-independent-jobs.html

0
On

Further to @Daniel's suggestion, in MATLAB releases R2013b and later, you can use parfeval to do this. Something like this:

% First, kick off the asynchronous work:
N = 12;
for idx = 1:N
    f(idx) = parfeval(@myFcn, 1, args);
end

% Next, consume the results
for idx = 1:N
    % fetchNext blocks until one of 'f' has completed,
    % returning the index into 'f' that completed, as
    % well as the result.
    [idxInF, result] = fetchNext(f);
    if result < 0.01
        % we're done!
        cancel(f); % Cancel all outstanding work
        break; % stop looping and calling fetchNext
    end
end