comms_array_split Subroutine

public subroutine comms_array_split(numpoints, counts, displs)

Uses

  • proc~~comms_array_split~~UsesGraph proc~comms_array_split comms_array_split module~w90_io w90_io proc~comms_array_split->module~w90_io module~w90_constants w90_constants module~w90_io->module~w90_constants

Given an array of size numpoints, we want to split on num_nodes nodes. This function returns two arrays: count and displs.

The i-th element of the count array gives the number of elements that must be calculated by the process with id (i-1). The i-th element of the displs array gives the displacement of the array calculated locally on the process with id (i-1) with respect to the global array.

These values are those to be passed to the functions MPI_Scatterv, MPI_Gatherv and MPI_Alltoallv.

one can use the following do loop to run over the needed elements, if the full array is stored on all nodes: do i=displs(my_node_id)+1,displs(my_node_id)+counts(my_node_id)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: numpoints

Number of elements of the array to be scattered

integer, intent(out), dimension(0:num_nodes - 1):: counts

Array (of size num_nodes) with the number of elements of the array on each node

integer, intent(out), dimension(0:num_nodes - 1):: displs

Array (of size num_nodes) with the displacement relative to the global array


Called by

proc~~comms_array_split~~CalledByGraph proc~comms_array_split comms_array_split proc~boltzwann_main boltzwann_main proc~boltzwann_main->proc~comms_array_split proc~wannier_run wannier_run proc~wannier_run->proc~comms_array_split proc~overlap_allocate overlap_allocate proc~wannier_run->proc~overlap_allocate proc~wann_main wann_main proc~wannier_run->proc~wann_main proc~dis_main dis_main proc~wannier_run->proc~dis_main proc~overlap_project overlap_project proc~wannier_run->proc~overlap_project proc~overlap_allocate->proc~comms_array_split proc~wann_main->proc~comms_array_split proc~k_slice k_slice proc~k_slice->proc~comms_array_split proc~dis_main->proc~comms_array_split proc~dis_extract dis_extract proc~dis_main->proc~dis_extract proc~overlap_read overlap_read proc~overlap_read->proc~comms_array_split proc~overlap_read->proc~overlap_project proc~k_path k_path proc~k_path->proc~comms_array_split proc~geninterp_main geninterp_main proc~geninterp_main->proc~comms_array_split proc~dis_extract->proc~comms_array_split proc~overlap_project->proc~comms_array_split program~wannier wannier program~wannier->proc~overlap_allocate program~wannier->proc~wann_main program~wannier->proc~dis_main program~wannier->proc~overlap_read

Contents

Source Code


Source Code

  subroutine comms_array_split(numpoints, counts, displs)
    !! Given an array of size numpoints, we want to split on num_nodes nodes. This function returns
    !! two arrays: count and displs.
    !!
    !! The i-th element of the count array gives the number of elements
    !! that must be calculated by the process with id (i-1).
    !! The i-th element of the displs array gives the displacement of the array calculated locally on
    !! the process with id (i-1) with respect to the global array.
    !!
    !! These values are those to be passed to the functions MPI_Scatterv, MPI_Gatherv and MPI_Alltoallv.
    !!
    !! one can use the following do loop to run over the needed elements, if the full array is stored
    !! on all nodes:
    !! do i=displs(my_node_id)+1,displs(my_node_id)+counts(my_node_id)
    !!
    use w90_io
    integer, intent(in) :: numpoints
    !! Number of elements of the array to be scattered
    integer, dimension(0:num_nodes - 1), intent(out) :: counts
    !! Array (of size num_nodes) with the number of elements of the array on each node
    integer, dimension(0:num_nodes - 1), intent(out) :: displs
    !! Array (of size num_nodes) with the displacement relative to the global array

    integer :: ratio, remainder, i

    ratio = numpoints/num_nodes
    remainder = MOD(numpoints, num_nodes)

    do i = 0, num_nodes - 1
      if (i < remainder) then
        counts(i) = ratio + 1
        displs(i) = i*(ratio + 1)
      else
        counts(i) = ratio
        displs(i) = remainder*(ratio + 1) + (i - remainder)*ratio
      end if
    end do

  end subroutine comms_array_split