Filter löschen
Filter löschen

Mex files with OpenMP

5 Ansichten (letzte 30 Tage)
chrisath
chrisath am 29 Mär. 2023
Kommentiert: chrisath am 6 Apr. 2023
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!

Antworten (1)

Meet
Meet am 4 Apr. 2023
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 Kommentar
chrisath
chrisath am 6 Apr. 2023
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!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by