首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matlab Spmd终端

Matlab Spmd终端
EN

Stack Overflow用户
提问于 2015-07-23 08:34:05
回答 2查看 295关注 0票数 0

我正在使用spmd在matlab中实现一个模拟退火算法。我将比较不同的实现类型。其中之一是异步paralellism。12名工人将运行代码。如果其中一个符合条件(error<0.01),代码将停止搜索。有什么命令可以这样做吗?如果我使用labBroadcast或labsend/lab接收站,它将是同步的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-23 08:55:20

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

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

票数 0
EN

Stack Overflow用户

发布于 2015-07-23 11:40:23

对于@Daniel的建议,在MATLAB中发布R2013b和以后,您可以使用parfeval来完成这一任务。就像这样:

代码语言:javascript
复制
% 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31582148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档