File Exchange

image thumbnail

maxNumCompThreads Replacement

version (1.75 KB) by Dirk-Jan Kroon
Returns the number of available CPU cores

1 Download

Updated 10 Jun 2010

View License

maxNumCompThreads returns the number of available CPU cores, works with Windows, Linux, OpenBSD and MAC-OS, using a c-coded mex-file.

N = maxNumCompThreads()

Replacement of the original "Matlab maxNumCompThreads" which will be removed in a future release.

Cite As

Dirk-Jan Kroon (2020). maxNumCompThreads Replacement (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

We need to control the number of threads in a large multiprocessor multiuser system.


let's you see max number of threads, halve it if you are hyperthreading, min with 12 or 8 depending which matlab version you have for max allowable matlab poolsize


This is hardly a replacement, as the original maxNumCompThreads is capable of actually setting the number of threads.

The planned removal of this capability has been bugging me for quite some time. I am thinking about reviving a custom function, using omp_set_num_threads: (see comment 12). This should work at least for the BLAS subsystem.


How about the number of cores? If you are launching (single-threaded) processes then I think that's the number that's important.

Cool, I never saw this undocumented function before. But it is of course the question if it will be presented in future versions.

All features : usehg2, useGBT2, HGUsingMatlabClasses, JavaFigures, UseJava, ClearJava, SetPrecision, SetRound, NewPrintAPI, accel, GetOS, GetWinSys, GetPid, NumCores, MemStats, CheckMallocMemoryUsage, CheckMallocHeapWalk, ShowCommandWindow, LogDir, HotLinks, UseOldFileDialogs, timing, memtic, locale, DefaultCharacterSet, COM_SafeArraySingleDim, COM_ActxProgidCheck, FigureTools, TimeSeriesTools, launch_activation, EightyColumns, GetSharedLibExt, GetDefaultPrinter, GetPrinterInfo, GetPrinterColor, GetSpecifiedPrinterPort, ShowFigureWindows, SearchUDDClassesForHelp, AutomationServer, EnableDDE, GetUserWorkFolder, DirsAddedFreeze, DirsAddedUnfreeze, ToolboxFreeze, ToolboxUnfreeze, DirChangeHandleWarn, DirReloadMsg, RemoteCWDPolicy, RemotePathPolicy, GetPref, IsDebugMode, ForceFramesOnBottom, UseMesaSoftwareOpenGL, UseGenericOpengl, GetOpenglInfo, GetOpenglData, OpenGLVerbose


or you could simply use the following undocumented function:



Replaced "wrapping" code by more elegant version of James Tursa

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux