initialize refactoring

omp-walther
StefanoPetrilli 2 years ago
parent cb660e044d
commit 4f07a70ed1

@ -5,7 +5,7 @@
///Find the owner of a ghost node: ///Find the owner of a ghost node:
MilanInt findOwnerOfGhost(MilanLongInt vtxIndex, MilanLongInt *mVerDistance, MilanInt findOwnerOfGhost(MilanLongInt vtxIndex, MilanLongInt *mVerDistance,
MilanInt myRank, MilanInt numProcs) { MilanInt myRank, MilanInt numProcs) {
//MilanLongInt Size = mVerDistance.size();
MilanLongInt mStartInd = mVerDistance[myRank]; MilanLongInt mStartInd = mVerDistance[myRank];
MilanInt Start = 0; MilanInt Start = 0;
MilanInt End = numProcs; MilanInt End = numProcs;

@ -2,8 +2,8 @@
void initialize(MilanLongInt NLVer, MilanLongInt NLEdge, void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
MilanLongInt StartIndex, MilanLongInt EndIndex, MilanLongInt StartIndex, MilanLongInt EndIndex,
MilanLongInt *numGhostEdgesPtr, MilanLongInt *numGhostEdges,
MilanLongInt *numGhostVerticesPtr, MilanLongInt *numGhostVertices,
MilanLongInt *S, MilanLongInt *S,
MilanLongInt *verLocInd, MilanLongInt *verLocInd,
MilanLongInt *verLocPtr, MilanLongInt *verLocPtr,
@ -27,10 +27,9 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
staticQueue &privateQOwner) staticQueue &privateQOwner)
{ {
MilanLongInt insertMe = 0, numGhostEdges = 0, numGhostVertices = 0; MilanLongInt insertMe = 0;
MilanLongInt adj1, adj2; MilanLongInt adj1, adj2;
int i, v, k, w; int i, v, k, w;
// index that starts with zero to |Vg| - 1 // index that starts with zero to |Vg| - 1
map<MilanLongInt, MilanLongInt>::iterator storedAlready; map<MilanLongInt, MilanLongInt>::iterator storedAlready;
@ -55,19 +54,17 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
* only when a ghost edge is found and ghost edges are a minority, * only when a ghost edge is found and ghost edges are a minority,
* circa 3.5% during the tests. * circa 3.5% during the tests.
*/ */
#pragma omp task depend(out \ #pragma omp task depend(out \
: numGhostEdges, Counter, Ghost2LocalMap, insertMe, storedAlready, numGhostVertices) : *numGhostEdges, Counter, Ghost2LocalMap, insertMe, storedAlready, *numGhostVertices)
{ {
#pragma omp taskloop num_tasks(NUM_THREAD)
#pragma omp taskloop num_tasks(NUM_THREAD) reduction(+ \
: numGhostEdges)
for (i = 0; i < NLEdge; i++) for (i = 0; i < NLEdge; i++)
{ // O(m) - Each edge stored twice { // O(m) - Each edge stored twice
insertMe = verLocInd[i]; insertMe = verLocInd[i];
if ((insertMe < StartIndex) || (insertMe > EndIndex)) if ((insertMe < StartIndex) || (insertMe > EndIndex))
{ // Find a ghost { // Find a ghost
numGhostEdges++; #pragma omp atomic
(*numGhostEdges)++;
#pragma omp critical #pragma omp critical
{ {
storedAlready = Ghost2LocalMap.find(insertMe); storedAlready = Ghost2LocalMap.find(insertMe);
@ -77,23 +74,23 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
} }
else else
{ // Insert an entry for the ghost: { // Insert an entry for the ghost:
Ghost2LocalMap[insertMe] = numGhostVertices; // Add a map entry Ghost2LocalMap[insertMe] = *numGhostVertices; // Add a map entry
Counter.push_back(1); // Initialize the counter Counter.push_back(1); // Initialize the counter
numGhostVertices++; // Increment the number of ghost vertices (*numGhostVertices)++; // Increment the number of ghost vertices
} // End of else() } // End of else()
} }
} // End of if ( (insertMe < StartIndex) || (insertMe > EndIndex) ) } // End of if ( (insertMe < StartIndex) || (insertMe > EndIndex) )
} // End of for(ghost vertices) } // End of for(ghost vertices)
} // end of task depend } // end of task depend
// numGhostEdges = atomicNumGhostEdges; // *numGhostEdges = atomicNumGhostEdges;
#ifdef TIME_TRACKER #ifdef TIME_TRACKER
Ghost2LocalInitialization = MPI_Wtime() - Ghost2LocalInitialization; Ghost2LocalInitialization = MPI_Wtime() - Ghost2LocalInitialization;
fprintf(stderr, "Ghost2LocalInitialization time: %f\n", Ghost2LocalInitialization); fprintf(stderr, "Ghost2LocalInitialization time: %f\n", Ghost2LocalInitialization);
#endif #endif
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")NGhosts:" << numGhostVertices << " GhostEdges: " << numGhostEdges; cout << "\n(" << myRank << ")NGhosts:" << *numGhostVertices << " GhostEdges: " << *numGhostEdges;
if (!Ghost2LocalMap.empty()) if (!Ghost2LocalMap.empty())
{ {
cout << "\n(" << myRank << ")Final Map : on process "; cout << "\n(" << myRank << ")Final Map : on process ";
@ -111,16 +108,16 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
#pragma omp task depend(out \ #pragma omp task depend(out \
: verGhostPtr, tempCounter, verGhostInd, GMate) depend(in \ : verGhostPtr, tempCounter, verGhostInd, GMate) depend(in \
: numGhostVertices, numGhostEdges) : *numGhostVertices, *numGhostEdges)
{ {
// Initialize adjacency Lists for Ghost Vertices: // Initialize adjacency Lists for Ghost Vertices:
try try
{ {
verGhostPtr.reserve(numGhostVertices + 1); // Pointer Vector verGhostPtr.reserve(*numGhostVertices + 1); // Pointer Vector
tempCounter.reserve(numGhostVertices); // Pointer Vector tempCounter.reserve(*numGhostVertices); // Pointer Vector
verGhostInd.reserve(numGhostEdges); // Index Vector verGhostInd.reserve(*numGhostEdges); // Index Vector
GMate.reserve(numGhostVertices); // Ghost Mate Vector GMate.reserve(*numGhostVertices); // Ghost Mate Vector
} }
catch (length_error) catch (length_error)
{ {
@ -129,10 +126,10 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
exit(1); exit(1);
} }
// Initialize the Vectors: // Initialize the Vectors:
verGhostPtr.resize(numGhostVertices + 1, 0); // Pointer Vector verGhostPtr.resize(*numGhostVertices + 1, 0); // Pointer Vector
tempCounter.resize(numGhostVertices, 0); // Temporary Counter tempCounter.resize(*numGhostVertices, 0); // Temporary Counter
verGhostInd.resize(numGhostEdges, -1); // Index Vector verGhostInd.resize(*numGhostEdges, -1); // Index Vector
GMate.resize(numGhostVertices, -1); // Temporary Counter GMate.resize(*numGhostVertices, -1); // Temporary Counter
verGhostPtr[0] = 0; // The first value verGhostPtr[0] = 0; // The first value
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")Ghost Vertex Pointer: "; cout << "\n(" << myRank << ")Ghost Vertex Pointer: ";
@ -143,13 +140,13 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
#pragma omp task depend(out \ #pragma omp task depend(out \
: verGhostPtr) depend(in \ : verGhostPtr) depend(in \
: Counter, numGhostVertices) : Counter, *numGhostVertices)
{ {
#ifdef TIME_TRACKER #ifdef TIME_TRACKER
double verGhostPtrInitialization = MPI_Wtime(); double verGhostPtrInitialization = MPI_Wtime();
#endif #endif
for (i = 0; i < numGhostVertices; i++) for (i = 0; i < *numGhostVertices; i++)
{ // O(|Ghost Vertices|) { // O(|Ghost Vertices|)
verGhostPtr[i + 1] = verGhostPtr[i] + Counter[i]; verGhostPtr[i + 1] = verGhostPtr[i] + Counter[i];
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
@ -165,8 +162,8 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
} // End of task } // End of task
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
if (numGhostVertices > 0) if (*numGhostVertices > 0)
cout << verGhostPtr[numGhostVertices] << "\n"; cout << verGhostPtr[*numGhostVertices] << "\n";
fflush(stdout); fflush(stdout);
#endif #endif
@ -220,22 +217,22 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
#ifdef PRINT_DEBUG_INFO_ #ifdef PRINT_DEBUG_INFO_
cout << "\n(" << myRank << ")Ghost Vertex Index: "; cout << "\n(" << myRank << ")Ghost Vertex Index: ";
for (v = 0; v < numGhostEdges; v++) for (v = 0; v < *numGhostEdges; v++)
cout << verGhostInd[v] << "\t"; cout << verGhostInd[v] << "\t";
cout << endl; cout << endl;
fflush(stdout); fflush(stdout);
#endif #endif
#pragma omp task depend(in \ #pragma omp task depend(in \
: numGhostEdges) depend(out \ : *numGhostEdges) depend(out \
: QLocalVtx, QGhostVtx, QMsgType, QOwner) : QLocalVtx, QGhostVtx, QMsgType, QOwner)
{ {
try try
{ {
QLocalVtx.reserve(numGhostEdges); // Local Vertex QLocalVtx.reserve(*numGhostEdges); // Local Vertex
QGhostVtx.reserve(numGhostEdges); // Ghost Vertex QGhostVtx.reserve(*numGhostEdges); // Ghost Vertex
QMsgType.reserve(numGhostEdges); // Message Type (Request/Failure) QMsgType.reserve(*numGhostEdges); // Message Type (Request/Failure)
QOwner.reserve(numGhostEdges); // Owner of the ghost: COmpute once and use later QOwner.reserve(*numGhostEdges); // Owner of the ghost: COmpute once and use later
} }
catch (length_error) catch (length_error)
{ {
@ -269,23 +266,19 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
#endif #endif
#pragma omp task depend(in \ #pragma omp task depend(in \
: numGhostEdges, numGhostVertices) depend(out \ : *numGhostVertices) depend(out \
: candidateMate, S, U, privateU, privateQLocalVtx, privateQGhostVtx, privateQMsgType, privateQOwner) : candidateMate, S, U, privateU, privateQLocalVtx, privateQGhostVtx, privateQMsgType, privateQOwner)
{ {
// The values calculated in this function are sent back to the calling function
*numGhostEdgesPtr = numGhostEdges;
*numGhostVerticesPtr = numGhostVertices;
// Allocate Data Structures: // Allocate Data Structures:
/* /*
* candidateMate was a vector and has been replaced with an array * candidateMate was a vector and has been replaced with an array
* there is no point in using the vector (or maybe there is (???)) * there is no point in using the vector (or maybe there is (???))
* so I replaced it with an array wich is slightly faster * so I replaced it with an array wich is slightly faster
*/ */
candidateMate = new MilanLongInt[NLVer + numGhostVertices]; candidateMate = new MilanLongInt[NLVer + (*numGhostVertices)];
*S = numGhostVertices; // Initialize S with number of Ghost Vertices *S = (*numGhostVertices); // Initialize S with number of Ghost Vertices
/* /*
* Create the Queue Data Structure for the Dominating Set * Create the Queue Data Structure for the Dominating Set
@ -295,13 +288,13 @@ void initialize(MilanLongInt NLVer, MilanLongInt NLEdge,
* of a staticQueue I had to destroy the previous object and instantiate * of a staticQueue I had to destroy the previous object and instantiate
* a new one of the correct size. * a new one of the correct size.
*/ */
new (&U) staticQueue(NLVer + numGhostVertices); new (&U) staticQueue(NLVer + (*numGhostVertices));
// TODO how can I decide a more meaningfull size? // TODO how can I decide a more meaningfull size?
MilanLongInt size = numGhostVertices; MilanLongInt size = (*numGhostVertices);
// Initialize the privte data structure // Initialize the privte data structure
new (&privateU) staticQueue(NLVer + numGhostVertices); // TODO how can I put a meaningfull size? new (&privateU) staticQueue(NLVer + (*numGhostVertices)); // TODO how can I put a meaningfull size?
new (&privateQLocalVtx) staticQueue(size); new (&privateQLocalVtx) staticQueue(size);
new (&privateQGhostVtx) staticQueue(size); new (&privateQGhostVtx) staticQueue(size);
new (&privateQMsgType) staticQueue(size); new (&privateQMsgType) staticQueue(size);

Loading…
Cancel
Save