How to get the number of logical cores - parallel computing toolbox
69 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Miles Stephenson
il 11 Ott 2016
Risposto: Lutz Pegel
il 22 Giu 2020
Is there a programmatic way to get the number of logical cores? The feature command shows me this in text, but I want a way to directly access the number. The code below returns the number of physical cores. Is there a similar way to do this for logical cores?
numcores = feature('numcores')
numcores =
2
feature('numcores')
MATLAB detected: 2 physical cores.
MATLAB detected: 4 logical cores.
MATLAB was assigned: 4 logical cores by the OS.
MATLAB is using: 2 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
ans =
2
0 Commenti
Risposta accettata
David Goodmanson
il 11 Ott 2016
Modificato: David Goodmanson
il 11 Ott 2016
Hi Miles,
One way would be to use 'evalc', which is like 'eval' but can redirect command window output. You need to double up on single quotes inside the outer quotes, so
core_info = evalc('feature(''numcores'')');
will give you a string variable containing " MATLAB detected .... etc. etc. " which you could then parse to get the number you want.
0 Commenti
Più risposte (1)
Lutz Pegel
il 22 Giu 2020
For logical cores this might be easier to use :
getenv('NUMBER_OF_PROCESSORS')
0 Commenti
Vedere anche
Categorie
Scopri di più su Parallel Computing Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!