From 5ca78fb871c963a93578af05e2b330a08a964334 Mon Sep 17 00:00:00 2001 From: StefanoPetrilli Date: Thu, 14 Jul 2022 17:10:36 -0500 Subject: [PATCH] Refactoring isAlreadyMatched and processCrossEdge --- amgprec/impl/aggregator/MatchBoxPC.h | 1 - ...mEdgesLinearSearchMesgBndlSmallMateCMP.cpp | 4 +-- amgprec/impl/aggregator/isAlreadyMatched.cpp | 6 ++-- amgprec/impl/aggregator/processCrossEdge.cpp | 7 ++-- .../impl/aggregator/processExposedVertex.cpp | 2 +- .../aggregator/processMatchedVertices.cpp | 2 +- amgprec/impl/aggregator/processMessages.cpp | 36 +++++++++---------- 7 files changed, 25 insertions(+), 33 deletions(-) diff --git a/amgprec/impl/aggregator/MatchBoxPC.h b/amgprec/impl/aggregator/MatchBoxPC.h index fc141b43..a8f22f49 100644 --- a/amgprec/impl/aggregator/MatchBoxPC.h +++ b/amgprec/impl/aggregator/MatchBoxPC.h @@ -290,7 +290,6 @@ extern "C" staticQueue &privateQOwner); void PROCESS_CROSS_EDGE(vector &Counter, - map &Ghost2LocalMap, MilanLongInt edge, MilanLongInt *SPtr); diff --git a/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp b/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp index 45c49ec0..6e24393b 100644 --- a/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp +++ b/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp @@ -142,7 +142,6 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( vector QLocalVtx, QGhostVtx, QMsgType; vector QOwner; // Changed by Fabio to be an integer, addresses needs to be integers! - // TODO move this inseide the initialization function MilanLongInt *PCounter = new MilanLongInt[numProcs]; for (int i = 0; i < numProcs; i++) PCounter[i] = 0; @@ -358,7 +357,6 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")Entering While(true) loop.."; fflush(stdout); - // U.display(); fflush(stdout); #endif #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << "=========================************===============================" << endl; @@ -468,7 +466,7 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( fflush(stdout); #endif - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, &S); + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[w], &S); } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex diff --git a/amgprec/impl/aggregator/isAlreadyMatched.cpp b/amgprec/impl/aggregator/isAlreadyMatched.cpp index dbb1052f..38ae73f5 100644 --- a/amgprec/impl/aggregator/isAlreadyMatched.cpp +++ b/amgprec/impl/aggregator/isAlreadyMatched.cpp @@ -23,11 +23,9 @@ bool isAlreadyMatched(MilanLongInt node, #pragma omp critical(Mate) { if ((node < StartIndex) || (node > EndIndex)) { //Is it a ghost vertex? - if (GMate[Ghost2LocalMap[node]] >= 0)// Already matched - result = true; + result = GMate[Ghost2LocalMap[node]] >= 0;// Already matched } else { //A local vertex - if (Mate[node - StartIndex] >= 0) // Already matched - result = true; + result = (Mate[node - StartIndex] >= 0); // Already matched } } diff --git a/amgprec/impl/aggregator/processCrossEdge.cpp b/amgprec/impl/aggregator/processCrossEdge.cpp index 1ef99560..ee367a61 100644 --- a/amgprec/impl/aggregator/processCrossEdge.cpp +++ b/amgprec/impl/aggregator/processCrossEdge.cpp @@ -1,16 +1,15 @@ #include "MatchBoxPC.h" void PROCESS_CROSS_EDGE(vector &Counter, - map &Ghost2LocalMap, MilanLongInt edge, MilanLongInt *SPtr) { // Decrement the counter: // Start: PARALLEL_PROCESS_CROSS_EDGE_B - if (Counter[Ghost2LocalMap[edge]] > 0) + if (Counter[edge] > 0) { - Counter[Ghost2LocalMap[edge]] -= 1; // Decrement - if (Counter[Ghost2LocalMap[edge]] == 0) + Counter[edge] -= 1; // Decrement + if (Counter[edge] == 0) { (*SPtr)--; // Decrement S #ifdef PRINT_DEBUG_INFO_ diff --git a/amgprec/impl/aggregator/processExposedVertex.cpp b/amgprec/impl/aggregator/processExposedVertex.cpp index 50a5ecfd..97840b19 100644 --- a/amgprec/impl/aggregator/processExposedVertex.cpp +++ b/amgprec/impl/aggregator/processExposedVertex.cpp @@ -115,7 +115,7 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, //TODO refactor this!! // Decrement the counter: - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, &S); + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[w], &S); } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex diff --git a/amgprec/impl/aggregator/processMatchedVertices.cpp b/amgprec/impl/aggregator/processMatchedVertices.cpp index aaef21a1..c1ae6d13 100644 --- a/amgprec/impl/aggregator/processMatchedVertices.cpp +++ b/amgprec/impl/aggregator/processMatchedVertices.cpp @@ -174,7 +174,7 @@ void processMatchedVertices( // TODO refactor this // Decrement the counter: - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, &S); + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[w], &S); } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex diff --git a/amgprec/impl/aggregator/processMessages.cpp b/amgprec/impl/aggregator/processMessages.cpp index 7ce867ff..7e5c3915 100644 --- a/amgprec/impl/aggregator/processMessages.cpp +++ b/amgprec/impl/aggregator/processMessages.cpp @@ -30,7 +30,7 @@ void processMessages( MilanInt Sender; MPI_Status computeStatus; - MilanLongInt bundleSize, bundleCounter = 0, myCard = *myCardPtr, msgInd = *msgIndPtr, msgActual = *msgActualPtr, w; + MilanLongInt bundleSize, myCard = *myCardPtr, msgInd = *msgIndPtr, msgActual = *msgActualPtr, w; MilanLongInt adj11, adj12, k1; MilanLongInt ghostOwner; int error_codeC; @@ -155,15 +155,13 @@ void processMessages( fflush(stdout); #endif - bundleCounter = 0; - while (bundleCounter < bundleSize) + + //Most of the time bundleSize == 3, thus, it's not worth parallelizing thi loop + for (MilanLongInt bundleCounter = 3; bundleCounter < bundleSize + 3; bundleCounter += 3) { - u = ReceiveBuffer[bundleCounter]; // GHOST - bundleCounter++; - v = ReceiveBuffer[bundleCounter]; // LOCAL - bundleCounter++; - message_type = ReceiveBuffer[bundleCounter]; // TYPE - bundleCounter++; + u = ReceiveBuffer[bundleCounter - 3]; // GHOST + v = ReceiveBuffer[bundleCounter - 2]; // LOCAL + message_type = ReceiveBuffer[bundleCounter - 1]; // TYPE // CASE I: REQUEST if (message_type == REQUEST) @@ -188,7 +186,6 @@ void processMessages( { GMate[Ghost2LocalMap[u]] = v; // u is ghost Mate[v - StartIndex] = u; // v is local - // Q.push_back(u); U.push_back(v); U.push_back(u); myCard++; @@ -196,7 +193,8 @@ void processMessages( cout << "\n(" << myRank << ")MATCH: (" << v << "," << u << ") " << endl; fflush(stdout); #endif - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, u, S); + + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[u], S); } // End of if ( candidateMate[v-StartIndex] == u )e } // End of if ( Mate[v] == -1 ) } // End of REQUEST @@ -208,8 +206,8 @@ void processMessages( cout << "\n(" << myRank << ")Message type is SUCCESS" << endl; fflush(stdout); #endif - GMate[Ghost2LocalMap[u]] = EndIndex + 1; // Set a Dummy Mate to make sure that we do not (u is a ghost) - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, u, S); + GMate[Ghost2LocalMap[u]] = EndIndex + 1; // Set a Dummy Mate to make sure that we do not (u is a ghost) process it again + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[u], S); #ifdef DEBUG_GHOST_ if ((v < 0) || (v < StartIndex) || ((v - StartIndex) > NLVer)) { @@ -261,8 +259,8 @@ void processMessages( cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl; fflush(stdout); #endif - // Decrement the counter: - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, S); + + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[w], S); } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex else @@ -320,10 +318,10 @@ void processMessages( cout << "\n(" << myRank << ")Message type is FAILURE" << endl; fflush(stdout); #endif - GMate[Ghost2LocalMap[u]] = EndIndex + 1; // Set a Dummy Mate to make sure that we do not (u is a ghost) process this anymore - PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, u, S); // Decrease the counter - } // End of else: CASE III - } // End of else: CASE I + GMate[Ghost2LocalMap[u]] = EndIndex + 1; // Set a Dummy Mate to make sure that we do not (u is a ghost) process this anymore + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap[u], S); // Decrease the counter + } // End of else: CASE III + } // End of else: CASE I } *myCardPtr = myCard;