【问题标题】:Using openmp and fftw on fortran在 fortran 上使用 openmp 和 fftw
【发布时间】:2014-11-28 10:21:31
【问题描述】:

我目前正在尝试在 Fortran 上使用 OpenMP 运行 fftw,但我在运行任何程序时遇到了一些问题。

我相信我已经正确安装/配置了 fftw:

./configure --enable-openmp --enable-threads

我似乎拥有所有正确的库和文件,但我无法运行任何程序,我不断收到错误

undefined reference to 'fftw_init_threads'

我使用的代码如下:

  program trial
    use omp_lib
    implicit none
    include "fftw3.f"
    integer :: id, nthreads, void
    integer :: error

    call fftw_init_threads(void)

    !$omp parallel private(id)
    id = omp_get_thread_num()
    write (*,*) 'Hello World from thread', id
    !$omp barrier

    if ( id == 0 ) then
      nthreads = omp_get_num_threads()
      write (*,*) 'There are', nthreads, 'threads'
    end if

    !$omp end parallel
  end program

我会运行它

gfortran trial.f90 -I/home/files/include -L/home/files/lib -lfftw3_omp -lfftw3 -lm -fopenmp

如果有人可以帮助我,将不胜感激。

【问题讨论】:

    标签: fortran openmp fftw


    【解决方案1】:

    旧的 FORTRAN 界面似乎不支持 OpenMP... 我建议您使用新的 Fortran 2003 界面。请注意fftw_init_threads() 是一个函数!

    您还需要包含ISO_C_binding 模块:

      program trial
        use,intrinsic :: ISO_C_binding
        use omp_lib
        implicit none
        include "fftw3.f03"
        integer :: id, nthreads, void
        integer :: error
    
        void = fftw_init_threads()
    
        !$omp parallel private(id)
        id = omp_get_thread_num()
        write (*,*) 'Hello World from thread', id
        !$omp barrier
    
        if ( id == 0 ) then
          nthreads = omp_get_num_threads()
          write (*,*) 'There are', nthreads, 'threads'
        end if
    
        !$omp end parallel
      end program
    

    【讨论】:

    • 正在工作,非常感谢!!如果没问题,我还有一个问题是它说我现在应该调用 void fftw_plan_with_nthreads(int nthreads);这是否意味着我只是说调用 fftw_plan_nthreads(int,nthreads) 其中 int 和 nthreads 都定义为整数值,非常感谢
    • 不,int nthreads 来自 C 语言,它只是意味着 nthreads 是一个整数。只需一个号码即可拨打电话:call fftw_plan_with_nthreads(int(nthreads,c_int))(见底部github.com/LadaF/PoisFFT/blob/master/src/fft-inc.f90)。
    • 太棒了,非常感谢。让我的生活轻松了一百万倍
    猜你喜欢
    • 2018-11-18
    • 2017-10-22
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    相关资源
    最近更新 更多