How to run independent for loops altogether

조회 수: 5 (최근 30일)
Ahmad Zueter
Ahmad Zueter 2021년 4월 7일
답변: Gargi Patil 2021년 4월 16일
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