mirror of
https://github.com/sfilippone/amg4psblas.git
synced 2026-10-06 22:55:12 +00:00
Refactoring, removed all useless Pointer passed in functions
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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<MilanLongInt> &GMate,
|
||||
map<MilanLongInt, MilanLongInt> &Ghost2LocalMap,
|
||||
MilanReal *edgeLocWeight,
|
||||
MilanLongInt *myCardPtr,
|
||||
MilanLongInt *msgIndPtr,
|
||||
MilanLongInt *NumMessagesBundledPtr,
|
||||
MilanLongInt *SPtr,
|
||||
MilanLongInt *verDistance,
|
||||
MilanLongInt *PCounter,
|
||||
vector<MilanLongInt> &Counter,
|
||||
MilanInt myRank,
|
||||
MilanInt numProcs,
|
||||
staticQueue &U,
|
||||
staticQueue &privateU,
|
||||
vector<MilanLongInt> &QLocalVtx,
|
||||
vector<MilanLongInt> &QGhostVtx,
|
||||
vector<MilanLongInt> &QMsgType,
|
||||
vector<MilanInt> &QOwner,
|
||||
staticQueue &privateQLocalVtx,
|
||||
staticQueue &privateQGhostVtx,
|
||||
staticQueue &privateQMsgType,
|
||||
staticQueue &privateQOwner)
|
||||
MilanLongInt *candidateMate,
|
||||
MilanLongInt *verLocInd,
|
||||
MilanLongInt *verLocPtr,
|
||||
MilanLongInt StartIndex,
|
||||
MilanLongInt EndIndex,
|
||||
MilanLongInt *Mate,
|
||||
vector<MilanLongInt> &GMate,
|
||||
map<MilanLongInt, MilanLongInt> &Ghost2LocalMap,
|
||||
MilanReal *edgeLocWeight,
|
||||
MilanLongInt *myCard,
|
||||
MilanLongInt *msgInd,
|
||||
MilanLongInt *NumMessagesBundled,
|
||||
MilanLongInt *S,
|
||||
MilanLongInt *verDistance,
|
||||
MilanLongInt *PCounter,
|
||||
vector<MilanLongInt> &Counter,
|
||||
MilanInt myRank,
|
||||
MilanInt numProcs,
|
||||
staticQueue &U,
|
||||
staticQueue &privateU,
|
||||
vector<MilanLongInt> &QLocalVtx,
|
||||
vector<MilanLongInt> &QGhostVtx,
|
||||
vector<MilanLongInt> &QMsgType,
|
||||
vector<MilanInt> &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);
|
||||
@@ -98,7 +97,6 @@ void PARALLEL_PROCESS_EXPOSED_VERTEX_B(MilanLongInt NLVer,
|
||||
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
|
||||
}
|
||||
@@ -9,9 +9,9 @@ void processMessages(
|
||||
vector<MilanLongInt> &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<MilanLongInt>(), 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<MilanLongInt>(), 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;
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "MatchBoxPC.h"
|
||||
|
||||
void sendBundledMessages(MilanLongInt *numGhostEdgesPtr,
|
||||
MilanInt *BufferSizePtr,
|
||||
void sendBundledMessages(MilanLongInt *numGhostEdges,
|
||||
MilanInt *BufferSize,
|
||||
MilanLongInt *Buffer,
|
||||
vector<MilanLongInt> &PCumulative,
|
||||
vector<MilanLongInt> &PMessageBundle,
|
||||
vector<MilanLongInt> &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<MPI_Status> &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<MilanLongInt>(), 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<MilanLongInt>(), i, BundleTag, comm, &SRequest[MessageIndex]);
|
||||
MessageIndex++;
|
||||
TypeMap<MilanLongInt>(), 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;
|
||||
}
|
||||
Reference in New Issue
Block a user