Detection od a data race in OpenMP

In the following code, there is a data race.
I would like to know which compiler option must be turn on in order to see that PGI C compiler detects this data race. And what will be the expected message from the compiler.

pragma omp parallel for {

for ( i=1; i< N; i++){
a(i) = a(i) + a(i – 1)
}


Thanks in advance
Ami

It seems that I did not get much attention from PGI experts regarding my question.

Therefore, I guess that PGI C-OpenMP compiler cannot detect data dependency situations.

If somebody thinks that I’m wrong, please correct me.

Thanks in advance
Ami

Hi Ami,

The -Minfo flag will relay some helpful information from the compiler. I created a small example with your code:

#define N 1000

int main(int argc, char *argv[])
{
  int i;
  double a[N];

  for ( i = 0; i < N; i++ )
    a[i] = 0.0;

#pragma omp parallel for
  for ( i = 1; i < N; i++ )
    a[i] = a[i] + a[i-1];

  return 0;
}

Then compiled it:

$ pgcc -o omp omp.c -mp -Minfo
main:
     12, Parallel region activated
         Parallel loop activated with static block schedule
     15, Barrier
         Parallel region terminated

As you may have observed, this particular loop should serialize due to the data dependency in the loop body. However, the compiler generates a parallel loop anyway, and attempts to execute every iteration in parallel. Thus, the dependency is not enforced, and you will get unpredictable answers in this case.

In this particular case, the compiler does exactly what you told it to do, not necessarily what you wanted it to do. I’m not aware of any flag that provides the functionality you are looking for here.

Best regards,

+chris

+chris,

First, thanks for your reply.
Second, the –Minfo flag is the one I looked for.

I’m not sure that I understood your answer.
So, let me say what I understood from the compilation report
and correct me if you think that I’m wrong:

  1. The compiler cannot detect the data dependence that appears in the code.
  2. Therefore, the compiler parallelizes the code based on the OpenMP directive.
  3. The result – the data of array a after executing the parallel code is not
    the same as the data after executing the serial code.

Am I right?

Thanks in advance
Ami

Ami,

You are correct.

Best regards,

+chris