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, but CPU counts above 1 will always be an even number. The minimum is always 1. 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 2 (rounds fractional down and rounds down to make even)

  • 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.