NUMA++ 0.12.0
Loading...
Searching...
No Matches
mempolicyExample1.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>
10#include <numapp/mempolicy.hpp>
11
12int main() {
14 using numapp::Nodemask;
15 if (!numapp::NumaAvailable()) {
16 std::cout << "NUMA not available";
17 return -1;
18 }
19
20 auto policy = MemPolicy(MemPolicy::Mode::Bind, Nodemask::MakeFromNodestring("0-1"));
21 // Set default policy 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 // And apply policy to stack
27 if (auto ec = numapp::thisThread::ApplyStack(policy); ec) {
28 std::cout << "Failed to apply policy: " << ec.message() << std::endl;
29 return 1;
30 }
31}
Class representing a memory policy that can be modified and used to apply to the current thread or a ...
std::error_code Apply(CpuAffinity const &affinity) noexcept
Apply policy to calling thread.
std::error_code ApplyStack(MemPolicy const &policy, MemPolicyFlag flags=MemPolicyFlag::Move|MemPolicyFlag::Strict) noexcept
Convenience function that applies a memory policy to current thread stack memory.
bool NumaAvailable() noexcept
Query whether system has NUMA support.
Definition numa.hpp:35
Contains declarations for numapp::MemPolicy.
Type-safe NUMA node mask.
Definition nodemask.hpp:25