怎样提高调用数学函数的程序的性能

来源:计算机等级考试    发布时间:2012-08-29    计算机等级考试视频    评论


  附录 3 – 驱动器程序
  下面是一个用于计时 DFT 代码的 Fortran 驱动器程序。
  program main
  interface
  subroutine dft(x,a,phi,n)
  real*8 x(n),a(n),phi(n)
  integer n
  end subroutine
  subroutine init(a,n)
  real*8 a(n)
  integer n
  end subroutine
  subroutine consume(a,b,c)
  real*8 a(*),b(*),c(*)
  end subroutine
  end interface
  ! Parameters:
  !  nmax is the problem size.
  !  nrep is the number of repetitions of the
  !   problem. This should be chosen so that
  !   the elapsed time is long enough to give
  !   sufficient timing resolution.
  !  cyc is the clock frequency in Hz for the
  !   processor that the program is to be run on.
  !   (Can be found from AIX command pmcycles.)
  integer, parameter :: nmax=1000
  integer, parameter :: nrep=100
  real*8, parameter :: cyc=4704000000.d0
  real*8 x(nmax), a(nmax), phi(nmax)
  real*8 tx, ty, accum, del(4)
  intrinsic sin, sqrt
  real*8 rtc
  del(4)=0.d0
  acc = 0.d0
  do k=1,nrep
  tx=rtc()
  call init(x,nmax)
  call dft(x,a,phi,nmax)
  ty=rtc()
  call consume(x,a,phi)
  do j=1,nmax
  acc = acc + a(j) + phi(j)
  end do
  del(4) = del(4) + (ty-tx)
  end do
  del(1) = del(4)/real(nmax,8)
  del(2) = del(1)/real(nrep,8)
  del(3) = cyc*del(2)
  print *,'acc=',acc/real(nrep,8),' n=',nmax,
  &  ' r=',nrep, ' a=',del(1),' b=',del(2),
  &  ' c=',del(3),' w=',del(4)
  end program
  声明
  获得的精确性可能会随着使用处理器的模型及其配置而发生变化,同时依赖的因素还有所用汇编器的版本。因此,在不同的操作条件下您将获得不同的使用经验。

  推荐:

  Int64与Currency

  更多相关资料:

  考试大教育全国计算机等级考试在线测试平台

  2010年9月全国计算机等级考试各科模拟试题冲刺

  全国计算机等级考试论坛

上一页234下一页

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答