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

can DIY functions be faster than intrinsic functions??

sbenati
Beginner
507 Views
Hi: I was a bit surprised that the code

max=0
do i=1,100000
if (a(i) > maxi) then
maxi = a(i)
end if
end do

is faster than

maxi = maxval(a)

where maxval is an intrinsic function (is 10% slower).
Is it possible and there is a meaningful reason for such unexpected behavior?
0 Kudos
2 Replies
tiddles
Beginner
507 Views
Running Visual Fortran v6.1 on windows I find that the example you gave ran slower than the intrinsic maxval. (Running in Release Configuration with speed optimisation throughout.) Typical results for an array of dimension 10,000,000 were:

0.453 sec for your example,
0.375 sec for the intrinsic maxval,

--or, a speed-up of 17% by use of the intrinsic maxval.

HOWEVER, for smaller length arrays, there is no significant difference in execution times.
0 Kudos
TimP
Honored Contributor III
507 Views
In my experience, g77 SSE/SSE2 code performs these operations faster than Intel supported compilers, although prof_gen/prof_use do help IFL/ifc. If you actually tested with that typo included, your compiler may have been able to eliminate basic operations as dead code.
0 Kudos
Reply