Alternative to Nested Parpool

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 ExchangeParallel 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