Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 830
weddle_32 Avatar asked Oct 17 '25 11:10

weddle_32


1 Answers

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
like image 85
Alexander Vogt Avatar answered Oct 20 '25 08:10

Alexander Vogt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!