56 topo.cpu_count =
static_cast<int>(std::thread::hardware_concurrency());
57 if (topo.cpu_count <= 0)
62 topo.node_to_cpus = {{}};
63 for (
int i = 0; i < topo.cpu_count; ++i)
64 topo.node_to_cpus[0].push_back(i);
70 std::string path =
"/sys/devices/system/node/node" + std::to_string(nodes);
71 if (access(path.c_str(), F_OK) != 0)
75 topo.numa_nodes = (nodes > 0) ? nodes : 1;
76 topo.node_to_cpus.resize(topo.numa_nodes);
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)
120 topo.node_to_cpus[nodeIndex].push_back(cpuIndex);
125 topo.node_to_cpus[nodeIndex].push_back(startCpu);
127 if (i < s.size() && s[i] ==
',')
134 topo.node_to_cpus = {{}};
135 for (
int i = 0; i < topo.cpu_count; ++i)
136 topo.node_to_cpus[0].push_back(i);