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

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