MAPL_CFIOPartition Subroutine

public subroutine MAPL_CFIOPartition(Slices, NumColls, NumNodes, Writing, Psize, Root)

Returns Psize and Root, the size (in nodes) and root node of each node partition assigned to active collections.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: Slices(NumColls)

number of 2-D sections or slices in each collection. The number in inactive collections is ignored.

integer, intent(in) :: NumColls

number of nodes being dealt out to the partitions

integer, intent(in) :: NumNodes

total number of collection, some of which may be inactive

logical, intent(in) :: Writing(NumColls)

identifies active collection

integer, intent(out) :: Psize(NumColls)
integer, intent(out) :: Root(NumColls)

Calls

proc~~mapl_cfiopartition~~CallsGraph proc~mapl_cfiopartition MAPL_CFIOPartition interface~mapl_sort MAPL_Sort proc~mapl_cfiopartition->interface~mapl_sort

Source Code

  subroutine MAPL_CFIOPartition(Slices, NumColls, NumNodes, Writing, Psize,Root)
    integer, intent(IN ) :: NumColls           !! number of nodes being dealt out to the partitions
    integer, intent(IN ) :: NumNodes           !! total number of collection,
                                               !! some of which may be inactive
    integer, intent(IN ) :: Slices(NumColls)   !! number of 2-D sections or slices in each collection.
                                               !! The number in inactive collections is ignored.
    logical, intent(IN ) :: Writing(NumColls)  !! identifies active collection
    integer, intent(OUT) :: Psize(NumColls)
    integer, intent(OUT) :: Root(NumColls)

    integer :: MaxSlicesPerNode, n
    integer :: CurrNode, Len, SlicesInNode

    integer, dimension(NumColls) :: SortedSlices, CollNo

! Begin
!------

! Make sure all outputs are initialized.
! Needed only for inactive collections.
!---------------------------------------

    Psize = 0
    Root  = 1

! Sort the collection sizes (# of slices) in ascending order.
!  Also sort the collection index the same way, to fill the
!  correct ones later.
!------------------------------------------------------------
    where(writing)
       SortedSlices = Slices
    elsewhere
       SortedSlices = 0
    endwhere

    do n=1,NumColls
       CollNo(n) = n
    end do

    call MAPL_Sort(SortedSlices, CollNo)

! This is the maximum number of slices in a node if all slices
!  were uniformly distributed without honoring collection and
!  node boundaries. Since every collection boundary must also be
!  a node boundary, this is a lower bound on MaxSlicesPerNode
! and is used as our initial guess.

    MaxSlicesPerNode = (sum(Slices,mask=Writing)-1)/NumNodes + 1
    ! ALT: The above expression could be zero if
    !      NumNodes==1 and the sum over "writing" slices is 0 (i.e. no writing)
    MaxSlicesPerNode = max(MaxSlicesPerNode,1) ! make sure it is not 0

! We try to distribute the slices in active collections as uniformly
!  as possible. "Small" collections (<= MaxSlicesPerNode) are
!  assigned to a single node, others span multiple nodes.
!  Small collections are grouped in a node without
!  exceeding MaxSlicesPerNode. Multi-node collections are
!  not grouped in nodes. Since MaxSlicesPerNode  is generally
!  too small to fit all the collections, it is then increased,until
!  all the active collections fit in the given nodes.
!--------------------------------------------------------------------
    do
       CurrNode     = 1
       SlicesInNode = 0

       COLLECTIONS: do n=1,NumColls
          ACTIVE: if(Writing(CollNo(n))) then

             if(SortedSlices(n)<MaxSlicesPerNode) then ! A single-node collection
                SlicesInNode = SlicesInNode + SortedSlices(n)

                if(SlicesInNode > MaxSlicesPerNode) then ! Current Coll oveerfills node
                   CurrNode     = CurrNode + 1
                   SlicesInNode = SortedSlices(n)
                end if

                Psize(CollNo(n)) = 1
                Root (CollNo(n)) = (CurrNode-1) + 1

             else                                      ! A multi-node collection
                Len = (SortedSlices(n)-1)/MaxSlicesPerNode + 1

                Psize(CollNo(n)) = Len
                Root (CollNo(n)) = (CurrNode-1) + 1

                CurrNode = CurrNode + len
             endif

          endif ACTIVE
       end do COLLECTIONS

       if(CurrNode<=NumNodes) exit

       MaxSlicesPerNode = MaxSlicesPerNode + 1
    enddo

    return

  end subroutine MAPL_CFIOPartition