File Exchange

image thumbnail

maxNumCompThreads Replacement

version 1.1.0.0 (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.

Comments and Ratings (6)

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

N = getenv('NUMBER_OF_PROCESSORS')

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

Sebastiaan

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:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/170152 (see comment 12). This should work at least for the BLAS subsystem.

Andrew

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

*JVeer
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

Jveer

or you could simply use the following undocumented function:

N=feature('Numcores');

Updates

1.1.0.0

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