+---------------------------------Fortran 95---------------------------------+
An elemental subprogram definition must have the ELEMENTAL prefix specifier. If the ELEMENTAL prefix specifier is used, the RECURSIVE specifier cannot be used.
You cannot use the -qrecur option when specifying elemental procedures.
An elemental subprogram is a pure subprogram. However, pure subprograms are not necessarily elemental subprograms. For elemental subprograms, it is not necessary to specify both the ELEMENTAL prefix specifier and the PURE prefix specifier; the PURE prefix specifier is implied by the presence of the ELEMENTAL prefix specifier. A standard conforming subprogram definition or interface body can have both the PURE and ELEMENTAL prefix specifiers.
Elemental procedures, subprograms, and user-defined elemental procedures must conform to the following rules:
A reference to an elemental procedure is elemental only if:
A reference to an elemental subprogram is not elemental if all of its arguments are scalar.
The actual arguments in a reference to an elemental procedure can be either of the following:
For elemental references, the resulting values of the elements are the same as would be obtained if the subroutine or function had been applied separately in any order to the corresponding elements of each array actual argument.
If the intrinsic subroutine MVBITS is used, the arguments that correspond to the TO and FROM dummy arguments may be the same variable. Apart from this, the actual arguments in a reference to an elemental subroutine or elemental function must satisfy the restrictions described in Argument Association.
Special rules apply to generic procedures that have an elemental specific procedure, see Resolving Procedure References to Generic Names.
Example 1:
! Example of an elemental function INTERFACE ELEMENTAL REAL FUNCTION LOGN(X,N) REAL, INTENT(IN) :: X INTEGER, INTENT(IN) :: N END FUNCTION LOGN END INTERFACE REAL RES(100), VAL(100,100) ... DO I=1,100 RES(I) = MAXVAL( LOGN(VAL(I,:),2) ) END DO ... END PROGRAM P
Example 2:
! Elemental procedure declared with a generic interface INTERFACE RAND ELEMENTAL FUNCTION SCALAR_RAND(x) REAL, INTENT(IN) :: X END FUNCTION SCALAR_RAND FUNCTION VECTOR_RANDOM(x) REAL X(:) REAL VECTOR_RANDOM(SIZE(x)) END FUNCTION VECTOR_RANDOM END INTERFACE RAND REAL A(10,10), AA(10,10) ! Since the actual argument 'AA' is a two-dimensional array, and ! a specific procedure that takes a two-dimensional array as an ! argument is not declared in the interface block, then the ! elemental procedure 'SCALAR_RAND' is called. A = RAND(AA) ! Since the actual argument is a one-dimensional array section, and ! a specific procedure that takes a one-dimensional array as an ! argument is declared in the interface block, then the specific ! one-dimensional procedure 'VECTOR_RANDOM' is called. This is an ! non-elemental reference since 'VECTOR_RANDOM' is not declared to ! be elemental. A = RAND(AA(6:10,2)) END
+-----------------------------End of Fortran 95------------------------------+