rwolst
rwolst

Reputation: 13662

Disabling OpenMP when Profiling Enabled

When profiling my C code, I would like to disable/reduce the number of OMP threads to 1. After a brief search, I found this question. I would therefore decided to do something like

#ifdef foo
    #define omp_get_thread_num() 0
#endif

where foo is a macro that is true if the -pg flag is set when compiling with GCC.

My question then is, what is the value of foo and will this method now allow me to get sensible profiling information (by forcing OpenMP to just use one thread).

Upvotes: 0

Views: 100

Answers (1)

user2548418
user2548418

Reputation: 1571

The easiest way to change the number of threads for OpenMP is during program launch with the environment variable OMP_NUM_THREADS. To get a single-threaded execution of a.out:

$> OMP_NUM_THREADS=1 ./a.out

This should return sensible data for profiling. If you completely remove OpenMP, you will be somewhat changing your application so profiling may not be as relevant.

Upvotes: 3

Related Questions