Oracle® Solaris Studio 12.4: Fortran User's Guide

Exit Print View

Updated: March 2015
 
 

2.3.3 IVDEP Directive

The !DIR$ IVDEP directive tells the compiler to ignore some or all loop-carried dependences on array references that it finds in a loop, allowing it to perform various loop optimizations such as microvectorization, distribution, software pipelining, among others, that would not be otherwise possible. It is employed in situations where the user knows either that the dependences do not matter or that they never occur in practice.

For example:

	 DO I = 1, N 
	   A(V(I)) = A(V(I)) + C(I) 
	 END DO        

In this loop there are several loop-carried dependences on A(V(I)), because V(I) may contain duplicate values to index A, and reordering the loop might result in different results. But if it is known that V contains only distinct values, the loop could be reordered safely, and an IVDEP directive could be used to allow optimization.

The —xivdep compiler option (see –xivdep[=p]) can be used to disable or determine the interpretation of IVDEP directives.

Some legacy interpretations of the IVDEP directive only assert that there are no backward loop-carried dependences. The Fortran compiler's default is —xivdep=loop, indicating that the IVDEP directive asserts there are no assumed loop dependences.

The following examples illustrate backward and forward dependences.

 	 do i = 1, n			! BACKWARD LOOP-CARRIED DEPENDENCE 
		... = a(i-1)		 ! S1 
	    a(i) = ...		 ! S2 
	 end do  
	 do i = 1, n			! FORWARD LOOP-CARRIED DEPENDENCE 
	    a(i) = ...		! S3 
		... = a(i-1)		! S4 
	 end do       

The first loop has a backward loop-carried dependence from S2 to S1, and the second loop has a forward loop-carried dependence from S3 to S4. Since the second loop has only a forward dependence, it can be distributed and/or microvectorized safely while the first one cannot.

Here is an example of the use of IVDEP under the default value of -xivdep=loop:

integer target a(n)
integer, pointer :: p(:), q(:)
!DIR$ IVDEP
do i = 1, n
	 p(i) = q(i) 
	 a(i) = a(i-1)
end do        

The assumed dependences between p(i) and q(i) and between p(i) and a(*) are ignored, but the obvious dependences between a(i) and a(i-1) are not. The loop can be divided into two loops and the resulting p(i) = q(i) loop can be microvectorized.

The IVDEP directive applies to the immediately following DO loop. No other code is allowed between the directive and the loop. !DIR$ IVDEP can also be applied to an array assignment, FORALL, or WHERE construct. If multiple directives are present for a particular loop (such as IVDEP and UNROLL), the compiler will obey all of them, if possible.