27 std::vector<std::size_t> cpus;
29 while (pos < text.size()) {
30 const auto comma = text.find(
',', pos);
31 const auto token = text.substr(pos, comma == std::string::npos ? std::string::npos : comma - pos);
32 const auto dash = token.find(
'-');
34 if (dash == std::string::npos) {
35 try { cpus.push_back(
static_cast<std::size_t
>(std::stoull(token))); }
catch (...) {}
38 const auto first =
static_cast<std::size_t
>(std::stoull(token.substr(0, dash)));
39 const auto last =
static_cast<std::size_t
>(std::stoull(token.substr(dash + 1)));
40 if (last >= first)
for (std::size_t cpu = first; cpu <= last; ++cpu) cpus.push_back(cpu);
44 if (comma == std::string::npos)
break;
53 namespace fs = std::filesystem;
54 const fs::path root{
"/sys/devices/system/node"};
56 if (fs::exists(root, ec) && !ec) {
57 for (
const auto& entry : fs::directory_iterator(root, ec)) {
59 const auto name = entry.path().filename().string();
60 if (name.rfind(
"node", 0) != 0 || name.size() <= 4)
continue;
62 const auto id =
static_cast<std::size_t
>(std::stoull(name.substr(4)));
63 std::ifstream in(entry.path() /
"cpulist");
66 std::getline(in, cpulist);
std::size_t hardware_threads
std::vector< NumaNodeInfo > topology