NUMA++ 0.12.0
Loading...
Searching...
No Matches
cpuaffinityExample1.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * SPDX-FileCopyrightText: 2023-2023 European Southern Observatory (ESO)
5 *
6 * SPDX-License-Identifier: LGPL-3.0-only
7 */
8#include <iostream>
9#include <numapp/numa.hpp>
11
12int main() {
14 using numapp::Cpumask;
15 if (!numapp::NumaAvailable()) {
16 std::cout << "NUMA not available";
17 return -1;
18 }
19
20 auto policy = CpuAffinity(Cpumask::MakeFromCpuStringAll("0-3"));
21 // Set CPU affinity for main thread
22 if (auto ec = numapp::thisThread::Apply(policy); ec) {
23 std::cout << "Failed to apply policy: " << ec.message() << std::endl;
24 return 1;
25 }
26}
Create CPU affinity and apply to current thread.
Type-safe CPU mask.
Definition cpumask.hpp:27
Contains declarations for CpuAffinity.
std::error_code Apply(CpuAffinity const &affinity) noexcept
Apply policy to calling thread.
bool NumaAvailable() noexcept
Query whether system has NUMA support.
Definition numa.hpp:35