필터 지우기
필터 지우기

parallel execution of loop

조회 수: 1 (최근 30일)
D_coder
D_coder 2019년 3월 22일
댓글: Walter Roberson 2019년 3월 23일
I have the following structure
for i = 1:N
%some lines of code
for j = 1:M
%some lines of code and M<N
end
end
How do I perform following parallel execution : i = 1 perform j = 1, i = 2 perform j = 1, i = 3 perform j = 1 and then i = 2 perform j = 1 and so on ?
  댓글 수: 2
Adam
Adam 2019년 3월 22일
I'm not sure I really get your description at the bottom. That basically just boils down to the for loops as you have shown them that you want parallelising?
If you have the Parallel Computing Toolbox then
doc parfor
can do this, depending what is in the body of the for loops. You would usually want to put the parfor on the outer loop. for obvious reasons you can't make both loops parfors.
Walter Roberson
Walter Roberson 2019년 3월 23일
Performing the iterations in the order you request would not be equivalent to doing them in serial.
A = 0;
for i = 1 : 10
B = 0;
for j = 1 : 5
A = A + 1;
B = B + 1;
end
end
When i = 2, j = 1, then A has to be 5 if you executed in serial mode. But if all of the j = 1 iterations for each possible i are executed first, as you request, then A would have been incremented to 10.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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