This program can be used to benchmark the multigrid routines. For simplicity, it does not compare results with a known solution.
6 program poisson_benchmark_2d
11 integer,
parameter :: n_boxes_base = 1
12 integer,
parameter :: n_var_cell = 3
13 integer,
parameter :: i_phi = 1
14 integer,
parameter :: i_rhs = 2
15 integer,
parameter :: i_tmp = 3
18 type(ref_info_t) :: ref_info
19 integer :: mg_iter, n_args
20 integer :: n_cell, n_iterations, max_ref_lvl
21 integer :: ix_list(2, n_boxes_base)
22 real(dp) :: dr, time, runtime
23 character(len=100) :: fname, arg_string
25 integer :: count_rate,t_start, t_end
27 print *,
"Running poisson_benchmark_2d" 28 print *,
"Number of threads", af_get_max_threads()
31 n_args = command_argument_count()
34 call get_command_argument(1, arg_string)
35 read(arg_string, *) n_cell
37 print *,
"No arguments specified, using default values" 38 print *,
"Usage: ./poisson_benchmark_2d n_cell max_ref_lvl runtime(s)" 43 call get_command_argument(2, arg_string)
44 read(arg_string, *) max_ref_lvl
50 call get_command_argument(3, arg_string)
51 read(arg_string, *) runtime
52 if (runtime < 1e-3_dp) stop
"Run time should be > 1e-3 seconds" 57 print *,
"Box size: ", n_cell
58 print *,
"Max refinement lvl: ", max_ref_lvl
59 print *,
"Run time (s): ", runtime
70 cc_names=[
"phi",
"rhs",
"tmp"])
74 ix_list(:, 1) = [1, 1]
77 call a2_set_base(tree, 1, ix_list)
79 call system_clock(t_start, count_rate)
82 call a2_loop_box(tree, set_init_cond)
88 call a2_adjust_refinement(tree, ref_routine, ref_info)
91 if (ref_info%n_add == 0)
exit 93 call system_clock(t_end, count_rate)
95 write(*,
"(A,Es10.3,A)")
" Wall-clock time generating AMR grid: ", &
96 (t_end-t_start) /
real(count_rate,dp),
" seconds" 98 call a2_print_info(tree)
104 mg%sides_bc => a2_bc_dirichlet_zero
113 call mg2_fas_fmg(tree, mg, .false., mg_iter>1)
117 call system_clock(t_start, count_rate)
118 do mg_iter = 1, n_iterations
119 call mg2_fas_fmg(tree, mg, .false., mg_iter>1)
120 call system_clock(t_end, count_rate)
121 time = (t_end-t_start) /
real(count_rate, dp)
122 if (time > 0.2_dp * runtime)
exit 125 n_iterations = ceiling((runtime/time) * mg_iter)
128 call system_clock(t_start, count_rate)
129 do mg_iter = 1, n_iterations
133 call mg2_fas_fmg(tree, mg, .false., mg_iter>1)
143 call system_clock(t_end, count_rate)
145 time = (t_end-t_start) /
real(count_rate, dp)
146 write(*,
"(A,I0,A,E10.3,A)") &
147 " Wall-clock time after ", n_iterations, &
148 " iterations: ", time,
" seconds" 149 write(*,
"(A,E10.3,A)")
" Per iteration: ", time/n_iterations,
" seconds" 158 call a2_destroy(tree)
163 subroutine ref_routine(box, cell_flags)
164 type(box2_t),
intent(in) :: box
165 integer,
intent(out) :: cell_flags(box%n_cell, box%n_cell)
168 if (box%lvl < max_ref_lvl)
then 169 cell_flags = af_do_ref
171 cell_flags = af_keep_ref
173 end subroutine ref_routine
176 subroutine set_init_cond(box)
177 type(box2_t),
intent(inout) :: box
181 box%cc(1:nc, 1:nc, i_rhs) = 1.0_dp
182 end subroutine set_init_cond
184 end program poisson_benchmark_2d