carb::thread::hardware_concurrency

Defined in carb/thread/Util.h

inline unsigned carb::thread::hardware_concurrency() noexcept

Similar to std::thread::hardware_concurrency(), but pays attention to docker cgroup config and CPU limits.

Docker container CPU limits are based on the ratio of /sys/fs/cgroup/cpu/cpu.cfs_quota_us to /sys/fs/cgroup/cpu/cpu.cfs_period_us. Fractional CPUs of a half or larger will round up to a full CPU. It is possible to have an odd number reported by this function. Examples:

  • Docker --cpus="3.75" will produce 4 (rounds fractional up)

  • Docker --cpus="3.50" will produce 4 (rounds fractional up)

  • Docker --cpus="3.25" will produce 3 (rounds fractional down)

  • Docker --cpus="0.25" will produce 1 (minimum of 1)

Returns

The number of CPUs available on the current system or within the current container, if applicable.