Three loops running in parallel simultaneously

Hello all. I am assigned to make a program in which multiple loops need to be executed at the same time and increment two counters simultaneously based on a certain condition for example: note, I tried with parfor but I confuse how to solve this issue
if true
N_M_O1=10;
N_M_O2=12;
N_M_O3=13;
conter_B1=0;
conter_B2=0;
x=[2 3 5 8 6 3 4 5 8 9];
y=[2 3 6 5 2 9 4 6 3 5];
x2=[2 8 5 8 6 3 6 5 6 9 10 12];
y2=[9 3 6 9 7 9 4 6 8 5 1 23];
x3=[2 3 1 8 6 3 55 5 6 9 2 3 5];
y3=[2 4 6 4 6 5 4 6 6 4 12 32 3];
for m=1:N_M_O1
z(m)=x(m)+y(m);
if z(m)>10
conter_B1=conter_B1+1;
else
conter_B2=conter_B2+1;
end
end
for m=1:N_M_O2
z2(m)=x2(m)+y2(m);
if z2(m)>10
conter_B1=conter_B1+1;
else
conter_B2=conter_B2+1;
end
end
for m=1:N_M_O3
z3(m)=x3(m)+y3(m);
if z3(m)>10
conter_B1=conter_B1+1;
else
conter_B2=conter_B2+1;
end
end
end

4 个评论

Matlab will run these loops sequentially. It is not meaningful to ask for a parallel processing. If the loops depend on each other, why not writing one loop instead of 3?
The situation I have three operators, each of them has its own mobile ( N_M_O1,N_M_O2, and N_M_O3) they are sharing the base stations (B1 and B2) represented by (conter_B1,conter_B2), the second operator'mobiles can not assign to B1 or B2 till finish the first loop, specifically I have condition if the counter of B1 or B2 more than 10 they reject to recive any mobile which means that the conter_B1 and conter_B2 will be full only from the first loop this is not fair assignment thats why i need to run the loops in parallel to assign the mobile from each loops at the same time and with fair manner
I do not see a reason to run the loops "in parallel".
Thank you Dear JAN I highly appreciate your concerning I am wondering, does Matlab support running multiple loops in parallel?? at the same time

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by