How to run independent for loops altogether

3 visualizaciones (últimos 30 días)
Ahmad Zueter
Ahmad Zueter el 7 de Abr. de 2021
Respondida: Gargi Patil el 16 de Abr. de 2021
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?

Respuestas (1)

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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by