Is 'parfor' running correctly when mex-ed ?

1 回表示 (過去 30 日間)
Victor Aldea
Victor Aldea 2017 年 4 月 12 日
コメント済み: Victor Aldea 2017 年 4 月 21 日
I have mex-ed a function containing a parfor loop and I get 0 Errors, Warnings, Notices or Messages.
When I run the original parallelized Matlab function on 10 cores, I can see in Task Manager (or ProcessExplorer) 10 Matlab threads each taking about 6% for a total of about 62% of CPU processing power.
When I run the mex function, I can only see one Matlab thread taking 50% of the CPU power.
Is the mex function actually running on 10 parallel threads (cores) or is it executing in single threaded fashion ? Can I verify that the compiler/OpenMP actually functioned correctly when mexing the code ?
I am using: 2x Intel Xeon X5560 @2.80GHz, Windows Server 2008 R2 Enterprise, Matlab R2015b, Microsoft Visual C++ compiler 2012.
Please see the attached file with the compilation report, if needed.
Thank you,
Victor

回答 (1 件)

Fei Deng
Fei Deng 2017 年 4 月 17 日
How did you run the mex-ed function with par-for loop? You can specify on how many threads (at most) it runs in parallel by executing function_with_par_for(number of threads) in command window. You can take a look of the example "Generate MEX for parfor" here https://www.mathworks.com/help/coder/ref/parfor.html
  1 件のコメント
Victor Aldea
Victor Aldea 2017 年 4 月 21 日
I have hard coded the number of threads in the function. It reads like this:
parfor (pixelIndex=1:(L1*L2), 10)
then I mex-ed it and ran it from a batch file. Thanks for the example from Matlab's help, but I had already followed it.
It seems very strange that the CPU utilization was lower when running the mex-ed function than when running the function directly in Matlab (there were no other users on that PC at the time, so all cores were free).
Also, only 1 Matlab thread was present taking 50% of the CPU power, instead of having 10 Matlab threads each taking about 6%. Is this normal behaviour ?

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by