@@ -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