Using openmp and fftw for fortran
I am currently trying to run fftw
using OpenMP on Fortran, but I am having problems running any programs.
I'm pretty sure I installed / configured fftw correctly:
./configure --enable-openmp --enable-threads
and I seem to have all the correct libraries and files, but I cannot run any program, I keep getting the error
undefined reference to 'fftw_init_threads'
The code I'm using 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 run it i do
gfortran trial.f90 -I/home/files/include -L/home/files/lib -lfftw3_omp -lfftw3 -lm -fopenmp
It would be very helpful if someone could help me.
+3
source to share
1 answer
The old FORTRAN interface doesn't seem to support OpenMP ... I suggest you take advantage of the new Fortran 2003 interface. Note that fftw_init_threads()
is a function!
You also need to enable the module 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
+4
source to share