Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/doc/html/FFTW-MPI-Fortran-Interface.html @ 167:bd3cc4d1df30
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
166:cbd6d7e562c7 | 167:bd3cc4d1df30 |
---|---|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
2 <html> | |
3 <!-- This manual is for FFTW | |
4 (version 3.3.8, 24 May 2018). | |
5 | |
6 Copyright (C) 2003 Matteo Frigo. | |
7 | |
8 Copyright (C) 2003 Massachusetts Institute of Technology. | |
9 | |
10 Permission is granted to make and distribute verbatim copies of this | |
11 manual provided the copyright notice and this permission notice are | |
12 preserved on all copies. | |
13 | |
14 Permission is granted to copy and distribute modified versions of this | |
15 manual under the conditions for verbatim copying, provided that the | |
16 entire resulting derived work is distributed under the terms of a | |
17 permission notice identical to this one. | |
18 | |
19 Permission is granted to copy and distribute translations of this manual | |
20 into another language, under the above conditions for modified versions, | |
21 except that this permission notice may be stated in a translation | |
22 approved by the Free Software Foundation. --> | |
23 <!-- Created by GNU Texinfo 6.3, http://www.gnu.org/software/texinfo/ --> | |
24 <head> | |
25 <title>FFTW 3.3.8: FFTW MPI Fortran Interface</title> | |
26 | |
27 <meta name="description" content="FFTW 3.3.8: FFTW MPI Fortran Interface"> | |
28 <meta name="keywords" content="FFTW 3.3.8: FFTW MPI Fortran Interface"> | |
29 <meta name="resource-type" content="document"> | |
30 <meta name="distribution" content="global"> | |
31 <meta name="Generator" content="makeinfo"> | |
32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
33 <link href="index.html#Top" rel="start" title="Top"> | |
34 <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> | |
35 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> | |
36 <link href="Distributed_002dmemory-FFTW-with-MPI.html#Distributed_002dmemory-FFTW-with-MPI" rel="up" title="Distributed-memory FFTW with MPI"> | |
37 <link href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" rel="next" title="Calling FFTW from Modern Fortran"> | |
38 <link href="MPI-Wisdom-Communication.html#MPI-Wisdom-Communication" rel="prev" title="MPI Wisdom Communication"> | |
39 <style type="text/css"> | |
40 <!-- | |
41 a.summary-letter {text-decoration: none} | |
42 blockquote.indentedblock {margin-right: 0em} | |
43 blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} | |
44 blockquote.smallquotation {font-size: smaller} | |
45 div.display {margin-left: 3.2em} | |
46 div.example {margin-left: 3.2em} | |
47 div.lisp {margin-left: 3.2em} | |
48 div.smalldisplay {margin-left: 3.2em} | |
49 div.smallexample {margin-left: 3.2em} | |
50 div.smalllisp {margin-left: 3.2em} | |
51 kbd {font-style: oblique} | |
52 pre.display {font-family: inherit} | |
53 pre.format {font-family: inherit} | |
54 pre.menu-comment {font-family: serif} | |
55 pre.menu-preformatted {font-family: serif} | |
56 pre.smalldisplay {font-family: inherit; font-size: smaller} | |
57 pre.smallexample {font-size: smaller} | |
58 pre.smallformat {font-family: inherit; font-size: smaller} | |
59 pre.smalllisp {font-size: smaller} | |
60 span.nolinebreak {white-space: nowrap} | |
61 span.roman {font-family: initial; font-weight: normal} | |
62 span.sansserif {font-family: sans-serif; font-weight: normal} | |
63 ul.no-bullet {list-style: none} | |
64 --> | |
65 </style> | |
66 | |
67 | |
68 </head> | |
69 | |
70 <body lang="en"> | |
71 <a name="FFTW-MPI-Fortran-Interface"></a> | |
72 <div class="header"> | |
73 <p> | |
74 Previous: <a href="FFTW-MPI-Reference.html#FFTW-MPI-Reference" accesskey="p" rel="prev">FFTW MPI Reference</a>, Up: <a href="Distributed_002dmemory-FFTW-with-MPI.html#Distributed_002dmemory-FFTW-with-MPI" accesskey="u" rel="up">Distributed-memory FFTW with MPI</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> | |
75 </div> | |
76 <hr> | |
77 <a name="FFTW-MPI-Fortran-Interface-1"></a> | |
78 <h3 class="section">6.13 FFTW MPI Fortran Interface</h3> | |
79 <a name="index-Fortran-interface-1"></a> | |
80 | |
81 <a name="index-iso_005fc_005fbinding"></a> | |
82 <p>The FFTW MPI interface is callable from modern Fortran compilers | |
83 supporting the Fortran 2003 <code>iso_c_binding</code> standard for calling | |
84 C functions. As described in <a href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran">Calling FFTW from Modern Fortran</a>, | |
85 this means that you can directly call FFTW’s C interface from Fortran | |
86 with only minor changes in syntax. There are, however, a few things | |
87 specific to the MPI interface to keep in mind: | |
88 </p> | |
89 <ul> | |
90 <li> Instead of including <code>fftw3.f03</code> as in <a href="Overview-of-Fortran-interface.html#Overview-of-Fortran-interface">Overview of Fortran interface</a>, you should <code>include 'fftw3-mpi.f03'</code> (after | |
91 <code>use, intrinsic :: iso_c_binding</code> as before). The | |
92 <code>fftw3-mpi.f03</code> file includes <code>fftw3.f03</code>, so you should | |
93 <em>not</em> <code>include</code> them both yourself. (You will also want to | |
94 include the MPI header file, usually via <code>include 'mpif.h'</code> or | |
95 similar, although though this is not needed by <code>fftw3-mpi.f03</code> | |
96 <i>per se</i>.) (To use the ‘<samp>fftwl_</samp>’ <code>long double</code> extended-precision routines in supporting compilers, you should include <code>fftw3f-mpi.f03</code> in <em>addition</em> to <code>fftw3-mpi.f03</code>. See <a href="Extended-and-quadruple-precision-in-Fortran.html#Extended-and-quadruple-precision-in-Fortran">Extended and quadruple precision in Fortran</a>.) | |
97 | |
98 </li><li> Because of the different storage conventions between C and Fortran, | |
99 you reverse the order of your array dimensions when passing them to | |
100 FFTW (see <a href="Reversing-array-dimensions.html#Reversing-array-dimensions">Reversing array dimensions</a>). This is merely a | |
101 difference in notation and incurs no performance overhead. However, | |
102 it means that, whereas in C the <em>first</em> dimension is distributed, | |
103 in Fortran the <em>last</em> dimension of your array is distributed. | |
104 | |
105 </li><li> <a name="index-MPI-communicator-3"></a> | |
106 In Fortran, communicators are stored as <code>integer</code> types; there is | |
107 no <code>MPI_Comm</code> type, nor is there any way to access a C | |
108 <code>MPI_Comm</code>. Fortunately, this is taken care of for you by the | |
109 FFTW Fortran interface: whenever the C interface expects an | |
110 <code>MPI_Comm</code> type, you should pass the Fortran communicator as an | |
111 <code>integer</code>.<a name="DOCF8" href="#FOOT8"><sup>8</sup></a> | |
112 | |
113 </li><li> Because you need to call the ‘<samp>local_size</samp>’ function to find out | |
114 how much space to allocate, and this may be <em>larger</em> than the | |
115 local portion of the array (see <a href="MPI-Data-Distribution.html#MPI-Data-Distribution">MPI Data Distribution</a>), you should | |
116 <em>always</em> allocate your arrays dynamically using FFTW’s allocation | |
117 routines as described in <a href="Allocating-aligned-memory-in-Fortran.html#Allocating-aligned-memory-in-Fortran">Allocating aligned memory in Fortran</a>. | |
118 (Coincidentally, this also provides the best performance by | |
119 guaranteeding proper data alignment.) | |
120 | |
121 </li><li> Because all sizes in the MPI FFTW interface are declared as | |
122 <code>ptrdiff_t</code> in C, you should use <code>integer(C_INTPTR_T)</code> in | |
123 Fortran (see <a href="FFTW-Fortran-type-reference.html#FFTW-Fortran-type-reference">FFTW Fortran type reference</a>). | |
124 | |
125 </li><li> <a name="index-fftw_005fexecute_005fdft-1"></a> | |
126 <a name="index-fftw_005fmpi_005fexecute_005fdft-1"></a> | |
127 <a name="index-new_002darray-execution-3"></a> | |
128 In Fortran, because of the language semantics, we generally recommend | |
129 using the new-array execute functions for all plans, even in the | |
130 common case where you are executing the plan on the same arrays for | |
131 which the plan was created (see <a href="Plan-execution-in-Fortran.html#Plan-execution-in-Fortran">Plan execution in Fortran</a>). | |
132 However, note that in the MPI interface these functions are changed: | |
133 <code>fftw_execute_dft</code> becomes <code>fftw_mpi_execute_dft</code>, | |
134 etcetera. See <a href="Using-MPI-Plans.html#Using-MPI-Plans">Using MPI Plans</a>. | |
135 | |
136 </li></ul> | |
137 | |
138 <p>For example, here is a Fortran code snippet to perform a distributed | |
139 L × M | |
140 complex DFT in-place. (This assumes you have already | |
141 initialized MPI with <code>MPI_init</code> and have also performed | |
142 <code>call fftw_mpi_init</code>.) | |
143 </p> | |
144 <div class="example"> | |
145 <pre class="example"> use, intrinsic :: iso_c_binding | |
146 include 'fftw3-mpi.f03' | |
147 integer(C_INTPTR_T), parameter :: L = ... | |
148 integer(C_INTPTR_T), parameter :: M = ... | |
149 type(C_PTR) :: plan, cdata | |
150 complex(C_DOUBLE_COMPLEX), pointer :: data(:,:) | |
151 integer(C_INTPTR_T) :: i, j, alloc_local, local_M, local_j_offset | |
152 | |
153 ! <span class="roman">get local data size and allocate (note dimension reversal)</span> | |
154 alloc_local = fftw_mpi_local_size_2d(M, L, MPI_COMM_WORLD, & | |
155 local_M, local_j_offset) | |
156 cdata = fftw_alloc_complex(alloc_local) | |
157 call c_f_pointer(cdata, data, [L,local_M]) | |
158 | |
159 ! <span class="roman">create MPI plan for in-place forward DFT (note dimension reversal)</span> | |
160 plan = fftw_mpi_plan_dft_2d(M, L, data, data, MPI_COMM_WORLD, & | |
161 FFTW_FORWARD, FFTW_MEASURE) | |
162 | |
163 ! <span class="roman">initialize data to some function</span> my_function(i,j) | |
164 do j = 1, local_M | |
165 do i = 1, L | |
166 data(i, j) = my_function(i, j + local_j_offset) | |
167 end do | |
168 end do | |
169 | |
170 ! <span class="roman">compute transform (as many times as desired)</span> | |
171 call fftw_mpi_execute_dft(plan, data, data) | |
172 | |
173 call fftw_destroy_plan(plan) | |
174 call fftw_free(cdata) | |
175 </pre></div> | |
176 | |
177 <p>Note that when we called <code>fftw_mpi_local_size_2d</code> and | |
178 <code>fftw_mpi_plan_dft_2d</code> with the dimensions in reversed order, | |
179 since a L × M | |
180 Fortran array is viewed by FFTW in C as a | |
181 M × L | |
182 array. This means that the array was distributed over | |
183 the <code>M</code> dimension, the local portion of which is a | |
184 L × local_M | |
185 array in Fortran. (You must <em>not</em> use an | |
186 <code>allocate</code> statement to allocate an L × local_M | |
187 array, | |
188 however; you must allocate <code>alloc_local</code> complex numbers, which | |
189 may be greater than <code>L * local_M</code>, in order to reserve space for | |
190 intermediate steps of the transform.) Finally, we mention that | |
191 because C’s array indices are zero-based, the <code>local_j_offset</code> | |
192 argument can conveniently be interpreted as an offset in the 1-based | |
193 <code>j</code> index (rather than as a starting index as in C). | |
194 </p> | |
195 <p>If instead you had used the <code>ior(FFTW_MEASURE, | |
196 FFTW_MPI_TRANSPOSED_OUT)</code> flag, the output of the transform would be a | |
197 transposed M × local_L | |
198 array, associated with the <em>same</em> | |
199 <code>cdata</code> allocation (since the transform is in-place), and which | |
200 you could declare with: | |
201 </p> | |
202 <div class="example"> | |
203 <pre class="example"> complex(C_DOUBLE_COMPLEX), pointer :: tdata(:,:) | |
204 ... | |
205 call c_f_pointer(cdata, tdata, [M,local_L]) | |
206 </pre></div> | |
207 | |
208 <p>where <code>local_L</code> would have been obtained by changing the | |
209 <code>fftw_mpi_local_size_2d</code> call to: | |
210 </p> | |
211 <div class="example"> | |
212 <pre class="example"> alloc_local = fftw_mpi_local_size_2d_transposed(M, L, MPI_COMM_WORLD, & | |
213 local_M, local_j_offset, local_L, local_i_offset) | |
214 </pre></div> | |
215 <div class="footnote"> | |
216 <hr> | |
217 <h4 class="footnotes-heading">Footnotes</h4> | |
218 | |
219 <h3><a name="FOOT8" href="#DOCF8">(8)</a></h3> | |
220 <p>Technically, this is because you aren’t | |
221 actually calling the C functions directly. You are calling wrapper | |
222 functions that translate the communicator with <code>MPI_Comm_f2c</code> | |
223 before calling the ordinary C interface. This is all done | |
224 transparently, however, since the <code>fftw3-mpi.f03</code> interface file | |
225 renames the wrappers so that they are called in Fortran with the same | |
226 names as the C interface functions.</p> | |
227 </div> | |
228 <hr> | |
229 <div class="header"> | |
230 <p> | |
231 Previous: <a href="FFTW-MPI-Reference.html#FFTW-MPI-Reference" accesskey="p" rel="prev">FFTW MPI Reference</a>, Up: <a href="Distributed_002dmemory-FFTW-with-MPI.html#Distributed_002dmemory-FFTW-with-MPI" accesskey="u" rel="up">Distributed-memory FFTW with MPI</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> | |
232 </div> | |
233 | |
234 | |
235 | |
236 </body> | |
237 </html> |