Refactoring, removed all useless Pointer passed in functions

omp-walther
StefanoPetrilli 3 years ago
parent a71fe82752
commit 3e945c75b4

@ -1,7 +1,7 @@
#include "MatchBoxPC.h" #include "MatchBoxPC.h"
void PROCESS_CROSS_EDGE(MilanLongInt *edge, void PROCESS_CROSS_EDGE(MilanLongInt *edge,
MilanLongInt *SPtr) MilanLongInt *S)
{ {
// Start: PARALLEL_PROCESS_CROSS_EDGE_B // Start: PARALLEL_PROCESS_CROSS_EDGE_B
MilanLongInt captureCounter; MilanLongInt captureCounter;
@ -13,7 +13,7 @@ void PROCESS_CROSS_EDGE(MilanLongInt *edge,
if (captureCounter == 0) if (captureCounter == 0)
#pragma omp atomic #pragma omp atomic
(*SPtr)--; // Decrement S (*S)--; // Decrement S
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << edge << " has received all its messages"; cout << "\n(" << myRank << ")Decrementing S: Ghost vertex " << edge << " has received all its messages";

@ -1,45 +1,43 @@
#include "MatchBoxPC.h" #include "MatchBoxPC.h"
void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer, void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer,
MilanLongInt *candidateMate, MilanLongInt *candidateMate,
MilanLongInt *verLocInd, MilanLongInt *verLocInd,
MilanLongInt *verLocPtr, MilanLongInt *verLocPtr,
MilanLongInt StartIndex, MilanLongInt StartIndex,
MilanLongInt EndIndex, MilanLongInt EndIndex,
MilanLongInt *Mate, MilanLongInt *Mate,
vector<MilanLongInt> &GMate, vector<MilanLongInt> &GMate,
map<MilanLongInt, MilanLongInt> &Ghost2LocalMap, map<MilanLongInt, MilanLongInt> &Ghost2LocalMap,
MilanReal *edgeLocWeight, MilanReal *edgeLocWeight,
MilanLongInt *myCardPtr, MilanLongInt *myCard,
MilanLongInt *msgIndPtr, MilanLongInt *msgInd,
MilanLongInt *NumMessagesBundledPtr, MilanLongInt *NumMessagesBundled,
MilanLongInt *SPtr, MilanLongInt *S,
MilanLongInt *verDistance, MilanLongInt *verDistance,
MilanLongInt *PCounter, MilanLongInt *PCounter,
vector<MilanLongInt> &Counter, vector<MilanLongInt> &Counter,
MilanInt myRank, MilanInt myRank,
MilanInt numProcs, MilanInt numProcs,
staticQueue &U, staticQueue &U,
staticQueue &privateU, staticQueue &privateU,
vector<MilanLongInt> &QLocalVtx, vector<MilanLongInt> &QLocalVtx,
vector<MilanLongInt> &QGhostVtx, vector<MilanLongInt> &QGhostVtx,
vector<MilanLongInt> &QMsgType, vector<MilanLongInt> &QMsgType,
vector<MilanInt> &QOwner, vector<MilanInt> &QOwner,
staticQueue &privateQLocalVtx, staticQueue &privateQLocalVtx,
staticQueue &privateQGhostVtx, staticQueue &privateQGhostVtx,
staticQueue &privateQMsgType, staticQueue &privateQMsgType,
staticQueue &privateQOwner) staticQueue &privateQOwner)
{ {
MilanLongInt v = -1, k = -1, w = -1, adj11 = 0, adj12 = 0, k1 = 0, S = *SPtr; MilanLongInt v = -1, k = -1, w = -1, adj11 = 0, adj12 = 0, k1 = 0;
MilanLongInt myCard = 0, msgInd = 0;
MilanLongInt NumMessagesBundled = 0;
MilanInt ghostOwner = 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 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(+ \ #pragma omp for reduction(+ \
: msgInd, NumMessagesBundled, myCard, PCounter[:numProcs]) schedule(static) : PCounter[:numProcs]) schedule(static)
for (v = 0; v < NLVer; v++) for (v = 0; v < NLVer; v++)
{ {
// Start: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v) // Start: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v)
@ -76,8 +74,8 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer,
if (w >= 0) if (w >= 0)
{ {
#pragma omp atomic
myCard++; (*myCard)++;
if ((w < StartIndex) || (w > EndIndex)) if ((w < StartIndex) || (w > EndIndex))
{ // w is a ghost vertex { // w is a ghost vertex
#ifdef PRINT_DEBUG_INFO_ #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; cout << "\n(" << myRank << ")Local is: " << v + StartIndex << " Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs) << endl;
fflush(stdout); fflush(stdout);
#endif #endif
#pragma omp atomic
msgInd++; (*msgInd)++;
NumMessagesBundled++; #pragma omp atomic
(*NumMessagesBundled)++;
ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs);
assert(ghostOwner != -1); assert(ghostOwner != -1);
assert(ghostOwner != myRank); assert(ghostOwner != myRank);
@ -97,7 +96,6 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer,
privateQGhostVtx.push_back(w); privateQGhostVtx.push_back(w);
privateQMsgType.push_back(REQUEST); privateQMsgType.push_back(REQUEST);
privateQOwner.push_back(ghostOwner); privateQOwner.push_back(ghostOwner);
if (candidateMate[NLVer + Ghost2LocalMap[w]] == v + StartIndex) if (candidateMate[NLVer + Ghost2LocalMap[w]] == v + StartIndex)
{ {
@ -113,9 +111,9 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer,
fflush(stdout); fflush(stdout);
#endif #endif
//TODO refactor this!! // TODO refactor this!!
// Decrement the counter: // 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 CandidateMate[w] = v
} // End of if a Ghost Vertex } // 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); cout << "\n(" << myRank << ")Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs);
fflush(stdout); fflush(stdout);
#endif #endif
#pragma omp atomic
msgInd++; (*msgInd)++;
NumMessagesBundled++; #pragma omp atomic
(*NumMessagesBundled)++;
ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs);
assert(ghostOwner != -1); assert(ghostOwner != -1);
assert(ghostOwner != myRank); assert(ghostOwner != myRank);
@ -184,14 +183,5 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer,
privateQMsgType, privateQMsgType,
privateQOwner); privateQOwner);
//TODO move this outside of the parallel region!!
#pragma omp master
{
*myCardPtr = myCard;
*msgIndPtr = msgInd;
*NumMessagesBundledPtr = NumMessagesBundled;
*SPtr = S;
}
} // End of parallel region } // End of parallel region
} }

@ -9,9 +9,9 @@ void processMessages(
vector<MilanLongInt> &Counter, vector<MilanLongInt> &Counter,
MilanLongInt StartIndex, MilanLongInt StartIndex,
MilanLongInt EndIndex, MilanLongInt EndIndex,
MilanLongInt *myCardPtr, MilanLongInt *myCard,
MilanLongInt *msgIndPtr, MilanLongInt *msgInd,
MilanLongInt *msgActualPtr, MilanLongInt *msgActual,
MilanReal *edgeLocWeight, MilanReal *edgeLocWeight,
MilanLongInt *verDistance, MilanLongInt *verDistance,
MilanLongInt *verLocPtr, MilanLongInt *verLocPtr,
@ -30,7 +30,7 @@ void processMessages(
MilanInt Sender; MilanInt Sender;
MPI_Status computeStatus; MPI_Status computeStatus;
MilanLongInt bundleSize, myCard = *myCardPtr, msgInd = *msgIndPtr, msgActual = *msgActualPtr, w; MilanLongInt bundleSize, w;
MilanLongInt adj11, adj12, k1; MilanLongInt adj11, adj12, k1;
MilanLongInt ghostOwner; MilanLongInt ghostOwner;
int error_codeC; int error_codeC;
@ -188,7 +188,7 @@ void processMessages(
Mate[v - StartIndex] = u; // v is local Mate[v - StartIndex] = u; // v is local
U.push_back(v); U.push_back(v);
U.push_back(u); U.push_back(u);
myCard++; (*myCard)++;
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")MATCH: (" << v << "," << u << ") " << endl; cout << "\n(" << myRank << ")MATCH: (" << v << "," << u << ") " << endl;
fflush(stdout); fflush(stdout);
@ -246,15 +246,15 @@ void processMessages(
assert(ghostOwner != myRank); assert(ghostOwner != myRank);
MPI_Bsend(&Message[0], 3, TypeMap<MilanLongInt>(), ghostOwner, ComputeTag, comm); MPI_Bsend(&Message[0], 3, TypeMap<MilanLongInt>(), ghostOwner, ComputeTag, comm);
msgInd++; (*msgInd)++;
msgActual++; (*msgActual)++;
if (candidateMate[NLVer + Ghost2LocalMap[w]] == v) if (candidateMate[NLVer + Ghost2LocalMap[w]] == v)
{ {
Mate[v - StartIndex] = w; // v is local Mate[v - StartIndex] = w; // v is local
GMate[Ghost2LocalMap[w]] = v; // w is ghost GMate[Ghost2LocalMap[w]] = v; // w is ghost
U.push_back(v); U.push_back(v);
U.push_back(w); U.push_back(w);
myCard++; (*myCard)++;
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl; cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl;
fflush(stdout); fflush(stdout);
@ -272,7 +272,7 @@ void processMessages(
// Q.push_back(u); // Q.push_back(u);
U.push_back(v); U.push_back(v);
U.push_back(w); U.push_back(w);
myCard++; (*myCard)++;
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl; cout << "\n(" << myRank << ")MATCH: (" << v << "," << w << ") " << endl;
fflush(stdout); fflush(stdout);
@ -303,8 +303,8 @@ void processMessages(
assert(ghostOwner != -1); assert(ghostOwner != -1);
assert(ghostOwner != myRank); assert(ghostOwner != myRank);
MPI_Bsend(&Message[0], 3, TypeMap<MilanLongInt>(), ghostOwner, ComputeTag, comm); MPI_Bsend(&Message[0], 3, TypeMap<MilanLongInt>(), ghostOwner, ComputeTag, comm);
msgInd++; (*msgInd)++;
msgActual++; (*msgActual)++;
} // End of if(GHOST) } // End of if(GHOST)
} // End of for loop } // End of for loop
} // End of Else: w == -1 } // End of Else: w == -1
@ -324,8 +324,5 @@ void processMessages(
} // End of else: CASE I } // End of else: CASE I
} }
*myCardPtr = myCard;
*msgIndPtr = msgInd;
*msgActualPtr = msgActual;
return; return;
} }

@ -1,15 +1,15 @@
#include "MatchBoxPC.h" #include "MatchBoxPC.h"
void sendBundledMessages(MilanLongInt *numGhostEdgesPtr, void sendBundledMessages(MilanLongInt *numGhostEdges,
MilanInt *BufferSizePtr, MilanInt *BufferSize,
MilanLongInt *Buffer, MilanLongInt *Buffer,
vector<MilanLongInt> &PCumulative, vector<MilanLongInt> &PCumulative,
vector<MilanLongInt> &PMessageBundle, vector<MilanLongInt> &PMessageBundle,
vector<MilanLongInt> &PSizeInfoMessages, vector<MilanLongInt> &PSizeInfoMessages,
MilanLongInt *PCounter, MilanLongInt *PCounter,
MilanLongInt NumMessagesBundled, MilanLongInt NumMessagesBundled,
MilanLongInt *msgActualPtr, MilanLongInt *msgActual,
MilanLongInt *MessageIndexPtr, MilanLongInt *MessageIndex,
MilanInt numProcs, MilanInt numProcs,
MilanInt myRank, MilanInt myRank,
MPI_Comm comm, MPI_Comm comm,
@ -21,8 +21,8 @@ void sendBundledMessages(MilanLongInt *numGhostEdgesPtr,
vector<MPI_Status> &SStatus) vector<MPI_Status> &SStatus)
{ {
MilanLongInt myIndex = 0, msgActual = *msgActualPtr, MessageIndex = *MessageIndexPtr, numGhostEdges = *numGhostEdgesPtr, numMessagesToSend; MilanLongInt myIndex = 0, numMessagesToSend;
MilanInt i = 0, OneMessageSize = 0, BufferSize = *BufferSizePtr; MilanInt i = 0, OneMessageSize = 0;
#ifdef DEBUG_HANG_ #ifdef DEBUG_HANG_
if (myRank == 0) if (myRank == 0)
@ -105,7 +105,7 @@ PSizeInfoMessages.resize(numProcs * 3, 0);
// Send the Messages // Send the Messages
#pragma omp task depend(inout \ #pragma omp task depend(inout \
: SRequest, PSizeInfoMessages, PCumulative) depend(out \ : SRequest, PSizeInfoMessages, PCumulative) depend(out \
: msgActual, MessageIndex) : *msgActual, *MessageIndex)
{ {
for (i = 0; i < numProcs; i++) for (i = 0; i < numProcs; i++)
{ // Changed by Fabio to be an integer, addresses needs to be integers! { // 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) if (PSizeInfoMessages[i * 3 + 0] > 0)
{ // Send only if it is a nonempty packet { // Send only if it is a nonempty packet
MPI_Isend(&PSizeInfoMessages[i * 3 + 0], 3, TypeMap<MilanLongInt>(), i, ComputeTag, comm, MPI_Isend(&PSizeInfoMessages[i * 3 + 0], 3, TypeMap<MilanLongInt>(), i, ComputeTag, comm,
&SRequest[MessageIndex]); &SRequest[(*MessageIndex)]);
msgActual++; (*msgActual)++;
MessageIndex++; (*MessageIndex)++;
// Now Send the message with the data packet: // Now Send the message with the data packet:
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")SendiFFng Bundle to : " << i << endl; cout << "\n(" << myRank << ")SendiFFng Bundle to : " << i << endl;
@ -136,8 +136,8 @@ PSizeInfoMessages.resize(numProcs * 3, 0);
fflush(stdout); fflush(stdout);
#endif #endif
MPI_Isend(&PMessageBundle[PCumulative[i] * 3], PSizeInfoMessages[i * 3 + 0], MPI_Isend(&PMessageBundle[PCumulative[i] * 3], PSizeInfoMessages[i * 3 + 0],
TypeMap<MilanLongInt>(), i, BundleTag, comm, &SRequest[MessageIndex]); TypeMap<MilanLongInt>(), i, BundleTag, comm, &SRequest[(*MessageIndex)]);
MessageIndex++; (*MessageIndex)++;
} // End of if size > 0 } // End of if size > 0
} }
} }
@ -154,16 +154,16 @@ PSizeInfoMessages.resize(numProcs * 3, 0);
QOwner.clear(); 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_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")Number of Ghost edges = " << numGhostEdges; cout << "\n(" << myRank << ")Number of Ghost edges = " << *numGhostEdges;
cout << "\n(" << myRank << ")Total number of potential message X 2 = " << numGhostEdges * 2; cout << "\n(" << myRank << ")Total number of potential message X 2 = " << *numGhostEdges * 2;
cout << "\n(" << myRank << ")Number messages already sent in bundles = " << NumMessagesBundled; 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); fflush(stdout);
#endif #endif
@ -177,39 +177,39 @@ PSizeInfoMessages.resize(numProcs * 3, 0);
// Request, Success, Failure. // Request, Success, Failure.
// But only two will be sent from a given processor. // But only two will be sent from a given processor.
// Substract the number of messages that have already been sent as bundled messages: // Substract the number of messages that have already been sent as bundled messages:
numMessagesToSend = numGhostEdges * 2 - NumMessagesBundled; numMessagesToSend = (*numGhostEdges) * 2 - NumMessagesBundled;
BufferSize = (OneMessageSize + MPI_BSEND_OVERHEAD) * numMessagesToSend; *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; Buffer = 0;
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")Size of One Message from PACK= " << OneMessageSize; cout << "\n(" << myRank << ")Size of One Message from PACK= " << OneMessageSize;
cout << "\n(" << myRank << ")Size of Message overhead = " << MPI_BSEND_OVERHEAD; 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 << ")Number of remaining message = " << numMessagesToSend;
cout << "\n(" << myRank << ")BufferSize = " << BufferSize; cout << "\n(" << myRank << ")BufferSize = " << (*BufferSize);
cout << "\n(" << myRank << ")Attaching Buffer on.. "; cout << "\n(" << myRank << ")Attaching Buffer on.. ";
fflush(stdout); fflush(stdout);
#endif #endif
if (BufferSize > 0) if ((*BufferSize) > 0)
{ {
Buffer = (MilanLongInt *)malloc(BufferSize); // Allocate memory Buffer = (MilanLongInt *)malloc((*BufferSize)); // Allocate memory
if (Buffer == 0) if (Buffer == 0)
{ {
cout << "Error in function algoDistEdgeApproxDominatingEdgesLinearSearch: \n"; cout << "Error in function algoDistEdgeApproxDominatingEdgesLinearSearch: \n";
cout << "Not enough memory to allocate for send buffer on process " << myRank << "\n"; cout << "Not enough memory to allocate for send buffer on process " << myRank << "\n";
exit(1); exit(1);
} }
MPI_Buffer_attach(Buffer, BufferSize); // Attach the Buffer MPI_Buffer_attach(Buffer, *BufferSize); // Attach the Buffer
} }
} }
} }
} }
*MessageIndexPtr = MessageIndex; //*MessageIndexPtr = MessageIndex;
*msgActualPtr = msgActual; //*msgActualPtr = msgActual;
*numGhostEdgesPtr = numGhostEdges; //*numGhostEdgesPtr = numGhostEdges;
*BufferSizePtr = BufferSize; //*BufferSizePtr = BufferSize;
} }
Loading…
Cancel
Save