67 integer(8):: rank_offset
68 integer(8):: task_offset=0_8
71 type(
list_t),
pointer:: list => null()
72 real,
allocatable:: buffer(:,:,:,:,:)
78 procedure:: output_list
79 procedure:: output_buffer
92 SUBROUTINE init (self, patch)
95 namelist /amr_io_params/ verbose, nt
97 logical,
save:: first_time = .true.
99 call trace%begin (
'amr_io_t%init')
103 read (io%input, amr_io_params, iostat=iostat)
104 write (io%output, amr_io_params)
105 call self%ranks_counter%init (mpi%size)
106 call self%offset_counter%init (0_8)
108 time_slices%order = 2
112 write (stdout,
"('amr_io_t%init: ',a,i6)") &
113 'ranks%i =', self%ranks_counter%i
122 SUBROUTINE output (self, patch, count)
125 class(
task_t),
pointer:: task
127 integer:: count, l(3), u(3), n(3), prv, now, remains, it, iv
128 real,
allocatable:: tmp(:,:,:,:)
129 logical,
save:: first_time=.true.
131 call trace%begin (
'amr_io_t%output')
141 if (io%guard_zones)
then 149 allocate (out%mem(n(1),n(2),n(3),out%nv,out%nt,out%nw))
153 if (patch%istep > 1)
then 154 prv = 1 + modulo(now-2,patch%nt)
158 allocate (out%t(2), out%dt(2))
165 call convert_variables (patch, out%mem(:,:,:,iv,1,1), iv, prv)
166 call convert_variables (patch, out%mem(:,:,:,iv,2,1), iv, now)
168 out%t(1) = patch%t(prv)
169 out%t(2) = patch%t(now)
170 out%dt(1) = patch%dt(prv)
171 out%dt(2) = patch%dt(now)
176 allocate (tmp(n(1),n(2),n(3),patch%nt-1))
179 call convert_variables (patch, tmp(:,:,:,it), iv, it)
181 call time_slices%interpolate (patch, tmp, out%mem(:,:,:,iv,1,1))
185 self%task_size = product(n)*nt
186 self%task_offset = self%task_offset + self%task_size
187 patch%amr_offset = self%task_offset
191 if (.not.
associated(self%list))
then 196 call self%list%append_task (task)
202 write (stdout,
"('amr_io_t%output: ',a,i6)") &
211 remains = self%ranks_counter%update(-1) - 1
217 write (stdout,
"('amr_io_t%output: ',a,i6)") &
219 self%iout = patch%iout
220 self%rank_size = self%task_size*self%list%n
221 if (remains == 0)
then 224 io%needs_check = .true.
228 END SUBROUTINE output
233 SUBROUTINE check (self)
237 call trace%begin (
'amr_io_t%check')
238 remains = self%ranks_counter%update(0)
240 write (stdout,
"('amr_io_t%check: ',a,i6)") &
242 if (remains == 0)
then 248 write (stdout,
"('amr_io_t%check: ',a,i10)") &
249 'var_size =', self%var_size
250 call self%output_list
256 io%needs_check = .false.
257 self%task_offset = 0_8
259 call trace%begin (
'counter_t%begin')
260 call self%ranks_counter%reset (mpi%size)
261 call self%offset_counter%reset (0_8)
272 SUBROUTINE output_list (self)
274 class(
link_t),
pointer:: link
275 class(
task_t),
pointer:: task
276 class(
patch_t),
pointer:: patch
277 integer:: i, iv, n(5)
278 integer(8):: rank_offset, var_size
279 character(len=64):: filename
280 namelist /offset_nml/ rank_offset, var_size
284 call trace%begin (
'amr_io_t%fill_buffer')
288 allocate (self%buffer(n(1),n(2),n(3),n(4),n(5)))
292 self%rank_offset = self%offset_counter%update (self%rank_size)
293 self%var_size = self%offset_counter%update (0_8)
294 io%gb_out = self%var_size*self%nv*4.0/1024.**3
296 write (stdout,
"('amr_io_t%output: ',a,5i10)") &
297 'task_size, rank_size, var_size, rank_offset =', &
298 self%task_size, self%rank_size, self%var_size, self%rank_offset
302 link => self%list%head
304 write (filename,
'(a,i5.5,"/snapshot.dat")') &
305 trim(io%outputname), self%iout
307 write (stdout,
"('amr_io_t%fill_buffer: ',a)") &
308 'filename = '//trim(filename)
312 call self%file%openw (filename)
315 link => self%list%head
316 do while (
associated(link))
322 self%buffer(:,:,:,:,i) = task%mem(:,:,:,iv,:,1)
327 call self%output_buffer (iv)
329 deallocate (self%buffer)
342 rank_offset = self%rank_offset
343 var_size = self%var_size
345 write (io_unit%nml2, offset_nml)
348 END SUBROUTINE output_list
356 SUBROUTINE output_buffer (self, iv)
361 call trace%begin (
'amr_io_t%output_buffer')
366 offset = (iv-1)*self%var_size + self%rank_offset
368 write (stdout,
"('amr_io_t%output_buffer: ',a,2i12)") &
369 'iv, offset =', iv, offset
370 call self%file%write (4_8*offset, self%rank_size, self%buffer)
372 END SUBROUTINE output_buffer
378 SUBROUTINE input (self, patch)
382 call trace%begin (
'amr_io_t%input')
391 SUBROUTINE convert_variables (patch, mem, iv, it)
395 integer:: io_format, l(3), u(3), i, j, k
397 call trace%begin (
'amr_io-t%convert_variables')
398 if (io%guard_zones)
then 400 u = max(patch%mesh%ub,patch%mesh%gn)
405 io_format = io%format
406 if (io_format >= 10)
then 407 io_format = io_format-10
408 else if (io_format >= 6)
then 409 io_format = io_format-6
412 if (io_format >= 2 .and. iv==patch%idx%d)
then 415 patch%mem(l(1):u(1),l(2):u(2),l(3):u(3),iv ,jt,1))
416 else if ((io%format == 0 .or. io%format==2) .and. patch%solver_is(
'ramses') &
417 .and. iv >= patch%idx%px .and. iv <= patch%idx%pz)
then 420 = patch%mem(l(1):u(1),l(2):u(2),l(3):u(3),iv ,jt,1) &
421 / patch%mem(l(1):u(1),l(2):u(2),l(3):u(3),patch%idx%d,jt,1)
424 patch%mem(l(1):u(1),l(2):u(2),l(3):u(3),iv ,jt,1)
427 END SUBROUTINE convert_variables
Compute time derivative from a sequence of time slices, using Lagrange interpolation.
Module with list handling for generic class task_t objects.
Template module for patches, which adds pointers to memory and mesh, and number of dimensions and var...
Module for handling blocking and non-blocking MPI parallel I/O to a single file.
Module handling convenient AMR I/O. We wish to have a file format that makes it easy to read when res...
Module with list handling for generic class task_t objects.
Template module for tasks.