From 44f174a5714063b50cb08a689b237258aea2f75b Mon Sep 17 00:00:00 2001 From: StefanoPetrilli Date: Sun, 17 Jul 2022 13:44:58 -0500 Subject: [PATCH] findOwnerOfGhost optimization and refactor --- amgprec/impl/aggregator/findOwnerOfGhost.cpp | 57 +++++++------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/amgprec/impl/aggregator/findOwnerOfGhost.cpp b/amgprec/impl/aggregator/findOwnerOfGhost.cpp index 109802de..b9d60614 100644 --- a/amgprec/impl/aggregator/findOwnerOfGhost.cpp +++ b/amgprec/impl/aggregator/findOwnerOfGhost.cpp @@ -1,48 +1,29 @@ #include "MatchBoxPC.h" - -//TODO parallelize this -///Find the owner of a ghost node: +/// Find the owner of a ghost node: MilanInt findOwnerOfGhost(MilanLongInt vtxIndex, MilanLongInt *mVerDistance, - MilanInt myRank, MilanInt numProcs) { + MilanInt myRank, MilanInt numProcs) +{ MilanLongInt mStartInd = mVerDistance[myRank]; MilanInt Start = 0; MilanInt End = numProcs; MilanInt Current = 0; -#if 0 - if ( vtxIndex < mStartInd ) - End = myRank; - else - Start = myRank; -#endif + while (Start <= End) + { + Current = (End + Start) / 2; + // CASE-1: + if (mVerDistance[Current] == vtxIndex) return Current; + else // CASE 2: + if (mVerDistance[Current] > vtxIndex) + End = Current - 1; + else // CASE 3: + Start = Current + 1; + } // End of While() + + if (mVerDistance[Current] > vtxIndex) + return (Current - 1); - while ( Start <= End ) { - Current = (End + Start)/2; - //CASE-1: - if ( mVerDistance[Current] == vtxIndex ) { - while ( mVerDistance[Current+1] == vtxIndex ) { - Current++; - if ( Current == numProcs ) - return (-1); - } - return (Current); - } - else { //CASE 2: - if ( mVerDistance[Current] > vtxIndex ) - End = Current - 1; - else //CASE 3: - Start = Current + 1; - } - } //End of While() - if ( Current == 0 ) - return (Current); - else { - if ( mVerDistance[Current] > vtxIndex ) - return (Current-1); - else - return (Current); - } //End of else - return (-1); //It should not reach here! -} //End of findOwnerOfGhost() + return Current; +} // End of findOwnerOfGhost()