Re: ELEMENTAL functions and performance
- From: Tobias Burnus <burnus@xxxxxxxx>
- Date: Wed, 30 Jul 2008 02:10:06 -0700 (PDT)
On Jul 30, 9:37 am, Daniel Kraft <d...@xxxxxxxx> wrote:
When called with an array argument, your ELEMENTAL procedure will be
called for each element as opposed to when your procedure accepts the
whole array for one call, and thus here's the possiblity that the
performance changes; but I don't think you can really know in advance if
it improves or degrades and how much; that probably depends on your code
and how your compiler interprets it.
If the compiler calls the elemental function once per each array
element, it largely depends whether the compiler can inline the
function. If it can, it should be quite fast, if it cannot, I would
expect that the program might slow down a lot, especially if you have
a large number of array elements and the calculation in the elemental
procedure is quick (i.e. the procedure-calling overhead is larger than
the calculations in the procedure). On the other hand, if you have
only an array-valued procedure, the construction of an array and doing
array assignments in the procedure can also take some time, which
means that for scalars a elemental procedure should be (a tiny bit,
presumably negligibly) faster.
I believe that in most of the cases, the performanceloss due to
elemental procedures is negligible and worrying about the algorithm or
other things is much more important.
Thus, unless you are sure that the procedure is called very often with
array arguments, I would not worry about it. If it is called a lot,
you should profile the code and verify that it is indeed a hot spot
for the compilers you use.
An alternative to an ELEMENTAL function is to have a generic procedure
containing a scalar and an array specific procedure. That gives a
convenient interface to the user and is fast - for both scalars and
arrays - but you replicate code with all its disadvantages.
(Therefore, you really should check whether it makes a difference for
your compiler; having a well-readable code is more important than
having a tiny performance gain. Especially as compilers make progress
and different compilers behave differently, some changes might be not
needed or worse make the program even slower.)
Tobias
.
- References:
- Re: ELEMENTAL functions and performance
- From: Daniel Kraft
- Re: ELEMENTAL functions and performance
- Prev by Date: Re: Preprocessing fortran
- Next by Date: Re: Issue from IVF 9.0 to IVF 10.1
- Previous by thread: Re: ELEMENTAL functions and performance
- Next by thread: Re: ELEMENTAL functions and performance
- Index(es):
Relevant Pages
|