SIGN in Sun Studio 11 (x86) running slowly
Hi,
I recently discovered that the sign (dsign) intrinsic function seems to be much slower than expected when using the -fast switch on an x86 platform. I compile with f95 -f77 -fast.
Specifically, the intrinsic sign function is much slower than replacing the sign with a homegrown function which consists of an if-then-else statement (see below: function "fastsign"). However, when using -g or no optional compiler switches at all, the intrinsic sign function is slightly faster than the homegrown function.
I'm experiencing this problem on Solaris 10, Sun Studio 11, Fortran 95 8.2 Patch 121020-02 2006/04/06 with an AMD Opteron CPU at 2.6GHz.
As a check, I ran the code on an UltraSparc II 450MHz with Solaris 9 and the Fortran 77 5.3 2001/05/15 compiler, also with the -fast switch and found that the intrinsic sign and the homegrown function mentioned above take about the same amount of time.
While it's not difficult to replace the uses of the intrinsic sign with the function I created, this problem only occurs when using the -fast switch.
Any help anyone could give me would be appreciated. Alternatively, if someone could suggest an alternative library to use, that would work too.
I realize that this post is sort of similar to a post by another user experiencing slow double intrinsic functions, so I apologize in advance if this should not be a new post.
Thanks in advance,
Jon
[code]
c
program test1
c
implicitnone
integeri, imax
real*8q1, q2, q3, q4, t1, t2
realetime , dummy(2)
parameter ( imax = 1000000 )
real*8fastsign
c
c--
c
cInitialise CPU timer
c
t1 = dble ( etime ( dummy ) )
c
q1 = 1.0d0
c
t1 = dble ( etime ( dummy ) )
q3 = 0.0d0
do i = 1,imax
q2 = sign ( 0.5d0, q1 )
q3 = q3 + ( 0.5d0 + q2 ) * 2.0d0
enddo
t1 = dble ( etime ( dummy ) ) - t1
c
t2 = dble ( etime ( dummy ) )
q4 = 0.0d0
do i = 1,imax
q2 = fastsign ( 0.5d0, q1)
q4 = q4 + ( 0.5d0 + q2 ) * 2.0d0
enddo
t2 = dble ( etime ( dummy ) ) - t2
c
write(6,2000) q3, q4
write(6,2010) 'd_sign', t1
write(6,2010) 'fastsign' , t2
write(6,2010) 'sign/fastsign', t1 / t2
c
c
2000format(2e16.8)
2010format(a16,1pe16.8)
c
stop
end
c
c--
c
function fastsign ( a1, a2 )
c
real*8fastsign, a1, a2
c
c--
c
if (a2 .ge. 0.0d0) then
fastsign =a1
else
fastsign = - a1
endif
c
return
end
c
c--
c
[/code]

