我正在使用spmd在matlab中实现一个模拟退火算法。我将比较不同的实现类型。其中之一是异步paralellism。12名工人将运行代码。如果其中一个符合条件(error<0.01),代码将停止搜索。有什么命令可以这样做吗?如果我使用labBroadcast或labsend/lab接收站,它将是同步的。
发布于 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
发布于 2015-07-23 11:40:23
对于@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
endhttps://stackoverflow.com/questions/31582148
复制相似问题