I'm trying to bind OpenMP threads to CPUs. Two methods have been tried.
The first one is sched_setaffinity. Every time threads are forked, I invoke sched_setaffinity to bind OpenMP threads to CPUs. It seems that binding for every time is far too costly. Is it really needed to bind for every time or just bind for once?
The second one is GOMP_CPU_AFFINITY. I set GOMP_CPU_AFFINITY=0-7 and OMP_NUM_THREADS=4. Two nodes are used for computing. Each node has 2 chips and each chip has 4 cores. I place a process in each node and each process forks 4 threads. If GOMP_CPU_AFFINITY is not set, OpenMP does speed up the program. If GOMP_CPU_AFFINITY is set, the following are returned and OpenMP does not work:
OMP: Warning #123: Ignoring invalid OS proc ID 1.
OMP: Warning #123: Ignoring invalid OS proc ID 2.
OMP: Warning #123: Ignoring invalid OS proc ID 3.
OMP: Warning #123: Ignoring invalid OS proc ID 4.
OMP: Warning #123: Ignoring invalid OS proc ID 5.
OMP: Warning #123: Ignoring invalid OS proc ID 6.
OMP: Warning #123: Ignoring invalid OS proc ID 7.