Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/doc/html/Allocating-aligned-memory-in-Fortran.html @ 82:d0c2a83c1364
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
81:7029a4916348 | 82:d0c2a83c1364 |
---|---|
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: Allocating aligned memory in Fortran</title> | |
26 | |
27 <meta name="description" content="FFTW 3.3.8: Allocating aligned memory in Fortran"> | |
28 <meta name="keywords" content="FFTW 3.3.8: Allocating aligned memory in Fortran"> | |
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="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" rel="up" title="Calling FFTW from Modern Fortran"> | |
37 <link href="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran" rel="next" title="Accessing the wisdom API from Fortran"> | |
38 <link href="Plan-execution-in-Fortran.html#Plan-execution-in-Fortran" rel="prev" title="Plan execution in Fortran"> | |
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="Allocating-aligned-memory-in-Fortran"></a> | |
72 <div class="header"> | |
73 <p> | |
74 Next: <a href="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran" accesskey="n" rel="next">Accessing the wisdom API from Fortran</a>, Previous: <a href="Plan-execution-in-Fortran.html#Plan-execution-in-Fortran" accesskey="p" rel="prev">Plan execution in Fortran</a>, Up: <a href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" accesskey="u" rel="up">Calling FFTW from Modern Fortran</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="Allocating-aligned-memory-in-Fortran-1"></a> | |
78 <h3 class="section">7.5 Allocating aligned memory in Fortran</h3> | |
79 | |
80 <a name="index-alignment-5"></a> | |
81 <a name="index-fftw_005falloc_005freal-5"></a> | |
82 <a name="index-fftw_005falloc_005fcomplex-5"></a> | |
83 <p>In order to obtain maximum performance in FFTW, you should store your | |
84 data in arrays that have been specially aligned in memory (see <a href="SIMD-alignment-and-fftw_005fmalloc.html#SIMD-alignment-and-fftw_005fmalloc">SIMD alignment and fftw_malloc</a>). Enforcing alignment also permits you to | |
85 safely use the new-array execute functions (see <a href="New_002darray-Execute-Functions.html#New_002darray-Execute-Functions">New-array Execute Functions</a>) to apply a given plan to more than one pair of in/out | |
86 arrays. Unfortunately, standard Fortran arrays do <em>not</em> provide | |
87 any alignment guarantees. The <em>only</em> way to allocate aligned | |
88 memory in standard Fortran is to allocate it with an external C | |
89 function, like the <code>fftw_alloc_real</code> and | |
90 <code>fftw_alloc_complex</code> functions. Fortunately, Fortran 2003 provides | |
91 a simple way to associate such allocated memory with a standard Fortran | |
92 array pointer that you can then use normally. | |
93 </p> | |
94 <p>We therefore recommend allocating all your input/output arrays using | |
95 the following technique: | |
96 </p> | |
97 <ol> | |
98 <li> Declare a <code>pointer</code>, <code>arr</code>, to your array of the desired type | |
99 and dimensions. For example, <code>real(C_DOUBLE), pointer :: a(:,:)</code> | |
100 for a 2d real array, or <code>complex(C_DOUBLE_COMPLEX), pointer :: | |
101 a(:,:,:)</code> for a 3d complex array. | |
102 | |
103 </li><li> The number of elements to allocate must be an | |
104 <code>integer(C_SIZE_T)</code>. You can either declare a variable of this | |
105 type, e.g. <code>integer(C_SIZE_T) :: sz</code>, to store the number of | |
106 elements to allocate, or you can use the <code>int(..., C_SIZE_T)</code> | |
107 intrinsic function. e.g. set <code>sz = L * M * N</code> or use | |
108 <code>int(L * M * N, C_SIZE_T)</code> for an L × M × N | |
109 array. | |
110 | |
111 </li><li> Declare a <code>type(C_PTR) :: p</code> to hold the return value from | |
112 FFTW’s allocation routine. Set <code>p = fftw_alloc_real(sz)</code> for a real array, or <code>p = fftw_alloc_complex(sz)</code> for a complex array. | |
113 | |
114 </li><li> <a name="index-c_005ff_005fpointer-2"></a> | |
115 Associate your pointer <code>arr</code> with the allocated memory <code>p</code> | |
116 using the standard <code>c_f_pointer</code> subroutine: <code>call | |
117 c_f_pointer(p, arr, [...dimensions...])</code>, where | |
118 <code>[...dimensions...])</code> are an array of the dimensions of the array | |
119 (in the usual Fortran order). e.g. <code>call c_f_pointer(p, arr, | |
120 [L,M,N])</code> for an L × M × N | |
121 array. (Alternatively, you can | |
122 omit the dimensions argument if you specified the shape explicitly | |
123 when declaring <code>arr</code>.) You can now use <code>arr</code> as a usual | |
124 multidimensional array. | |
125 | |
126 </li><li> When you are done using the array, deallocate the memory by <code>call | |
127 fftw_free(p)</code> on <code>p</code>. | |
128 | |
129 </li></ol> | |
130 | |
131 <p>For example, here is how we would allocate an L × M | |
132 2d real array: | |
133 </p> | |
134 <div class="example"> | |
135 <pre class="example"> real(C_DOUBLE), pointer :: arr(:,:) | |
136 type(C_PTR) :: p | |
137 p = fftw_alloc_real(int(L * M, C_SIZE_T)) | |
138 call c_f_pointer(p, arr, [L,M]) | |
139 <em>...use arr and arr(i,j) as usual...</em> | |
140 call fftw_free(p) | |
141 </pre></div> | |
142 | |
143 <p>and here is an L × M × N | |
144 3d complex array: | |
145 </p> | |
146 <div class="example"> | |
147 <pre class="example"> complex(C_DOUBLE_COMPLEX), pointer :: arr(:,:,:) | |
148 type(C_PTR) :: p | |
149 p = fftw_alloc_complex(int(L * M * N, C_SIZE_T)) | |
150 call c_f_pointer(p, arr, [L,M,N]) | |
151 <em>...use arr and arr(i,j,k) as usual...</em> | |
152 call fftw_free(p) | |
153 </pre></div> | |
154 | |
155 <p>See <a href="Reversing-array-dimensions.html#Reversing-array-dimensions">Reversing array dimensions</a> for an example allocating a | |
156 single array and associating both real and complex array pointers with | |
157 it, for in-place real-to-complex transforms. | |
158 </p> | |
159 <hr> | |
160 <div class="header"> | |
161 <p> | |
162 Next: <a href="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran" accesskey="n" rel="next">Accessing the wisdom API from Fortran</a>, Previous: <a href="Plan-execution-in-Fortran.html#Plan-execution-in-Fortran" accesskey="p" rel="prev">Plan execution in Fortran</a>, Up: <a href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" accesskey="u" rel="up">Calling FFTW from Modern Fortran</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> | |
163 </div> | |
164 | |
165 | |
166 | |
167 </body> | |
168 </html> |