Uninitialized OpenMP* PRIVATE variable

A PRIVATE variable is uninitialized.

PRIVATE variables are not, by default, initialized to the value of the corresponding outer variable. To cause this to occur, you must use the FIRSTPRIVATE clause instead of the PRIVATE clause. Therefore, each thread is responsible for initializing its own PRIVATE variables before they are used. This error is simply another form of the uninitialized variable error where the variable is PRIVATE.

ID

Observation

Description

1

Uninitialized read

The place the uninitialized PRIVATE variable was read

Example


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

int b;

void do_work()
{
    int i;

    #pragma omp parallel
    {
        #pragma omp for ordered private(b)
        // INCORRECT: private variable "b" not initialized before entry to the loop
        for (i = b; i < 100; i++) {
            b++;
            #pragma omp ordered
            printf("i = %d, #threads = %d, b = %d\n", i, omp_get_thread_num (), b);
        }

    }
}

int main(int argc, char **argv)
{
    b = 50;
    omp_set_num_threads(3);
    do_work();
    return 0;
}
        

Copyright © 2010, Intel Corporation. All rights reserved.