Storage
Registers from your own pool
A solver that manages its own memory (a pool, a device arena) passes registers to the stepper instead of letting it allocate them. Size the pool once for the largest need: registers_needed(scheme, form) for each scheme the solver may use.
fortran
integer(I4P), parameter :: LB(5) = [1, -2, -2, -2, 1], UB(5) = [5, 9, 9, 9, 8] ! the field's bounds
character(7), parameter :: SCHEMES(3) = [character(7) :: SCHEME_SSP_54, SCHEME_RK4, SCHEME_SSP_33]
real(R_P), pointer :: regs(:,:,:,:,:,:) => null()
type(stepper) :: st
integer(I4P) :: s, slots
slots = 0
do s=1, size(SCHEMES)
slots = max(slots, registers_needed(trim(SCHEMES(s)), FORM_BUTCHER))
enddo
allocate(regs(LB(1):UB(1), LB(2):UB(2), LB(3):UB(3), LB(4):UB(4), LB(5):UB(5), 1:slots)) ! slots from 1
print '(A,I0,A,F6.1,A)', 'pool: ', slots, ' registers, ', real(size(regs), R_P) * storage_size(regs) / 8 / 2**20, ' MiB'
do s=1, size(SCHEMES)
call st%initialize(trim(SCHEMES(s)), FORM_BUTCHER, lb=LB, ub=UB, registers=regs) ! the stepper uses, never frees
print '(A,A,I0,A)', trim(SCHEMES(s)), ': uses ', registers_needed(trim(SCHEMES(s)), FORM_BUTCHER), ' of the pool'
call st%destroy
enddo
deallocate(regs)text
$ cookbook_storage pool
pool: 6 registers, 3.2 MiB
ssp-54: uses 6 of the pool
rk4: uses 5 of the pool
ssp-33: uses 4 of the poolThe rules, checked by initialize (it stops with a message otherwise):
- the array is rank 6, with the field's bounds on dimensions 1–5 (
lb,ub); - the slots are numbered from 1 on dimension 6, and there are at least
registers_neededof them.
The rules the stepper cannot check:
- Memory space: in a device build the pool must be device memory (FUNDAL's
dev_alloc). - Ownership: the stepper never frees it;
destroyonly forgets it. - No sharing between live steppers: two steppers in use at the same time need two pools, because the registers are scratch between
begin_stepandfinish_step. - No zeroing needed: no form reads a register before writing it.
The working precision
SELAH computes in one real kind per build, R_P: double precision by default. The *-r4 build modes compile SELAH and PENF with -D_R_P_IS_R4P and give single precision. Quadruple precision (-D_R_P_IS_R16P) is rejected at compile time. A build in which SELAH and PENF disagree on the kind does not compile.
fortran
print '(A,I0,A,I0)', 'R_P: kind ', R_P, ', decimal digits ', precision(1._R_P)
print '(A,L1)', 'double precision build: ', R_P == R8Ptext
$ cookbook_storage precision
R_P: kind 8, decimal digits 15
double precision build: TSee Precision for what single precision does to the coefficients and the verification.