Berk U.
Berk U.

Reputation: 7188

Determine the Maximum Number of Processors Available for matlabpool (MATLAB Parallel Toolbox)

I'm currently writing some code in MATLAB that uses the parfor loop to speed up some tedious calculations.

My issue is that the code will be run on a remote cluster, and could be run on 4-core, 8-core or 12-core machines (I won't know which one in advance)...

I basically need a code snippet that will allow MATLAB to determine the maximum number of cores that can be used in matlabpool. If we call this variable maxcores, I can then go ahead and use

matlabpool('open',maxcores).

so that I can make sure that I am using all the cores that are available to me.

Upvotes: 3

Views: 6768

Answers (2)

user2709572
user2709572

Reputation: 21

Beyond Dougal's response, I found getenv('NUMBER_OF_PROCESSORS') returns the number of threads on my Windows systems.

Upvotes: 2

Danica
Danica

Reputation: 28846

You can get the number of cores on the machine through feature('numCores'), which is undocumented but seems unlikely to break. (source)

Someone claims there that getNumberOfComputationalThreads also works since R2007a, but it doesn't on my R2012a.

Upvotes: 9

Related Questions