Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ELEMENTAL

Keyword: Asserts that a user-defined procedure is defined on scalar arguments that may be called with array arguments. An elemental procedure may be a pure procedure or an impure procedure. An elemental procedure is an elemental intrinsic procedure, an intrinsic module procedure that is specified to be elemental, a user-defined procedure that is specified to be elemental, or a type-bound procedure that is bound to an elemental procedure. A procedure pointer or a dummy procedure can not be specified to be elemental.

Description

To specify an elemental procedure, use this keyword in a FUNCTION or SUBROUTINE statement.

An explicit interface must be visible to the caller of an ELEMENTAL procedure.

An elemental procedure can be passed an array, which is acted upon one element at a time.

For functions, the result must be scalar; it cannot have the POINTER or ALLOCATABLE attribute.

Dummy arguments in ELEMENTAL procedures may appear in specification expressions in the procedure.

Dummy arguments have the following restrictions:

  • They must be scalar.

  • They cannot have the POINTER or ALLOCATABLE attribute.

  • They cannot be an alternate return specifier (*).

  • They cannot be dummy procedures.

If the actual arguments are all scalar, the result is scalar. If the actual arguments are array valued, the values of the elements (if any) of the result are the same as if the function or subroutine had been applied separately, in any order, to corresponding elements of each array actual argument.

Elemental procedures are pure procedures and all rules that apply to pure procedures also apply to elemental procedures, unless you specify that the elemental procedure is IMPURE. In that case, the rules for pure procedures do not apply.

Example

Consider the following:

  MIN (A, 0, B)             ! A and B are arrays of shape (S, T)

In this case, the elemental reference to the MIN intrinsic function is an array expression whose elements have the following values:

  MIN (A(I,J), 0, B(I,J)), I = 1, 2, ..., S, J = 1, 2, ..., T

Consider the following example:

ELEMENTAL REAL FUNCTION F (A, B, ORDER) 
REAL, INTENT (IN)       :: A, B 
INTEGER, INTENT (IN)    :: ORDER 
REAL                    :: TEMP (ORDER) 

In the above, the size of TEMP depends on the specification expression that is the value of the ORDER dummy argument.