1

I have a simple C++ code that uses Intel's TBB to run a list of scripts on a cluster using PBS. I want to confirm that I am using all the cores as intended. Each node has 16 cores. I have created the scripts to take varying amounts of time such that if the list is divided evenly I will have idle cores. If the list is divided out as cores become available I should have no idle cores. The code appears to work fine on a single node but not for multiple nodes.

I want something similar to echo $HOSTNAME except for the core. Google failed me and produced results for echoing the number of cores or how much the cores are used. I have tried using top and monitoring the job run but this doesn't tell me which core.

Matt
  • 2,554
  • 2
  • 24
  • 45
  • Can you add a pseudo-code please? I'm not sure I understand what is your problem. Do you use `parallel_for(0, N, [](int i){ run_script(i); }`? – Anton May 07 '15 at 10:11

1 Answers1

0

It is up to the Linux scheduler to decide which process gets which core at any given moment. It makes those decisions many times a second frequently moving processes from core to core depending on the load.

You can get a snapshot of the process to cpu allocation with the psr option of the ps command:

ps -o pid,psr,cmd -28832
  PID PSR CMD
28832   1 bash

I.e. here bash (pid=28832) is assigned to the second core that has processor id=1.

From C code you could use the getcpu(2) call defined in linux/getcpu.h.

To assign a process to a specific set of cores you could run numactl(8) or taskset(1) specifying a cpu affinity mask.

Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
  • I ended up going with the sched_getcpu that I found through the getcpu method. Thanks for the solution. – Matt May 07 '15 at 15:27