Repository navigation
Expand file tree
/
Copy pathmodmfft1.f90
More file actions
220 lines (220 loc) · 6.89 KB
/
Copy pathmodmfft1.f90
File metadata and controls
220 lines (220 loc) · 6.89 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
!-----------------------------------------------------------------------
!
module mfft1
!
! Fortran90 wrappers to 1d OpenMP PIC library libmfft1.f
! mfft1_init calculates tables needed by 1d FFTs
! calls WFFT1RINIT
! mfft1r wrapper function for in place scalar 1d real/complex FFT
! calls FFT1RXX
! mfft1rn wrapper function for in place vector 1d real/complex FFT
! calls FFT1R2X or FFT1R3X
! mfft1cr wrapper function for scalar 1d complex to real FFT
! calls FFT1RXX
! mfft1crn wrapper function for vector 1d complex to real FFT
! calls FFT1R2X or FFT1R3X
! written by viktor k. decyk, ucla
! copyright 2016, regents of the university of california
! update: january 9, 2017
!
use libmfft1_h
implicit none
!
! t = scratch array for mfft1rn
complex, dimension(:), allocatable :: t
integer :: szt = 0
save
!
private :: t, szt
!
contains
!
!-----------------------------------------------------------------------
subroutine mfft1_init(mixup,sct,indx)
! calculates tables needed by 1d FFTs
implicit none
integer, intent(in) :: indx
integer, dimension(:), intent(inout) :: mixup
complex, dimension(:), intent(inout) :: sct
! local data
integer :: nxhd
! extract dimensions
nxhd = size(mixup,1)
! call low level procedure
call WFFT1RINIT(mixup,sct,indx,nxhd)
end subroutine
!
!-----------------------------------------------------------------------
subroutine mfft1r(f,isign,mixup,sct,tfft,indx)
! wrapper function for scalar 1d real/complex FFT
implicit none
integer, intent(in) :: isign, indx
real, dimension(:), intent(inout) :: f
integer, dimension(:), intent(in) :: mixup
complex, dimension(:), intent(in) :: sct
real, intent(inout) :: tfft
! local data
integer :: nxd, nxhd
integer, dimension(4) :: itime
double precision :: dtime
! extract dimensions
nxd = size(f,1)
nxhd = size(mixup,1)
! check if required size of buffer has increased
if (szt < nxhd) then
if (szt /= 0) deallocate(t)
! allocate new buffers
allocate(t(nxhd))
szt = nxhd
endif
! initialize timer
call dtimer(dtime,itime,-1)
! call low level procedure
call FFT1RXX(f,t,isign,mixup,sct,indx,nxd,nxhd)
! record time
call dtimer(dtime,itime,1)
tfft = tfft + real(dtime)
end subroutine
!
!-----------------------------------------------------------------------
subroutine mfft1rn(f,isign,mixup,sct,tfft,indx)
! wrapper function for n component vector 1d real/complex FFT
implicit none
integer, intent(in) :: isign, indx
real, dimension(:,:), intent(inout) :: f
integer, dimension(:), intent(in) :: mixup
complex, dimension(:), intent(in) :: sct
real, intent(inout) :: tfft
! local data
integer :: ndim, nxd, nxhd
integer, dimension(4) :: itime
double precision :: dtime
! extract dimensions
ndim = size(f,1); nxd = size(f,2)
nxhd = size(mixup,1)
! check if required size of buffer has increased
if (szt < ndim*nxhd) then
if (szt /= 0) deallocate(t)
! allocate new buffers
allocate(t(ndim*nxhd))
szt = ndim*nxhd
endif
! initialize timer
call dtimer(dtime,itime,-1)
! call low level procedure
select case(ndim)
case (2)
call FFT1R2X(f,t,isign,mixup,sct,indx,nxd,nxhd)
case (3)
call FFT1R3X(f,t,isign,mixup,sct,indx,nxd,nxhd)
end select
! record time
call dtimer(dtime,itime,1)
tfft = tfft + real(dtime)
end subroutine
!
!-----------------------------------------------------------------------
subroutine mfft1cr(fc,f,mixup,sct,tfft,indx)
! wrapper function for scalar 1d complex to real FFT
! input fc is complex, output f is real
implicit none
integer, intent(in) :: indx
complex, dimension(:), intent(in) :: fc
real, dimension(:), intent(inout) :: f
integer, dimension(:), intent(in) :: mixup
complex, dimension(:), intent(in) :: sct
real, intent(inout) :: tfft
! local data
integer :: j, n, isign, nxd, nxhd
integer, dimension(4) :: itime
double precision :: dtime
! extract dimensions
isign = 1
n = size(fc,1)
nxd = size(f,1)
nxhd = size(mixup,1)
! check if required size of buffer has increased
if (szt < nxhd) then
if (szt /= 0) deallocate(t)
! allocate new buffers
allocate(t(nxhd))
szt = nxhd
endif
! initialize timer
call dtimer(dtime,itime,-1)
if (nxd.ge.(2*n)) then
do j = 1, n
f(2*j-1) = real(fc(j))
f(2*j) = aimag(fc(j))
enddo
else
write (*,*) 'mfft1cr f too small: nxd, 2*n = ', nxd, 2*n
endif
! call low level procedure
call FFT1RXX(f,t,isign,mixup,sct,indx,nxd,nxhd)
! record time
call dtimer(dtime,itime,1)
tfft = tfft + real(dtime)
end subroutine
!
!-----------------------------------------------------------------------
subroutine mfft1crn(fc,f,mixup,sct,tfft,indx)
! wrapper function for n component vector 1d complex to real FFT
! input fc is complex, output f is real
implicit none
integer, intent(in) :: indx
complex, dimension(:,:), intent(in) :: fc
real, dimension(:,:), intent(inout) :: f
integer, dimension(:), intent(in) :: mixup
complex, dimension(:), intent(in) :: sct
real, intent(inout) :: tfft
! local data
integer :: j, n, m, isign, ndim, nxd, nxhd
integer, dimension(4) :: itime
double precision :: dtime
! extract dimensions
isign = 1
m = size(fc,1); n = size(fc,2)
ndim = size(f,1); nxd = size(f,2)
nxhd = size(mixup,1)
if (m /= ndim) then
write (*,*) 'mfft1crn invalid vectors: ndim, m = ', ndim, m
else if (nxd.lt.(2*n)) then
write (*,*) 'mfft1crn f too small: nxd, 2*n = ', nxd, 2*n
endif
! check if required size of buffer has increased
if (szt < ndim*nxhd) then
if (szt /= 0) deallocate(t)
! allocate new buffers
allocate(t(ndim*nxhd))
szt = ndim*nxhd
endif
! initialize timer
call dtimer(dtime,itime,-1)
! call low level procedure
select case(ndim)
case (2)
do j = 1, n
f(1,2*j-1) = real(fc(1,j))
f(2,2*j-1) = aimag(fc(1,j))
f(1,2*j) = real(fc(2,j))
f(2,2*j) = aimag(fc(2,j))
enddo
call FFT1R2X(f,t,isign,mixup,sct,indx,nxd,nxhd)
case (3)
do j = 1, n
f(1,2*j-1) = real(fc(1,j))
f(2,2*j-1) = aimag(fc(1,j))
f(3,2*j-1) = real(fc(2,j))
f(1,2*j) = aimag(fc(2,j))
f(2,2*j) = real(fc(3,j))
f(3,2*j) = aimag(fc(3,j))
enddo
call FFT1R3X(f,t,isign,mixup,sct,indx,nxd,nxhd)
end select
! record time
call dtimer(dtime,itime,1)
tfft = tfft + real(dtime)
end subroutine
!
end module