PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

Thread safe FFTW

Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message

Joined: 17 Jan 2013
Posts: 9

PostPosted: Thu Apr 25, 2013 4:58 am    Post subject: Thread safe FFTW Reply with quote


I am attempting to incorporate a layer of OpenMP code within an MPI program.
Unfortunately I seem to be falling foul of thread safety when attempting to perform FFTs within the OpenMP threads.

I am fairly convinced that thread safety is the issue as the code executes without issue if the call to dfftw_execute_dft is performed within an omp critical region but fails in parallel with a double free or corruption error.

As far as I can tell the code is structured in the manner advised by the fftw documentation: The plan is generated before the OpenMP region is created and dfftw_execute_dft is supposed to be a thread safe routine for executing the FFTs.

I have attempted to use the FFTW_UNALIGNED flag as specified in a post that describes a very similar problem on: with no joy.

Before I resort to changing the manner in which the workload is distributed I wondered of there may be anything I missed?

Thanks in advance,

Back to top
View user's profile

Joined: 30 Jun 2004
Posts: 6691
Location: The Portland Group Inc.

PostPosted: Mon Apr 29, 2013 1:28 pm    Post subject: Reply with quote

Hi Karl,

I'm not sure. Using the sample code in the link you reference, if I move the create and destroy plan calls outside the OpenMP region, the code runs correctly. I did make the mistake of forgetting to move the "plan_r2c" out of the private clause which caused a segv, but was find once made shared. Could this be your issue as well?

- Mat

% cat main.F
program main
implicit none
#include ""
integer nx,ny
double precision val(nx,ny)
double precision tp(nx), tf(nx)
integer i,j,k
real*8 deltax,rlenx
real*8 pi,amp

integer*8 plan_r2c
integer tid,OMP_GET_THREAD_NUM

! write(*,*)'rlenx:',rlenx


do j=1,ny
do i=1,nx
call dfftw_plan_dft_r2c_1d(plan_r2c,nx,tp,tf,FFTW_MEASURE)


!omp parallel do private(tid,k,plan_r2c,tp,tf)
!$omp parallel do private(tid,k,tp,tf)
!omp parallel do default(private)
do k =1,ny
write(*,*) 'Thread ID = ', tid, ' Loop # = ', k

do i=1,nx

!call dfftw_plan_dft_r2c_1d(plan_r2c,nx,tp,tf,FFTW_MEASURE)
call dfftw_execute(plan_r2c)
!call dfftw_destroy_plan(plan_r2c)

write(*,*) 'plan_r2c = ', plan_r2c

call dfftw_destroy_plan(plan_r2c)

% pgf90 main.F -Mfree -L/local/home/colgrove/fftw/lib -lfftw3 -g -mp
% setenv OMP_NUM_THREADS 4
% a.out
 Thread ID =             0  Loop # =             1
 Thread ID =             2  Loop # =             5
 plan_r2c =                   8760496
 Thread ID =             0  Loop # =             2
 plan_r2c =                   8760496
 Thread ID =             2  Loop # =             6
 Thread ID =             3  Loop # =             7
 plan_r2c =                   8760496
 plan_r2c =                   8760496
 plan_r2c =                   8760496
 Thread ID =             3  Loop # =             8
 plan_r2c =                   8760496
 Thread ID =             1  Loop # =             3
 plan_r2c =                   8760496
 Thread ID =             1  Loop # =             4
 plan_r2c =                   8760496
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © phpBB Group