Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

A.15 Determining the Number of Threads Used 

Consider the following incorrect example (for Section 3.1.2 on page 37):

np = omp_get_num_threads(); // misplaced 
#pragma omp parallel for schedule(static)
    for (i=0; i<np; i++)

The omp_get_num_threads() call returns 1 in the serial section of the code, so np will always be equal to 1 in the preceding example. To determine the number of threads that will be deployed for the parallel region, the call should be inside the parallel region.

The following example shows how to rewrite this program without including a query for the number of threads:

#pragma omp parallel private(i)
    i = omp_get_thread_num();

Community Additions

© 2015 Microsoft