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