24 INTEGER :: errors, my_rank, status
27 my_rank = mp_comm%mepos
34 IF (status /= 0) error stop
"FFT library initialization failed"
37 errors = errors +
test_1d_c2c(15, 13, .true., .true.)
38 errors = errors +
test_1d_c2c(9, 11, .true., .false.)
39 errors = errors +
test_1d_c2c(10, 14, .false., .true.)
40 errors = errors +
test_1d_c2c(14, 13, .false., .false.)
42 errors = errors + test_1d_c2c_inplace(15, 13, .true.)
43 errors = errors + test_1d_c2c_inplace(14, 13, .false.)
45 errors = errors + test_2d_c2c([10, 10], 10, .true., .true.)
46 errors = errors + test_2d_c2c([8, 9], 10, .true., .false.)
47 errors = errors + test_2d_c2c([7, 10], 11, .false., .true.)
48 errors = errors + test_2d_c2c([6, 7], 10, .false., .false.)
50 errors = errors + test_2d_c2c_inplace([8, 9], 10, .true.)
51 errors = errors + test_2d_c2c_inplace([7, 10], 11, .false.)
53 errors = errors + test_3d_c2c([8, 8, 8], .false., .false.)
54 errors = errors + test_3d_c2c([7, 5, 3], .true., .true.)
56 errors = errors + test_3d_c2c_inplace([8, 8, 8], .false.)
57 errors = errors + test_3d_c2c_inplace([7, 5, 3], .true.)
62 IF (my_rank == 0)
THEN
64 WRITE (*,
'(A)')
"All Fortran FFT-API tests have passed :-)"
66 WRITE (*,
'(A,I0)')
"Fortran FFT-API tests failed: ", errors
69 IF (errors /= 0) error stop
81 INTEGER FUNCTION test_1d_c2c(fft_size, number_of_ffts, transpose_in, transpose_out)
82 INTEGER,
INTENT(IN) :: fft_size, number_of_ffts
83 LOGICAL,
INTENT(IN) :: transpose_in, transpose_out
85 COMPLEX(KIND=dp),
ALLOCATABLE :: input(:), output(:), reference(:)
86 INTEGER :: i, ld_in, ld_out
87 REAL(kind=
dp) :: max_error
89 ld_in = merge(number_of_ffts, fft_size, transpose_in)
90 ld_out = merge(number_of_ffts, fft_size, transpose_out)
91 ALLOCATE (input(fft_size*number_of_ffts), output(fft_size*number_of_ffts), &
92 reference(fft_size*number_of_ffts))
94 input(i) = cmplx(sin(0.1_dp*i), cos(0.07_dp*i), kind=
dp)
96 reference(:) = input(:)
99 ld_in, ld_out, input, output)
100 CALL fft_1d_local(.true., fft_size, number_of_ffts, transpose_in, transpose_out, &
101 ld_in, ld_out, input, output)
103 ld_out, ld_in, output, input)
104 CALL fft_1d_local(.false., fft_size, number_of_ffts, transpose_out, transpose_in, &
105 ld_out, ld_in, output, input)
107 max_error = maxval(abs(input - real(fft_size, kind=
dp)*reference))
109 IF (max_error > 1.0e-8_dp)
THEN
110 IF (my_rank == 0)
WRITE (*,
'(A,F12.3,A,2I4,2L2)') &
111 "1D C2C roundtrip error ", max_error,
" size/batch ", fft_size, number_of_ffts, &
112 transpose_in, transpose_out
115 DEALLOCATE (input, output, reference)
125 INTEGER FUNCTION test_1d_c2c_inplace(fft_size, number_of_ffts, transpose)
126 INTEGER,
INTENT(IN) :: fft_size, number_of_ffts
127 LOGICAL,
INTENT(IN) :: transpose
129 COMPLEX(KIND=dp),
ALLOCATABLE :: grid(:), reference(:)
131 REAL(kind=
dp) :: max_error
133 ld = merge(number_of_ffts, fft_size, transpose)
134 ALLOCATE (grid(fft_size*number_of_ffts), reference(fft_size*number_of_ffts))
136 grid(i) = cmplx(sin(0.11_dp*i), cos(0.05_dp*i), kind=
dp)
138 reference(:) = grid(:)
144 max_error = maxval(abs(grid - real(fft_size, kind=
dp)*reference))
145 test_1d_c2c_inplace = 0
146 IF (max_error > 1.0e-8_dp)
THEN
147 IF (my_rank == 0)
WRITE (*,
'(A,F12.3,A,2I4,L2)') &
148 "1D C2C inplace roundtrip error ", max_error,
" size/batch ", fft_size, &
149 number_of_ffts, transpose
150 test_1d_c2c_inplace = 1
152 DEALLOCATE (grid, reference)
153 END FUNCTION test_1d_c2c_inplace
163 INTEGER FUNCTION test_2d_c2c(fft_size, number_of_ffts, transpose_in, transpose_out)
164 INTEGER,
DIMENSION(2),
INTENT(IN) :: fft_size
165 INTEGER,
INTENT(IN) :: number_of_ffts
166 LOGICAL,
INTENT(IN) :: transpose_in, transpose_out
168 COMPLEX(KIND=dp),
ALLOCATABLE :: input(:), output(:), reference(:)
170 REAL(kind=
dp) :: max_error
172 ALLOCATE (input(product(fft_size)*number_of_ffts), &
173 output(product(fft_size)*number_of_ffts), &
174 reference(product(fft_size)*number_of_ffts))
175 DO i = 1,
SIZE(input)
176 input(i) = cmplx(sin(0.09_dp*i), cos(0.04_dp*i), kind=
dp)
178 reference(:) = input(:)
182 CALL fft_2d_local(.true., fft_size, number_of_ffts, transpose_in, transpose_out, input, output)
185 CALL fft_2d_local(.false., fft_size, number_of_ffts, transpose_out, transpose_in, output, input)
187 max_error = maxval(abs(input - real(product(fft_size), kind=
dp)*reference))
189 IF (max_error > 1.0e-8_dp)
THEN
190 IF (my_rank == 0)
WRITE (*,
'(A,F12.3,A,3I4,2L2)') &
191 "2D C2C roundtrip error ", max_error,
" size/batch ", fft_size, number_of_ffts, &
192 transpose_in, transpose_out
195 DEALLOCATE (input, output, reference)
196 END FUNCTION test_2d_c2c
205 INTEGER FUNCTION test_2d_c2c_inplace(fft_size, number_of_ffts, transpose)
206 INTEGER,
DIMENSION(2),
INTENT(IN) :: fft_size
207 INTEGER,
INTENT(IN) :: number_of_ffts
208 LOGICAL,
INTENT(IN) :: transpose
210 COMPLEX(KIND=dp),
ALLOCATABLE :: grid(:), reference(:)
212 REAL(kind=
dp) :: max_error
214 ALLOCATE (grid(product(fft_size)*number_of_ffts), &
215 reference(product(fft_size)*number_of_ffts))
217 grid(i) = cmplx(sin(0.08_dp*i), cos(0.03_dp*i), kind=
dp)
219 reference(:) = grid(:)
225 max_error = maxval(abs(grid - real(product(fft_size), kind=
dp)*reference))
226 test_2d_c2c_inplace = 0
227 IF (max_error > 1.0e-8_dp)
THEN
228 IF (my_rank == 0)
WRITE (*,
'(A,F12.3,A,3I4,L2)') &
229 "2D C2C inplace roundtrip error ", max_error,
" size/batch ", fft_size, &
230 number_of_ffts, transpose
231 test_2d_c2c_inplace = 1
233 DEALLOCATE (grid, reference)
234 END FUNCTION test_2d_c2c_inplace
243 INTEGER FUNCTION test_3d_c2c(fft_size, transpose_in, transpose_out)
244 INTEGER,
DIMENSION(3),
INTENT(IN) :: fft_size
245 LOGICAL,
INTENT(IN) :: transpose_in, transpose_out
247 COMPLEX(KIND=dp),
ALLOCATABLE :: input(:), output(:), reference(:)
248 INTEGER :: i, number_of_ffts
249 REAL(kind=
dp) :: max_error
251 number_of_ffts = product(fft_size)
252 ALLOCATE (input(product(fft_size)*number_of_ffts), &
253 output(product(fft_size)*number_of_ffts), &
254 reference(product(fft_size)*number_of_ffts))
255 DO i = 1,
SIZE(input)
256 input(i) = cmplx(sin(0.07_dp*i), cos(0.02_dp*i), kind=
dp)
258 reference(:) = input(:)
262 CALL fft_3d_local(.true., fft_size, number_of_ffts, transpose_in, transpose_out, input, output)
265 CALL fft_3d_local(.false., fft_size, number_of_ffts, transpose_out, transpose_in, output, input)
267 max_error = maxval(abs(input - real(product(fft_size), kind=
dp)*reference))
269 IF (max_error > 1.0e-8_dp)
THEN
270 IF (my_rank == 0)
WRITE (*,
'(A,F12.3,A,4I4,2L2)') &
271 "3D C2C roundtrip error ", max_error,
" size/batch ", fft_size, number_of_ffts, &
272 transpose_in, transpose_out
275 DEALLOCATE (input, output, reference)
276 END FUNCTION test_3d_c2c
284 INTEGER FUNCTION test_3d_c2c_inplace(fft_size, transpose)
285 INTEGER,
DIMENSION(3),
INTENT(IN) :: fft_size
286 LOGICAL,
INTENT(IN) :: transpose
288 COMPLEX(KIND=dp),
ALLOCATABLE :: grid(:), reference(:)
289 INTEGER :: i, number_of_ffts
290 REAL(kind=
dp) :: max_error
292 number_of_ffts = product(fft_size)
293 ALLOCATE (grid(product(fft_size)*number_of_ffts), &
294 reference(product(fft_size)*number_of_ffts))
296 grid(i) = cmplx(sin(0.06_dp*i), cos(0.015_dp*i), kind=
dp)
298 reference(:) = grid(:)
304 max_error = maxval(abs(grid - real(product(fft_size), kind=
dp)*reference))
305 test_3d_c2c_inplace = 0
306 IF (max_error > 1.0e-8_dp)
THEN
307 IF (my_rank == 0)
WRITE (*,
'(A,F12.3,A,4I4,L2)') &
308 "3D C2C inplace roundtrip error ", max_error,
" size/batch ", fft_size, &
309 number_of_ffts, transpose
310 test_3d_c2c_inplace = 1
312 DEALLOCATE (grid, reference)
313 END FUNCTION test_3d_c2c_inplace
integer function test_1d_c2c(fft_size, number_of_ffts, transpose_in, transpose_out)
...
Fortran API for the FFT package, which is written in C.
subroutine, public fft_register_3d_local_inplace(direction, fft_size, number_of_ffts, transpose, grid)
Registers a complex-to-complex 3D FFT.
subroutine, public fft_register_1d_local_inplace(direction, fft_size, number_of_ffts, transpose, leading_dimension, grid)
Registers a complex-to-complex 1D FFT.
subroutine, public fft_2d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Performs a complex-to-complex 2D FFT.
subroutine, public fft_2d_local_inplace(direction, fft_size, number_of_ffts, transpose, grid)
Performs a complex-to-complex 2D FFT.
subroutine, public fft_register_3d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Registers a complex-to-complex 3D FFT.
subroutine, public fft_register_2d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Registers a complex-to-complex 2D FFT.
subroutine, public fft_3d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Performs a complex-to-complex 3D FFT.
subroutine, public fft_1d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, leading_dimension_in, leading_dimension_out, grid_in, grid_out)
Performs a complex-to-complex 1D FFT.
integer, parameter, public fft_library_fftw_mode_estimate
subroutine, public fft_library_init(backend, planning_mode, use_guru_interface, wisdom_file, status)
Initialize FFT library.
integer, parameter, public fft_library_backend_default
subroutine, public fft_3d_local_inplace(direction, fft_size, number_of_ffts, transpose, grid)
Performs a complex-to-complex 3D FFT.
subroutine, public fft_1d_local_inplace(direction, fft_size, number_of_ffts, transpose, leading_dimension, grid)
Performs a complex-to-complex 1D FFT.
subroutine, public fft_library_finalize(wisdom_file)
Finalize FFT library.
subroutine, public fft_register_2d_local_inplace(direction, fft_size, number_of_ffts, transpose, grid)
Registers a complex-to-complex 2D FFT.
subroutine, public fft_register_1d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, leading_dimension_in, leading_dimension_out, grid_in, grid_out)
Registers a complex-to-complex 1D FFT.
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
subroutine, public mp_world_init(mp_comm)
initializes the system default communicator
subroutine, public mp_world_finalize()
Finalize the system default communicator and MPI when CP2K owns MPI.
Fortran API for the offload package, which is written in C.
subroutine, public offload_set_chosen_device(device_id)
Selects the chosen device to be used.
integer function, public offload_get_device_count()
Returns the number of available devices.