NUMA Get Current Node/Core

前端 未结 3 1941
有刺的猬
有刺的猬 2020-12-30 15:17

I\'m using libnuma on Linux. My threads should be aware of the node/core they\'re running on. Is it possible to get the current threads\'s node/core somehow? I\'ve been thro

3条回答
  •  青春惊慌失措
    2020-12-30 16:06

    I found this solution:

    #include 
    #include 
    
    int main(void) {
      printf("CPU: %d\n", sched_getcpu());
      return 0;
    }
    

    Then, if you need the node of the cpu, you can use numa.h:

    int cpu = sched_getcpu();
    int node = numa_node_of_cpu(cpu);
    

提交回复
热议问题