Re: elemental function versus loop over function
- From: "Arjen Markus" <arjen.markus@xxxxxxxxxx>
- Date: 28 Nov 2006 06:48:30 -0800
Mark Morss schreef:
I have to perform a scalar function on each of the elements of a large
array. In general, for speed, does it matter much whether I loop over
the array or define an elemental function? One aspect of my problem is
that my array result depends not only on the input array, but on one or
two scalar inputs. So if I define an elemental function, before I can
call it with these arguments, my understanding is that I have to "blow
up" these scalars into constant-valued arrays of the same dimension as
my input array.
My preliminary assumption is that isn't worth doing this, and just
looping over the array is likely to be faster.
You can define an elemental function like:
real elemental function f( a, b, c )
...
end function f
and use it like this:
real, dimension(1000,1000) :: array, barray, result
real :: b, c
result = f(array, b, c)
result = f(array, b, barray)
All elements should be either conforming arrays or scalars.
I recently had the same issue. The compiler is quite happy to do this
and measuring the performance made clear that (in my case) there
was no significant overhead. (In fact, in some cases this solution
was faster than explicit do-loops)
Regards,
Arjen
.
- References:
- elemental function versus loop over function
- From: Mark Morss
- elemental function versus loop over function
- Prev by Date: Re: elemental function versus loop over function
- Next by Date: Re: languages influencing Fortran
- Previous by thread: Re: elemental function versus loop over function
- Next by thread: Re: elemental function versus loop over function
- Index(es):
Relevant Pages
|