questions on gfortran

Tim Prince n8tm@aol.com
Sat May 12 13:40:00 GMT 2007


lucatrv@hotmail.com wrote:
> 
>> Luca Trevisani wrote:
>>> PROGRAM PROVA
>>>  IMPLICIT NONE
>>>  INTEGER, PARAMETER :: WP = KIND(1.0D0)
>>>  INTEGER, PARAMETER :: NX=10000, NY=10000
>>>  INTEGER :: I, J
>>>  REAL(WP) :: A(NX,NY), X(NX), Y(NY)
>>>  REAL(WP) :: T1, T2
>>>  CALL CPU_TIME(T1)
>>>  DO I=1,NX
>>>     X(I)=2.0_WP/REAL((NX+1)*I-1,WP)
>>>  END DO
>>>  DO I=1,NY
>>>     Y(I)=2.0_WP/REAL((NY+1)*I-1,WP)
>>>  END DO
>>>  DO J=1,NY
>>>     DO I=1,NX
>>>        A(I,J)=SIN(1.0_WP+REAL(I+J,WP))
>>>     END DO
>>>  END DO
>>>  CALL CPU_TIME(T2)
>>>  PRINT *, 'Execution time:', T2-T1
>>> END PROGRAM PROVA
>>>
>>>
>>> In conclusion, now it seems to me that actually all flags other than
>>> -O2 are
>>> almost uninfluential on the execution speed, both under win32 and under
>>> linux...
>>>
>> You're talking about execution speed of sin(), but I doubt you
>> recompiled the sin() function or used a vectorized library.
>>
> 
> Could you please explain me better? I thought I didn't have to recompile
> internal fortran functions in order to have them vectorized... and I
> wouldn't even know how to do that. By the way, since the sin() function is
> elemental, shouldn't it be already vectorized?
> Are you saying that even a SIN(X) where X is a vector is not actually
> vectorized if the fortran libraries where not vectorized themselves when
> they were compiled?
> 

Among Fortran compilers for linux x86[32/64] , I think only ifort would 
vectorize sin().  It does it by automatically substituting calls to 
"short vector math library."  All functions to be vectorized must have 
pre-built library support.
No compiler rebuilds the math library, or vectorizes automatically those 
functions which aren't available as built-in parallel instructions. The 
only built-in for sin() on x86 architectures is the original x86 
instruction, dating back to i386 and beyond.
You could easily check whether your vectorization option has changed the 
generated code in the sin() test loop, using the command line options, 
or by the -S option, for example.



More information about the Fortran mailing list