Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29390 Discussions

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

Sean_S_2
Beginner
949 Views

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).

0 Kudos
4 Replies
Steven_L_Intel1
Employee
949 Views

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,

0 Kudos
Sean_S_2
Beginner
949 Views

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.

0 Kudos
Steven_L_Intel1
Employee
949 Views

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.)

0 Kudos
Sean_S_2
Beginner
949 Views

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.

0 Kudos
Reply