-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.F90
67 lines (51 loc) · 1.69 KB
/
main.F90
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
! A simple benchmark for FFTW.
!
! Tests real-to-complex transform. Uses single-precision.
!
! Based on https://gist.github.com/appleparan/c048c44668ede7ef28ba63c660b6dcf3.
program main
use ISO_C_BINDING
implicit none
include 'fftw3.f03.h'
! Size of FFTW input/output array
integer, parameter :: n = 10000
! Number of times to repeat FFT cycle
integer, parameter :: n_repeats = 100000
! Storage array for input/output
real(4) :: test_in(n+2)
! FFTW plan variables
integer(8) :: plan_c2r, plan_r2c
! Timing variables
integer :: tic, toc, t_rate
! Loop indices
integer :: i, j
! Create FFTW plans for direct and inverse transforms
call sfftw_plan_dft_r2c_1d(plan_r2c, n, test_in, test_in, FFTW_MEASURE)
call sfftw_plan_dft_c2r_1d(plan_c2r, n, test_in, test_in, FFTW_MEASURE)
! Initialize input array with random numbers
do i = 1, n
call random_number(test_in(i))
end do
! Print slice of input
print *, "IN(1:5) before: "
write(*, *) (test_in(i),i = 1,5)
write(*, *) ""
! Run n_repeats direct/inverse FFT cycles
call system_clock(tic)
do i = 1, n_repeats
call sfftw_execute_dft_r2c(plan_r2c, test_in, test_in)
call sfftw_execute_dft_c2r(plan_c2r, test_in, test_in)
test_in = test_in / n
end do
call system_clock(toc, t_rate)
! Print slice of output
print *, "IN(1:5) after: "
write(*, *) (test_in(i),i = 1,5)
write(*, *) ""
! Print wallclock time
write (*,*) "Took", (toc - tic) / real(t_rate,8), "seconds"
write(*, *) ""
! Destroy both plans
call sfftw_destroy_plan(plan_r2c)
call sfftw_destroy_plan(plan_c2r)
end program