From df1e4a4616f1b7d9a2aaa8a4b790d7c7d9dca302 Mon Sep 17 00:00:00 2001 From: StefanoPetrilli Date: Sun, 10 Jul 2022 04:31:51 -0500 Subject: [PATCH] PROCESS_CROSS_EDGE refactoring --- ...mEdgesLinearSearchMesgBndlSmallMateCMP.cpp | 81 ++----------------- amgprec/impl/aggregator/processCrossEdge.cpp | 33 ++++++++ .../impl/aggregator/processExposedVertex.cpp | 20 +---- .../aggregator/processMatchedVertices.cpp | 16 +--- 4 files changed, 45 insertions(+), 105 deletions(-) create mode 100644 amgprec/impl/aggregator/processCrossEdge.cpp diff --git a/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp b/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp index cfd6b927..6b189da5 100644 --- a/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp +++ b/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp @@ -9,6 +9,7 @@ #include "processExposedVertex.cpp" #include "processMatchedVertices.cpp" #include "sendBundledMessages.cpp" +//#include "processCrossEdge.cpp" // *********************************************************************** // @@ -506,21 +507,9 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") "; fflush(stdout); #endif - // Decrement the counter: - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) - if (Counter[Ghost2LocalMap[w]] > 0) - { - Counter[Ghost2LocalMap[w]] = Counter[Ghost2LocalMap[w]] - 1; // Decrement - if (Counter[Ghost2LocalMap[w]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << w << " has received all its messages"; - fflush(stdout); -#endif - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) + + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, &S); + } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex else @@ -759,20 +748,7 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( cout << "\n(" << myRank << ")MATCH: (" << v << "," << u << ") " << endl; fflush(stdout); #endif - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) - if (Counter[Ghost2LocalMap[u]] > 0) - { - Counter[Ghost2LocalMap[u]] = Counter[Ghost2LocalMap[u]] - 1; // Decrement - if (Counter[Ghost2LocalMap[u]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << u << " has received all its messages" << endl; - fflush(stdout); -#endif - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, u, &S); } // End of if ( candidateMate[v-StartIndex] == u )e } // End of if ( Mate[v] == -1 ) } // End of REQUEST @@ -784,22 +760,8 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( cout << "\n(" << myRank << ")Message type is SUCCESS" << endl; fflush(stdout); #endif - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) GMate[Ghost2LocalMap[u]] = EndIndex + 1; // Set a Dummy Mate to make sure that we do not (u is a ghost) - // process it again - if (Counter[Ghost2LocalMap[u]] > 0) - { - Counter[Ghost2LocalMap[u]] = Counter[Ghost2LocalMap[u]] - 1; // Decrement - if (Counter[Ghost2LocalMap[u]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << u << " has received all its messages"; - fflush(stdout); -#endif - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, u, &S); #ifdef DEBUG_GHOST_ if ((v < 0) || (v < StartIndex) || ((v - StartIndex) > NLVer)) { @@ -877,20 +839,7 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( fflush(stdout); #endif // Decrement the counter: - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) - if (Counter[Ghost2LocalMap[w]] > 0) - { - Counter[Ghost2LocalMap[w]] = Counter[Ghost2LocalMap[w]] - 1; // Decrement - if (Counter[Ghost2LocalMap[w]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << w << " has received all its messages"; - fflush(stdout); -#endif - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, &S); } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex else @@ -949,22 +898,8 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( cout << "\n(" << myRank << ")Message type is FAILURE" << endl; fflush(stdout); #endif - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) GMate[Ghost2LocalMap[u]] = EndIndex + 1; // Set a Dummy Mate to make sure that we do not (u is a ghost) - // process it again - if (Counter[Ghost2LocalMap[u]] > 0) - { - Counter[Ghost2LocalMap[u]] = Counter[Ghost2LocalMap[u]] - 1; // Decrement - if (Counter[Ghost2LocalMap[u]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << u << " has received all its messages"; - fflush(stdout); -#endif - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, u, &S); } // End of else: CASE III } // End of else: CASE I } // End of if (!MsgQ.empty()) diff --git a/amgprec/impl/aggregator/processCrossEdge.cpp b/amgprec/impl/aggregator/processCrossEdge.cpp new file mode 100644 index 00000000..f99bee1a --- /dev/null +++ b/amgprec/impl/aggregator/processCrossEdge.cpp @@ -0,0 +1,33 @@ +#include "MatchBoxPC.h" +#include +#include +#include +#include +#include +#include "primitiveDataTypeDefinitions.h" +#include "dataStrStaticQueue.h" +#include "omp.h" + +inline void PROCESS_CROSS_EDGE(vector &Counter, + map &Ghost2LocalMap, + MilanLongInt edge, + MilanLongInt *SPtr) +{ + MilanLongInt S = *SPtr; + // Decrement the counter: + // Start: PARALLEL_PROCESS_CROSS_EDGE_B + if (Counter[Ghost2LocalMap[edge]] > 0) + { + Counter[Ghost2LocalMap[edge]] -= 1; // Decrement + if (Counter[Ghost2LocalMap[edge]] == 0) + { + S--; // Decrement S +#ifdef PRINT_DEBUG_INFO_ + cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << edge << " has received all its messages"; + fflush(stdout); +#endif + } + } // End of if Counter[edge] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B + *SPtr = S; +} \ No newline at end of file diff --git a/amgprec/impl/aggregator/processExposedVertex.cpp b/amgprec/impl/aggregator/processExposedVertex.cpp index dd9562d5..9ba155f9 100644 --- a/amgprec/impl/aggregator/processExposedVertex.cpp +++ b/amgprec/impl/aggregator/processExposedVertex.cpp @@ -8,6 +8,7 @@ #include "dataStrStaticQueue.h" #include "omp.h" #include "queueTransfer.cpp" +#include "processCrossEdge.cpp" inline void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, MilanLongInt *candidateMate, @@ -129,24 +130,7 @@ inline void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, //TODO refactor this!! // Decrement the counter: - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v) -#pragma omp critical - { - if (Counter[Ghost2LocalMap[w]] > 0) - { - - Counter[Ghost2LocalMap[w]] -= 1; // Decrement - if (Counter[Ghost2LocalMap[w]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << w << " has received all its messages"; - fflush(stdout); -#endif - } - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v) + 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 5f54ef79..1e496888 100644 --- a/amgprec/impl/aggregator/processMatchedVertices.cpp +++ b/amgprec/impl/aggregator/processMatchedVertices.cpp @@ -177,20 +177,8 @@ inline void processMatchedVertices( // TODO refactor this // Decrement the counter: - // Start: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) - if (Counter[Ghost2LocalMap[w]] > 0) - { - Counter[Ghost2LocalMap[w]] = Counter[Ghost2LocalMap[w]] - 1; // Decrement - if (Counter[Ghost2LocalMap[w]] == 0) - { - S--; // Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << w << " has received all its messages"; - fflush(stdout); -#endif - } - } // End of if Counter[w] > 0 - // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) + PROCESS_CROSS_EDGE(Counter, Ghost2LocalMap, w, &S); + } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex else