profiling function call in backgroundpool

1 回表示 (過去 30 日間)
Matthias Wurm
Matthias Wurm 2025 年 2 月 27 日
回答済み: Matthias Wurm 2025 年 2 月 28 日
I have two versions of my function (OLD and NEW).
I am trying to optimize the speed of my code. In normal mode, NEW runs faster than OLD.
When I use parfeval to run the functions in the backgroundpool, OLD is faster than NEW.
How can I find out what slows down NEW in the backgroundpool?
  3 件のコメント
Oliver Jaehrig
Oliver Jaehrig 2025 年 2 月 27 日
Rick Amos
Rick Amos 2025 年 2 月 27 日
The mpiprofile feature is not yet supported for thread-based pools, however the underlying profile feature has been since R2023b. If you have R2023b or later, you can do the following to profile code running on the background until we do have something like mpiprofile:
info = fetchOutputs(parfeval(backgroundPool, @profileMyExample, 1));
profview(0, info);
function info = profileMyExample
profile("on");
runMyExample;
profile("off");
info = profile("info");
end
function runMyExample
% Some code to be profiled
for ii = 1:10
eig(rand(1000));
end
end
In terms of the differences in performance, the main suspect would be whether the function is itself implicitly multi-threaded and something changed when running from the background. If you do maxNumCompThreads(1), does the performance match between running normally and running in the background?

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

採用された回答

Matthias Wurm
Matthias Wurm 2025 年 2 月 28 日
Thank you for your valuable comments.
Rick Amos' profiling example in particular was very helpful. I was able to implement it and find the error.
The error was mine:
While the comparison was fair in non-parallel mode (same conditions), it was no longer fair in parallel mode (backgroundPool). The test result was therefore meaningless.
After I was able to clarify this, NEW now always runs faster than OLD.
Many thanks for your support.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming Utilities についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by