View on GitHub

cpuaff

C++ interface to CPU affinity management

Home  Description  Documentation  Downloads  Installation  News 

News

Version 1.0.6 Released

[2017-10-29 11:53:00 -0500]

After quite some time, I have decided to roll a new release of cpuaff. It has a couple of small bugfixes, one big bugfix, and some reorganization and better test code. Everything else is pretty much the same and things have more or less just worked. If anyone sees any issues or has new feature requests please post them in issues at github.

Also please note that I have changed the PPA where the Ubuntu packages live. They now live at ppa:dcdillon/cpuaff

Download cpuaff-1.0.6

Short Description

cpuaff is a C++ library that abstracts CPU affinity settings for multiple platforms. It is a header-only library on some platforms. Other platforms are supported using hwloc. The project aims to fully support all platforms as header-only eventually.

For a more detailed description of cpuaff, click here

To see a list of supported platforms click here.

Releases

The latest source release is cpuaff-1.0.6.

The latest Ubuntu packages are available from ppa:dcdillon/cpuaff.

To get other releases, go to the downloads page.

For installation instructions, click here

Simple Example

#include <cpuaff/cpuaff.hpp>
#include <iostream>

int main(int argc, char *argv[])
{
    cpuaff::affinity_manager manager;

    if (manager.has_cpus())
    {
        cpuaff::cpu_set cpus;
        manager.get_affinity(cpus);

        std::cout << "Initial Affinity:" << std::endl;

        cpuaff::cpu_set::iterator i = cpus.begin();
        cpuaff::cpu_set::iterator iend = cpus.end();

        for (; i != iend; ++i)
        {
            std::cout << "  " << (*i) << std::endl;
        }

        std::cout << std::endl;

        // set the affinity to all the processing units on
        // the first core
        cpuaff::cpu_set core_0;
        manager.get_cpus_by_core(core_0, 0);

        manager.set_affinity(core_0);
        manager.get_affinity(cpus);

        std::cout << "Affinity After Calling set_affinity():"
                  << std::endl;
        i = cpus.begin();
        iend = cpus.end();

        for (; i != iend; ++i)
        {
            std::cout << "  " << (*i) << std::endl;
        }

        return 0;
    }

    std::cerr << "cpuaff: unable to load cpus." << std::endl;
    return -1;
}

Pronunciation

Due to popular demand, we now have a guide on pronunciation. cpuaff is pronounced “spoof” because all other pronunciations I have come up with sound like garbled French.

Licensing

cpuaff is distributed under the New BSD (or BSD 3-Clause) license.