This topic has not yet been rated - Rate this topic

A.26 Using the threadprivate Directive

The following examples demonstrate how to use the threadprivate directive (Section 2.7.1 on page 23) to give each thread a separate counter.

Example 1:

int counter = 0;
#pragma omp threadprivate(counter)

int sub()
{
    counter++;
    return(counter);
}

Example 2:

int sub()
{
    static int counter = 0;
    #pragma omp threadprivate(counter)
    counter++;
    return(counter);
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ