comms_array_split Subroutine

public subroutine comms_array_split(numpoints, counts, displs, comm)

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 Attributes Name
integer, intent(in) :: numpoints

Number of elements of the array to be scattered

integer, intent(inout) :: counts(0:)

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

integer, intent(inout) :: displs(0:)

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

type(w90_comm_type), intent(in) :: comm

Calls

proc~~comms_array_split~~CallsGraph proc~comms_array_split comms_array_split proc~mpisize mpisize proc~comms_array_split->proc~mpisize

Called by

proc~~comms_array_split~~CalledByGraph proc~comms_array_split comms_array_split proc~berry_main berry_main proc~berry_main->proc~comms_array_split proc~get_aa_r get_AA_R proc~berry_main->proc~get_aa_r proc~get_bb_r get_BB_R proc~berry_main->proc~get_bb_r proc~get_cc_r get_CC_R proc~berry_main->proc~get_cc_r proc~get_saa_r get_SAA_R proc~berry_main->proc~get_saa_r proc~get_sbb_r get_SBB_R proc~berry_main->proc~get_sbb_r proc~berry_get_sc_klist berry_get_sc_klist proc~berry_main->proc~berry_get_sc_klist proc~boltzwann_main boltzwann_main proc~boltzwann_main->proc~comms_array_split proc~geninterp_main geninterp_main proc~geninterp_main->proc~comms_array_split proc~get_aa_r->proc~comms_array_split proc~get_bb_r->proc~comms_array_split proc~get_cc_r->proc~comms_array_split proc~get_saa_r->proc~comms_array_split proc~get_sbb_r->proc~comms_array_split proc~k_path k_path proc~k_path->proc~comms_array_split proc~k_path->proc~get_aa_r proc~k_path->proc~get_bb_r proc~k_path->proc~get_cc_r proc~k_slice k_slice proc~k_slice->proc~comms_array_split proc~k_slice->proc~get_aa_r proc~k_slice->proc~get_bb_r proc~k_slice->proc~get_cc_r proc~plot_interpolate_bands plot_interpolate_bands proc~plot_interpolate_bands->proc~comms_array_split proc~gyrotropic_main gyrotropic_main proc~gyrotropic_main->proc~get_aa_r proc~gyrotropic_main->proc~get_bb_r proc~gyrotropic_main->proc~get_cc_r proc~plot_main plot_main proc~plot_main->proc~plot_interpolate_bands proc~wham_get_eig_uu_hh_aa_sc_tb_conv wham_get_eig_UU_HH_AA_sc_TB_conv proc~wham_get_eig_uu_hh_aa_sc_tb_conv->proc~get_aa_r program~postw90 postw90 program~postw90->proc~berry_main program~postw90->proc~boltzwann_main program~postw90->proc~geninterp_main program~postw90->proc~k_path program~postw90->proc~k_slice program~postw90->proc~gyrotropic_main proc~berry_get_sc_klist->proc~wham_get_eig_uu_hh_aa_sc_tb_conv proc~w90_plot w90_plot proc~w90_plot->proc~plot_main program~wannier wannier program~wannier->proc~w90_plot

Source Code

  subroutine comms_array_split(numpoints, counts, displs, comm)
    !! 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)
    !!

    integer, intent(in) :: numpoints  !! Number of elements of the array to be scattered
    integer, intent(inout) :: counts(0:) !! Array (of size num_nodes) with the number of elements of the array on each node
    integer, intent(inout) :: displs(0:) !! Array (of size num_nodes) with the displacement relative to the global array
    type(w90_comm_type), intent(in) :: comm

    integer :: ratio, remainder, i
    integer :: num_nodes

    num_nodes = mpisize(comm)

    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