Openmp thread affinity: Set 2 threads in the program, how many cores are running?

650 views Asked by At

I wrote an Openmp Program, running it on a two core machine.

When I changed the thread number from 1 to 2 and from 2 to 4, I couldn't get the 2x speed up.

2 threads to 4 threads, that's the hyperthreads. Hyperthreads generally can't get 2x speed up because of resources limitation.

However, 1 threads to 2 threads, still can't get the 2x speed up, I feel confused about this.I searched and found the CPU affinity concept, but I can't figure out how Openmp works.

When I use 2 threads, does Openmp static schedule arrange 2 threads into 1 core or 2 core?

omp_get_thread_num() function can't tell me the answer since the return value is 0 or 1, but I don't know they are running on 1 core or 2.

Thanks for help.

1

There are 1 answers

3
Ruslan Dautov On

Can use thread affinity with proc_bind:

Close enter image description here

Spread enter image description here

Master enter image description here

I hope this will help you choose the appropriate option to work.