Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.5/doc/html/Allocating-aligned-memory-in-Fortran.html @ 127:7867fa7e1b6b
Current fftw source
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 18 Oct 2016 13:40:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
126:4a7071416412 | 127:7867fa7e1b6b |
---|---|
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.5, 30 July 2016). | |
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 5.2, http://www.gnu.org/software/texinfo/ --> | |
24 <head> | |
25 <title>FFTW 3.3.5: Allocating aligned memory in Fortran</title> | |
26 | |
27 <meta name="description" content="FFTW 3.3.5: Allocating aligned memory in Fortran"> | |
28 <meta name="keywords" content="FFTW 3.3.5: 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.smallquotation {font-size: smaller} | |
43 div.display {margin-left: 3.2em} | |
44 div.example {margin-left: 3.2em} | |
45 div.indentedblock {margin-left: 3.2em} | |
46 div.lisp {margin-left: 3.2em} | |
47 div.smalldisplay {margin-left: 3.2em} | |
48 div.smallexample {margin-left: 3.2em} | |
49 div.smallindentedblock {margin-left: 3.2em; font-size: smaller} | |
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.nocodebreak {white-space:nowrap} | |
61 span.nolinebreak {white-space:nowrap} | |
62 span.roman {font-family:serif; font-weight:normal} | |
63 span.sansserif {font-family:sans-serif; font-weight:normal} | |
64 ul.no-bullet {list-style: none} | |
65 --> | |
66 </style> | |
67 | |
68 | |
69 </head> | |
70 | |
71 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> | |
72 <a name="Allocating-aligned-memory-in-Fortran"></a> | |
73 <div class="header"> | |
74 <p> | |
75 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> | |
76 </div> | |
77 <hr> | |
78 <a name="Allocating-aligned-memory-in-Fortran-1"></a> | |
79 <h3 class="section">7.5 Allocating aligned memory in Fortran</h3> | |
80 | |
81 <a name="index-alignment-5"></a> | |
82 <a name="index-fftw_005falloc_005freal-5"></a> | |
83 <a name="index-fftw_005falloc_005fcomplex-5"></a> | |
84 <p>In order to obtain maximum performance in FFTW, you should store your | |
85 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 | |
86 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 | |
87 arrays. Unfortunately, standard Fortran arrays do <em>not</em> provide | |
88 any alignment guarantees. The <em>only</em> way to allocate aligned | |
89 memory in standard Fortran is to allocate it with an external C | |
90 function, like the <code>fftw_alloc_real</code> and | |
91 <code>fftw_alloc_complex</code> functions. Fortunately, Fortran 2003 provides | |
92 a simple way to associate such allocated memory with a standard Fortran | |
93 array pointer that you can then use normally. | |
94 </p> | |
95 <p>We therefore recommend allocating all your input/output arrays using | |
96 the following technique: | |
97 </p> | |
98 <ol> | |
99 <li> Declare a <code>pointer</code>, <code>arr</code>, to your array of the desired type | |
100 and dimensions. For example, <code>real(C_DOUBLE), pointer :: a(:,:)</code> | |
101 for a 2d real array, or <code>complex(C_DOUBLE_COMPLEX), pointer :: | |
102 a(:,:,:)</code> for a 3d complex array. | |
103 | |
104 </li><li> The number of elements to allocate must be an | |
105 <code>integer(C_SIZE_T)</code>. You can either declare a variable of this | |
106 type, e.g. <code>integer(C_SIZE_T) :: sz</code>, to store the number of | |
107 elements to allocate, or you can use the <code>int(..., C_SIZE_T)</code> | |
108 intrinsic function. e.g. set <code>sz = L * M * N</code> or use | |
109 <code>int(L * M * N, C_SIZE_T)</code> for an L × M × N 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 array. (Alternatively, you can | |
121 omit the dimensions argument if you specified the shape explicitly | |
122 when declaring <code>arr</code>.) You can now use <code>arr</code> as a usual | |
123 multidimensional array. | |
124 | |
125 </li><li> When you are done using the array, deallocate the memory by <code>call | |
126 fftw_free(p)</code> on <code>p</code>. | |
127 | |
128 </li></ol> | |
129 | |
130 <p>For example, here is how we would allocate an L × M 2d real array: | |
131 </p> | |
132 <div class="example"> | |
133 <pre class="example"> real(C_DOUBLE), pointer :: arr(:,:) | |
134 type(C_PTR) :: p | |
135 p = fftw_alloc_real(int(L * M, C_SIZE_T)) | |
136 call c_f_pointer(p, arr, [L,M]) | |
137 <em>...use arr and arr(i,j) as usual...</em> | |
138 call fftw_free(p) | |
139 </pre></div> | |
140 | |
141 <p>and here is an L × M × N 3d complex array: | |
142 </p> | |
143 <div class="example"> | |
144 <pre class="example"> complex(C_DOUBLE_COMPLEX), pointer :: arr(:,:,:) | |
145 type(C_PTR) :: p | |
146 p = fftw_alloc_complex(int(L * M * N, C_SIZE_T)) | |
147 call c_f_pointer(p, arr, [L,M,N]) | |
148 <em>...use arr and arr(i,j,k) as usual...</em> | |
149 call fftw_free(p) | |
150 </pre></div> | |
151 | |
152 <p>See <a href="Reversing-array-dimensions.html#Reversing-array-dimensions">Reversing array dimensions</a> for an example allocating a | |
153 single array and associating both real and complex array pointers with | |
154 it, for in-place real-to-complex transforms. | |
155 </p> | |
156 <hr> | |
157 <div class="header"> | |
158 <p> | |
159 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> | |
160 </div> | |
161 | |
162 | |
163 | |
164 </body> | |
165 </html> |