On Tuesday, 4 August 2015 19:12:01 UTC+3, Victor Bazarov wrote:
> On 8/4/2015 12:09 PM, Öö Tiib wrote:
> > On Tuesday, 4 August 2015 18:48:23 UTC+3, Melzzzzz wrote:
> >> I can't seem to find standard way, is there one?
> >
> > With C++11:
> >
> > #include <thread>
> > unsigned int nthreads = std::thread::hardware_concurrency();
>
> But that doesn't actually give the number of CPUs, does it? And the
> implementation is allowed to return 0 (which isn't helpful to those who
> need to know the number of CPUs)...
Yes, it gives number of threads that can run concurrently and that may
be more than number of CPU-s since modern CPU can be hyperthreadable
unit. CPU becomes all more and more dim concept and so the number of
those may be is not what we actually want? If it really does return 0 then
there are the other options below.
Additionally all more and more C++ compilers support OpenMP and
that brings 'omp_get_num_procs' with it. It does return processors
available to the calling process at moment of calling. That may be also
something of interest for a running program.