Tricks and Tips – Using omp_set_num_threads and omp_get_num_threads

When programming with OpenMP, it should be noticed that omp_get_num_threads() returns 1 in sequential sections of the code.

Accordingly, even if setting, by omp_set_num_threads(), an overall number of threads larger than 1, any call to omp_get_num_threads() will return 1, unless we are in a parallel section.

The example on our GitHub website tries to clarify this point.

Leave a Reply

Your email address will not be published. Required fields are marked *