How to run independent for loops altogether

3 次查看(过去 30 天)
Hello all,
So I have a code that has one large for loop inside which three for loops are nested. The three loops do calculations which are indepndent from each other. The outpuf of each loop is evntually used at the end of the large for loop. The code looks as the following
kmax = 1000;
T(1:100,1:100,1:kmax)=0;
T(1:100,1:100,1)=270;
for o=2:omax %large for loop
% in the real code, there are lot of calculations inside each for loop
% including calculation of an inverse of a large matrix (size is 5000);
% however, for clarification purposes, the code is simplified as
% follows
for i=1:100 %first inner loop
x1(i,1:100)=T(i,1:100,o-1)+5;
end
for i=1:100 %first inner loop
x2(i,1:100)=T(i,1:100,o-1)-3;
end
for j=1:100 %first inner loop
y1(1:100,j)=T(1:100,j,o-1)-10;
end
for j=1:100 %first inner loop
y2(1:100,j)=T(1:100,j,o-1)+6;
end
%after the end of all four loops, their outcome is added as follows
T(:,:,o)=T(:,:,o-1)+x1+x2+y1+y2;
end
Now, my question is, how can I run the four different for loops in parallel using different solvers, noting that they are independent from each other?

回答(1 个)

Gargi Patil
Gargi Patil 2021-4-16
Hi,
You can refer to this thread which introduces parallel computing and parfor to run for loops in parallel.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by