Skip to content

Commit dcb46e3

Browse files
author
lvupupui
committed
post_process: extract shared Lagrangian-bubble restart-header read
Extract the byte-identical MPI-IO restart-header read block from s_write_lag_bubbles_results_to_text and s_write_lag_bubbles_to_formatted_database_file into a new s_read_lag_restart_header subroutine. Also consolidates the base header-offset expression (5\xc3\x97 copies reduced to 1\xc2\xb9 in the shared helper + 3\xc2\xb9 remaining in divergent code, vs 5\xc2\xb9 before). The new helper opens the restart file on MPI_COMM_SELF, reads file_tot_part / file_time / file_dt / file_num_procs, broadcasts, allocates proc_bubble_counts, then reopens/reads/broadcasts the per-proc counts. Risk is low: input-side code motion of an identical block; downstream output logic is unchanged. 1\xc2\xb9 approximate counts after the patch.
1 parent 4a73bf3 commit dcb46e3

1 file changed

Lines changed: 53 additions & 60 deletions

File tree

src/post_process/m_data_output.fpp

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,55 @@ contains
707707
708708
end subroutine s_write_variable_to_formatted_database_file
709709
710+
!> Read the shared Lagrangian-bubble restart header: file metadata and per-proc bubble counts.
711+
!> Extracted from duplicate blocks in s_write_lag_bubbles_results_to_text and
712+
!> s_write_lag_bubbles_to_formatted_database_file.
713+
impure subroutine s_read_lag_restart_header(file_loc, file_tot_part, file_time, file_dt, &
714+
file_num_procs, proc_bubble_counts)
715+
716+
character(len=*), intent(in) :: file_loc
717+
integer, intent(out) :: file_tot_part
718+
real(wp), intent(out) :: file_time, file_dt
719+
integer, intent(out) :: file_num_procs
720+
integer, dimension(:), allocatable, intent(out) :: proc_bubble_counts
721+
integer(KIND=MPI_OFFSET_KIND) :: disp
722+
integer, dimension(MPI_STATUS_SIZE) :: status
723+
integer :: ifile, ierr
724+
725+
if (proc_rank == 0) then
726+
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
727+
728+
call MPI_FILE_READ(ifile, file_tot_part, 1, MPI_INTEGER, status, ierr)
729+
call MPI_FILE_READ(ifile, file_time, 1, mpi_p, status, ierr)
730+
call MPI_FILE_READ(ifile, file_dt, 1, mpi_p, status, ierr)
731+
call MPI_FILE_READ(ifile, file_num_procs, 1, MPI_INTEGER, status, ierr)
732+
733+
call MPI_FILE_CLOSE(ifile, ierr)
734+
end if
735+
736+
call MPI_BCAST(file_tot_part, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
737+
call MPI_BCAST(file_time, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
738+
call MPI_BCAST(file_dt, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
739+
call MPI_BCAST(file_num_procs, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
740+
741+
allocate (proc_bubble_counts(file_num_procs))
742+
743+
if (proc_rank == 0) then
744+
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
745+
746+
! Skip to processor counts position
747+
disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), MPI_OFFSET_KIND)
748+
call MPI_FILE_SEEK(ifile, disp, MPI_SEEK_SET, ierr)
749+
750+
call MPI_FILE_READ(ifile, proc_bubble_counts, file_num_procs, MPI_INTEGER, status, ierr)
751+
752+
call MPI_FILE_CLOSE(ifile, ierr)
753+
end if
754+
755+
call MPI_BCAST(proc_bubble_counts, file_num_procs, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
756+
757+
end subroutine s_read_lag_restart_header
758+
710759
!> Write the post-processed results in the folder 'lag_bubbles_data'
711760
impure subroutine s_write_lag_bubbles_results_to_text(t_step)
712761
@@ -744,38 +793,10 @@ contains
744793
745794
if (.not. parallel_io) return
746795
747-
if (proc_rank == 0) then
748-
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
749-
750-
call MPI_FILE_READ(ifile, file_tot_part, 1, MPI_INTEGER, status, ierr)
751-
call MPI_FILE_READ(ifile, file_time, 1, mpi_p, status, ierr)
752-
call MPI_FILE_READ(ifile, file_dt, 1, mpi_p, status, ierr)
753-
call MPI_FILE_READ(ifile, file_num_procs, 1, MPI_INTEGER, status, ierr)
754-
755-
call MPI_FILE_CLOSE(ifile, ierr)
756-
end if
757-
758-
call MPI_BCAST(file_tot_part, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
759-
call MPI_BCAST(file_time, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
760-
call MPI_BCAST(file_dt, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
761-
call MPI_BCAST(file_num_procs, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
796+
call s_read_lag_restart_header(file_loc, file_tot_part, file_time, file_dt, &
797+
file_num_procs, proc_bubble_counts)
762798
time_real = file_time
763799
764-
allocate (proc_bubble_counts(file_num_procs))
765-
766-
if (proc_rank == 0) then
767-
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
768-
769-
! Skip to processor counts position
770-
disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), MPI_OFFSET_KIND)
771-
call MPI_FILE_SEEK(ifile, disp, MPI_SEEK_SET, ierr)
772-
call MPI_FILE_READ(ifile, proc_bubble_counts, file_num_procs, MPI_INTEGER, status, ierr)
773-
774-
call MPI_FILE_CLOSE(ifile, ierr)
775-
end if
776-
777-
call MPI_BCAST(proc_bubble_counts, file_num_procs, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
778-
779800
gsizes(1) = file_tot_part
780801
gsizes(2) = lag_io_vars
781802
lsizes(1) = file_tot_part
@@ -903,38 +924,10 @@ contains
903924
904925
if (.not. parallel_io) return
905926
906-
if (proc_rank == 0) then
907-
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
908-
909-
call MPI_FILE_READ(ifile, file_tot_part, 1, MPI_INTEGER, status, ierr)
910-
call MPI_FILE_READ(ifile, file_time, 1, mpi_p, status, ierr)
911-
call MPI_FILE_READ(ifile, file_dt, 1, mpi_p, status, ierr)
912-
call MPI_FILE_READ(ifile, file_num_procs, 1, MPI_INTEGER, status, ierr)
913-
914-
call MPI_FILE_CLOSE(ifile, ierr)
915-
end if
916-
917-
call MPI_BCAST(file_tot_part, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
918-
call MPI_BCAST(file_time, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
919-
call MPI_BCAST(file_dt, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
920-
call MPI_BCAST(file_num_procs, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
927+
call s_read_lag_restart_header(file_loc, file_tot_part, file_time, file_dt, &
928+
file_num_procs, proc_bubble_counts)
921929
time_real = file_time
922930
923-
allocate (proc_bubble_counts(file_num_procs))
924-
925-
if (proc_rank == 0) then
926-
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
927-
928-
! Skip to processor counts position
929-
disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), MPI_OFFSET_KIND)
930-
call MPI_FILE_SEEK(ifile, disp, MPI_SEEK_SET, ierr)
931-
call MPI_FILE_READ(ifile, proc_bubble_counts, file_num_procs, MPI_INTEGER, status, ierr)
932-
933-
call MPI_FILE_CLOSE(ifile, ierr)
934-
end if
935-
936-
call MPI_BCAST(proc_bubble_counts, file_num_procs, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
937-
938931
! Set time variables from file
939932
940933
nBub = proc_bubble_counts(proc_rank + 1)

0 commit comments

Comments
 (0)