NUMA++ 0.11.0
Loading...
Searching...
No Matches
cpuaffinityExample1.cpp
1#include <iostream>
2#include <numapp/numa.hpp>
4
5int main() {
7 using numapp::Cpumask;
9 std::cout << "NUMA not available";
10 return -1;
11 }
12
13 auto policy = CpuAffinity(Cpumask::MakeFromCpuStringAll("0-3"));
14 // Set CPU affinity for main thread
15 if (auto ec = numapp::thisThread::Apply(policy); ec) {
16 std::cout << "Failed to apply policy: " << ec.message() << std::endl;
17 return 1;
18 }
19}
Create CPU affinity and apply to current thread.
Type-safe CPU mask.
Definition cpumask.hpp:25
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:34