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_char, nf90_byte, nf90_int, nf90_def_var, nf90_put_var, nf90_def_dim
13 use mpi,
only : mpi_in_place, mpi_int, mpi_long_long_int, mpi_sum, mpi_status_ignore, mpi_wait
27 use iso_c_binding,
only: c_int, c_size_t, c_char
29 integer(kind=c_int),
value :: ncid
30 character(kind=c_char),
intent(in) :: name(*)
31 integer(kind=c_size_t),
value :: nlen
32 integer(kind=c_int),
intent(inout) :: idp
38 use iso_c_binding,
only: c_int, c_ptr, c_char
40 integer(kind=c_int),
value :: ncid, varid
41 type(c_ptr),
value :: startp, countp, stridep
42 character(kind=c_char),
intent(in) :: op(*)
48 use iso_c_binding,
only: c_int, c_ptr, c_long
50 integer(kind=c_int),
value :: ncid, varid
51 type(c_ptr),
value :: indexp
52 integer(kind=c_long),
intent(in) :: op
57 function nc_def_var(ncid, name, xtype, ndims, dimidsp, varidp)
bind(C)
58 use iso_c_binding,
only: c_int, c_char
60 integer(kind=c_int),
value :: ncid
61 character(kind=c_char),
intent(in) :: name(*)
62 integer(kind=c_int),
value :: xtype
63 integer(kind=c_int),
value :: ndims
64 integer(kind=c_int),
intent(in) :: dimidsp(*)
65 integer(kind=c_int),
intent(out) :: varidp
75 character,
dimension(:),
allocatable,
intent(inout) :: byte_data
79 integer,
intent(in) :: timestep
102 prepare_to_serialise_writer_field_manager_state_arg, is_write_field_manager_up_to_date_arg)
107 integer(kind=c_size_t) :: size_t_test
113 if (c_sizeof(size_t_test) .lt. 8)
then
115 "Your system's size_t is not 64 bit, this will limit the size of IO server state storage to 4GB")
123 integer,
intent(in) :: timestep
135 type(
writer_type),
volatile,
dimension(:),
intent(inout) :: writer_entries
136 type(
hashmap_type),
volatile,
intent(inout) :: time_points
138 integer :: i, current_data_point, number_writer_entries_included, ierr, current_index
139 character,
dimension(:),
allocatable :: dvt_byte_data, temp
141 number_writer_entries_included=0
142 do i=1,
size(writer_entries)
143 if (writer_entries(i)%include_in_io_state_write) number_writer_entries_included=number_writer_entries_included+1
151 do i=1,
size(writer_entries)
152 if (writer_entries(i)%include_in_io_state_write)
then
154 current_index=current_index+1
177 type(
hashmap_type),
volatile,
intent(inout) :: time_points
189 type(
hashmap_type),
volatile,
intent(inout) :: time_points
190 character,
dimension(:),
allocatable,
intent(inout) :: byte_data
192 integer :: key, current_data_point
205 current_data_point=
pack_scalar_field(byte_data, current_data_point, double_real_value=r_value)
215 type(
writer_type),
volatile,
dimension(:),
intent(inout) :: writer_entries
216 type(
hashmap_type),
volatile,
intent(inout) :: time_points
219 integer :: ncdf_dimid, ncdf_varid, current_index, i
220 character,
dimension(:),
allocatable :: byte
226 size(io_configuration%text_configuration), ncdf_dimid))
227 call c_put_integer(netcdf_file%dimension_to_id,
"io_configuration_dim", ncdf_dimid)
229 call check_netcdf_status(nf90_def_var(netcdf_file%ncid,
"io_configuration", nf90_char, ncdf_dimid, ncdf_varid))
230 call c_put_integer(netcdf_file%variable_to_id,
"io_configuration", ncdf_varid)
232 call check_netcdf_status(nf90_def_dim(netcdf_file%ncid,
"entries_directory_dim", io_configuration%number_of_io_servers, &
235 call c_put_integer(netcdf_file%dimension_to_id,
"entries_directory_dim", ncdf_dimid)
240 do i=1,
size(writer_entries)
241 if (writer_entries(i)%include_in_io_state_write)
then
244 current_index=current_index+1
265 integer,
intent(in) :: entries_directory_dim_id
266 integer(kind=8),
intent(in) :: expected_global_entries
267 character(len=*),
intent(in) :: base_key
269 integer :: ncdf_varid
270 integer :: ncdf_dimid
271 integer(kind=c_int) :: cncid, cdimid, cvarid, cxtype, cnvdims
272 integer(kind=c_int) :: cvdims(1)
274 cncid = netcdf_file%ncid
276 cvdims(1)=entries_directory_dim_id-1
281 cnvdims, cvdims, cvarid))
284 call c_put_integer(netcdf_file%variable_to_id, trim(base_key)//
"_directory", ncdf_varid)
287 int(expected_global_entries, c_size_t), cdimid))
289 call c_put_integer(netcdf_file%dimension_to_id, trim(base_key)//
"_dim", ncdf_dimid)
290 call check_netcdf_status(nf90_def_var(netcdf_file%ncid, trim(base_key), nf90_char, ncdf_dimid, ncdf_varid))
291 call c_put_integer(netcdf_file%variable_to_id, trim(base_key), ncdf_varid)
304 type(
writer_type),
volatile,
dimension(:),
intent(inout) :: writer_entries
305 type(
hashmap_type),
volatile,
intent(inout) :: time_points
308 integer :: field_id, var_id, current_index, i
309 character,
dimension(:),
allocatable :: serialised_bytes
311 field_id=
c_get_integer(netcdf_file%variable_to_id,
"io_configuration")
313 if (io_configuration%my_io_rank == 0)
then
315 call check_netcdf_status(nf90_put_var(netcdf_file%ncid, field_id, io_configuration%text_configuration, &
316 count=(/
size(io_configuration%text_configuration)/)))
322 do i=1,
size(writer_entries)
323 if (writer_entries(i)%include_in_io_state_write)
then
327 "serialised_writer_entry_"//trim(
conv_to_string(i)), serialised_bytes)
328 deallocate(serialised_bytes)
329 current_index=current_index+1
336 "serialised_timeaveraged_manipulation", serialised_bytes)
337 deallocate(serialised_bytes)
342 "serialised_instantaneous_manipulation", serialised_bytes)
343 deallocate(serialised_bytes)
348 "serialised_writer_manager", serialised_bytes)
349 deallocate(serialised_bytes)
354 "serialised_timepoints", serialised_bytes)
355 deallocate(serialised_bytes)
367 subroutine write_state_storage(netcdf_file, writer_entry_start_point, my_io_rank, base_key, raw_byte_code)
369 integer,
intent(in) :: my_io_rank
370 integer(kind=8),
intent(in) :: writer_entry_start_point
371 character(len=*),
intent(in) :: base_key
372 character,
dimension(:),
intent(in) :: raw_byte_code
374 integer(kind=c_int) :: cncid, cvarid, cndims, cstat1, cstatus
375 integer(kind=c_size_t),
target :: cstart(1), ccounts(1)
376 integer(kind=c_ptrdiff_t),
target :: cstrides(1)
377 integer(kind=c_long) :: c_writer_corrected_start_point
378 type(c_ptr) :: cstartptr, ccountsptr, cstridesptr
380 cncid=netcdf_file%ncid
382 cvarid=
c_get_integer(netcdf_file%variable_to_id, trim(base_key)//
"_directory")-1
383 c_writer_corrected_start_point=(writer_entry_start_point-
size(raw_byte_code))+1
385 ccounts(1)=
size(raw_byte_code)
388 cstartptr=c_loc(cstart)
389 ccountsptr=c_loc(ccounts)
390 cstridesptr=c_loc(cstrides)
394 cvarid=
c_get_integer(netcdf_file%variable_to_id, trim(base_key))-1
395 cstart(1)=c_writer_corrected_start_point-1