cpucount
: functions module for shellfire
This module provides utility functions for counting cpus to a shellfire application. It is deliberately separate to the core module as it is not likely to be frequently needed.
An example user is the cmake-scripted tool.
- Tag
release_2015.0117.1750-1
is compatible with shellfire releaserelease_2015.0117.1750-1
.
To find the number of hyperthreaded CPUs on a system:
local cpucount_discoveredNumberOfCpus
cpucount_findNumberOfHyperthreadedCpus
echo "Number of CPUs: $cpucount_discoveredNumberOfCpu"
local cpucount_makeJobs
local cpucount_makeLoadAverage
cpucount_computeMakeJobsAndLoadAverage 0 75
echo "Number of make jobs: $cpucount_makeJobs"
echo "Make load average: $cpucount_makeLoadAverage"
To import this module, add a git submodule to your repository. From the root of your git repository in the terminal, type:-
mkdir -p lib/shellfire
cd lib/shellfire
git submodule add "https://github.com/shellfire-dev/cpucount.git"
cd -
git submodule init --update
You may need to change the url https://github.com/shellfire-dev/cpucount.git"
above if using a fork.
You will also need to add paths - include the module paths.d.
If calling from another shellfire module, add to your shell code the line
core_usesIn configure
in the global scope (ie outside of any functions). A good convention is to put it above any function that depends on functions in this module. If using it directly in a program, put this line inside the _program()
function:-
_program()
{
core_usesIn cpucount
…
}
Parameter | Value | Optional |
---|
Takes no parameters.
Sets cpucount_discoveredNumberOfCpus
to the number of hyperthreaded CPUs.
Parameter | Value | Optional |
---|---|---|
configuredCpuCount |
Integer. Set to 0 to use the value of cpucount_discoveredNumberOfCpus . Set to a negative value to use cpucount_discoveredNumberOfCpus reduced by the magnitude of the negative value. |
No |
configuredLoadAverageCorrection |
Integer percentage between 0 and 100. Used to reduce the load average by this percent. | No |
Sets cpucount_makeJobs
to the number of make jobs and cpucount_makeLoadAverage
to the make load average to use.
The configuredLoadAverageCorrection
is used to overcome the shell's lack of floating point maths. For instance, if the uncorrected load average would be 4.00, using a configuredLoadAverageCorrection
of 75 will result in cpucount_makeLoadAverage
being 3.25
. If cpucount_makeLoadAverage
would be 0.00
then it is forced to 0.01
.