I have some code in which I need to call a function multiple times, by iterating through a for loop. The function itself runs in parallel, and I would like to use parallelization on both the outer loop, and inside the function. I'm running this on an HPC, so I have plenty of cores available, but each function call will use a significant portion of memory, so that I cannot use all of the cores on the outer loop. All the answers I've seen say that matlab doesn't support nested for loops. I can submit each element of the outer for loop as its own job in the HPC, but I was wondering if there was a better option.

댓글 수: 2

Walter Roberson
Walter Roberson 2018년 9월 13일
Are you running directly on the HPC, or are you using DCS (Distributed Computing Server) ?
Kevin Johnston
Kevin Johnston 2018년 9월 13일
Directly on the HPC.

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

답변 (1개)

Matt J
Matt J 2018년 9월 13일
편집: Matt J 2018년 9월 13일

0 개 추천

Instead of doing this
parfor i = 1:10
MyFun(i)
end
function MyFun(i)
parfor j = 1:5
func2(i,j);
end
end
you should try to reconfigure MyFun so that it can do a specified subset of iterations. Then you can re-implement with a single parfor loop as follows:
parfor k = 1:50
[j,i]=sub2ind([5,10], k);
MyFun(i,j);
end
function MyFun(i,Jsubset)
for j=Jsubset
func2(i,j);
end
end

카테고리

도움말 센터File Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 9월 13일

편집:

2018년 9월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by