5 integer,
parameter :: dp = kind(0.0d0)
6 integer,
parameter :: test_size = 1000*1000
7 integer,
parameter :: min_table_size = 10
10 integer :: i, cntr, table_size
13 real(dp),
allocatable :: x_values(:), y_values(:)
14 real(dp),
allocatable :: y2_values(:, :), lkp_results(:)
15 real(dp),
allocatable :: lkp2_results(:, :)
17 real(dp) :: total_time, time_t1, time_t2
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))
25 print *,
'start test_lookup_table'
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))/)
34 print *,
"Testing m_lookup_table.f90 implementation..."
36 print *,
" *** Get one column with LT_get_col ***"
37 print *,
"Iteration table_size max. difference"
39 table_size = min_table_size
45 table_size = table_size * 2
46 if (table_size > test_size)
exit
50 lkp_tbl =
lt_create(x_values(1), x_values(test_size), table_size, 1, &
54 call lt_set_col(lkp_tbl, 1, x_values, y_values)
56 call cpu_time(time_t1)
58 call cpu_time(time_t2)
59 total_time = total_time + (time_t2 - time_t1)
61 max_diff = maxval(abs(lkp_results-y_values))
62 print *, cntr, table_size, max_diff
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)
74 print *,
"Testing multiple column mode (2 columns)"
75 print *,
" *** Get all columns with LT_get_mcol ***"
76 print *,
"Iteration table_size max. difference"
78 table_size = min_table_size
84 table_size = table_size * 2
85 if (table_size > test_size)
exit
89 lkp_tbl =
lt_create(x_values(1), x_values(test_size), table_size, 2, &
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, :))
96 call cpu_time(time_t1)
98 lkp2_results(:, i) =
lt_get_mcol(lkp_tbl, x_values(i))
100 call cpu_time(time_t2)
101 total_time = total_time + (time_t2 - time_t1)
103 max_diff = maxval(abs(lkp2_results-y2_values))
104 print *, cntr, table_size, max_diff
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)
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...