NUMA++ 0.12.0
Loading...
Searching...
No Matches
makeThreadExample2.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 <numapp/memory.hpp>
9#include <numapp/thread.hpp>
10
11template <class F, class... Args>
12auto MakePinnedThread(int cpu, std::string_view name, F&& f, Args... args) -> std::thread {
13 using namespace numapp;
14
15 NumaPolicies policies;
17 auto node = GetNodeOfCpu(cpu);
18 if (!node.has_value()) {
19 throw std::invalid_argument("cpu invalid");
20 }
22 return MakeThread(name, policies, std::forward<F>(f), std::forward<Args>(args)...);
23}
static CpuAffinity MakeBindCpu(int cpu)
Create CpuAffinity bound to the specified CPU.
static MemPolicy MakeBindNode(int node)
Creates a strict policy (using MPOL_BIND) to allocate all memory to the specified node.
Combines the the available NUMA policy types in one object.
void SetCpuAffinity(std::optional< CpuAffinity > affinity) noexcept
Set CPU affinity.
void SetMemPolicy(std::optional< MemPolicy > policy) noexcept
Set memory policy.
std::optional< int > GetNodeOfCpu(int cpu) noexcept
Get NUMA node of the given CPU.
Definition memory.cpp:55
std::thread MakeThread(std::string_view thread_name, NumaPolicies const &policies, Func &&func, Args &&... args)
Primary overload accepting string-view for thread_name.
Definition thread.hpp:146
Contains memory function declarations.
Contains declarations for numapp thread utilities.