Evaluate the imbalance of all the processes by each rank.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in) | :: | myCost |
each process cpu cost. Basis to evaluate the imbalance |
||
integer, | intent(in) | :: | comm |
MPI Communicator |
||
integer, | intent(in) | :: | nProcs |
MPI Communicator |
||
logical, | intent(in) | :: | isRoot |
Whether this rank is the root |
in percentage
function tem_calc_imbalance( myCost, comm, nProcs, isRoot ) result ( imbalance ) ! --------------------------------------------------------------------------- !> each process cpu cost. Basis to evaluate the imbalance real(kind=rk), intent(in) :: myCost !> MPI Communicator integer, intent(in) :: comm, nProcs !> in percentage real(kind=rk) :: imbalance !> Whether this rank is the root logical, intent(in) :: isRoot ! --------------------------------------------------------------------------- ! computation cost over all processes real(kind=rk) :: totalCost, maxCost integer :: iErr ! error handle ! --------------------------------------------------------------------------- call mpi_reduce( myCost, maxCost, 1, rk_mpi, mpi_max, 0, comm, iErr) call mpi_reduce( myCost, totalCost, 1, rk_mpi, mpi_sum, 0, comm, iErr) imbalance = -9999._rk ! the value range of imbalance is [100%, nProcs] ! The smaller the value, the better the balance is if ( isRoot ) then totalCost = totalCost/dble(nProcs) imbalance = maxCost / totalCost * 100 call tem_horizontalSpacer(fUnit=logUnit(5)) write(logUnit(3),"(A)") ' Load balance evaluation:' write(logUnit(3),"(A,F10.2,A)") ' max CPU cost:', maxCost, ' (s)' write(logUnit(3),"(A,F10.2,A)") ' ave CPU cost:', totalCost, ' (s)' write(logUnit(3),"(A,F10.2,A)") ' imbalance (i.e. max/ave):', imbalance, '%' call tem_horizontalSpacer(fUnit=logUnit(5)) end if end function tem_calc_imbalance