multithreading - Is it possible to print the CPU and core using pthreads on Linux -


i'm struggling getting multi-threaded app run on multiple cores. i've looked affinity, scheduling, etc. there way find out cpu id thread running on? i'm using sched_getaffinity - think related process id, not thread within process. mulit-threaded app works great on windows, seems cpu bound (using 1 cpu) on linux

update:

if linux app launches 64 threads - still have 1 pid right? it's still understanding each thread launched can run on different cpu/core on target hardware, right?

a sample app here : how make multi-threaded app use cores on ubuntu under vmware?

your first question

is there way find out cpu id thread running on? i'm using sched_getaffinity now

sched_getaffinity doesn't return cpu, returns mask of eligible cpus. says:

the affinity mask per-thread attribute can adjusted independently each of threads in thread group.

and then

if using posix threads api, use pthread_setaffinity_np(3) instead of sched_setaffinity().

to find out cpu used, /proc/[pid]/stat has "processor" field:

processor %d (since linux 2.2.8) cpu number last executed on.

your second question:

the mulit-threaded app works great on windows, seems cpu bound (using 1 cpu) on linux

show smallest example exhibits problem.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -