2014-10-03 93 views
3

我目前正試圖在Fortran上運行帶有OpenMP的fftw,但是我在運行任何程序時遇到了一些問題。在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 

這將不勝感激,如果任何人都可以幫助我。

回答

4

舊的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 
+0

現在的工作,非常感謝你!如果多數民衆贊成的話,還有一個問題是,它說我現在應該調用void fftw_plan_with_nthreads(int nthreads);這是否意味着我只是說調用fftw_plan_nthreads(int,nthreads)int和nthreads都被定義爲整型值,非常感謝 – 2014-10-03 11:25:27

+0

不,int nthreads來自C語言,它只是意味着'nnthreads'是一個整數。調用它只需一個數字:'調用fftw_plan_with_nthreads(int(nthreads,c_int))''(參見https://github.com/LadaF/PtilFFT/blob/master/src/fft-inc.f90的底部)。 – 2014-10-03 12:19:17

+0

太棒了,非常感謝。使我的生活大約簡化了一百萬次 – 2014-10-03 12:49:06