annotate fft/fftw/fftw-3.3.4/doc/html/Overview-of-Fortran-interface.html @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 <html lang="en">
Chris@19 2 <head>
Chris@19 3 <title>Overview of Fortran interface - FFTW 3.3.4</title>
Chris@19 4 <meta http-equiv="Content-Type" content="text/html">
Chris@19 5 <meta name="description" content="FFTW 3.3.4">
Chris@19 6 <meta name="generator" content="makeinfo 4.13">
Chris@19 7 <link title="Top" rel="start" href="index.html#Top">
Chris@19 8 <link rel="up" href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" title="Calling FFTW from Modern Fortran">
Chris@19 9 <link rel="prev" href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" title="Calling FFTW from Modern Fortran">
Chris@19 10 <link rel="next" href="Reversing-array-dimensions.html#Reversing-array-dimensions" title="Reversing array dimensions">
Chris@19 11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
Chris@19 12 <!--
Chris@19 13 This manual is for FFTW
Chris@19 14 (version 3.3.4, 20 September 2013).
Chris@19 15
Chris@19 16 Copyright (C) 2003 Matteo Frigo.
Chris@19 17
Chris@19 18 Copyright (C) 2003 Massachusetts Institute of Technology.
Chris@19 19
Chris@19 20 Permission is granted to make and distribute verbatim copies of
Chris@19 21 this manual provided the copyright notice and this permission
Chris@19 22 notice are preserved on all copies.
Chris@19 23
Chris@19 24 Permission is granted to copy and distribute modified versions of
Chris@19 25 this manual under the conditions for verbatim copying, provided
Chris@19 26 that the entire resulting derived work is distributed under the
Chris@19 27 terms of a permission notice identical to this one.
Chris@19 28
Chris@19 29 Permission is granted to copy and distribute translations of this
Chris@19 30 manual into another language, under the above conditions for
Chris@19 31 modified versions, except that this permission notice may be
Chris@19 32 stated in a translation approved by the Free Software Foundation.
Chris@19 33 -->
Chris@19 34 <meta http-equiv="Content-Style-Type" content="text/css">
Chris@19 35 <style type="text/css"><!--
Chris@19 36 pre.display { font-family:inherit }
Chris@19 37 pre.format { font-family:inherit }
Chris@19 38 pre.smalldisplay { font-family:inherit; font-size:smaller }
Chris@19 39 pre.smallformat { font-family:inherit; font-size:smaller }
Chris@19 40 pre.smallexample { font-size:smaller }
Chris@19 41 pre.smalllisp { font-size:smaller }
Chris@19 42 span.sc { font-variant:small-caps }
Chris@19 43 span.roman { font-family:serif; font-weight:normal; }
Chris@19 44 span.sansserif { font-family:sans-serif; font-weight:normal; }
Chris@19 45 --></style>
Chris@19 46 </head>
Chris@19 47 <body>
Chris@19 48 <div class="node">
Chris@19 49 <a name="Overview-of-Fortran-interface"></a>
Chris@19 50 <p>
Chris@19 51 Next:&nbsp;<a rel="next" accesskey="n" href="Reversing-array-dimensions.html#Reversing-array-dimensions">Reversing array dimensions</a>,
Chris@19 52 Previous:&nbsp;<a rel="previous" accesskey="p" href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran">Calling FFTW from Modern Fortran</a>,
Chris@19 53 Up:&nbsp;<a rel="up" accesskey="u" href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran">Calling FFTW from Modern Fortran</a>
Chris@19 54 <hr>
Chris@19 55 </div>
Chris@19 56
Chris@19 57 <h3 class="section">7.1 Overview of Fortran interface</h3>
Chris@19 58
Chris@19 59 <p>FFTW provides a file <code>fftw3.f03</code> that defines Fortran 2003
Chris@19 60 interfaces for all of its C routines, except for the MPI routines
Chris@19 61 described elsewhere, which can be found in the same directory as
Chris@19 62 <code>fftw3.h</code> (the C header file). In any Fortran subroutine where
Chris@19 63 you want to use FFTW functions, you should begin with:
Chris@19 64
Chris@19 65 <p><a name="index-iso_005fc_005fbinding-505"></a>
Chris@19 66 <pre class="example"> use, intrinsic :: iso_c_binding
Chris@19 67 include 'fftw3.f03'
Chris@19 68 </pre>
Chris@19 69 <p>This includes the interface definitions and the standard
Chris@19 70 <code>iso_c_binding</code> module (which defines the equivalents of C
Chris@19 71 types). You can also put the FFTW functions into a module if you
Chris@19 72 prefer (see <a href="Defining-an-FFTW-module.html#Defining-an-FFTW-module">Defining an FFTW module</a>).
Chris@19 73
Chris@19 74 <p>At this point, you can now call anything in the FFTW C interface
Chris@19 75 directly, almost exactly as in C other than minor changes in syntax.
Chris@19 76 For example:
Chris@19 77
Chris@19 78 <p><a name="index-fftw_005fplan_005fdft_005f2d-506"></a><a name="index-fftw_005fexecute_005fdft-507"></a><a name="index-fftw_005fdestroy_005fplan-508"></a>
Chris@19 79 <pre class="example"> type(C_PTR) :: plan
Chris@19 80 complex(C_DOUBLE_COMPLEX), dimension(1024,1000) :: in, out
Chris@19 81 plan = fftw_plan_dft_2d(1000,1024, in,out, FFTW_FORWARD,FFTW_ESTIMATE)
Chris@19 82 ...
Chris@19 83 call fftw_execute_dft(plan, in, out)
Chris@19 84 ...
Chris@19 85 call fftw_destroy_plan(plan)
Chris@19 86 </pre>
Chris@19 87 <p>A few important things to keep in mind are:
Chris@19 88
Chris@19 89 <ul>
Chris@19 90 <li><a name="index-fftw_005fcomplex-509"></a><a name="index-C_005fPTR-510"></a><a name="index-C_005fINT-511"></a><a name="index-C_005fDOUBLE-512"></a><a name="index-C_005fDOUBLE_005fCOMPLEX-513"></a>FFTW plans are <code>type(C_PTR)</code>. Other C types are mapped in the
Chris@19 91 obvious way via the <code>iso_c_binding</code> standard: <code>int</code> turns
Chris@19 92 into <code>integer(C_INT)</code>, <code>fftw_complex</code> turns into
Chris@19 93 <code>complex(C_DOUBLE_COMPLEX)</code>, <code>double</code> turns into
Chris@19 94 <code>real(C_DOUBLE)</code>, and so on. See <a href="FFTW-Fortran-type-reference.html#FFTW-Fortran-type-reference">FFTW Fortran type reference</a>.
Chris@19 95
Chris@19 96 <li>Functions in C become functions in Fortran if they have a return value,
Chris@19 97 and subroutines in Fortran otherwise.
Chris@19 98
Chris@19 99 <li>The ordering of the Fortran array dimensions must be <em>reversed</em>
Chris@19 100 when they are passed to the FFTW plan creation, thanks to differences
Chris@19 101 in array indexing conventions (see <a href="Multi_002ddimensional-Array-Format.html#Multi_002ddimensional-Array-Format">Multi-dimensional Array Format</a>). This is <em>unlike</em> the legacy Fortran interface
Chris@19 102 (see <a href="Fortran_002dinterface-routines.html#Fortran_002dinterface-routines">Fortran-interface routines</a>), which reversed the dimensions
Chris@19 103 for you. See <a href="Reversing-array-dimensions.html#Reversing-array-dimensions">Reversing array dimensions</a>.
Chris@19 104
Chris@19 105 <li><a name="index-alignment-514"></a><a name="index-SIMD-515"></a>Using ordinary Fortran array declarations like this works, but may
Chris@19 106 yield suboptimal performance because the data may not be not aligned
Chris@19 107 to exploit SIMD instructions on modern proessors (see <a href="SIMD-alignment-and-fftw_005fmalloc.html#SIMD-alignment-and-fftw_005fmalloc">SIMD alignment and fftw_malloc</a>). Better performance will often be obtained
Chris@19 108 by allocating with &lsquo;<samp><span class="samp">fftw_alloc</span></samp>&rsquo;. See <a href="Allocating-aligned-memory-in-Fortran.html#Allocating-aligned-memory-in-Fortran">Allocating aligned memory in Fortran</a>.
Chris@19 109
Chris@19 110 <li><a name="index-fftw_005fexecute-516"></a>Similar to the legacy Fortran interface (see <a href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran">FFTW Execution in Fortran</a>), we currently recommend <em>not</em> using <code>fftw_execute</code>
Chris@19 111 but rather using the more specialized functions like
Chris@19 112 <code>fftw_execute_dft</code> (see <a href="New_002darray-Execute-Functions.html#New_002darray-Execute-Functions">New-array Execute Functions</a>).
Chris@19 113 However, you should execute the plan on the <code>same arrays</code> as the
Chris@19 114 ones for which you created the plan, unless you are especially
Chris@19 115 careful. See <a href="Plan-execution-in-Fortran.html#Plan-execution-in-Fortran">Plan execution in Fortran</a>. To prevent
Chris@19 116 you from using <code>fftw_execute</code> by mistake, the <code>fftw3.f03</code>
Chris@19 117 file does not provide an <code>fftw_execute</code> interface declaration.
Chris@19 118
Chris@19 119 <li><a name="index-flags-517"></a>Multiple planner flags are combined with <code>ior</code> (equivalent to &lsquo;<samp><span class="samp">|</span></samp>&rsquo; in C). e.g. <code>FFTW_MEASURE | FFTW_DESTROY_INPUT</code> becomes <code>ior(FFTW_MEASURE, FFTW_DESTROY_INPUT)</code>. (You can also use &lsquo;<samp><span class="samp">+</span></samp>&rsquo; as long as you don't try to include a given flag more than once.)
Chris@19 120
Chris@19 121 </ul>
Chris@19 122
Chris@19 123 <ul class="menu">
Chris@19 124 <li><a accesskey="1" href="Extended-and-quadruple-precision-in-Fortran.html#Extended-and-quadruple-precision-in-Fortran">Extended and quadruple precision in Fortran</a>
Chris@19 125 </ul>
Chris@19 126
Chris@19 127 </body></html>
Chris@19 128