ELEMENTAL attribute

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

ELEMENTAL

The ELEMENTAL keyword may appear only in the prefix of a FUNCTION or SUBROUTINE statement.

<Semantics>

The ELEMENTAL keyword specifies that all procedures defined by this subprogram are “elemental”; that is, they can be applied elementally to one or more arrays, and if a function, produce an array of the same shape. (A subprogram can define several procedures by using the ENTRY statement.)

An elemental subprogram must obey the following rules:

The ELEMENTAL attribute also implies the PURE attribute, except when ELEMENTAL is accompanied by the IMPURE attribute; a pure elemental subprogram must additionally obey the rules for a pure subprogram. From Fortran 2018, an elemental procedure is permitted to be recursive (and this is the default).

All arguments to an elemental procedure must be conformable; that is, they may be scalar but all the array ones must have the same shape. A pure elemental procedure is applied elementwise to corresponding elements of its arguments, and is not called in any particular order; indeed, on a parallel processor it might be applied to more than one element at the same time. Because pure procedures cannot have side effects, the order of application does not make any difference to the result.

An impure elemental procedure is applied to its array arguments in array element order. Because an impure procedure can have side effects, this can make a difference to the result.}

When an elemental procedure appears in an expression in a WHERE construct, it is only applied to elements for which the current control mask is true.

<Related>

ENTRY statement, FUNCTION statement, IMPURE attribute, NON_RECURSIVE attribute, PURE attribute, RECURSIVE attribute, RESULT clause, SUBROUTINE statement