Code covered by the BSD License  

Highlights from
maxNumCompThreads Replacement

1.0

1.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 1.75 KB File ID: #27856

maxNumCompThreads Replacement

by Dirk-Jan Kroon

 

09 Jun 2010 (Updated 10 Jun 2010)

Returns the number of available CPU cores

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
10 Jun 2010 Jveer

or you could simply use the following undocumented function:

N=feature('Numcores');

10 Jun 2010 Dirk-Jan Kroon

*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

07 Dec 2010 Andrew

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

29 Apr 2011 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.

28 Feb 2012 Mark Mikofski

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

Please login to add a comment or rating.
Updates
10 Jun 2010

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

Tag Activity for this File
Tag Applied By Date/Time
maxnumcompthreads Dirk-Jan Kroon 09 Jun 2010 11:32:19
cpu Dirk-Jan Kroon 09 Jun 2010 11:32:20
linux Dirk-Jan Kroon 09 Jun 2010 11:32:20
windows Dirk-Jan Kroon 09 Jun 2010 11:32:20
openbsd Dirk-Jan Kroon 09 Jun 2010 11:32:20
thread Dirk-Jan Kroon 09 Jun 2010 11:32:20
ccode Dirk-Jan Kroon 09 Jun 2010 11:32:20
threads Dirk-Jan Kroon 09 Jun 2010 11:32:20
macos Dirk-Jan Kroon 09 Jun 2010 11:32:20
cores Shari Freedman 28 Oct 2010 11:13:51

Contact us at files@mathworks.com