2013-12-15 19:06:50 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-09-18 21:10:28 +02:00
|
|
|
#
|
2016-09-22 19:14:50 +02:00
|
|
|
# Print the number of enabled CPUs by either using nproc or ncpus.
|
|
|
|
# If both commands fail, fall back to a platform-independent C++ solution.
|
|
|
|
# If that also fails, just echo 1...
|
|
|
|
#
|
2013-12-15 19:06:50 +01:00
|
|
|
|
2016-09-22 19:14:50 +02:00
|
|
|
pushd "${0%/*}" &>/dev/null
|
2013-12-15 19:06:50 +01:00
|
|
|
|
2016-09-22 19:14:50 +02:00
|
|
|
nproc 2>/dev/null && exit 0 || ncpus 2>/dev/null && exit 0 || {
|
|
|
|
if [ ! -f cpucount ]; then
|
|
|
|
c++ cpucount.cpp -std=c++0x -o cpucount &>/dev/null || { echo 1 && exit 0; }
|
|
|
|
fi
|
|
|
|
}
|
2016-09-18 21:10:28 +02:00
|
|
|
|
2016-09-22 19:14:50 +02:00
|
|
|
./cpucount
|
2016-09-18 21:10:28 +02:00
|
|
|
|
2016-09-22 19:14:50 +02:00
|
|
|
popd &>/dev/null
|