Mex files with OpenMP

조회 수: 13 (최근 30일)
chrisath
chrisath 2023년 3월 29일
댓글: chrisath 2023년 4월 6일
Hello!
I have been trying to make use of a specific amount of threads to run my matlab code. I am using mex to run code in C that includes OpenMP
This is the part of the code, there are 8 more parts in the code that have that same code, but they are not executed at the same time.
Now the code compiles normaly, however when I watch it run on task manager I see that the CPU usage spreads across every thread, not just 2/4 that I put in my code.
I have tried compiling using many different compilers, Visual Studio 2015, 2017, 2022, mingw and using various flags when compiling, COMPFLAGS, CFLAGS and CXXFLAGS, on Matlab 2018b and Matlab 2022b but I get the same result every time. I installed the parallel computing toolbox and tried creating and enabling clusters from withing the Matlab interface.
Instead of num_threads I have also tried forcing the number of threads with omp_set_num_threads(2) and removing the num_threads but I also get the same result.
omp_get_num_threads returns 8 but omp_get_thread_num is always 1, doesn't change values.
I have tried every solution I found online but nothing works.
Any help would be appreciated!

답변 (1개)

Meet
Meet 2023년 4월 4일
By default, MATLAB makes use of the multithreading capabilities of the computer on which it is running. On Windows platforms with multiple processor groups, the default maximum number of computational threads is equal to the number of physical cores within the processor group that is running MATLAB. You can try using the maxNumCompThreads function to control the maximum number of computational threads in a MATLAB session.
  댓글 수: 1
chrisath
chrisath 2023년 4월 6일
But shouldn't the part of OpenMP code dictate how many threads to specifically use? Does that mean that the command to run the code in 2 threads for example is ignored? Would it make any difference if the OpenMP was directly written in matlab instead of a Mex file?
Thank you for your help!

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

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by