Fortran90: Loop vectorization failed - data dependency

Hi,

I’m using PGI-Fortran compilers (10.2.0) on Cray XT5 and having trouble vectorizing part of my code. I would appreciate if someone could shed some light on this issue.

I’m invoking the compiler with the following options:
ftn -fast -Minfo -c test.F90
17, Loop not vectorized: data dependency
Loop unrolled 2 times
22, Loop not vectorized: data dependency
Loop unrolled 2 times

AFAIK there are no dependencies between the loop statements and also across iterations. When I encountered a similar issue in a C program, I used the -Msafeptr flag to resolve it, is there something similar for Fortran90?

Thanks in advance.

1 PROGRAM test
  2 
  3 IMPLICIT NONE
  4 
  5 type  reaction
  6 integer, pointer :: foo(:)
  7 real, pointer :: foo1(:)
  8 real, pointer :: bar(:)
  9 end type reaction
 10 
 11 integer num, i, j, k
 12 type(reaction) node
 13 real, allocatable :: temp(:)
 14 
 15 allocate(temp(num))
 16 
 17     do i = 1, num
 18        k = node%foo(i)
 19        node%bar(k) = node%bar(k) + node%foo1(i)
 20     enddo
 21 
 22     do i = 1, num
 23        node%bar(node%foo(i)) = node%bar(node%foo(i)) + node%foo1(i)
 24     enddo
 25 
 26 END PROGRAM test

Hi r2d2085,

 17     do i = 1, num
 18        k = node%foo(i)
 19        node%bar(k) = node%bar(k) + node%foo1(i)
 20     enddo

What happens if some or all values of “k” are the same? The result will depend upon the order in which the vectors are executed and the memory updated. Since the order can vary from run to run, your results will be non-deterministic.

The compiler must be conservative (it’s better to get correct answers, then wrong answers fast) and not vectorize this loop.

Hope this helps,
Mat

Thanks, Mat for the explanation. It was helpful.

I’ve one more question, if I make sure that “k” always has an unique value, is there some way to tell the compiler to go ahead with its vectorization?

Yes, you can use the “-Mnodepchk” flag. However, use with care since it can cause wrong answers of all value of K are not independent. Also, it will be applied to all loops in the file, not just this one. Because of this, you might want to use the “nodepchk” directive instead since it can be localized to particular loops.

Note that these loops still won’t vectorize even with “-Mnodepchk” since there isn’t enough work to justify vectorization.

Hope this helps,
Mat