Unordered use of I/O operation

Unordered use of I/O operation.

Performing I/O operations in a parallel region but outside of an ORDERED, MASTER, or SINGLE block can result in unpredictable order of input and output operations. This can cause different execution results in parallel and sequential mode.

ID

Observation

Description

1

Call site

The place the I/O function was called

Examples


#include <stdio.h>

int main(int argc, char **argv)
{
    int i;
    FILE *fp;
    fp = fopen("random.txt", "w");
    #pragma omp parallel for
    for (i = 0; i < 10; i++) {
        // bad: order is not guaranteed
        fprintf(fp, "i = %d\n", i);
    }
    fclose(fp);
    
    fp = fopen("ordered.txt", "w");
    #pragma omp parallel for ordered
    for (i = 0; i < 10; i++) {
        // this is OK
        #pragma omp ordered
        fprintf(fp, "i = %d\n", i);
    }
    fclose(fp);
    
    return 0;
}
        

Copyright © 2010, Intel Corporation. All rights reserved.