MATLAB parallel loop with slight delays

조회 수: 10 (최근 30일)
Re Kh
Re Kh 2016년 12월 8일
답변: Edric Ellis 2016년 12월 9일
I have a parallel loop in matlab shown below. Is there a way to make sure the loops are not running simultaneously but with a slight delay? I am open to use batch or spmd also but have limited knowledge of them and will appreciate any help. I am calling another program, myprogexe.exe, but this program needs to access a specific port on a pc and multiple requests cant go in. hence i need to make sure there is a very slight delay in requests. myprogexe.exe is a very computational heavy code itself (takes about 10 mins for each input to run)
parfor i=1:length(MinorRoots)
runmodels = MinorRoots{i};
cmd = ['$myprogexe -v 2014.2 ', runmodels];
[status, result] = system(cmd);
end

답변 (1개)

Edric Ellis
Edric Ellis 2016년 12월 9일
You could use spmd to do this, but note that the following approach isn't completely ideal because it adds additional synchronisation points.
spmd
origLimit = length(MinorRoots);
loopLimit = numlabs * ceil(origLimit/numlabs);
for i = labindex:numlabs:loopLimit
labBarrier; % synchronise all workers
if i <= origLimit
pause(labindex-1); % timing offset
... run your code ...
end
end
end

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by