annotate src/fftw-3.3.5/doc/html/FFTW-MPI-Fortran-Interface.html @ 169:223a55898ab9 tip default

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