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
Intent
Optional
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
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
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 scatteredinteger,intent(inout)::counts(0:)!! Array (of size num_nodes) with the number of elements of the array on each nodeinteger,intent(inout)::displs(0:)!! Array (of size num_nodes) with the displacement relative to the global arraytype(w90_comm_type),intent(in)::comminteger::ratio,remainder,iinteger::num_nodesnum_nodes=mpisize(comm)ratio=numpoints/num_nodesremainder=MOD(numpoints,num_nodes)do i=0,num_nodes-1if(i<remainder)thencounts(i)=ratio+1displs(i)=i*(ratio+1)elsecounts(i)=ratiodispls(i)=remainder*(ratio+1)+(i-remainder)*ratioend if end do end subroutine comms_array_split