Computing on multiple notes with multiple cores

1 回表示 (過去 30 日間)
Paul Muster
Paul Muster 2023 年 11 月 6 日
コメント済み: Paul Muster 2023 年 11 月 9 日
Hello,
I have a code with the following structure:
for ... % Split between multiple nodes
parfor ... % Split betwenn mutliple cores
...
end
end
Is it possible to tell MATLAB, that it has to split the for-Loop between the nodes? Or does that MATLAB automatically if I use parfor 2 times? I.e.
parfor ... % Split between multiple nodes
parfor ... % Split betwenn mutliple cores
...
end
end

採用された回答

Matt J
Matt J 2023 年 11 月 9 日
The problem is, that the outer loop has 10 repetitions and the inner loop 50 repetitions
Combine the loops into one, i.e., instead of
for i=1:10% Split between multiple nodes
parfor j=1:50 % Split betwenn mutliple cores
...
end
end
do instead,
parfor k=1:10*50
[i,j]=ind2sub([10,50],k);
...
end
  2 件のコメント
Paul Muster
Paul Muster 2023 年 11 月 9 日
I have to check, if I have to change my used data structure for that. But thank you, that's an option.
Matt J
Matt J 2023 年 11 月 9 日
You're welcome, but if you find that it works (it should), please Accept-click the answer.

サインインしてコメントする。

その他の回答 (1 件)

Harald
Harald 2023 年 11 月 6 日
Hi Paul,
you can only have one level of parallelization, thus no nested parfor statements within a single script / function.
If the parallel pool that runs the parfor has cores on multiple nodes, they will automatically be used. While there might be reasons to parallelize the inner loop, I typically first try to parallelize the outer loop.
Best wishes,
Harald
  5 件のコメント
Harald
Harald 2023 年 11 月 9 日
Hi Paul,
in many cases, there may not be a problem of parallelizing the inner loop as you initially suggested.
Matt J has offered a nice alternative to thinking about which loop to parallelize.
My understanding is that your main question was if your code was going to use multiple cores on multiple nodes, and the answer to that was: If the parallel pool that runs the parfor has cores on multiple nodes, they will automatically be used.
Please let me know if I can be of further help.
Best wishes,
Harald
Paul Muster
Paul Muster 2023 年 11 月 9 日
Ok, thank you very much!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by