How is the ordered clause in OpenMP supposed to be correctly used? There is this test code to check if the loop will be executed by increasing values of n but it is not always the case.
Did I misinterpret the definition of the ordered clause?
The ordered construct specifies a structured block in a loop region that will be executed in the order of the loop iterations. This sequentializes and orders the code within an ordered region while allowing code outside the region to run in parallel.
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(){
int n;
omp_set_num_threads(4);
#pragma omp parallel
{
#pragma omp for ordered
for (n=0;n<10;n++)
printf("n = %d\n",n);
}
return 0;
}
When compiling with
gcc -Wall -Wextra -fopenmp test_par.c
The output is
./a.out
n = 0
n = 1
n = 2
n = 9
n = 3
n = 4
n = 5
n = 6
n = 7
n = 8