我在并行计算和构建计算机集群中使用Matpower工具箱来模拟程序,如下所示:
matlabpool open job1 5 % matlabpool means computer cluster
spmd %the statement from the Parallel computing toolbox
% Run all the statements in parallel
% first part of code
if labindex==1
runopf('casea');
end
% second part of code
if labindex==2
runopf('caseb');
end
end
matlabpool close;当labindex为1时,程序中的第一部分代码在集群中的"computer1“中运行,而当labindex为2时,则程序中的第二部分代码是”在computer2中运行“。我的问题是上面显示的主要代码是顺序运行还是并行运行?
我的意思是,第二部分代码是否必须等待执行,直到代码的第一部分被执行,或者两部分代码可以在集群中的两台不同的计算机上并行执行?
发布于 2014-08-28 01:43:07
spmd和相应的end之间的代码被发送给所有工作人员(在您的例子中是5),他们并行地执行这些指令。然后,在代码中指示worker #1执行runopf('casea');和worker #2 runopf('caseb');。第三到第五名工人实际上什么也做不了。
从技术上讲,工作人员#2将在稍后执行runopf('caseb');。出现延迟是因为worker #2也将检查第一个if语句(但不会执行其中的代码)。
https://stackoverflow.com/questions/25539276
复制相似问题