subroutine communicate_rdm_spawn_t_wrapper(spawn, rdm_recv, finished, all_finished)
! This is a wrapper function around communicate_rdm_spawn_t, which is
! useful for certain routines in rdm_finalising and rdm_estimators.
! Upon calling this routine, each process will input the logical
! finished as either .true. or .false., with the former indicating
! that this will be the final call to communicate_rdm_spawn_t by the
! routine. This routine then checks if ever routine is on its final
! required call, and if so, the calling functions can know to not
! perform any further communications.
use Parallel_neci, only: MPIAllGather
type(rdm_spawn_t), intent(inout) :: spawn
type(rdm_list_t), optional, intent(inout) :: rdm_recv
logical, intent(in) :: finished
logical, intent(inout) :: all_finished
logical :: finished_array(nProcessors)
integer :: ierr
call communicate_rdm_spawn_t(spawn, rdm_recv)
! Find if all processes have finished their communication.
call MPIAllGather(finished, finished_array, ierr)
all_finished = all(finished_array)
end subroutine communicate_rdm_spawn_t_wrapper