Skip to content

10. Production ​

Three things a production solver adds to chapter 4:

  • registers from its own memory pool;
  • no copy for the first stage;
  • the step residual, for convergence monitoring.
fortran
! the caller's pool: the field's bounds, the slots numbered from 1, as many as the form needs
allocate(pool(1:1, 0:NI+1, 0:2, 0:2, 1:NB, 1:registers_needed(SCHEME_SSP_54, FORM_BUTCHER)))
call st%initialize(SCHEME_SSP_54, FORM_BUTCHER, lb=lbound(q), ub=ubound(q), registers=pool, stages_on_q=.true.)
  • Your registers. registers= takes a rank-6 array with the field's bounds and enough slots, numbered from 1 (registers_needed says how many). The stepper checks the bounds and stops on a mismatch. In a device build the pool must be device memory. The stepper never frees it, and it does not need it zeroed: no form reads a register before writing it.
  • stages_on_q=.true. The state of stage 1 of an explicit scheme is qn itself. With this option the Butcher form skips the copy into its register: stage_state_is_q(1) is true, and you evaluate that stage's residual on q. On the A30 this takes 6% off the integrator's step (Performance).
fortran
call st%begin_step(bx, q)
do k=1, st%stages()
   call st%begin_stage(k, bx, dt, q)
   if (st%stage_state_is_q(k)) then                    ! stage 1: its state is q, no copy was made
      u => q
   else
      u => st%stage_state()
   endif
   r => st%rhs_register()
   call fill_ghosts(u)
   call residual(u, r, dx)
   call st%end_stage(k, bx, dt, q)
enddo
call st%finish_step(bx, dt, q, dq=dq)                  ! the update writes dq = sum_k b_k F_k in the same pass
  • finish_step(..., dq=dq) writes the step residual dq=∑kbkFk in the same pass as the update, so the monitoring costs one write and no extra read of the registers. Only the Butcher form has it: the in-place forms never hold all the stage residuals at once.

Running it ​

text
$ production
step   max |dq|    max |q_new - q_old - dt dq|
   1   6.271E+00      5.38E-17
   2   6.271E+00      5.55E-17
   3   6.271E+00      5.55E-17
   4   6.271E+00      5.55E-17
   5   6.271E+00      5.20E-17
   6   6.271E+00      5.55E-17

dq is exactly the rate of the step, (qn+1−qn)/Δt, to round-off.

Ghost cells of q at stage 1

With stages_on_q, stage 1's ghost fill writes the ghost cells of q (the stage state is q). That is allowed: ghost cells are the caller's (contract clause 3). A plain Butcher form never shows q to the ghost fill.

What you learned

A production loop: your pool, stage 1 on q, the fused step residual. Reference: Stepper, Cookbook.

That is the whole API surface a solver needs. The Cookbook has recipes for specific tasks, and Verification shows the evidence behind every claim on these pages.

GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT, at your choice