Chris@19: Chris@19:
Chris@19:Chris@19: Next: Allocating aligned memory in Fortran, Chris@19: Previous: FFTW Fortran type reference, Chris@19: Up: Calling FFTW from Modern Fortran Chris@19:
In C, in order to use a plan, one normally calls fftw_execute
,
Chris@19: which executes the plan to perform the transform on the input/output
Chris@19: arrays passed when the plan was created (see Using Plans). The
Chris@19: corresponding subroutine call in modern Fortran is:
Chris@19:
call fftw_execute(plan) Chris@19:Chris@19:
Chris@19: However, we have had reports that this causes problems with some
Chris@19: recent optimizing Fortran compilers. The problem is, because the
Chris@19: input/output arrays are not passed as explicit arguments to
Chris@19: fftw_execute
, the semantics of Fortran (unlike C) allow the
Chris@19: compiler to assume that the input/output arrays are not changed by
Chris@19: fftw_execute
. As a consequence, certain compilers end up
Chris@19: repositioning the call to fftw_execute
, assuming incorrectly
Chris@19: that it does nothing to the arrays.
Chris@19:
Chris@19:
There are various workarounds to this, but the safest and simplest
Chris@19: thing is to not use fftw_execute
in Fortran. Instead, use the
Chris@19: functions described in New-array Execute Functions, which take
Chris@19: the input/output arrays as explicit arguments. For example, if the
Chris@19: plan is for a complex-data DFT and was created for the arrays
Chris@19: in
and out
, you would do:
Chris@19:
call fftw_execute_dft(plan, in, out) Chris@19:Chris@19:
Chris@19: There are a few things to be careful of, however: Chris@19: Chris@19:
fftw_execute_dft
, Real-input (r2c) DFT plans should use use
Chris@19: fftw_execute_dft_r2c
, and real-output (c2r) DFT plans should
Chris@19: use fftw_execute_dft_c2r
. The various r2r plans should use
Chris@19: fftw_execute_r2r
. Fortunately, if you use the wrong one you
Chris@19: will get a compile-time type-mismatch error (unlike legacy Fortran).
Chris@19:
Chris@19: FFTW_UNALIGNED
flag when creating the
Chris@19: plan, in which case the plan does not depend on the alignment, but
Chris@19: this may sacrifice substantial performance on architectures (like x86)
Chris@19: with SIMD instructions (see SIMD alignment and fftw_malloc).
Chris@19:
Chris@19: