19 INTEGER(KIND=int_8),
PARAMETER :: cache_budget = 128_int_8*1024*1024
25 LOGICAL :: active = .false.
28 TYPE stencil_entry_type
30 REAL(
dp) :: point(3) = 0.0_dp
31 LOGICAL :: ready = .false.
32 END TYPE stencil_entry_type
36 TYPE(stencil_entry_type),
ALLOCATABLE :: entries(:)
37 REAL(
dp) :: dh_inv(3, 3) = 0.0_dp, hmat(3, 3) = 0.0_dp
38 INTEGER :: npts(3) = 0, periodic(3) = 0, nrows = -1
39 LOGICAL :: wrap = .false., prepared = .false.
59 INTEGER,
INTENT(IN) :: nrows
60 LOGICAL,
INTENT(IN) :: wrap
61 INTEGER(KIND=int_8),
INTENT(IN),
OPTIONAL :: max_bytes
63 INTEGER :: count, ierr
64 INTEGER(KIND=int_8) :: budget, bytes_per_entry
66 TYPE(stencil_entry_type) :: entry
69 IF (
PRESENT(max_bytes)) budget = max(0_int_8, max_bytes)
70 bytes_per_entry = int((storage_size(entry) + 7)/8,
int_8)
71 count = int(min(int(max(0, nrows),
int_8), budget/bytes_per_entry))
73 IF (
ALLOCATED(cache%entries))
THEN
74 unchanged =
SIZE(cache%entries) == count
77 IF (.NOT.
ALLOCATED(cache%entries))
THEN
78 ALLOCATE (cache%entries(count), stat=ierr)
81 unchanged = unchanged .AND. cache%prepared .AND. cache%nrows == nrows
82 unchanged = unchanged .AND. all(cache%dh_inv == grid%dh_inv) .AND. all(cache%npts == grid%npts)
83 unchanged = unchanged .AND. all(cache%hmat == cell%hmat) .AND. all(cache%periodic == cell%perd)
84 unchanged = unchanged .AND. (cache%wrap .EQV. wrap)
85 IF (.NOT. unchanged) cache%entries%ready = .false.
86 cache%dh_inv = grid%dh_inv
87 cache%npts = grid%npts
88 cache%hmat = cell%hmat
89 cache%periodic = cell%perd
92 cache%prepared = .true.
102 IF (
ALLOCATED(cache%entries))
DEALLOCATE (cache%entries)
103 cache%prepared = .false.
116 INTEGER,
INTENT(IN) :: row
117 REAL(
dp),
INTENT(IN) :: point(3)
119 INTENT(OUT) :: stencil
123 IF (.NOT. cache%prepared .OR. .NOT.
ALLOCATED(cache%entries))
RETURN
124 IF (row < 1 .OR. row >
SIZE(cache%entries))
RETURN
125 IF (.NOT. cache%entries(row)%ready)
RETURN
126 IF (any(cache%entries(row)%point /= point))
RETURN
127 stencil = cache%entries(row)%stencil
140 INTEGER,
INTENT(IN) :: row
141 REAL(
dp),
INTENT(IN) :: point(3)
143 INTENT(IN) :: stencil
145 IF (.NOT. cache%prepared .OR. .NOT.
ALLOCATED(cache%entries))
RETURN
146 IF (row < 1 .OR. row >
SIZE(cache%entries))
RETURN
147 cache%entries(row)%stencil = stencil
148 cache%entries(row)%point = point
149 cache%entries(row)%ready = .true.
Handles all functions related to the CELL.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
Bounded geometry-only cache for native atom-grid interpolation.
logical function, public fetch_native_grid_stencil(cache, row, point, stencil)
Read a stencil only on an exact coordinate match. Safe for concurrent readers.
subroutine, public store_native_grid_stencil(cache, row, point, stencil)
Store from the unique forward owner of a row, never from concurrent adjoint readers.
subroutine, public release_native_grid_cache(cache)
Release geometry storage, including when the QS environment is only partly released.
integer, parameter, public native_grid_interp_npts
integer, parameter, public native_grid_interp_offset_max
subroutine, public prepare_native_grid_cache(cache, grid, cell, nrows, wrap, max_bytes)
Prepare outside parallel regions. Cache a bounded prefix and compute the rest normally.
integer, parameter, public native_grid_interp_offset_min
Type defining parameters related to the simulation cell.