No performance gain after using openMP on a program optimize for sequential running

Even if your program benefits from using OpenMP, you won’t see it because you are measuring the wrong time.

clock() returns the total CPU time spent in all threads. If you run with four threads and each runs for 1/4 of the time, clock() will still return the same value since 4*(1/4) = 1. You should be measuring the wall-clock time instead.

Replace calls to clock() with omp_get_wtime() or gettimeofday(). They both provide high precision wall-clock timing.

P.S. Why are there so many people around SO using clock() for timing?

Leave a Comment