45 topo.cpu_count =
static_cast<int>(std::thread::hardware_concurrency());
46 if (topo.cpu_count <= 0)
51 topo.node_to_cpus = {{}};
52 for (
int i = 0; i < topo.cpu_count; ++i)
53 topo.node_to_cpus[0].push_back(i);
59 std::string path =
"/sys/devices/system/node/node" + std::to_string(nodes);
60 if (access(path.c_str(), F_OK) != 0)
64 topo.numa_nodes = (nodes > 0) ? nodes : 1;
65 topo.node_to_cpus.resize(topo.numa_nodes);
69 for (
int nodeIndex = 0; nodeIndex < nodes; ++nodeIndex)
71 std::string list_path =
"/sys/devices/system/node/node" + std::to_string(nodeIndex) +
"/cpulist";
72 std::ifstream in(list_path);
84 while (i < s.size() && (std::isdigit(
static_cast<unsigned char>(s[i])) != 0))
87 startCpu = startCpu * 10 + (s[i] -
'0');
95 if (i < s.size() && s[i] ==
'-')
100 while (i < s.size() && (std::isdigit(
static_cast<unsigned char>(s[i])) != 0))
103 endCpu = endCpu * 10 + (s[i] -
'0');
106 if (gotb && endCpu >= startCpu)
108 for (
int cpuIndex = startCpu; cpuIndex <= endCpu; ++cpuIndex)
109 topo.node_to_cpus[nodeIndex].push_back(cpuIndex);
114 topo.node_to_cpus[nodeIndex].push_back(startCpu);
116 if (i < s.size() && s[i] ==
',')
123 topo.node_to_cpus = {{}};
124 for (
int i = 0; i < topo.cpu_count; ++i)
125 topo.node_to_cpus[0].push_back(i);