setup_owned_gather Subroutine

private subroutine setup_owned_gather(mesh, flow, max_gather_components)

Pre-calculates MPI gather offsets and counts for allgather operations.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(flow_mpi_t), intent(inout) :: flow
integer, intent(in), optional :: max_gather_components

Calls

proc~~setup_owned_gather~~CallsGraph proc~setup_owned_gather mod_mpi_flow::setup_owned_gather mpi_allgather mpi_allgather proc~setup_owned_gather->mpi_allgather proc~check_mpi~2 mod_mpi_flow::check_mpi proc~setup_owned_gather->proc~check_mpi~2 proc~fatal_error mod_kinds::fatal_error proc~setup_owned_gather->proc~fatal_error proc~check_mpi~2->proc~fatal_error

Called by

proc~~setup_owned_gather~~CalledByGraph proc~setup_owned_gather mod_mpi_flow::setup_owned_gather proc~flow_mpi_initialize mod_mpi_flow::flow_mpi_initialize proc~flow_mpi_initialize->proc~setup_owned_gather program~lowmach_react_hex lowmach_react_hex program~lowmach_react_hex->proc~flow_mpi_initialize

Source Code

   subroutine setup_owned_gather(mesh, flow, max_gather_components)
      type(mesh_t), intent(in) :: mesh
      type(flow_mpi_t), intent(inout) :: flow
      integer, intent(in), optional :: max_gather_components
      integer :: ierr, r, total_count
      integer :: max_components

      allocate(flow%gather_counts(flow%nprocs))
      allocate(flow%gather_displs(flow%nprocs))
      allocate(flow%gather_firsts(flow%nprocs))

      call MPI_Allgather(flow%nlocal, 1, MPI_INTEGER, &
                         flow%gather_counts, 1, MPI_INTEGER, flow%comm, ierr)
      call check_mpi(ierr, 'MPI_Allgather gather counts')

      call MPI_Allgather(flow%first_cell, 1, MPI_INTEGER, &
                         flow%gather_firsts, 1, MPI_INTEGER, flow%comm, ierr)
      call check_mpi(ierr, 'MPI_Allgather gather firsts')

      flow%gather_displs(1) = 0
      do r = 2, flow%nprocs
         flow%gather_displs(r) = flow%gather_displs(r - 1) + flow%gather_counts(r - 1)
      end do

      total_count = sum(flow%gather_counts)

      if (total_count /= mesh%ncells) then
         call fatal_error('mpi_flow', 'owned gather counts do not sum to ncells')
      end if

      allocate(flow%gather_sendbuf(flow%nlocal))
      allocate(flow%gather_recvbuf(total_count))

      max_components = 4
      if (present(max_gather_components)) max_components = max(max_components, max_gather_components)
      max_components = max(1, max_components)

      flow%gather_max_components = max_components
      allocate(flow%gather_matrix_counts(flow%nprocs))
      allocate(flow%gather_matrix_displs(flow%nprocs))
      allocate(flow%gather_matrix_sendbuf(flow%nlocal * max_components))
      allocate(flow%gather_matrix_recvbuf(total_count * max_components))
   end subroutine setup_owned_gather