No way to vectorize the implicit loop in an elemental subroutine?

No way to vectorize the implicit loop in an elemental subroutine?

It seems to me that the implicit loop in Fortran elemental functions is never vectorized unless declared as a vector function, like so:

!dec$ attributes vector :: foo

elemental function foo(x)

But this doesn't work for subroutines (and it puts inconvenient restrictions on functions). I'd be interested to know if there's any way to vectorize an elemental subroutine (other than inlining it).

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

There is no implicit loop in the elemental procedure - the procedure is scalar. The loop happens in the caller.

Vector functions may indeed be what you want.Otherwise, as you say, inlining,

Retired 12/31/2016

Hmm, unfortunate, since it's impossible have multiple outputs in this case, and Fortran does not provide any meaningful support for implementation of rank-generic functions except via elemental routines.

Fortran, the language, will have something for you in the next standard, with "assumed-rank" dummy arguments, but that's a future (and probably would not help with optimization.)

Retired 12/31/2016

Hmm, true. I suppose assumed rank *would* still help if it was worth it to simply rewrite the function in C/C++ (e.g. if it's big and expensive and you can still write with vectorizable loops in the other language); then at least you don't have to write some very large number of Fortran interfaces in order to give an explicit interface to every array rank. Which I gather is roughly why assumed rank was important for MPI interfaces in the first place.

Leave a Comment

Please sign in to add a comment. Not a member? Join today