Ok, I changed the example a bit so that each iteration is doing some work. The threads don’t show up with top since there is no actual computation.
% cat test.c
#include <omp.h>
#include <math.h>
int main() {
float x, y, z;
int i,j, tid;
x = y = z = 0.0;
omp_set_num_threads(3);
#pragma omp parallel private (tid)
{
tid = omp_get_thread_num();
#pragma omp for nowait
for(i =0 ; i <10000; i++)
for(j =0 ; j <10000; j++) {
x = sin((y+i) * (z+j) / 1.2);
// printf ("%d [%d, %d] %f\n", tid, i, j, x);
}
}
exit(0);
}
Compile the code and bind each process to CPU 3, 4, and 5. Note that setting MP_BIND and MP_BLIST is optional.
% pgcc -mp -V6.2-4 test.c -O0
% setenv MP_BIND yes
% setenv MP_BLIST 3,4,5
% a.out
top - 09:26:24 up 40 days, 11:05, 4 users, load average: 0.79, 0.55, 0.29
Tasks: 145 total, 2 running, 141 sleeping, 2 stopped, 0 zombie
Cpu0 : 0.0% us, 15.9% sy, 0.0% ni, 84.1% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu1 : 0.0% us, 0.3% sy, 0.0% ni, 99.7% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu2 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu3 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu4 : 94.0% us, 6.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu5 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu6 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu7 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 8179780k total, 2210816k used, 5968964k free, 70044k buffers
Swap: 8393920k total, 580392k used, 7813528k free, 460760k cached