Last active
October 17, 2016 11:04
-
-
Save zmiimz/1e85ea37e3b02226068ad4b3f2ba41c4 to your computer and use it in GitHub Desktop.
pow and sqrt timing in fortran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! gfortran -O3 pow_timing.f90 -o pow_timing.x -mcmodel=medium | |
!----------------------------------------------------------------------- | |
!Main program test | |
!----------------------------------------------------------------------- | |
program test | |
implicit none | |
integer, parameter :: dp = kind(1.d0) | |
integer :: i | |
integer, parameter :: s = 100000000 | |
real(dp) :: a | |
real(dp), dimension(s) :: b1,b2,b3,b4,b5,b6,b7 | |
real(dp), dimension(2) :: time | |
character(len=11):: fmt = '(A30,F12.6)' | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b1(i) = a*a | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "a*a elapsed time = ", time(2)-time(1) | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b2(i) = a**2 | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "a**2 elapsed time = ", time(2)-time(1) | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b3(i) = a**2.0 | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "a**2.0 elapsed time = ", time(2)-time(1) | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b4(i) = a**2.0_dp | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "a**2.0_dp elapsed time = ", time(2)-time(1) | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b5(i) = sqrt(a) | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "sqrt(a) elapsed time = ", time(2)-time(1) | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b6(i) = a**0.5 | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "a**0.5 elapsed time = ", time(2)-time(1) | |
call cpu_time (time(1)) | |
do i = 1, s | |
a = real(i,dp) | |
b7(i) = a**0.5_dp | |
enddo | |
call cpu_time (time(2)) | |
write(*,fmt) "a**0.5_dp elapsed time = ", time(2)-time(1) | |
! to force bx loops computation | |
do i = 1, s | |
if(b1(i) /= b2(i)) stop "error" | |
if(b1(i) /= b3(i)) stop "error" | |
if(b1(i) /= b4(i)) stop "error" | |
if(b5(i) /= b6(i)) stop "error" | |
if(b5(i) /= b7(i)) stop "error" | |
enddo | |
end program test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gfortran 6.2.1 20160830
./pow_timing.x
ifort (IFORT) 17.0.0 20160721
./pow_timing.x