From 3e945c75b44ccf75a097deaabb5700286e052b2c Mon Sep 17 00:00:00 2001 From: StefanoPetrilli Date: Sun, 17 Jul 2022 13:20:49 -0500 Subject: [PATCH] Refactoring, removed all useless Pointer passed in functions --- amgprec/impl/aggregator/processCrossEdge.cpp | 4 +- .../impl/aggregator/processExposedVertex.cpp | 96 +++++++++---------- amgprec/impl/aggregator/processMessages.cpp | 25 +++-- .../impl/aggregator/sendBundledMessages.cpp | 58 +++++------ 4 files changed, 85 insertions(+), 98 deletions(-) diff --git a/amgprec/impl/aggregator/processCrossEdge.cpp b/amgprec/impl/aggregator/processCrossEdge.cpp index 30af9f20..e844f127 100644 --- a/amgprec/impl/aggregator/processCrossEdge.cpp +++ b/amgprec/impl/aggregator/processCrossEdge.cpp @@ -1,7 +1,7 @@ #include "MatchBoxPC.h" void PROCESS_CROSS_EDGE(MilanLongInt *edge, - MilanLongInt *SPtr) + MilanLongInt *S) { // Start: PARALLEL_PROCESS_CROSS_EDGE_B MilanLongInt captureCounter; @@ -13,7 +13,7 @@ void PROCESS_CROSS_EDGE(MilanLongInt *edge, if (captureCounter == 0) #pragma omp atomic - (*SPtr)--; // Decrement S + (*S)--; // Decrement S #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << edge << " has received all its messages"; diff --git a/amgprec/impl/aggregator/processExposedVertex.cpp b/amgprec/impl/aggregator/processExposedVertex.cpp index a2ea6c8d..c28a7c66 100644 --- a/amgprec/impl/aggregator/processExposedVertex.cpp +++ b/amgprec/impl/aggregator/processExposedVertex.cpp @@ -1,45 +1,43 @@ #include "MatchBoxPC.h" void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, - MilanLongInt *candidateMate, - MilanLongInt *verLocInd, - MilanLongInt *verLocPtr, - MilanLongInt StartIndex, - MilanLongInt EndIndex, - MilanLongInt *Mate, - vector &GMate, - map &Ghost2LocalMap, - MilanReal *edgeLocWeight, - MilanLongInt *myCardPtr, - MilanLongInt *msgIndPtr, - MilanLongInt *NumMessagesBundledPtr, - MilanLongInt *SPtr, - MilanLongInt *verDistance, - MilanLongInt *PCounter, - vector &Counter, - MilanInt myRank, - MilanInt numProcs, - staticQueue &U, - staticQueue &privateU, - vector &QLocalVtx, - vector &QGhostVtx, - vector &QMsgType, - vector &QOwner, - staticQueue &privateQLocalVtx, - staticQueue &privateQGhostVtx, - staticQueue &privateQMsgType, - staticQueue &privateQOwner) + MilanLongInt *candidateMate, + MilanLongInt *verLocInd, + MilanLongInt *verLocPtr, + MilanLongInt StartIndex, + MilanLongInt EndIndex, + MilanLongInt *Mate, + vector &GMate, + map &Ghost2LocalMap, + MilanReal *edgeLocWeight, + MilanLongInt *myCard, + MilanLongInt *msgInd, + MilanLongInt *NumMessagesBundled, + MilanLongInt *S, + MilanLongInt *verDistance, + MilanLongInt *PCounter, + vector &Counter, + MilanInt myRank, + MilanInt numProcs, + staticQueue &U, + staticQueue &privateU, + vector &QLocalVtx, + vector &QGhostVtx, + vector &QMsgType, + vector &QOwner, + staticQueue &privateQLocalVtx, + staticQueue &privateQGhostVtx, + staticQueue &privateQMsgType, + staticQueue &privateQOwner) { - MilanLongInt v = -1, k = -1, w = -1, adj11 = 0, adj12 = 0, k1 = 0, S = *SPtr; - MilanLongInt myCard = 0, msgInd = 0; - MilanLongInt NumMessagesBundled = 0; + MilanLongInt v = -1, k = -1, w = -1, adj11 = 0, adj12 = 0, k1 = 0; MilanInt ghostOwner = 0; #pragma omp parallel private(k, w, v, k1, adj11, adj12, ghostOwner) firstprivate(privateU, StartIndex, EndIndex, privateQLocalVtx, privateQGhostVtx, privateQMsgType, privateQOwner) default(shared) num_threads(NUM_THREAD) { #pragma omp for reduction(+ \ - : msgInd, NumMessagesBundled, myCard, PCounter[:numProcs]) schedule(static) + : PCounter[:numProcs]) schedule(static) for (v = 0; v < NLVer; v++) { // Start: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v) @@ -76,8 +74,8 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, if (w >= 0) { - - myCard++; +#pragma omp atomic + (*myCard)++; if ((w < StartIndex) || (w > EndIndex)) { // w is a ghost vertex #ifdef PRINT_DEBUG_INFO_ @@ -85,9 +83,10 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, cout << "\n(" << myRank << ")Local is: " << v + StartIndex << " Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs) << endl; fflush(stdout); #endif - - msgInd++; - NumMessagesBundled++; +#pragma omp atomic + (*msgInd)++; +#pragma omp atomic + (*NumMessagesBundled)++; ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); @@ -97,7 +96,6 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, privateQGhostVtx.push_back(w); privateQMsgType.push_back(REQUEST); privateQOwner.push_back(ghostOwner); - if (candidateMate[NLVer + Ghost2LocalMap[w]] == v + StartIndex) { @@ -113,9 +111,9 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, fflush(stdout); #endif - //TODO refactor this!! - // Decrement the counter: - PROCESS_CROSS_EDGE(&Counter[Ghost2LocalMap[w]], &S); + // TODO refactor this!! + // Decrement the counter: + PROCESS_CROSS_EDGE(&Counter[Ghost2LocalMap[w]], S); } // End of if CandidateMate[w] = v } // End of if a Ghost Vertex @@ -159,9 +157,10 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, cout << "\n(" << myRank << ")Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs); fflush(stdout); #endif - - msgInd++; - NumMessagesBundled++; +#pragma omp atomic + (*msgInd)++; +#pragma omp atomic + (*NumMessagesBundled)++; ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); @@ -184,14 +183,5 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, privateQMsgType, privateQOwner); -//TODO move this outside of the parallel region!! -#pragma omp master - { - *myCardPtr = myCard; - *msgIndPtr = msgInd; - *NumMessagesBundledPtr = NumMessagesBundled; - *SPtr = S; - } - } // End of parallel region } \ No newline at end of file diff --git a/amgprec/impl/aggregator/processMessages.cpp b/amgprec/impl/aggregator/processMessages.cpp index c812e96d..43fc5ce9 100644 --- a/amgprec/impl/aggregator/processMessages.cpp +++ b/amgprec/impl/aggregator/processMessages.cpp @@ -9,9 +9,9 @@ void processMessages( vector &Counter, MilanLongInt StartIndex, MilanLongInt EndIndex, - MilanLongInt *myCardPtr, - MilanLongInt *msgIndPtr, - MilanLongInt *msgActualPtr, + MilanLongInt *myCard, + MilanLongInt *msgInd, + MilanLongInt *msgActual, MilanReal *edgeLocWeight, MilanLongInt *verDistance, MilanLongInt *verLocPtr, @@ -30,7 +30,7 @@ void processMessages( MilanInt Sender; MPI_Status computeStatus; - MilanLongInt bundleSize, myCard = *myCardPtr, msgInd = *msgIndPtr, msgActual = *msgActualPtr, w; + MilanLongInt bundleSize, w; MilanLongInt adj11, adj12, k1; MilanLongInt ghostOwner; int error_codeC; @@ -188,7 +188,7 @@ void processMessages( Mate[v - StartIndex] = u; // v is local U.push_back(v); U.push_back(u); - myCard++; + (*myCard)++; #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")MATCH: (" << v << "," << u << ") " << endl; fflush(stdout); @@ -246,15 +246,15 @@ void processMessages( assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); - msgInd++; - msgActual++; + (*msgInd)++; + (*msgActual)++; if (candidateMate[NLVer + Ghost2LocalMap[w]] == v) { Mate[v - StartIndex] = w; // v is local GMate[Ghost2LocalMap[w]] = v; // w is ghost U.push_back(v); U.push_back(w); - myCard++; + (*myCard)++; #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl; fflush(stdout); @@ -272,7 +272,7 @@ void processMessages( // Q.push_back(u); U.push_back(v); U.push_back(w); - myCard++; + (*myCard)++; #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl; fflush(stdout); @@ -303,8 +303,8 @@ void processMessages( assert(ghostOwner != -1); assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); - msgInd++; - msgActual++; + (*msgInd)++; + (*msgActual)++; } // End of if(GHOST) } // End of for loop } // End of Else: w == -1 @@ -324,8 +324,5 @@ void processMessages( } // End of else: CASE I } - *myCardPtr = myCard; - *msgIndPtr = msgInd; - *msgActualPtr = msgActual; return; } \ No newline at end of file diff --git a/amgprec/impl/aggregator/sendBundledMessages.cpp b/amgprec/impl/aggregator/sendBundledMessages.cpp index f3dd3e46..8665759c 100644 --- a/amgprec/impl/aggregator/sendBundledMessages.cpp +++ b/amgprec/impl/aggregator/sendBundledMessages.cpp @@ -1,15 +1,15 @@ #include "MatchBoxPC.h" -void sendBundledMessages(MilanLongInt *numGhostEdgesPtr, - MilanInt *BufferSizePtr, +void sendBundledMessages(MilanLongInt *numGhostEdges, + MilanInt *BufferSize, MilanLongInt *Buffer, vector &PCumulative, vector &PMessageBundle, vector &PSizeInfoMessages, MilanLongInt *PCounter, MilanLongInt NumMessagesBundled, - MilanLongInt *msgActualPtr, - MilanLongInt *MessageIndexPtr, + MilanLongInt *msgActual, + MilanLongInt *MessageIndex, MilanInt numProcs, MilanInt myRank, MPI_Comm comm, @@ -21,8 +21,8 @@ void sendBundledMessages(MilanLongInt *numGhostEdgesPtr, vector &SStatus) { - MilanLongInt myIndex = 0, msgActual = *msgActualPtr, MessageIndex = *MessageIndexPtr, numGhostEdges = *numGhostEdgesPtr, numMessagesToSend; - MilanInt i = 0, OneMessageSize = 0, BufferSize = *BufferSizePtr; + MilanLongInt myIndex = 0, numMessagesToSend; + MilanInt i = 0, OneMessageSize = 0; #ifdef DEBUG_HANG_ if (myRank == 0) @@ -105,7 +105,7 @@ PSizeInfoMessages.resize(numProcs * 3, 0); // Send the Messages #pragma omp task depend(inout \ : SRequest, PSizeInfoMessages, PCumulative) depend(out \ - : msgActual, MessageIndex) + : *msgActual, *MessageIndex) { for (i = 0; i < numProcs; i++) { // Changed by Fabio to be an integer, addresses needs to be integers! @@ -124,9 +124,9 @@ PSizeInfoMessages.resize(numProcs * 3, 0); if (PSizeInfoMessages[i * 3 + 0] > 0) { // Send only if it is a nonempty packet MPI_Isend(&PSizeInfoMessages[i * 3 + 0], 3, TypeMap(), i, ComputeTag, comm, - &SRequest[MessageIndex]); - msgActual++; - MessageIndex++; + &SRequest[(*MessageIndex)]); + (*msgActual)++; + (*MessageIndex)++; // Now Send the message with the data packet: #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")SendiFFng Bundle to : " << i << endl; @@ -136,8 +136,8 @@ PSizeInfoMessages.resize(numProcs * 3, 0); fflush(stdout); #endif MPI_Isend(&PMessageBundle[PCumulative[i] * 3], PSizeInfoMessages[i * 3 + 0], - TypeMap(), i, BundleTag, comm, &SRequest[MessageIndex]); - MessageIndex++; + TypeMap(), i, BundleTag, comm, &SRequest[(*MessageIndex)]); + (*MessageIndex)++; } // End of if size > 0 } } @@ -154,16 +154,16 @@ PSizeInfoMessages.resize(numProcs * 3, 0); QOwner.clear(); } -#pragma omp task depend(inout : OneMessageSize, BufferSize) depend(out : numMessagesToSend) depend(in : numGhostEdges) +#pragma omp task depend(inout : OneMessageSize, *BufferSize) depend(out : numMessagesToSend) depend(in : *numGhostEdges) { #ifdef PRINT_DEBUG_INFO_ - cout << "\n(" << myRank << ")Number of Ghost edges = " << numGhostEdges; - cout << "\n(" << myRank << ")Total number of potential message X 2 = " << numGhostEdges * 2; + cout << "\n(" << myRank << ")Number of Ghost edges = " << *numGhostEdges; + cout << "\n(" << myRank << ")Total number of potential message X 2 = " << *numGhostEdges * 2; cout << "\n(" << myRank << ")Number messages already sent in bundles = " << NumMessagesBundled; - if (numGhostEdges > 0) + if (*numGhostEdges > 0) { - cout << "\n(" << myRank << ")Percentage of total = " << ((double)NumMessagesBundled / (double)(numGhostEdges * 2)) * 100.0 << "% \n"; + cout << "\n(" << myRank << ")Percentage of total = " << ((double)NumMessagesBundled / (double)(*numGhostEdges * 2)) * 100.0 << "% \n"; } fflush(stdout); #endif @@ -177,39 +177,39 @@ PSizeInfoMessages.resize(numProcs * 3, 0); // Request, Success, Failure. // But only two will be sent from a given processor. // Substract the number of messages that have already been sent as bundled messages: - numMessagesToSend = numGhostEdges * 2 - NumMessagesBundled; - BufferSize = (OneMessageSize + MPI_BSEND_OVERHEAD) * numMessagesToSend; + numMessagesToSend = (*numGhostEdges) * 2 - NumMessagesBundled; + *BufferSize = (OneMessageSize + MPI_BSEND_OVERHEAD) * numMessagesToSend; } -#pragma omp task depend(out : Buffer) depend(in : BufferSize) +#pragma omp task depend(out : Buffer) depend(in : *BufferSize) { Buffer = 0; #ifdef PRINT_DEBUG_INFO_ cout << "\n(" << myRank << ")Size of One Message from PACK= " << OneMessageSize; cout << "\n(" << myRank << ")Size of Message overhead = " << MPI_BSEND_OVERHEAD; - cout << "\n(" << myRank << ")Number of Ghost edges = " << numGhostEdges; + cout << "\n(" << myRank << ")Number of Ghost edges = " << *numGhostEdges; cout << "\n(" << myRank << ")Number of remaining message = " << numMessagesToSend; - cout << "\n(" << myRank << ")BufferSize = " << BufferSize; + cout << "\n(" << myRank << ")BufferSize = " << (*BufferSize); cout << "\n(" << myRank << ")Attaching Buffer on.. "; fflush(stdout); #endif - if (BufferSize > 0) + if ((*BufferSize) > 0) { - Buffer = (MilanLongInt *)malloc(BufferSize); // Allocate memory + Buffer = (MilanLongInt *)malloc((*BufferSize)); // Allocate memory if (Buffer == 0) { cout << "Error in function algoDistEdgeApproxDominatingEdgesLinearSearch: \n"; cout << "Not enough memory to allocate for send buffer on process " << myRank << "\n"; exit(1); } - MPI_Buffer_attach(Buffer, BufferSize); // Attach the Buffer + MPI_Buffer_attach(Buffer, *BufferSize); // Attach the Buffer } } } } -*MessageIndexPtr = MessageIndex; -*msgActualPtr = msgActual; -*numGhostEdgesPtr = numGhostEdges; -*BufferSizePtr = BufferSize; +//*MessageIndexPtr = MessageIndex; +//*msgActualPtr = msgActual; +//*numGhostEdgesPtr = numGhostEdges; +//*BufferSizePtr = BufferSize; } \ No newline at end of file