I’m struggling with getting a multi-threaded app to run on multiple cores. I’ve looked into affinity, scheduling, etc. Is there a way to find out the CPU Id that any thread is running on? I’m using sched_getaffinity now – but I think that is related to the process id, not the thread within the process. The mulit-threaded app works great on Windows, but seems to be CPU bound (using only one CPU) on linux
Update:
If my linux app launches 64 threads – I still only have one pid right? It’s still my understanding that each thread launched can run on a different CPU/core on the target hardware, right?
A sample app is here : How do I make a multi-threaded app use all the cores on Ubuntu under VMWare?
Your first question
sched_getaffinitydoesn’t return the CPU, it returns a mask of eligible CPUs. It says:And then
To simply find out the CPU used,
/proc/[pid]/stathas a “processor” field:Your second question:
Show the smallest example that exhibits this problem.