afivo-streamer 1.1
1D/2D/3D streamer simulations with AMR
Loading...
Searching...
No Matches
test_lookup_table_performance.f90
Go to the documentation of this file.
1program test
3 implicit none
4
5 integer, parameter :: dp = kind(0.0d0)
6 integer, parameter :: test_size = 1000*1000
7 integer, parameter :: min_table_size = 10
8 integer, parameter :: spacing = lt_xspacing_linear
9
10 integer :: i, cntr, table_size
11 type(lt_t) :: lkp_tbl
12
13 real(dp), allocatable :: x_values(:), y_values(:)
14 real(dp), allocatable :: y2_values(:, :), lkp_results(:)
15 real(dp), allocatable :: lkp2_results(:, :)
16 real(dp) :: max_diff
17 real(dp) :: total_time, time_t1, time_t2
18
19 allocate(x_values(test_size))
20 allocate(y_values(test_size))
21 allocate(y2_values(2, test_size))
22 allocate(lkp_results(test_size))
23 allocate(lkp2_results(2, test_size))
24
25 print *, 'start test_lookup_table'
26
27 ! Create some testing data
28 do i = 1, test_size
29 x_values(i) = i / (0.1_dp * test_size)
30 y_values(i) = sin(x_values(i))
31 y2_values(:, i) = (/sin(x_values(i)), atan(x_values(i))/)
32 end do
33
34 print *, "Testing m_lookup_table.f90 implementation..."
35 print *, ""
36 print *, " *** Get one column with LT_get_col ***"
37 print *, "Iteration table_size max. difference"
38
39 table_size = min_table_size
40 cntr = 0
41 total_time = 0.0_dp
42
43 do
44 cntr = cntr + 1
45 table_size = table_size * 2
46 if (table_size > test_size) exit
47
48 ! Create a lookup table between x_values(1) and x_values(test_size), using
49 ! table_size rows and one column
50 lkp_tbl = lt_create(x_values(1), x_values(test_size), table_size, 1, &
51 spacing)
52
53 ! Add the data to the table
54 call lt_set_col(lkp_tbl, 1, x_values, y_values)
55
56 call cpu_time(time_t1)
57 lkp_results = lt_get_col(lkp_tbl, 1, x_values)
58 call cpu_time(time_t2)
59 total_time = total_time + (time_t2 - time_t1)
60
61 max_diff = maxval(abs(lkp_results-y_values))
62 print *, cntr, table_size, max_diff
63 end do
64
65 print *, "You should see 2nd order convergence"
66 print *, "Number of lookups performed:", cntr * test_size
67 print *, "Number of lookups / second:", &
68 (cntr * test_size) / (total_time + epsilon(1.0_dp))
69 print *, "Nanosecond per lookup:", &
70 1e9_dp * total_time / (cntr * test_size)
71 print *, ""
72
73 print *, ""
74 print *, "Testing multiple column mode (2 columns)"
75 print *, " *** Get all columns with LT_get_mcol ***"
76 print *, "Iteration table_size max. difference"
77
78 table_size = min_table_size
79 cntr = 0
80 total_time = 0.0_dp
81
82 do
83 cntr = cntr + 1
84 table_size = table_size * 2
85 if (table_size > test_size) exit
86
87 ! Create a lookup table between x_values(1) and x_values(test_size), using
88 ! table_size rows and one column
89 lkp_tbl = lt_create(x_values(1), x_values(test_size), table_size, 2, &
90 spacing)
91
92 ! Add the data to the table
93 call lt_set_col(lkp_tbl, 1, x_values, y2_values(1, :))
94 call lt_set_col(lkp_tbl, 2, x_values, y2_values(2, :))
95
96 call cpu_time(time_t1)
97 do i = 1, test_size
98 lkp2_results(:, i) = lt_get_mcol(lkp_tbl, x_values(i))
99 end do
100 call cpu_time(time_t2)
101 total_time = total_time + (time_t2 - time_t1)
102
103 max_diff = maxval(abs(lkp2_results-y2_values))
104 print *, cntr, table_size, max_diff
105 end do
106
107 print *, "You should see 2nd order convergence"
108 print *, "Number of lookups performed:", cntr * test_size
109 print *, "Number of lookups / second:", &
110 (cntr * test_size) / (total_time + epsilon(1.0_dp))
111 print *, "Nanosecond per lookup:", &
112 1e9_dp * total_time / (cntr * test_size)
113 print *, ""
114
115end program test
A Fortran 90 module for creating lookup tables. These tables can be used to efficiently interpolate o...
subroutine, public lt_set_col(my_lt, col_ix, x, y)
Fill the column with index col_ix after linearly interpolating.
type(lt_t) function, public lt_create(x_min, x_max, n_points, n_cols, xspacing, extrapolate_above)
This function returns a new lookup table.
pure real(dp) function, dimension(my_lt%n_cols), public lt_get_mcol(my_lt, x)
Get the values of all columns at x.
elemental real(dp) function, public lt_get_col(my_lt, col_ix, x)
Get the value of a single column at x.
integer, parameter, public lt_xspacing_linear
The lookup table type. There can be one or more columns, for which values can be looked up for a give...
program test