LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 690|回复: 3

编译器性能差距大啊

[复制链接]
发表于 2006-11-30 23:12:15 | 显示全部楼层 |阅读模式
同一个程序,在linux下用Intel Fortran Complier编译后运行时间为4.9s, 然后到windows下用 Visual Fortran 编译后运行,居然要10.2s.
不知道是编译器的问题还是OS的问题
附源码
[php]
program int_sin
implicit none

! Create a value DP that is the "kind" number of a double precision value
! We will use this value in our declarations and constants.
integer, parameter :: DP = kind(0.0D0)

! Declare a named constant for pi, specifying the kind type
real(DP), parameter :: pi = 3.141592653589793238_DP

! Declare interval begin and end
real(DP), parameter :: interval_begin = 0.0_DP
real(DP), parameter :: interval_end   = 2.0_DP * pi

real(DP) :: step, sum, x_i
integer :: N, i, j
real clock_start, clock_finish

write (*,'(A)') "  "
write (*,'(A)') "    Number of    | Computed Integral |"
write (*,'(A)') " Interior Points |                   |"
call cpu_time (clock_start)

do j=2,26
  write (*,'(A)') "--------------------------------------"
  N = 2**j
  ! Compute stepsize for N-1 internal rectangles
  step = (interval_end - interval_begin) / real(N,DP);
  
  ! Approximate 1/2 area in first rectangle: f(x0) * (step/2)
  sum = INTEG_FUNC(interval_begin) * (step / 2.0_DP)
  
  do i=1,N-1
    x_i = real(i,DP) * step
    ! Apply midpoint rule:
    ! Given length = f(x), compute the area of the
    ! rectangle of width step
    sum = sum + (INTEG_FUNC(x_i) * step)
    end do
   
  ! Add approximate area in last rectangle for f(xN) * (step/2)
  sum = sum + (INTEG_FUNC(interval_end) * (step / 2.0_DP))
  
  write (*,'(T5,I10,T18,"|",2X,1P,E14.7,T38,"|")') N, sum
  end do

call cpu_time(clock_finish)
write (*,'(A)') "--------------------------------------"
write (*,'(A)') "  "
write (*,*) "CPU Time = ",(clock_finish - clock_start), " seconds"

contains

! Function to integrate
real(DP) function INTEG_FUNC (x)
real(DP), intent(IN) :: x

INTEG_FUNC = abs(sin(x))
return
end function INTEG_FUNC

end program int_sin
[/php]
发表于 2006-12-1 00:52:58 | 显示全部楼层
这方面也不奇怪,icc 比 gcc 性能优胜也是公认的事实。

Intel 的 compiler 的确难以匹敌!
回复 支持 反对

使用道具 举报

发表于 2006-12-1 05:33:40 | 显示全部楼层
你编译选项不写出来这种比较就毫无意义。
回复 支持 反对

使用道具 举报

发表于 2006-12-1 08:47:43 | 显示全部楼层
现在的gcc4也很厉害,跟icc不相上下。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表