- Code: Select all
`#include <stdio.h>`

#include <stdlib.h>

#include <omp.h>

int main(int argc, char *argv[]) {

int N = 4;

int i,j;

// Let's try a loop

#pragma omp parallel for

for (j=0;j<N;j++) {

for (i=0;i<N;i++) {

printf("id: %d; ij: %d %d; total: %2d, N: %d\n", omp_get_thread_num(), i, j, j*N+i, N);

}

}

return 0;

}

I compile with: gcc -fopenmp -o test1 test1.c

using gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC).

Sometime the output is normal, but often and unpredictably skips elements in the inner loop:

- Code: Select all
`$ ./test1 | sort -n -k7`

id: 0; ij: 0 0; total: 0, N: 4

id: 0; ij: 2 0; total: 2, N: 4

id: 0; ij: 3 0; total: 3, N: 4

id: 0; ij: 0 1; total: 4, N: 4

id: 0; ij: 1 1; total: 5, N: 4

id: 1; ij: 0 2; total: 8, N: 4

id: 1; ij: 1 2; total: 9, N: 4

id: 1; ij: 2 2; total: 10, N: 4

id: 1; ij: 3 2; total: 11, N: 4

id: 1; ij: 0 3; total: 12, N: 4

id: 1; ij: 1 3; total: 13, N: 4

id: 1; ij: 2 3; total: 14, N: 4

id: 1; ij: 3 3; total: 15, N: 4

Here (i,j) = (1,0); (2,1); and (3,1) are missing. Which steps are skipped and by which threads varies in subsequent runs.