I want to run multiple for-loops in Matlab, each for-loop have large number of iterations so I use spmd to run them in parallel. All the for-loops will be break out if in a for-loop, a criterion is met. How do I do this? Here is the simplified version of my program:
spmd
flag = false;
for i = 1:1:inf
if flag == true
break;
end
fprintf("x = %d, i = %d\n", labindex, i);
if labindex == 7 && i == 111 %some condition is met
flag = true;
end
flag = labBroadcast(?, flag); %I don't know how to broadcast flag to other workers
end
end
Instead of
labBroadcast, what you need to use here isgop. (In newer versions, this has been renamed tospmdReduce. This will let you combine together all the local values offlagfrom each worker to see if any worker has setflagtotrue, like this: