Skip to content

Commit 07ce29d

Browse files
committed
mpi barrier to synchronise xios_close_context_definition for MPI-IO coordination
1 parent 0982697 commit 07ce29d

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

components/lfric-xios/source/lfric_xios_context_mod.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module lfric_xios_context_mod
5151
type(xios_context) :: handle
5252
type(linked_list_type) :: filelist
5353
integer(i_def) :: context_clock_step = 1_i_def
54+
type(lfric_comm_type) :: communicator
5455

5556
logical :: uses_timer = .false.
5657
logical :: xios_context_initialised = .false.
@@ -147,6 +148,8 @@ subroutine initialise_xios_context( this, &
147148
zero_start = .false.
148149
end if
149150

151+
this%communicator = communicator
152+
150153
call xios_context_initialize( this%get_context_name(), &
151154
communicator%get_comm_mpi_val() )
152155
call xios_get_handle( this%get_context_name(), this%handle )
@@ -191,6 +194,8 @@ subroutine close_context_definition(this)
191194
! can be defined after this point
192195
if ( LPROF ) call start_timing(timing_id, 'xios.close_context_definition')
193196
call log_event('XIOS context definition closing', log_level_debug)
197+
! Set an MPI barrier to support MPI-IO metadata interaction synchronisation.
198+
call this%communicator%barrier_mpi()
194199
call xios_close_context_definition()
195200
if ( LPROF ) call stop_timing(timing_id, 'xios.close_context_definition')
196201
call log_event('XIOS context definition closed', log_level_debug)

infrastructure/source/utilities/lfric_mpi_mod.F90

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module lfric_mpi_mod
2323
mpi_character, &
2424
mpi_init, mpi_finalize, &
2525
mpi_comm_dup, mpi_comm_free, &
26-
mpi_comm_size, mpi_comm_rank
26+
mpi_comm_size, mpi_comm_rank, mpi_barrier
2727
#else
2828
use mpi_f08, only: mpi_comm, mpi_datatype, mpi_comm_world, &
2929
mpi_sum, mpi_min, mpi_max, mpi_success, &
@@ -32,7 +32,7 @@ module lfric_mpi_mod
3232
mpi_character, &
3333
mpi_init, mpi_finalize, &
3434
mpi_comm_dup, mpi_comm_free, &
35-
mpi_comm_size, mpi_comm_rank
35+
mpi_comm_size, mpi_comm_rank, mpi_barrier
3636
#endif
3737
! The above use statement should include mpi_bcast, mpi_allreduce and
3838
! mpi_allgather, but an apparent bug in Cray mpich causes a failure if
@@ -150,6 +150,7 @@ module lfric_mpi_mod
150150
contains
151151
procedure, public :: get_comm_mpi_val
152152
procedure, public :: set_comm_mpi_val
153+
procedure, public :: barrier_mpi
153154
end type
154155

155156
#ifdef NO_MPI
@@ -1526,6 +1527,23 @@ subroutine set_comm_mpi_val(self, comm)
15261527
#endif
15271528
end subroutine set_comm_mpi_val
15281529

1530+
!> Call an MPI Barrier, synchronising ranks in the communicator.
1531+
subroutine barrier_mpi(self)
1532+
implicit none
1533+
class(lfric_comm_type), intent(in) :: self
1534+
integer :: ierr
1535+
1536+
#ifdef NO_MPI
1537+
! null operation, barrier is non-existant
1538+
ierr = 0
1539+
#else
1540+
call mpi_barrier(self%comm, ierr)
1541+
if (ierr /= mpi_success) then
1542+
call log_event('Unable to progress through MPI barrier', LOG_LEVEL_ERROR )
1543+
end if
1544+
#endif
1545+
end subroutine barrier_mpi
1546+
15291547
!> Returns the integer datatype
15301548
!>
15311549
!> @return datatype The integer component of the datatype

0 commit comments

Comments
 (0)