forked from daverio/LATfield2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_fft.dox
127 lines (70 loc) · 4.78 KB
/
examples_fft.dox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*! \example FFTs
This is a simple example of the usage of the FFT wrapper of LATfield2. The wrapper uses the FFTW library to perform 1d serial FFTs. And so FFTW 2 (or higher) need to be installed on the system.
\include fft.cpp
\section fft_compile Compile and Run
Go to the LATfield2/examples folder. and compile this example with e.g. mpic++:
Double precision:
\verbatim
mpic++ -o fft_exec fft.cpp -I../ -DFFT3D -lfftw
\endverbatim
Single precision:
\verbatim
mpic++ -o fft_exec fft.cpp -I../ -DFFT3D -DSINGLE -lfftwf
\endverbatim
It can be executed using (here using "mpirun -np 4" to run with 4 processes):
\verbatim
mpirun -np 4 ./fft_exec -n 2 -m 2
\endverbatim
The executable will not return anything, and the FFT are perform on fields which have not been assigned. It exist just to show the usage of the FFT wrapper of LATfield2.
\section code_IOserver Going through the code
\dontinclude fft.cpp
\subsection latdec_fft Declaration of the lattice in real space.
The lattice in real space is declared as usual.
\skip Lattice
\until Lattice
\subsection r2c_fft Real to Complex (r2c) Fourier transform
First thing to do is to declare the lattice in Fourier space. For a r2c FFT it is done using the initializeRealFFT method of the Lattice class.
\skip Lattice
\line Lattice
\line init
At that point, one should be aware that the lattice in Fourier space does not have the same data distribution in a single process and not the same distribution in the cluster. Indeed the local part of the lattice which is stored in a process is not the same, and the local part have not anymore the same data distribution in the memory. Therefor one should use different site objet for both lattice. For r2c transform, the Fourier space site is the rKSite class.
\line x
\line k
Once both lattice (real and Fourier one) are initialized, one can declare the fields. The PlanFFT class will allocate the needed memory both field and some temporary memory. Therefor the field need to be initialized but not allocated.
For the real field one should use the Real datatype (which is a redefinition of float or double, depending the precision requirement)
\line Field
\line init
For the Fourier field one should use the Imag datatype (which is a redefinition of fftwf_complex or fftw_complex, depending the precision requirement)
\line Field
\line init
Once both field are initialized, the planner can be declared and initialized:
\line Plan
One should notice that the reference of the field has to be passed as the initialization of the planner will allocate the fields.
Then you can perform the Fourier transform using the execute method of the PlanFFT class.
\line execute
\line execute
\subsection c2c_fft Complex to Complex (c2c) Fourier transform
First thing to do is to declare the lattice in Fourier space. For a c2c FFT it is done using the initializeComplexFFT method of the Lattice class.
\skip Lattice
\line Lattice
\line init
At that point, one should be aware that the lattice in Fourier space does not have the same data distribution in a single process and not the same distribution in the cluster. Indeed the local part of the lattice which is stored in a process is not the same, and the local part have not anymore the same data distribution in the memory. Therefor one should use different site objet for both lattice. For c2c transform, the Fourier space site is the cKSite class.
\line x
\line k
Once both lattice (real and Fourier one) are initialized, one can declare the fields. The PlanFFT class will allocate the needed memory both field and some temporary memory. Therefor the field need to be initialized but not allocated.
For both the real and the fourier fields one should use the Imag datatype (which is a redefinition of fftwf_complex or fftw_complex, depending the precision requirement)
\line Field
\line init
\line Field
\line init
Once both fields are initialized, the planner can be declared and initialized:
\line Plan
One should notice that the reference of the fields has to be passed as the initialization of the planner will allocate the field.
Then you can perform the fourier transform using the execute method of the PlanFFT class.
\line execute
\line execute
\subsection Additional important points
One should notice that the wrapper is based on the FFTW library, more precisely the 1d serial transform of FFTW. Therefore to know exactly what is computed the best is to refer to the FFTW documentation and look at the 1d version of FFTW.
http://www.fftw.org/doc/What-FFTW-Really-Computes.html
Secondly, one should notice that FFTW forward methods will return a result which have been multiply by the size of the array. Therefor, to have the correct result once should divide by Lattice.sites() the result given by the wrapper. This is not done within the wrapper to return the same result as FFTW.
*/