Build the registry, pull every DEVICE-MAPPED registered array
down with !$acc update self, then write the per-rank file
durably (tmp + rename). Safe to call mid-run (state is
device-resident) — the D->H pulls leave the device copy
authoritative. intent(inout): the update self mutates the
host copy of state (review #12), and pointer association into
state requires the target attribute.
ierr (P7, same treatment as the read side): absent behaves as
today (error stop on any NetCDF/rename failure, or on a
no-NetCDF build); present returns OCEAN_STATUS_ERR_IO instead.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(ocean_state_t), | intent(inout), | target | :: | state | ||
| type(hgrid_t), | intent(in) | :: | grid | |||
| type(decomp_t), | intent(in) | :: | decomp | |||
| character(len=*), | intent(in) | :: | filename | |||
| real(kind=wp), | intent(in) | :: | t | |||
| integer, | intent(in) | :: | step | |||
| integer, | intent(out), | optional | :: | ierr |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | e | ||||
| type(ocean_restart_metadata_t), | private | :: | meta | ||||
| type(restart_registry_t), | private | :: | reg |
subroutine ocean_state_restart_write(state, grid, decomp, filename, t, step, ierr) !! Build the registry, pull every DEVICE-MAPPED registered array !! down with `!$acc update self`, then write the per-rank file !! durably (tmp + rename). Safe to call mid-run (state is !! device-resident) — the D->H pulls leave the device copy !! authoritative. `intent(inout)`: the `update self` mutates the !! host copy of `state` (review #12), and pointer association into !! `state` requires the `target` attribute. !! !! `ierr` (P7, same treatment as the read side): absent behaves as !! today (`error stop` on any NetCDF/rename failure, or on a !! no-NetCDF build); present returns `OCEAN_STATUS_ERR_IO` instead. type(ocean_state_t), intent(inout), target :: state type(hgrid_t), intent(in) :: grid type(decomp_t), intent(in) :: decomp character(len=*), intent(in) :: filename real(wp), intent(in) :: t integer, intent(in) :: step integer, intent(out), optional :: ierr #ifndef RDB_NO_NETCDF type(restart_registry_t) :: reg type(ocean_restart_metadata_t) :: meta integer :: e if (present(ierr)) ierr = OCEAN_STATUS_OK call ocean_state_build_restart_registry(state, grid, reg) call ocean_state_fill_restart_metadata(state, grid, meta) ! Device sync: pull each DEVICE-MAPPED registered array host-ward. ! Host-only entries (rank-0 scalars, never-mapped buffers) are ! skipped — `update self` on an unmapped array crashes on GPU ! (review #8). do e = 1, reg%n associate (en => reg%entries(e)) if (.not. en%device_mapped) cycle if (en%rank == 2) then !$acc update self(en%p2) else if (en%rank == 3) then !$acc update self(en%p3) end if end associate end do call ocean_restart_write_local(filename, reg, decomp, meta, t, step, & state%dyn%outer_step_count, ierr=ierr) #else call fail("ocean_state_restart_write: built without NetCDF (RDB_ENABLE_NETCDF=ON required)", & ierr, OCEAN_STATUS_ERR_IO) #endif end subroutine ocean_state_restart_write