Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the number of threads Matlab is using?

When I run simply "matlab", maxNumCompThreads returns 4.

When I run "matlab -singleCompThread", maxNumCompThreads returns 1.

However in both instances, ps uH p <PID> | wc -l (which I picked up from another question on SO to determine the number of threads a process is using) returns 35.

What gives? Can somebody explain to me what the 35 represents, and whether or not I can trust maxNumCompThreads as indicating that Matlab is only using one thread?

like image 486
CptSupermrkt Avatar asked Mar 21 '23 06:03

CptSupermrkt


2 Answers

The number of threads used by MATLAB for computation (maxNumCompThreads) is different from the number of threads MATLAB.exe uses to manage its internal functions: the interpreter, memory manager, command line, who knows what else. If you were writing MATLAB, imagine the number of threads required to manage the various ongoing, independent tasks. Perhaps have a look at the Octave or FreeMat code to get an idea.

like image 67
chappjc Avatar answered Mar 23 '23 19:03

chappjc


Many of the threads you see are used by the JVM that MATLAB launches. You could try the flag "-nojvm" to cut things down further. Obviously, without the JVM, functionality is very limited. "-singleCompThread" limits only the threads used by numeric computation such as MATLAB's intrinsic multithreading as well as threads used by external libraries such as MKL and FFTW.

like image 25
Edric Avatar answered Mar 23 '23 19:03

Edric