From: Dirk-Jan Kroon on
Hi all,

All my c-code files in Matlab use the function maxNumCompThreads to determine the optimal number of threads. But this function will be removed in future versions of Matlab.

Determining the number of cores in c would is possible, but is very difficult. Because most code works only with Windows or only with Linux. Also most code return the maximum amount of cores which could be available on the CPU, and not the real amount of cores enabled during CPU production. Thus probably you will need a list will a cpu-id's, and number of cores to get the real amount of cores.

I wrote some code which does some heavy calculations, and tried to find the number of cores by measuring the time with different number of threads. But it almost takes 30s to get reliable timing results.

Does anyone know a good replacement, or code which can give the number of cores available?

Thanks in advance,

Dirk-Jan
From: us on
"Dirk-Jan Kroon" <kdirkjan(a)hhhhhhhotmail.com> wrote in message <hosh54$8eh$1(a)fred.mathworks.com>...
> Hi all,
>
> All my c-code files in Matlab use the function maxNumCompThreads to determine the optimal number of threads. But this function will be removed in future versions of Matlab.
>
> Determining the number of cores in c would is possible, but is very difficult. Because most code works only with Windows or only with Linux. Also most code return the maximum amount of cores which could be available on the CPU, and not the real amount of cores enabled during CPU production. Thus probably you will need a list will a cpu-id's, and number of cores to get the real amount of cores.
>
> I wrote some code which does some heavy calculations, and tried to find the number of cores by measuring the time with different number of threads. But it almost takes 30s to get reliable timing results.
>
> Does anyone know a good replacement, or code which can give the number of cores available?
>
> Thanks in advance,
>
> Dirk-Jan

one of the solutions
- requires
wintel sys
.net installed
ML ver that knows about the .net interface

nc=System.Environment.ProcessorCount
% nc = 2 % <- our sys

us
From: Oliver Woodford on
"Dirk-Jan Kroon" <kdirkjan(a)hhhhhhhotmail.com> wrote in message <hosh54$8eh$1(a)fred.mathworks.com>...
> Hi all,
>
> All my c-code files in Matlab use the function maxNumCompThreads to determine the optimal number of threads. But this function will be removed in future versions of Matlab.
>
> Determining the number of cores in c would is possible, but is very difficult. Because most code works only with Windows or only with Linux. Also most code return the maximum amount of cores which could be available on the CPU, and not the real amount of cores enabled during CPU production. Thus probably you will need a list will a cpu-id's, and number of cores to get the real amount of cores.
>
> I wrote some code which does some heavy calculations, and tried to find the number of cores by measuring the time with different number of threads. But it almost takes 30s to get reliable timing results.
>
> Does anyone know a good replacement, or code which can give the number of cores available?
>
> Thanks in advance,
>
> Dirk-Jan

OpenMP comes with a function omp_get_num_procs. The library is cross platform.
 | 
Pages: 1
Prev: Structure to matrix
Next: erosion code