OpenMP* LASTPRIVATE variable not properly assigned

When a LASTPRIVATE clause appears on a SECTIONS construct, the variable must be assigned in the last SECTION.

The LASTPRIVATE clause causes the variable to be treated as PRIVATE within the body of the construct. On exit from the construct, the value of the outer variable is assigned from the corresponding thread-private variable belonging to the thread that executes the last unit of work in the region. In the case of a SECTIONS construct, the last unit of work corresponds to the SECTION that appears last.

To ensure deterministic behavior, the LASTPRIVATE variable must be assigned in the last SECTION if it is assigned in any SECTION. This is necessary because there is no way to know what other SECTION(s) will be executed by the thread that executes the last SECTION. This error indicates that this rule has been violated.

ID

Observation

Description

1

Memory read

The place the variable was read

2

OpenMP declaration

The location of the SECTIONS directive

Example


#include <stdio.h>
#include <omp.h>

int main(int argc, char **argv)
{
    int ii = 0;
    int jj = 0;

    omp_set_num_threads(3);

    #pragma omp parallel
    #pragma omp sections lastprivate (ii, jj)
    {
        #pragma omp section
        ii = 10;
                
        #pragma omp section
        jj = 2;
    }
    
    // Bad: ii is indeterminate here
    printf("After parallel section ii = %d and jj = %d\n", ii, jj);
    
    return 0;
}
        

Copyright © 2010, Intel Corporation. All rights reserved.