How to tell if OpenMP is working?
Asked Answered
R

2

13

I am trying to run LIBSVM in parallel mode, however my question is in OpenMP in general. According to LIBSVM FAQ, I have modified the code with #pragma calls to use OpenMP. I also modified the Makefile (for un*x) by adding a -fopenmp argument so it becomes:

CFLAGS = -Wall -Wconversion -O3 -fPIC -fopenmp

The code compiles well. I check (since it's not my PC) whether OpenMP is installed by :

/sbin/ldconfig -p | grep gomp

and see that it is -probably- installed:

 libgomp.so.1 (libc6,x86-64) => /usr/lib64/libgomp.so.1
 libgomp.so.1 (libc6) => /usr/lib/libgomp.so.1

Now; when I run the program, I don't see any speed improvements. Also when I check with "top" the process is using at most %100 CPU (there are 8 cores), also there is not a CPU bottleneck (only one more user with %100 CPU usage), I was expecting to see more than %100 (or a different indicator) that process is using multiple cores.

Is there a way to check that it is working multiple core?

Rotifer answered 7/5, 2012 at 11:55 Comment(3)
Just a thought, but shouldn't it be max. 100%/number of cores when only one thread is running?Hymnal
no, when multicores are employed (at least in my server's installation) we see values much larger than 100%Rotifer
@Tibor, top defaults to Irix mode that shows 100% for the full load of a single CPU and n*100% for the full load of n CPUs. If you toggle Irix mode off (press 'I') it shows 100% when all CPUs are used.Puett
H
12

You can use the function omp_get_num_threads(). It will return you the number of threads that are used by your program.

Heisenberg answered 7/5, 2012 at 12:0 Comment(1)
One must call omp_get_num_threads() inside a parallel region. Otherwise it always returns 1!Puett
F
2

With omp_get_max_threads() you get the maximum number of threads available to your program. It is also the maximum of all possible return values of omp_get_num_threads(). You can explicitly set the number of threads to be used by your program with the environment variable OMP_NUM_THREADS, e.g. in bash via

$export OMP_NUM_THREADS=8; your_program
Funke answered 1/3, 2014 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.