3 use iso_c_binding
, only: c_int, c_char, c_null_char, c_size_t, c_ptrdiff_t, c_ptr, c_loc, c_sizeof, c_long
5 use netcdf
, only : nf90_global, nf90_nowrite, nf90_inquire_attribute, nf90_open, nf90_inq_dimid, nf90_inquire_dimension, &
6 nf90_inq_varid, nf90_get_var, nf90_get_att, nf90_close
12 use mpi
, only : mpi_comm_rank, mpi_comm_size
27 use iso_c_binding
, only: c_int, c_size_t, c_char
29 integer(kind=c_int),
value :: ncid
30 integer(kind=c_int),
value :: dimid
31 character(kind=c_char),
intent(inout) :: name(*)
32 integer(kind=c_size_t),
intent(out) :: lenp
33 integer(kind=c_int) :: nc_inq_dim
38 use iso_c_binding
, only: c_int, c_long, c_ptr
40 integer(kind=c_int),
value :: ncid, varid
41 type(c_ptr),
value :: startp, countp
42 integer(kind=c_long),
intent(out) :: ip(*)
43 integer(kind=c_int) :: nc_get_vara_long
48 use iso_c_binding
, only: c_int, c_ptr, c_char
50 integer(kind=c_int),
value :: ncid, varid
51 type(c_ptr),
value :: startp, countp, stridep
52 character(kind=c_char),
intent(out) :: ip(*)
53 integer(kind=c_int) :: nc_get_vars_text
59 character,
dimension(:),
intent(in) :: byte_data
72 character(len=STRING_LENGTH),
intent(in) :: checkpoint_filename
73 character,
dimension(:),
allocatable,
intent(inout) :: io_xml_configuration
74 integer,
intent(in) :: io_communicator_arg
76 integer :: ncid, number_io_server, my_io_server_rank, ierr
77 integer :: dim_id, dim_size
80 call mpi_comm_rank(io_communicator_arg, my_io_server_rank, ierr)
81 call mpi_comm_size(io_communicator_arg, number_io_server, ierr)
82 call check_netcdf_status(nf90_open(path = checkpoint_filename, mode = nf90_nowrite, ncid = ncid))
85 if (my_io_server_rank==0)
then 86 call log_log(
log_warn,
"Restarting the IO server fresh as the checkpoint file does not contain IO state")
92 if (dim_size .ne. number_io_server)
then 93 call log_log(
log_error,
"Can not restart IO server with a different number of IO servers")
108 type(
hashmap_type),
volatile,
intent(inout) :: time_points
110 integer :: ncid, ierr, i
111 character,
dimension(:),
allocatable :: raw_bytes
114 mode = nf90_nowrite, ncid = ncid))
116 do i=1,
size(writer_entries)
118 if (writer_entries(i)%include_in_io_state_write)
then 122 deallocate(raw_bytes)
127 "serialised_timeaveraged_manipulation", raw_bytes)
129 deallocate(raw_bytes)
132 "serialised_instantaneous_manipulation", raw_bytes)
134 deallocate(raw_bytes)
137 "serialised_timepoints", raw_bytes)
139 deallocate(raw_bytes)
152 integer :: ncid, ierr
153 character,
dimension(:),
allocatable :: raw_bytes
156 mode = nf90_nowrite, ncid = ncid))
159 "serialised_writer_manager", raw_bytes)
161 deallocate(raw_bytes)
170 integer,
intent(in) :: ncid
171 character,
dimension(:),
allocatable,
intent(inout) :: io_xml_configuration
173 integer :: dim_id, var_id, dim_size
177 if (.not. found)
return 181 if (.not. found)
return 182 allocate(io_xml_configuration(dim_size))
183 call check_netcdf_status(nf90_get_var(ncid, var_id, io_xml_configuration, count=(/dim_size/)))
194 integer,
intent(in) :: ncid, number_io_server, my_io_server_rank
195 character(len=*),
intent(in) :: base_key
196 character,
dimension(:),
allocatable,
intent(out) :: raw_bytes
198 integer :: dim_id, var_id
200 integer(kind=8) :: dim_size, serialised_range(2), number_serialised_entries
202 integer(kind=c_int) :: cncid, cdimid, cstatus, cvarid
203 integer(kind=c_size_t) :: cdlen
204 character(len=256) :: tmpname
205 integer(KIND=c_size_t),
target :: cstart(1), ccounts(1)
206 Integer(KIND=c_ptrdiff_t),
target :: cstrides(1)
207 type(c_ptr) :: cstartptr, ccountsptr, cstridesptr
210 cstartptr=c_loc(cstart)
211 ccountsptr=c_loc(ccounts)
212 cstridesptr=c_loc(cstrides)
215 if (.not. found)
return 221 call check_netcdf_status(nf90_inq_varid(ncid, trim(base_key)//
"_directory", var_id), found)
222 if (.not. found)
return 224 cstart(1)=my_io_server_rank
225 if (my_io_server_rank .lt. number_io_server-1)
then 228 if (serialised_range(2) .gt. dim_size)
then 234 serialised_range(2)=dim_size
236 number_serialised_entries=(serialised_range(2)-serialised_range(1)) + 1
238 if (.not. found)
return 239 allocate(raw_bytes(number_serialised_entries))
242 cstart=serialised_range(1)-1
243 ccounts=number_serialised_entries
253 character,
dimension(:),
allocatable :: raw_bytes
255 integer :: i, number_entries, current_point, byte_size
257 if (.not.
allocated(raw_bytes))
then 263 if (number_entries .ne.
size(writer_entries))
then 264 call log_log(
log_error,
"On restart have a different number of configured entries than those in the checkpoint file")
266 do i=1,
size(writer_entries)
267 if (writer_entries(i)%include_in_io_state_write)
then 270 current_point=current_point+byte_size
280 character,
dimension(:),
allocatable :: raw_bytes
282 integer :: i, number_entries, current_point, byte_size, timestep_key
283 real(kind=DEFAULT_PRECISION) :: r_value
285 if (.not.
allocated(raw_bytes))
then 291 do i=1, number_entries
301 character,
dimension(:),
allocatable :: raw_bytes
303 if (.not.
allocated(raw_bytes))
then 313 character,
dimension(:),
allocatable :: raw_bytes
315 if (.not.
allocated(raw_bytes))
then 327 character,
dimension(:),
allocatable :: raw_bytes
329 if (.not.
allocated(raw_bytes))
then 333 call unserialise_writer_field_manager(raw_bytes)
Performs time averaged, time manipulation and only returns a value if the output frequency determines...
subroutine, public unserialise_writer_type(writer_to_unserialise, byte_data)
Unserialises some byte data into the writer in order to recreate the state of the writer...
Overall IO configuration.
integer, parameter, public log_error
Only log ERROR messages.
subroutine, public unserialise_instantaneous_state(byte_data)
Unpacks some serialised byte data to initialise this manipulator to some previous state...
character(len=string_length) function, public options_get_string(options_database, key, index)
Retrieves a string value from the database that matches the provided key.
Reads the IO server state that was stored in a NetCDF checkpoint file.
ISO C binding for NetCDF get long scalar variable, required for retrieving long variables.
Contains functionality for managing and extracting data from the raw data dumps that the IO server re...
Performs instantaneous time manipulation and only returns a value if the output frequency determines ...
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Contains common definitions for the data and datatypes used by MONC.
subroutine, public log_master_log(level, message)
Will log just from the master process.
A hashmap structure, the same as a map but uses hashing for greatly improved performance when storing...
Conversion between common inbuilt FORTRAN data types.
Converts data types to strings.
subroutine, public unserialise_time_averaged_state(byte_data)
Unserialises some byte data to initialise the state from some previous version.
subroutine, public log_log(level, message, str)
Logs a message at the specified level. If the level is above the current level then the message is ig...
Writer types which are shared across writing functionality. Also includes serialisation functionality...
subroutine, public check_netcdf_status(status, found_flag)
Will check a NetCDF status and write to log_log error any decoded statuses. Can be used to decode whe...
ISO C binding for NetCDF inquire dimension, required for 64 bit dimension length. ...
real(kind=double_precision) function, public unpack_scalar_dp_real_from_bytedata(data, start_point)
Unpacks a double precision scalar real from some byte data, this is a very simple unpack routine wrap...
subroutine restart_timeaveraged_state_from_checkpoint(raw_bytes)
Will restart the time averaged manipulation state from the checkpoint file.
Collection data structures.
integer, parameter, public log_warn
Log WARNING and ERROR messages.
subroutine restart_writer_state_from_checkpoint(writer_entries, raw_bytes)
Restarts the writer state from a specific checkpoint byte data chunk of memory.
integer, parameter, public string_length
Default length of strings.
integer function, public unpack_scalar_integer_from_bytedata(data, start_point)
Unpacks a scalar integer from some byte data, this is a very simple unpack routine wrapping the trans...
subroutine get_io_server_serialised_bytes(ncid, number_io_server, my_io_server_rank, base_key, raw_bytes)
Retrieves some IO server serialised bytes which will make up the state of a specific facet...
subroutine, public read_io_server_configuration(checkpoint_filename, io_xml_configuration, io_communicator_arg)
Reads the IO server configuration, which is the XML configuration initially run with and stored in th...
Manages the options database. Contains administration functions and deduce runtime options from the c...
subroutine, public reactivate_writer_federator_state(io_configuration, writer_entries, time_points)
Reactivates the writer federator and everything beneath it (i.e. just not the writer field manager...
subroutine restart_instantaneous_state_from_checkpoint(raw_bytes)
Will restart the instantaneous manipulation state from the checkpoint file.
subroutine restart_writer_state_timepoints(time_points, raw_bytes)
Restarts the writer state timepoints held in the writer federator.
subroutine restart_writer_field_manager_from_checkpoint(unserialise_writer_field_manager, raw_bytes)
Will restart the field manager state from the checkpoint file.
NetCDF misc functionality which can be shared between modules that work with NetCDF files...
ISO C binding for NetCDF get text vars, required for 64 bit start, count & stride.
subroutine, public reactivate_writer_field_manager_state(io_configuration, unserialise_writer_field_manager)
Reactivates the writer field manager state from the checkpoint file, for memory reasons this will ope...
Parses the XML configuration file to produce the io configuration description which contains the data...
subroutine get_io_server_configuration(ncid, io_xml_configuration)
Retrieves the IO server XML configuration from the checkpoint file.
Puts a double precision real key-value pair into the map.