How to run independent for loops altogether

4 ビュー (過去 30 日間)
Ahmad Zueter 2021 年 4 月 7 日

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 2021 年 4 月 16 日
Hi,
You can refer to this thread which introduces parallel computing and parfor to run for loops in parallel.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by