From 7cfe198d0f383c541c83d61b7e99e016699e086d Mon Sep 17 00:00:00 2001 From: StefanoPetrilli Date: Sun, 26 Jun 2022 10:45:06 -0500 Subject: [PATCH] Format --- amgprec/impl/aggregator/MatchBoxPC.h | 315 ++-- ...mEdgesLinearSearchMesgBndlSmallMateCMP.cpp | 1562 +++++++++-------- 2 files changed, 1024 insertions(+), 853 deletions(-) diff --git a/amgprec/impl/aggregator/MatchBoxPC.h b/amgprec/impl/aggregator/MatchBoxPC.h index 54830919..530933e5 100644 --- a/amgprec/impl/aggregator/MatchBoxPC.h +++ b/amgprec/impl/aggregator/MatchBoxPC.h @@ -52,7 +52,7 @@ #ifndef _matchboxpC_H_ #define _matchboxpC_H_ -//Turn on a lot of debugging information with this switch: +// Turn on a lot of debugging information with this switch: //#define PRINT_DEBUG_INFO_ #include #include @@ -66,193 +66,190 @@ using namespace std; #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #if !defined(SERIAL_MPI) - -#define MilanMpiLongInt MPI_LONG_LONG + +#define MilanMpiLongInt MPI_LONG_LONG #ifndef _primitiveDataType_Definition_ #define _primitiveDataType_Definition_ - //Regular integer: - #ifndef INTEGER_H - #define INTEGER_H - typedef int32_t MilanInt; - #endif +// Regular integer: +#ifndef INTEGER_H +#define INTEGER_H + typedef int32_t MilanInt; +#endif - //Regular long integer: - #ifndef LONG_INT_H - #define LONG_INT_H - #ifdef BIT64 - typedef int64_t MilanLongInt; - typedef MPI_LONG MilanMpiLongInt; - #else - typedef int32_t MilanLongInt; - typedef MPI_INT MilanMpiLongInt; - #endif - #endif +// Regular long integer: +#ifndef LONG_INT_H +#define LONG_INT_H +#ifdef BIT64 + typedef int64_t MilanLongInt; + typedef MPI_LONG MilanMpiLongInt; +#else + typedef int32_t MilanLongInt; + typedef MPI_INT MilanMpiLongInt; +#endif +#endif - //Regular boolean - #ifndef BOOL_H - #define BOOL_H - typedef bool MilanBool; - #endif +// Regular boolean +#ifndef BOOL_H +#define BOOL_H + typedef bool MilanBool; +#endif - //Regular double and absolute value computation: - #ifndef REAL_H - #define REAL_H - typedef double MilanReal; - typedef MPI_DOUBLE MilanMpiReal; - inline MilanReal MilanAbs(MilanReal value) - { - return fabs(value); - } - #endif +// Regular double and absolute value computation: +#ifndef REAL_H +#define REAL_H + typedef double MilanReal; + typedef MPI_DOUBLE MilanMpiReal; + inline MilanReal MilanAbs(MilanReal value) + { + return fabs(value); + } +#endif - //Regular float and absolute value computation: - #ifndef FLOAT_H - #define FLOAT_H - typedef float MilanFloat; - typedef MPI_FLOAT MilanMpiFloat; - inline MilanFloat MilanAbsFloat(MilanFloat value) - { - return fabs(value); - } - #endif +// Regular float and absolute value computation: +#ifndef FLOAT_H +#define FLOAT_H + typedef float MilanFloat; + typedef MPI_FLOAT MilanMpiFloat; + inline MilanFloat MilanAbsFloat(MilanFloat value) + { + return fabs(value); + } +#endif - //// Define the limits: - #ifndef LIMITS_H - #define LIMITS_H - //Integer Maximum and Minimum: - // #define MilanIntMax INT_MAX - // #define MilanIntMin INT_MIN - #define MilanIntMax INT32_MAX - #define MilanIntMin INT32_MIN +//// Define the limits: +#ifndef LIMITS_H +#define LIMITS_H + // Integer Maximum and Minimum: + // #define MilanIntMax INT_MAX + // #define MilanIntMin INT_MIN +#define MilanIntMax INT32_MAX +#define MilanIntMin INT32_MIN - #ifdef BIT64 - #define MilanLongIntMax INT64_MAX - #define MilanLongIntMin -INT64_MAX - #else - #define MilanLongIntMax INT32_MAX - #define MilanLongIntMin -INT32_MAX - #endif +#ifdef BIT64 +#define MilanLongIntMax INT64_MAX +#define MilanLongIntMin -INT64_MAX +#else +#define MilanLongIntMax INT32_MAX +#define MilanLongIntMin -INT32_MAX +#endif - #endif +#endif // +INFINITY const double PLUS_INFINITY = numeric_limits::infinity(); const double MINUS_INFINITY = -PLUS_INFINITY; - //#define MilanRealMax LDBL_MAX - #define MilanRealMax PLUS_INFINITY - #define MilanRealMin MINUS_INFINITY +//#define MilanRealMax LDBL_MAX +#define MilanRealMax PLUS_INFINITY +#define MilanRealMin MINUS_INFINITY #endif -//Function of find the owner of a ghost vertex using binary search: -inline MilanInt findOwnerOfGhost(MilanLongInt vtxIndex, MilanLongInt *mVerDistance, + // Function of find the owner of a ghost vertex using binary search: + inline MilanInt findOwnerOfGhost(MilanLongInt vtxIndex, MilanLongInt *mVerDistance, MilanInt myRank, MilanInt numProcs); -inline MilanLongInt firstComputeCandidateMate(MilanLongInt adj1, - MilanLongInt adj2, - MilanLongInt* verLocInd, - MilanReal* edgeLocWeight); + inline MilanLongInt firstComputeCandidateMate(MilanLongInt adj1, + MilanLongInt adj2, + MilanLongInt *verLocInd, + MilanReal *edgeLocWeight); -inline bool isAlreadyMatched(MilanLongInt node, - MilanLongInt StartIndex, - MilanLongInt EndIndex, - vector &GMate, - MilanLongInt* Mate, - map &Ghost2LocalMap); + inline bool isAlreadyMatched(MilanLongInt node, + MilanLongInt StartIndex, + MilanLongInt EndIndex, + vector &GMate, + MilanLongInt *Mate, + map &Ghost2LocalMap); -inline MilanLongInt computeCandidateMate(MilanLongInt adj1, - MilanLongInt adj2, - MilanReal* edgeLocWeight, - MilanLongInt k, - MilanLongInt* verLocInd, - MilanLongInt StartIndex, - MilanLongInt EndIndex, - vector &GMate, - MilanLongInt* Mate, - map &Ghost2LocalMap); + inline MilanLongInt computeCandidateMate(MilanLongInt adj1, + MilanLongInt adj2, + MilanReal *edgeLocWeight, + MilanLongInt k, + MilanLongInt *verLocInd, + MilanLongInt StartIndex, + MilanLongInt EndIndex, + vector &GMate, + MilanLongInt *Mate, + map &Ghost2LocalMap); -inline void initialize(MilanLongInt NLVer, MilanLongInt NLEdge, - MilanLongInt StartIndex, MilanLongInt EndIndex, - MilanLongInt* numGhostEdgesPtr, - MilanLongInt* numGhostVerticesPtr, - MilanLongInt* S, - MilanLongInt* verLocInd, - MilanLongInt* verLocPtr, - omp_lock_t* MateLock, - map &Ghost2LocalMap, - vector & Counter, - vector & verGhostPtr, - vector & verGhostInd, - vector & tempCounter, - vector & GMate, - vector& Message, - vector& QLocalVtx, - vector& QGhostVtx, - vector& QMsgType, - vector& QOwner, - MilanLongInt* &candidateMate, - staticQueue& U, - staticQueue& privateU, - staticQueue& privateQLocalVtx, - staticQueue& privateQGhostVtx, - staticQueue& privateQMsgType, - staticQueue& privateQOwner - ); + inline void initialize(MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt StartIndex, MilanLongInt EndIndex, + MilanLongInt *numGhostEdgesPtr, + MilanLongInt *numGhostVerticesPtr, + MilanLongInt *S, + MilanLongInt *verLocInd, + MilanLongInt *verLocPtr, + omp_lock_t *MateLock, + map &Ghost2LocalMap, + vector &Counter, + vector &verGhostPtr, + vector &verGhostInd, + vector &tempCounter, + vector &GMate, + vector &Message, + vector &QLocalVtx, + vector &QGhostVtx, + vector &QMsgType, + vector &QOwner, + MilanLongInt *&candidateMate, + staticQueue &U, + staticQueue &privateU, + staticQueue &privateQLocalVtx, + staticQueue &privateQGhostVtx, + staticQueue &privateQMsgType, + staticQueue &privateQOwner); -void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP - ( - MilanLongInt NLVer, MilanLongInt NLEdge, - MilanLongInt* verLocPtr, MilanLongInt* verLocInd, MilanReal* edgeLocWeight, - MilanLongInt* verDistance, - MilanLongInt* Mate, - MilanInt myRank, MilanInt numProcs, MPI_Comm comm, - MilanLongInt* msgIndSent, MilanLongInt* msgActualSent, MilanReal* msgPercent, - MilanReal* ph0_time, MilanReal* ph1_time, MilanReal* ph2_time, - MilanLongInt* ph1_card, MilanLongInt* ph2_card ); + void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( + MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt *verLocPtr, MilanLongInt *verLocInd, MilanReal *edgeLocWeight, + MilanLongInt *verDistance, + MilanLongInt *Mate, + MilanInt myRank, MilanInt numProcs, MPI_Comm comm, + MilanLongInt *msgIndSent, MilanLongInt *msgActualSent, MilanReal *msgPercent, + MilanReal *ph0_time, MilanReal *ph1_time, MilanReal *ph2_time, + MilanLongInt *ph1_card, MilanLongInt *ph2_card); - void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateC -( - MilanLongInt NLVer, MilanLongInt NLEdge, - MilanLongInt* verLocPtr, MilanLongInt* verLocInd, MilanReal* edgeLocWeight, - MilanLongInt* verDistance, - MilanLongInt* Mate, - MilanInt myRank, MilanInt numProcs, MPI_Comm comm, - MilanLongInt* msgIndSent, MilanLongInt* msgActualSent, MilanReal* msgPercent, - MilanReal* ph0_time, MilanReal* ph1_time, MilanReal* ph2_time, - MilanLongInt* ph1_card, MilanLongInt* ph2_card ); + void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateC( + MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt *verLocPtr, MilanLongInt *verLocInd, MilanReal *edgeLocWeight, + MilanLongInt *verDistance, + MilanLongInt *Mate, + MilanInt myRank, MilanInt numProcs, MPI_Comm comm, + MilanLongInt *msgIndSent, MilanLongInt *msgActualSent, MilanReal *msgPercent, + MilanReal *ph0_time, MilanReal *ph1_time, MilanReal *ph2_time, + MilanLongInt *ph1_card, MilanLongInt *ph2_card); - void salgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateC -( -MilanLongInt NLVer, MilanLongInt NLEdge, -MilanLongInt* verLocPtr, MilanLongInt* verLocInd, MilanFloat* edgeLocWeight, -MilanLongInt* verDistance, -MilanLongInt* Mate, -MilanInt myRank, MilanInt numProcs, MPI_Comm comm, -MilanLongInt* msgIndSent, MilanLongInt* msgActualSent, MilanReal* msgPercent, -MilanReal* ph0_time, MilanReal* ph1_time, MilanReal* ph2_time, -MilanLongInt* ph1_card, MilanLongInt* ph2_card ); + void salgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateC( + MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt *verLocPtr, MilanLongInt *verLocInd, MilanFloat *edgeLocWeight, + MilanLongInt *verDistance, + MilanLongInt *Mate, + MilanInt myRank, MilanInt numProcs, MPI_Comm comm, + MilanLongInt *msgIndSent, MilanLongInt *msgActualSent, MilanReal *msgPercent, + MilanReal *ph0_time, MilanReal *ph1_time, MilanReal *ph2_time, + MilanLongInt *ph1_card, MilanLongInt *ph2_card); -void dMatchBoxPC(MilanLongInt NLVer, MilanLongInt NLEdge, - MilanLongInt* verLocPtr, MilanLongInt* verLocInd, MilanReal* edgeLocWeight, - MilanLongInt* verDistance, - MilanLongInt* Mate, - MilanInt myRank, MilanInt numProcs, MilanInt icomm, - MilanLongInt* msgIndSent, MilanLongInt* msgActualSent, MilanReal* msgPercent, - MilanReal* ph0_time, MilanReal* ph1_time, MilanReal* ph2_time, - MilanLongInt* ph1_card, MilanLongInt* ph2_card ); + void dMatchBoxPC(MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt *verLocPtr, MilanLongInt *verLocInd, MilanReal *edgeLocWeight, + MilanLongInt *verDistance, + MilanLongInt *Mate, + MilanInt myRank, MilanInt numProcs, MilanInt icomm, + MilanLongInt *msgIndSent, MilanLongInt *msgActualSent, MilanReal *msgPercent, + MilanReal *ph0_time, MilanReal *ph1_time, MilanReal *ph2_time, + MilanLongInt *ph1_card, MilanLongInt *ph2_card); -void sMatchBoxPC(MilanLongInt NLVer, MilanLongInt NLEdge, - MilanLongInt* verLocPtr, MilanLongInt* verLocInd, MilanFloat* edgeLocWeight, - MilanLongInt* verDistance, - MilanLongInt* Mate, - MilanInt myRank, MilanInt numProcs, MilanInt icomm, - MilanLongInt* msgIndSent, MilanLongInt* msgActualSent, MilanReal* msgPercent, - MilanReal* ph0_time, MilanReal* ph1_time, MilanReal* ph2_time, - MilanLongInt* ph1_card, MilanLongInt* ph2_card ); + void sMatchBoxPC(MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt *verLocPtr, MilanLongInt *verLocInd, MilanFloat *edgeLocWeight, + MilanLongInt *verDistance, + MilanLongInt *Mate, + MilanInt myRank, MilanInt numProcs, MilanInt icomm, + MilanLongInt *msgIndSent, MilanLongInt *msgActualSent, MilanReal *msgPercent, + MilanReal *ph0_time, MilanReal *ph1_time, MilanReal *ph2_time, + MilanLongInt *ph1_card, MilanLongInt *ph2_card); #endif #ifdef __cplusplus diff --git a/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp b/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp index d6c58852..d470b1ab 100644 --- a/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp +++ b/amgprec/impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp @@ -81,26 +81,32 @@ #ifdef SERIAL_MPI #else -//MPI type map -template MPI_Datatype TypeMap(); -template<> inline MPI_Datatype TypeMap() { return MPI_LONG_LONG; } -template<> inline MPI_Datatype TypeMap() { return MPI_INT; } -template<> inline MPI_Datatype TypeMap() { return MPI_DOUBLE; } -template<> inline MPI_Datatype TypeMap() { return MPI_FLOAT; } +// MPI type map +template +MPI_Datatype TypeMap(); +template <> +inline MPI_Datatype TypeMap() { return MPI_LONG_LONG; } +template <> +inline MPI_Datatype TypeMap() { return MPI_INT; } +template <> +inline MPI_Datatype TypeMap() { return MPI_DOUBLE; } +template <> +inline MPI_Datatype TypeMap() { return MPI_FLOAT; } // DOUBLE PRECISION VERSION -//WARNING: The vertex block on a given rank is contiguous +// WARNING: The vertex block on a given rank is contiguous void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( - MilanLongInt NLVer, MilanLongInt NLEdge, - MilanLongInt* verLocPtr, MilanLongInt* verLocInd, - MilanReal* edgeLocWeight, - MilanLongInt* verDistance, - MilanLongInt* Mate, - MilanInt myRank, MilanInt numProcs, MPI_Comm comm, - MilanLongInt* msgIndSent, MilanLongInt* msgActualSent, - MilanReal* msgPercent, - MilanReal* ph0_time, MilanReal* ph1_time, MilanReal* ph2_time, - MilanLongInt* ph1_card, MilanLongInt* ph2_card ) { + MilanLongInt NLVer, MilanLongInt NLEdge, + MilanLongInt *verLocPtr, MilanLongInt *verLocInd, + MilanReal *edgeLocWeight, + MilanLongInt *verDistance, + MilanLongInt *Mate, + MilanInt myRank, MilanInt numProcs, MPI_Comm comm, + MilanLongInt *msgIndSent, MilanLongInt *msgActualSent, + MilanReal *msgPercent, + MilanReal *ph0_time, MilanReal *ph1_time, MilanReal *ph2_time, + MilanLongInt *ph1_card, MilanLongInt *ph2_card) +{ /* * verDistance: it's a vector long as the number of processors. @@ -118,152 +124,159 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( #if !defined(SERIAL_MPI) #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< Message; // [ u, v, message_type ] - Message.resize(3,-1); - const MilanLongInt REQUEST = 1; - const MilanLongInt SUCCESS = 2; - const MilanLongInt FAILURE = 3; + Message.resize(3, -1); + const MilanLongInt REQUEST = 1; + const MilanLongInt SUCCESS = 2; + const MilanLongInt FAILURE = 3; const MilanLongInt SIZEINFO = 4; MilanLongInt message_type = 0; - //Data structures for Message Bundling: - //Although up to two messages can be sent along any cross edge, - //only one message will be sent in the initialization phase - - //one of: REQUEST/FAILURE/SUCCESS + // Data structures for Message Bundling: + // Although up to two messages can be sent along any cross edge, + // only one message will be sent in the initialization phase - + // one of: REQUEST/FAILURE/SUCCESS vector QLocalVtx, QGhostVtx, QMsgType; vector QOwner; // Changed by Fabio to be an integer, addresses needs to be integers! - MilanLongInt* PCounter = new MilanLongInt [numProcs]; + MilanLongInt *PCounter = new MilanLongInt[numProcs]; for (int i = 0; i < numProcs; i++) PCounter[i] = 0; - MilanLongInt NumMessagesBundled = 0; MilanInt ghostOwner = 0; // Changed by Fabio to be an integer, addresses needs to be integers! - MilanLongInt* candidateMate = nullptr; + MilanLongInt *candidateMate = nullptr; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< Ghost2LocalMap; //Map each ghost vertex to a local vertex - vector Counter; //Store the edge count for each ghost vertex - MilanLongInt numGhostVertices = 0, numGhostEdges = 0; //Number of Ghost vertices + // Build the Ghost Vertex Set: Vg + map Ghost2LocalMap; // Map each ghost vertex to a local vertex + vector Counter; // Store the edge count for each ghost vertex + MilanLongInt numGhostVertices = 0, numGhostEdges = 0; // Number of Ghost vertices #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< verGhostPtr, verGhostInd, tempCounter; - //Mate array for ghost vertices: - vector GMate; //Proportional to the number of ghost vertices + // Define Adjacency Lists for Ghost Vertices: + // cout<<"Building Ghost data structures ... \n\n"; + vector verGhostPtr, verGhostInd, tempCounter; + // Mate array for ghost vertices: + vector GMate; // Proportional to the number of ghost vertices MilanLongInt S; MilanLongInt privateMyCard = 0; staticQueue U, privateU, privateQLocalVtx, privateQGhostVtx, privateQMsgType, privateQOwner; MilanLongInt myIndex = 0; - vector PCumulative, PMessageBundle, PSizeInfoMessages; - vector SRequest; //Requests that are used for each send message - vector SStatus; //Status of sent messages, used in MPI_Wait - MilanLongInt MessageIndex = 0; //Pointer for current message + vector PCumulative, PMessageBundle, PSizeInfoMessages; + vector SRequest; // Requests that are used for each send message + vector SStatus; // Status of sent messages, used in MPI_Wait + MilanLongInt MessageIndex = 0; // Pointer for current message MilanInt OneMessageSize = 0; MilanLongInt numMessagesToSend; MilanInt BufferSize; MilanLongInt *Buffer; bool isEmpty; - //Declare the locks - // TODO destroy the locks + // Declare the locks + // TODO destroy the locks omp_lock_t MateLock[NLVer]; - initialize(NLVer, NLEdge, StartIndex, - EndIndex, &numGhostEdges, - &numGhostVertices, &S, - verLocInd, verLocPtr, - MateLock, - Ghost2LocalMap, Counter, - verGhostPtr, verGhostInd, - tempCounter, GMate, - Message, QLocalVtx, - QGhostVtx, QMsgType, QOwner, - candidateMate, U, - privateU, - privateQLocalVtx, - privateQGhostVtx, - privateQMsgType, - privateQOwner - ); - + initialize(NLVer, NLEdge, StartIndex, + EndIndex, &numGhostEdges, + &numGhostVertices, &S, + verLocInd, verLocPtr, + MateLock, + Ghost2LocalMap, Counter, + verGhostPtr, verGhostInd, + tempCounter, GMate, + Message, QLocalVtx, + QGhostVtx, QMsgType, QOwner, + candidateMate, U, + privateU, + privateQLocalVtx, + privateQGhostVtx, + privateQMsgType, + privateQOwner); + finishTime = MPI_Wtime(); - *ph0_time = finishTime - startTime; //Time taken for Phase-0: Initialization + *ph0_time = finishTime - startTime; // Time taken for Phase-0: Initialization - startTime = MPI_Wtime(); - ///////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// INITIALIZATION ///////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// - //Compute the Initial Matching Set: + // Compute the Initial Matching Set: #pragma omp parallel private(k, u, w, v, k1, adj1, adj2, adj11, adj12, heaviestEdgeWt, ghostOwner, privateMyCard, isEmpty) firstprivate(privateU, StartIndex, EndIndex, privateQLocalVtx, privateQGhostVtx, privateQMsgType, privateQOwner) default(shared) num_threads(4) { /* - * OMP PARALLEL_COMPUTE_CANDIDATE_MATE_B has been splitted from - * PARALLEL_PROCESS_EXPOSED_VERTEX_B in order to better parallelize - * the two. - * In particular PARALLEL_COMPUTE_CANDIDATE_MATE_B is now totally parallel. - */ + * OMP PARALLEL_COMPUTE_CANDIDATE_MATE_B has been splitted from + * PARALLEL_PROCESS_EXPOSED_VERTEX_B in order to better parallelize + * the two. + * In particular PARALLEL_COMPUTE_CANDIDATE_MATE_B is now totally parallel. + */ #pragma omp for schedule(static) - for ( v=0; v < NLVer; v++ ) { + for (v = 0; v < NLVer; v++) + { #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= 0) { + // If found a dominating edge: + if (w >= 0) + { - if (isAlreadyMatched(verLocInd[k], StartIndex, EndIndex, GMate, Mate, Ghost2LocalMap)) { + if (isAlreadyMatched(verLocInd[k], StartIndex, EndIndex, GMate, Mate, Ghost2LocalMap)) + { w = computeCandidateMate(verLocPtr[v], verLocPtr[v + 1], edgeLocWeight, 0, @@ -310,13 +328,15 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( candidateMate[v] = w; } - if (w >= 0) { + if (w >= 0) + { myCard++; - if ((w < StartIndex) || (w > EndIndex)) { //w is a ghost vertex + if ((w < StartIndex) || (w > EndIndex)) + { // w is a ghost vertex #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0) { + if (Counter[Ghost2LocalMap[w]] > 0) + { - Counter[Ghost2LocalMap[w]] -= 1; //Decrement - if (Counter[Ghost2LocalMap[w]] == 0) { - S--; //Decrement S + Counter[Ghost2LocalMap[w]] -= 1; // Decrement + if (Counter[Ghost2LocalMap[w]] == 0) + { + S--; // Decrement S #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 - //End: PARALLEL_PROCESS_CROSS_EDGE_B(v) - } //End of if CandidateMate[w] = v - + } // End of if Counter[w] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v) + } // End of if CandidateMate[w] = v - } //End of if a Ghost Vertex - else { // w is a local vertex + } // End of if a Ghost Vertex + else + { // w is a local vertex - if (candidateMate[w - StartIndex] == (v + StartIndex)) { + if (candidateMate[w - StartIndex] == (v + StartIndex)) + { privateU.push_back(v + StartIndex); privateU.push_back(w); - Mate[v] = w; //v is local - //FIXME this instruction could create errors - Mate[w - StartIndex] = v + StartIndex; //w is local - + Mate[v] = w; // v is local + // FIXME this instruction could create errors + Mate[w - StartIndex] = v + StartIndex; // w is local #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<=0) + } // End of if(w >=0) - //This piece of code is executed a really small amount of times, I will not allocate a - //huge amount of memory to the private data structures. + // This piece of code is executed a really small amount of times, I will not allocate a + // huge amount of memory to the private data structures. adj11 = verLocPtr[v]; adj12 = verLocPtr[v + 1]; - for (k1 = adj11; k1 < adj12; k1++) { + for (k1 = adj11; k1 < adj12; k1++) + { w = verLocInd[k1]; - if ((w < StartIndex) || (w > EndIndex)) { //A ghost + if ((w < StartIndex) || (w > EndIndex)) + { // A ghost #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< Us; + // TODO what would be the optimal UCHUNK + vector Us; Us.reserve(UCHUNK); - while( true ) { + while (true) + { Us.clear(); #pragma omp critical(U) { - //If U is emptu and there are no new node to add to U + // If U is emptu and there are no new node to add to U if (U.empty() && privateU.empty()) isEmpty = true; - else { + else + { if (U.empty() && !privateU.empty()) // If U is empty but there are nodes in private U - while (!privateU.empty()) { + while (!privateU.empty()) + { U.push_back(privateU.pop_front()); myCard += privateMyCard; } - for (int i = 0; i < UCHUNK; i++) { // Pop the new nodes - if (U.empty()) break; + for (int i = 0; i < UCHUNK; i++) + { // Pop the new nodes + if (U.empty()) + break; Us.push_back(U.pop_front()); } } } // End of critical U - if (isEmpty) break; + if (isEmpty) + break; for (MilanLongInt u : Us) { #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= StartIndex) && (u <= EndIndex)) { //Process Only the Local Vertices + if ((u >= StartIndex) && (u <= EndIndex)) + { // Process Only the Local Vertices #ifdef COUNT_LOCAL_VERTEX - localVertices ++; + localVertices++; #endif - //Get the Adjacency list for u - adj1 = verLocPtr[u - StartIndex]; //Pointer + // Get the Adjacency list for u + adj1 = verLocPtr[u - StartIndex]; // Pointer adj2 = verLocPtr[u - StartIndex + 1]; - for (k = adj1; k < adj2; k++) { + for (k = adj1; k < adj2; k++) + { v = verLocInd[k]; - if ((v >= StartIndex) && (v <= EndIndex)) { //If Local Vertex: + if ((v >= StartIndex) && (v <= EndIndex)) + { // If Local Vertex: #pragma omp critical(innerProcessMatched) { #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= 0) { + // If found a dominating edge: + if (w >= 0) + { - //TODO is it possible to lock without a critical region? - //TODO there must be a more elegant and efficient way to do this + // TODO is it possible to lock without a critical region? + // TODO there must be a more elegant and efficient way to do this /* while(true) { if (omp_test_lock(&MateLock[v - StartIndex])) { @@ -562,11 +598,11 @@ void dalgoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP( } */ - - if ((w < StartIndex) || (w > EndIndex)) { //A ghost + if ((w < StartIndex) || (w > EndIndex)) + { // A ghost #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0) { - Counter[Ghost2LocalMap[w]] = Counter[Ghost2LocalMap[w]] - 1; //Decrement - if (Counter[Ghost2LocalMap[w]] == 0) { - S--; //Decrement S + // 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("< 0 - //End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) - } //End of if CandidateMate[w] = v - } //End of if a Ghost Vertex - else { //w is a local vertex - if (candidateMate[w - StartIndex] == v) { - Mate[v - StartIndex] = w; //v is a local vertex - Mate[w - StartIndex] = v; //w is a local vertex - //Q.push_back(u); + } // End of if Counter[w] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) + } // End of if CandidateMate[w] = v + } // End of if a Ghost Vertex + else + { // w is a local vertex + if (candidateMate[w - StartIndex] == v) + { + Mate[v - StartIndex] = w; // v is a local vertex + Mate[w - StartIndex] = v; // w is a local vertex + // Q.push_back(u); privateU.push_back(v); privateU.push_back(w); privateMyCard++; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<=0) - else { + } // End of if(w >=0) + else + { adj11 = verLocPtr[v - StartIndex]; adj12 = verLocPtr[v - StartIndex + 1]; - for (k1 = adj11; k1 < adj12; k1++) { + for (k1 = adj11; k1 < adj12; k1++) + { w = verLocInd[k1]; - if ((w < StartIndex) || (w > EndIndex)) { //A ghost + if ((w < StartIndex) || (w > EndIndex)) + { // A ghost #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= StartIndex) && (v <= EndIndex) ) //If Local Vertex: - else { //Neighbor is a ghost vertex + } // End of if ( (v >= StartIndex) && (v <= EndIndex) ) //If Local Vertex: + else + { // Neighbor is a ghost vertex #pragma omp critical(innerProcessMatched) { - //while(!omp_test_lock(&MateLock[u - StartIndex])); + // while(!omp_test_lock(&MateLock[u - StartIndex])); if (candidateMate[NLVer + Ghost2LocalMap[v]] == u) candidateMate[NLVer + Ghost2LocalMap[v]] = -1; - if (v != Mate[u - StartIndex]) { //u is local - //Build the Message Packet: - //Message[0] = u; //LOCAL - //Message[1] = v; //GHOST - //Message[2] = SUCCESS; //TYPE - //Send a Request (Asynchronous) + if (v != Mate[u - StartIndex]) + { // u is local + // Build the Message Packet: + // Message[0] = u; //LOCAL + // Message[1] = v; //GHOST + // Message[2] = SUCCESS; //TYPE + // Send a Request (Asynchronous) #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= StartIndex) && (u <= EndIndex) ) //Process Only If a Local Vertex + } // End of if ( (u >= StartIndex) && (u <= EndIndex) ) //Process Only If a Local Vertex - //Avoid to ask for the critical section if there is nothing to add - if (privateU.size() < UCHUNK && !U.empty()) continue; + // Avoid to ask for the critical section if there is nothing to add + if (privateU.size() < UCHUNK && !U.empty()) + continue; #pragma omp critical(U) { - while (!privateU.empty()) { + while (!privateU.empty()) + { U.push_back(privateU.pop_front()); } myCard += privateMyCard; - } //End of critical U - + } // End of critical U } - } //End of while ( /*!Q.empty()*/ !U.empty() ) + } // End of while ( /*!Q.empty()*/ !U.empty() ) - #pragma omp critical(privateMsg) +#pragma omp critical(privateMsg) { - while (!privateQLocalVtx.empty()) { + while (!privateQLocalVtx.empty()) + { QLocalVtx.push_back(privateQLocalVtx.pop_front()); QGhostVtx.push_back(privateQGhostVtx.pop_front()); QMsgType.push_back(privateQMsgType.pop_front()); QOwner.push_back(privateQOwner.pop_front()); - } - } - #ifdef COUNT_LOCAL_VERTEX printf("Count local vertexes: %ld for thread %d of processor %d\n", - localVertices, - omp_get_thread_num(), - myRank); + localVertices, + omp_get_thread_num(), + myRank); #endif - ///////////////////////// END OF PROCESS MATCHED VERTICES ///////////////////////// #ifdef DEBUG_HANG_ - if (myRank == 0) cout<<"\n("< 0) { //Send only if it is a nonempty packet + 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++; - //Now Send the message with the data packet: + // Now Send the message with the data packet: #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<(), i, BundleTag, comm, &SRequest[MessageIndex]); MessageIndex++; - } //End of if size > 0 + } // End of if size > 0 } - //Free up temporary memory: + // Free up temporary memory: PCumulative.clear(); QLocalVtx.clear(); QGhostVtx.clear(); QMsgType.clear(); QOwner.clear(); - #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<(), comm, &OneMessageSize); //Size of one message packet - //How many messages to send? - //Potentially three kinds of messages will be sent/received: - //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; - - Buffer=0; -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<(), comm, &OneMessageSize); // Size of one message packet + // How many messages to send? + // Potentially three kinds of messages will be sent/received: + // 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; + + 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 remaining message = " << numMessagesToSend; + cout << "\n(" << myRank << ")BufferSize = " << BufferSize; + cout << "\n(" << myRank << ")Attaching Buffer on.. "; + fflush(stdout); #endif - if ( BufferSize > 0 ) { - 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 "< 0) + { + 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 } - } //End of master + } // End of master } // end of parallel region ///////////////////////// END OF SEND BUNDLED MESSAGES ////////////////////////////////// finishTime = MPI_Wtime(); - *ph1_time = finishTime-startTime; //Time taken for Phase-1 - *ph1_card = myCard; //Cardinality at the end of Phase-1 + *ph1_time = finishTime - startTime; // Time taken for Phase-1 + *ph1_card = myCard; // Cardinality at the end of Phase-1 startTime = MPI_Wtime(); ///////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// MAIN LOOP ////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// - //Main While Loop: + // Main While Loop: #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< ReceiveBuffer; - MilanLongInt bundleSize=0, bundleCounter=0; - try { - ReceiveBuffer.reserve(numGhostEdges*2*3); //Three integers per cross edge - } catch ( length_error ) { - cout<<"Error in function algoDistEdgeApproxDominatingEdgesMessageBundling: \n"; - cout<<"Not enough memory to allocate the internal variables \n"; + MilanLongInt bundleSize = 0, bundleCounter = 0; + try + { + ReceiveBuffer.reserve(numGhostEdges * 2 * 3); // Three integers per cross edge + } + catch (length_error) + { + cout << "Error in function algoDistEdgeApproxDominatingEdgesMessageBundling: \n"; + cout << "Not enough memory to allocate the internal variables \n"; exit(1); } - while ( true ) { + while (true) + { #ifdef DEBUG_HANG_ - if (myRank == 0) cout<<"\n("<= StartIndex) && (u <= EndIndex) ) { //Process Only If a Local Vertex - //Get the Adjacency list for u - adj1 = verLocPtr[u-StartIndex]; //Pointer - adj2 = verLocPtr[u-StartIndex+1]; - for( k = adj1; k < adj2; k++ ) { + if ((u >= StartIndex) && (u <= EndIndex)) + { // Process Only If a Local Vertex + // Get the Adjacency list for u + adj1 = verLocPtr[u - StartIndex]; // Pointer + adj2 = verLocPtr[u - StartIndex + 1]; + for (k = adj1; k < adj2; k++) + { v = verLocInd[k]; - if ( (v >= StartIndex) && (v <= EndIndex) ) { //v is a Local Vertex: - if ( Mate[v-StartIndex] >= 0 ) // v is already matched + if ((v >= StartIndex) && (v <= EndIndex)) + { // v is a Local Vertex: + if (Mate[v - StartIndex] >= 0) // v is already matched continue; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<EndIndex) ) { //Is it a ghost vertex? - if(GMate[Ghost2LocalMap[verLocInd[k1]]] >= 0 )// Already matched + heaviestEdgeWt = MilanRealMin; // Assign the smallest Value possible first LDBL_MIN + for (k1 = adj11; k1 < adj12; k1++) + { + if ((verLocInd[k1] < StartIndex) || (verLocInd[k1] > EndIndex)) + { // Is it a ghost vertex? + if (GMate[Ghost2LocalMap[verLocInd[k1]]] >= 0) // Already matched continue; } - else { //A local vertex - if( Mate[verLocInd[k1]-StartIndex] >= 0 ) // Already matched + else + { // A local vertex + if (Mate[verLocInd[k1] - StartIndex] >= 0) // Already matched continue; } - if( (edgeLocWeight[k1] > heaviestEdgeWt) || - ((edgeLocWeight[k1] == heaviestEdgeWt)&&(w < verLocInd[k1])) ) { + if ((edgeLocWeight[k1] > heaviestEdgeWt) || + ((edgeLocWeight[k1] == heaviestEdgeWt) && (w < verLocInd[k1]))) + { heaviestEdgeWt = edgeLocWeight[k1]; w = verLocInd[k1]; } - } //End of for loop - candidateMate[v-StartIndex] = w; - //End: PARALLEL_COMPUTE_CANDIDATE_MATE_B(v) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= 0 ) { - if ( (w < StartIndex) || (w > EndIndex) ) { //w is a ghost - //Build the Message Packet: - Message[0] = v; //LOCAL - Message[1] = w; //GHOST - Message[2] = REQUEST; //TYPE - //Send a Request (Asynchronous) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= 0) + { + if ((w < StartIndex) || (w > EndIndex)) + { // w is a ghost + // Build the Message Packet: + Message[0] = v; // LOCAL + Message[1] = w; // GHOST + Message[2] = REQUEST; // TYPE + // Send a Request (Asynchronous) +#ifdef PRINT_DEBUG_INFO_ + cout << "\n(" << myRank << ")Sending a request message:"; + cout << "\n(" << myRank << ")Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs); fflush(stdout); #endif - ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); + ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); + assert(ghostOwner != -1); + assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); - msgInd++; msgActual++; - if ( candidateMate[NLVer+Ghost2LocalMap[w]] == v ) { - Mate[v-StartIndex] = w; //v is local - GMate[Ghost2LocalMap[w]] = v; //w is ghost - //Q.push_back(u); + msgInd++; + msgActual++; + if (candidateMate[NLVer + Ghost2LocalMap[w]] == v) + { + Mate[v - StartIndex] = w; // v is local + GMate[Ghost2LocalMap[w]] = v; // w is ghost + // Q.push_back(u); U.push_back(v); U.push_back(w); myCard++; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 ) { - Counter[Ghost2LocalMap[w]] = Counter[Ghost2LocalMap[w]] - 1; //Decrement - if ( Counter[Ghost2LocalMap[w]] == 0 ) { - S--; //Decrement S + // 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("< 0 - //End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) - } //End of if CandidateMate[w] = v - } //End of if a Ghost Vertex - else { //w is a local vertex - if ( candidateMate[w-StartIndex] == v ) { - Mate[v-StartIndex] = w; //v is local - Mate[w-StartIndex] = v; //w is local - //Q.push_back(u); + } // End of if Counter[w] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) + } // End of if CandidateMate[w] = v + } // End of if a Ghost Vertex + else + { // w is a local vertex + if (candidateMate[w - StartIndex] == v) + { + Mate[v - StartIndex] = w; // v is local + Mate[w - StartIndex] = v; // w is local + // Q.push_back(u); U.push_back(v); U.push_back(w); myCard++; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<=0) - else { //no dominating edge found: w == -1 - adj11 = verLocPtr[v-StartIndex]; - adj12 = verLocPtr[v-StartIndex+1]; - for( k1 = adj11; k1 < adj12; k1++ ) { + } // End of if(CandidateMate(w) = v + } // End of Else + } // End of if(w >=0) + else + { // no dominating edge found: w == -1 + adj11 = verLocPtr[v - StartIndex]; + adj12 = verLocPtr[v - StartIndex + 1]; + for (k1 = adj11; k1 < adj12; k1++) + { w = verLocInd[k1]; - if ( (w < StartIndex) || (w > EndIndex) ) { //A ghost - //Build the Message Packet: - Message[0] = v; //LOCAL - Message[1] = w; //GHOST - Message[2] = FAILURE; //TYPE - //Send a Request (Asynchronous) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< EndIndex)) + { // A ghost + // Build the Message Packet: + Message[0] = v; // LOCAL + Message[1] = w; // GHOST + Message[2] = FAILURE; // TYPE + // Send a Request (Asynchronous) +#ifdef PRINT_DEBUG_INFO_ + cout << "\n(" << myRank << ")Sending a failure message: "; + cout << "\n(" << myRank << ")Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs); fflush(stdout); #endif - ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); + ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); + assert(ghostOwner != -1); + assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); - msgInd++; msgActual++; - } //End of if(GHOST) - } //End of for loop - } // End of Else: w == -1 - //End: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v) - } //End of If (candidateMate[v-StartIndex] == u) - } //End of if ( (v >= StartIndex) && (v <= EndIndex) ) //If Local Vertex: - else { //Neighbor v is a ghost vertex - if ( candidateMate[NLVer+Ghost2LocalMap[v]] == u ) - candidateMate[NLVer+Ghost2LocalMap[v]] = -1; - if ( v != Mate[u-StartIndex] ) { //u is a local vertex - //Build the Message Packet: - Message[0] = u; //LOCAL - Message[1] = v; //GHOST - Message[2] = SUCCESS; //TYPE - //Send a Request (Asynchronous) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= StartIndex) && (v <= EndIndex) ) //If Local Vertex: + else + { // Neighbor v is a ghost vertex + if (candidateMate[NLVer + Ghost2LocalMap[v]] == u) + candidateMate[NLVer + Ghost2LocalMap[v]] = -1; + if (v != Mate[u - StartIndex]) + { // u is a local vertex + // Build the Message Packet: + Message[0] = u; // LOCAL + Message[1] = v; // GHOST + Message[2] = SUCCESS; // TYPE + // Send a Request (Asynchronous) +#ifdef PRINT_DEBUG_INFO_ + cout << "\n(" << myRank << ")Sending a success message: "; + cout << "\n(" << myRank << ")Ghost is " << v << " Owner is: " << findOwnerOfGhost(v, verDistance, myRank, numProcs); fflush(stdout); #endif - ghostOwner = findOwnerOfGhost(v, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); + ghostOwner = findOwnerOfGhost(v, verDistance, myRank, numProcs); + assert(ghostOwner != -1); + assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); msgInd++; msgActual++; #ifdef DEBUG_GHOST_ - if ((uEndIndex)) { - cout<<"\n("<= StartIndex) && (u <= EndIndex) ) //Process Only If a Local Vertex - } //End of while ( /*!Q.empty()*/ !U.empty() ) + if ((u < StartIndex) || (u > EndIndex)) + { + cout << "\n(" << myRank << ") " << __LINE__ << " From Send: should not happen: u= " << u << " v= " << v << " StartIndex " << StartIndex << " EndIndex " << EndIndex << endl; + fflush(stdout); + } +#endif + + } // End of If( v != Mate[u] ) + } // End of Else //A Ghost Vertex + } // End of For Loop adj(u) + } // End of if ( (u >= StartIndex) && (u <= EndIndex) ) //Process Only If a Local Vertex + } // End of while ( /*!Q.empty()*/ !U.empty() ) ///////////////////////// END OF PROCESS MATCHED VERTICES ///////////////////////// //// BREAK IF NO MESSAGES EXPECTED ///////// #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<(), MPI_ANY_SOURCE, ComputeTag, comm, &computeStatus); - if (error_codeC != MPI_SUCCESS ) { + if (error_codeC != MPI_SUCCESS) + { MPI_Error_string(error_codeC, error_message, &message_length); - cout<<"\n*Error in call to MPI_Receive on Slave: "<(), Sender, BundleTag, comm, &computeStatus); - if (error_codeC != MPI_SUCCESS ) { + if (error_codeC != MPI_SUCCESS) + { MPI_Error_string(error_codeC, error_message, &message_length); - cout<<"\n*Error in call to MPI_Receive on processor "< EndIndex)) + { + cout << "\n(" << myRank << ") From ReceiveBuffer: This should not happen: u= " << u << " v= " << v << " Type= " << message_type << " StartIndex " << StartIndex << " EndIndex " << EndIndex << endl; + fflush(stdout); + } #endif #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<NLVer)) { - cout<<"\n("< NLVer)) + { + cout << "\n(" << myRank << ") case 1 Bad address " << v << " " << StartIndex << " " << v - StartIndex << " " << NLVer << endl; + fflush(stdout); + } #endif - if ( Mate[v-StartIndex] == -1 ) { //Process only if not already matched (v is local) - candidateMate[NLVer+Ghost2LocalMap[u]] = v; //Set CandidateMate for the ghost - if ( candidateMate[v-StartIndex] == u ) { - GMate[Ghost2LocalMap[u]] = v; //u is ghost - Mate[v-StartIndex] = u; //v is local - //Q.push_back(u); + if (Mate[v - StartIndex] == -1) + { // Process only if not already matched (v is local) + candidateMate[NLVer + Ghost2LocalMap[u]] = v; // Set CandidateMate for the ghost + if (candidateMate[v - StartIndex] == u) + { + GMate[Ghost2LocalMap[u]] = v; // u is ghost + Mate[v - StartIndex] = u; // v is local + // Q.push_back(u); U.push_back(v); U.push_back(u); myCard++; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 ) { - Counter[Ghost2LocalMap[u]] = Counter[Ghost2LocalMap[u]] - 1; //Decrement - if ( Counter[Ghost2LocalMap[u]] == 0 ) { - S--; //Decrement S + // 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("< 0 - //End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) - } //End of if ( candidateMate[v-StartIndex] == u )e - } //End of if ( Mate[v] == -1 ) - } //End of REQUEST - else { //CASE II: SUCCESS - if ( message_type == SUCCESS ) { -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 ) { - Counter[Ghost2LocalMap[u]] = Counter[Ghost2LocalMap[u]] - 1; //Decrement - if ( Counter[Ghost2LocalMap[u]] == 0 ) { - S--; //Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) + } // End of if ( candidateMate[v-StartIndex] == u )e + } // End of if ( Mate[v] == -1 ) + } // End of REQUEST + else + { // CASE II: SUCCESS + if (message_type == SUCCESS) + { +#ifdef PRINT_DEBUG_INFO_ + 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) + } // End of if Counter[w] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) #ifdef DEBUG_GHOST_ - if ((v<0)||(vNLVer)) { - cout<<"\n("< NLVer)) + { + cout << "\n(" << myRank << ") case 2 Bad address " << v << " " << StartIndex << " " << v - StartIndex << " " << NLVer << endl; + fflush(stdout); + } +#endif + if (Mate[v - StartIndex] == -1) + { // Process only if not already matched ( v is local) + if (candidateMate[v - StartIndex] == u) + { + // Start: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v) + // Start: PARALLEL_COMPUTE_CANDIDATE_MATE_B(v) + adj11 = verLocPtr[v - StartIndex]; + adj12 = verLocPtr[v - StartIndex + 1]; w = -1; - heaviestEdgeWt = MilanRealMin; //Assign the smallest Value possible first LDBL_MIN - for( k1 = adj11; k1 < adj12; k1++ ) { - if ( (verLocInd[k1]EndIndex) ) { //Is it a ghost vertex? - if(GMate[Ghost2LocalMap[verLocInd[k1]]] >= 0 )// Already matched + heaviestEdgeWt = MilanRealMin; // Assign the smallest Value possible first LDBL_MIN + for (k1 = adj11; k1 < adj12; k1++) + { + if ((verLocInd[k1] < StartIndex) || (verLocInd[k1] > EndIndex)) + { // Is it a ghost vertex? + if (GMate[Ghost2LocalMap[verLocInd[k1]]] >= 0) // Already matched continue; } - else { //A local vertex - if( Mate[verLocInd[k1]-StartIndex] >= 0 ) // Already matched + else + { // A local vertex + if (Mate[verLocInd[k1] - StartIndex] >= 0) // Already matched continue; } - if( (edgeLocWeight[k1] > heaviestEdgeWt) || - ((edgeLocWeight[k1] == heaviestEdgeWt)&&(w < verLocInd[k1])) ) { + if ((edgeLocWeight[k1] > heaviestEdgeWt) || + ((edgeLocWeight[k1] == heaviestEdgeWt) && (w < verLocInd[k1]))) + { heaviestEdgeWt = edgeLocWeight[k1]; w = verLocInd[k1]; } - } //End of for loop - candidateMate[v-StartIndex] = w; - //End: PARALLEL_COMPUTE_CANDIDATE_MATE_B(v) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= 0 ) { - if ( (w < StartIndex) || (w > EndIndex) ) { //w is a ghost - //Build the Message Packet: - Message[0] = v; //LOCAL - Message[1] = w; //GHOST - Message[2] = REQUEST; //TYPE - //Send a Request (Asynchronous) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<= 0) + { + if ((w < StartIndex) || (w > EndIndex)) + { // w is a ghost + // Build the Message Packet: + Message[0] = v; // LOCAL + Message[1] = w; // GHOST + Message[2] = REQUEST; // TYPE + // Send a Request (Asynchronous) +#ifdef PRINT_DEBUG_INFO_ + cout << "\n(" << myRank << ")Sending a request message: "; + cout << "\n(" << myRank << ")Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs) << endl; fflush(stdout); #endif - ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); + ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); + assert(ghostOwner != -1); + assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); - msgInd++; msgActual++; - if ( candidateMate[NLVer+Ghost2LocalMap[w]] == v ) { - Mate[v-StartIndex] = w; //v is local - GMate[Ghost2LocalMap[w]] = v; //w is ghost - //Q.push_back(u); + msgInd++; + msgActual++; + if (candidateMate[NLVer + Ghost2LocalMap[w]] == v) + { + Mate[v - StartIndex] = w; // v is local + GMate[Ghost2LocalMap[w]] = v; // w is ghost + // Q.push_back(u); U.push_back(v); U.push_back(w); myCard++; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 ) { - Counter[Ghost2LocalMap[w]] = Counter[Ghost2LocalMap[w]] - 1; //Decrement - if ( Counter[Ghost2LocalMap[w]] == 0 ) { - S--; //Decrement S + // 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("< 0 - //End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) - } //End of if CandidateMate[w] = v - } //End of if a Ghost Vertex - else { //w is a local vertex - if ( candidateMate[w-StartIndex] == v ) { - Mate[v-StartIndex] = w; //v is local - Mate[w-StartIndex] = v; //w is local - //Q.push_back(u); + } // End of if Counter[w] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,w) + } // End of if CandidateMate[w] = v + } // End of if a Ghost Vertex + else + { // w is a local vertex + if (candidateMate[w - StartIndex] == v) + { + Mate[v - StartIndex] = w; // v is local + Mate[w - StartIndex] = v; // w is local + // Q.push_back(u); U.push_back(v); U.push_back(w); myCard++; #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("<=0) - else { //No dominant edge found - adj11 = verLocPtr[v-StartIndex]; - adj12 = verLocPtr[v-StartIndex+1]; - for( k1 = adj11; k1 < adj12; k1++ ) { + } // End of if(CandidateMate(w) = v + } // End of Else + } // End of if(w >=0) + else + { // No dominant edge found + adj11 = verLocPtr[v - StartIndex]; + adj12 = verLocPtr[v - StartIndex + 1]; + for (k1 = adj11; k1 < adj12; k1++) + { w = verLocInd[k1]; - if ( (w < StartIndex) || (w > EndIndex) ) { //A ghost - //Build the Message Packet: - Message[0] = v; //LOCAL - Message[1] = w; //GHOST - Message[2] = FAILURE; //TYPE - //Send a Request (Asynchronous) -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< EndIndex)) + { // A ghost + // Build the Message Packet: + Message[0] = v; // LOCAL + Message[1] = w; // GHOST + Message[2] = FAILURE; // TYPE + // Send a Request (Asynchronous) +#ifdef PRINT_DEBUG_INFO_ + cout << "\n(" << myRank << ")Sending a failure message: "; + cout << "\n(" << myRank << ")Ghost is " << w << " Owner is: " << findOwnerOfGhost(w, verDistance, myRank, numProcs) << endl; fflush(stdout); #endif - //MPI_Bsend(&Message[0], 3, MilanMpiLongInt, findOwnerOfGhost(w, verDistance, myRank, numProcs), - ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); assert(ghostOwner != -1); assert(ghostOwner != myRank); + // MPI_Bsend(&Message[0], 3, MilanMpiLongInt, findOwnerOfGhost(w, verDistance, myRank, numProcs), + ghostOwner = findOwnerOfGhost(w, verDistance, myRank, numProcs); + assert(ghostOwner != -1); + assert(ghostOwner != myRank); MPI_Bsend(&Message[0], 3, TypeMap(), ghostOwner, ComputeTag, comm); - msgInd++; msgActual++; - } //End of if(GHOST) - } //End of for loop - } // End of Else: w == -1 - //End: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v) - } //End of if ( candidateMate[v-StartIndex] == u ) - } //End of if ( Mate[v] == -1 ) - } //End of if ( message_type == SUCCESS ) - else { //CASE III: FAILURE -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 ) { - Counter[Ghost2LocalMap[u]] = Counter[Ghost2LocalMap[u]] - 1; //Decrement - if ( Counter[Ghost2LocalMap[u]] == 0 ) { - S--; //Decrement S -#ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 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) - } //End of else: CASE III - } //End of else: CASE I - } //End of if (!MsgQ.empty()) + } // End of if Counter[w] > 0 + // End: PARALLEL_PROCESS_CROSS_EDGE_B(v,u) + } // End of else: CASE III + } // End of else: CASE I + } // End of if (!MsgQ.empty()) ///////////////////////// END OF PROCESS MESSAGES ///////////////////////////////// #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0 ) { - MPI_Buffer_detach(&Buffer, &BufferSize); //Detach the Buffer - free(Buffer); //Free the memory that was allocated + // MPI_Buffer_attach(&Buffer, BufferSize); //Attach the Buffer + if (BufferSize > 0) + { + MPI_Buffer_detach(&Buffer, &BufferSize); // Detach the Buffer + free(Buffer); // Free the memory that was allocated } finishTime = MPI_Wtime(); - *ph2_time = finishTime-startTime; //Time taken for Phase-2 - *ph2_card = myCard ; //Cardinality at the end of Phase-2 + *ph2_time = finishTime - startTime; // Time taken for Phase-2 + *ph2_card = myCard; // Cardinality at the end of Phase-2 #ifdef PRINT_DEBUG_INFO_ - cout<<"\n("< 0) { - *msgPercent = ((double)NumMessagesBundled/(double)(msgInd))*100.0; - } else { + if (msgInd > 0) + { + *msgPercent = ((double)NumMessagesBundled / (double)(msgInd)) * 100.0; + } + else + { *msgPercent = 0; } #ifdef DEBUG_HANG_ - if (myRank == 0) cout<<"\n("<