简体   繁体   中英

Using openmp and fftw on fortran

I am currently trying to run fftw with OpenMP on Fortran but I am having some problems running any programs.

I believe I have installed/configured fftw correctly:

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

and I seem to have all the correct libraries and files but i cannot get any program to run, I keep getting the error

undefined reference to 'fftw_init_threads'

The code I use is below:

  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

and to run it I do

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

It would be greatly appreciated, if anyone could help me.

The old FORTRAN interface seems not to support OpenMP... I suggest you take the new Fortran 2003 interface. Please note that fftw_init_threads() is a function!

You also need to include the ISO_C_binding module:

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM