next up previous

4.4 Array-valued Functions

Fortran 90 functions can return array-valued results. A number of intrinsic functions always return array values and most intrinsic functions can return array values. In addition, user-written functions may be array valued. Array-valued functions provide two (related) tremendous benefits. First, array-valued functions may be used as operands in array-valued expressions, allowing data-parallel computations to be expressed in the most natural forms. Second, this facilitates composing a computation from array-valued subexpressions, which often can be evaluated in parallel. Thus array-valued functions provide increased opportunities to combine process parallelism with data parallelism in a natural way.

For example, where and are large conformable two-dimensional arrays, + cshift(u,1,2) - cshift(u,-1,2) is an expression similar to some commonly found in seismic modeling computations. (CSHIFT is the intrinsic function that circularly shifts the first argument - an array - the amount of the second argument along the dimension specified by the third argument.) This expression very clearly expresses the nature of the computation, which the following diagram stylizes for a single element of the result of the expression,

once one is thinking data parallel, and offers the compiler the opportunity to evaluate any subexpressions in parallel. This might be particularly appropriate, for example, if g were itself a function reference, in which case it probably would be advantageous to evaluate the subexpression cshift(u,1,2)-cshift(u,-1,2) in parallel with the evaluation of .