0

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).

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Or even (but not as portable as export OMP_NUM_THREADS=1) taskset -c 0 ./a.out, to limit CPU cores, available to the omp runtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.