Matlab Spmd 终止

Matlab Spmd Termination

我正在使用 spmd 在 matlab 中实现模拟退火算法。我将比较不同的实现类型。其中之一是异步并行。 12 名工人将 运行 代码。如果其中之一符合条件(错误<0.01)代码将停止搜索。 有没有命令可以做到这一点? 如果我使用 labBroadcast 或 labsend/labreceive 它将是同步的。

我将使用作业启动所有 12 个进程。您可以检查是否有一个已完成的作业符合您的条件,然后取消其他作业。

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

根据@Daniel 的建议,在 MATLAB 版本 R2013b 及更高版本中,您可以使用 parfeval 来执行此操作。像这样:

% 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