56 topo.
cpu_count =
static_cast<int>(std::thread::hardware_concurrency());
70 std::string path =
"/sys/devices/system/node/node" + std::to_string(nodes);
71 if (access(path.c_str(), F_OK) != 0)
80 for (
int nodeIndex = 0; nodeIndex < nodes; ++nodeIndex)
82 std::string list_path =
"/sys/devices/system/node/node" + std::to_string(nodeIndex) +
"/cpulist";
83 std::ifstream in(list_path);
95 while (i < s.size() && (std::isdigit(
static_cast<unsigned char>(s[i])) != 0))
98 startCpu = startCpu * 10 + (s[i] -
'0');
106 if (i < s.size() && s[i] ==
'-')
111 while (i < s.size() && (std::isdigit(
static_cast<unsigned char>(s[i])) != 0))
114 endCpu = endCpu * 10 + (s[i] -
'0');
117 if (gotb && endCpu >= startCpu)
119 for (
int cpuIndex = startCpu; cpuIndex <= endCpu; ++cpuIndex)
127 if (i < s.size() && s[i] ==
',')
196 std::vector<ThreadAffinity> result;
197 result.reserve(num_threads);
198 for (
size_t i = 0; i < num_threads; ++i)
200 int node = (topo.numa_nodes > 0) ?
static_cast<int>(i % topo.numa_nodes) : 0;
auto affinity_for_node(CpuTopology const &topo, int node_index, int thread_index, int threads_per_node=1) -> ThreadAffinity
Build a ThreadAffinity for the given NUMA node using a pre-read topology.