gFortran & FFTW

Hi All,

I wrote a program in my macbook with Fortran90 that calls FFTW subroutines and I used gfortran to compile it. The program works pretty well, however very often I get random noise in the data (2D file). I tracked the possible origins to the problem and it seems that is something to do with FFTW subroutines.

I had 4.2-20060805 and I thought when I compiled the FFTW library there was some sort of a problem due to gfortran. I updated my gfortran version to 4.3-20070810 and I still get the same kind of random noise. The interesting thing is that when I compiled the code to a SP5-based supercomputer (Bassi @ NERSC) using FFTW library I do not get any kind of noise.

So my question is that if somebody else has come across this kind of problem? Has somebody used FFTW libraries extensively in macs using gfortran as a compiler? What is your take in that?

I guess that I could use vDSP, but then I will have to rewrite part of the code and then portability will also suffer.

Thank you,
Juan Carlos

=========
For the interested people, this is how I implemented the fftw in f90:


subroutine cfftw(mat1,mat2,n1,n2,mode)
use nrtype
implicit none

!Input/Output variables:
integer, intent(in) :: n1,n2,mode
complex(dp), intent(in) :: mat1(n1,n2)
complex(dp), intent(out) :: mat2(n1,n2)
! Work variables:
integer dirn,flg,len,succ
integer (kind=8) plan
complex(dp) :: fac
character (len=10) :: file_name
integer, parameter :: fftw_forward = -1
integer, parameter :: fftw_backward = +1
integer, parameter :: fftw_estimate = 0
integer, parameter :: fftw_measure = 1
integer, parameter :: fftw_use_wisdom = 64

len = n1*n2
if (mode .gt. 0) then
file_name = 'forwardfft'
dirn = fftw_forward
else
file_name = 'backwrdfft'
dirn = fftw_backward
endif
call dfftw_plan_dft_2d(plan, n1, n2, mat1, mat2, dirn, fftw_estimate)
call dfftw_execute(plan)
call dfftw_destroy_plan(plan)

if (mode .gt. 0) then
fac = zone / real(len,dp)
call zscal(len,fac,mat2,1)
endif
end subroutine cfftw

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Is it possible that the

Is it possible that the arrays you are passing in (mat1, mat2) are not properly aligned? I think that data must be 16-byte aligned in order for FFTW to work properly if you are using SSE instructions. See: http://www.tddft.org/trac/octopus/ticket/94

If the arrays are stored on the stack, you can probably force the proper alignment using compiler flags. If the arrays are allocated at run time using ALLOCATE, then it may not be possible to ensure that gfortran is aligning the array properly in 32-bit mode. I think that on 64-bit Intel systems, memory is always 16-byte aligned. On 32-bit Intel systems, memory is always 8-byte aligned, and this may be causing your problem.

Perhaps you can try compiling with -m64 and see if the problem goes away?