@ -1,4 +1,5 @@
# include "MatchBoxPC.h"
# include "MatchBoxPC.h"
//#define DEBUG_HANG_
void processMessages (
void processMessages (
MilanLongInt NLVer ,
MilanLongInt NLVer ,
@ -78,6 +79,7 @@ void processMessages(
fflush ( stdout ) ;
fflush ( stdout ) ;
# endif
# endif
//cout << myRank<<" Receiving ...";
error_codeC = MPI_Recv ( & Message [ 0 ] , 3 , TypeMap < MilanLongInt > ( ) , MPI_ANY_SOURCE , ComputeTag , comm , & computeStatus ) ;
error_codeC = MPI_Recv ( & Message [ 0 ] , 3 , TypeMap < MilanLongInt > ( ) , MPI_ANY_SOURCE , ComputeTag , comm , & computeStatus ) ;
if ( error_codeC ! = MPI_SUCCESS )
if ( error_codeC ! = MPI_SUCCESS )
{
{
@ -86,14 +88,13 @@ void processMessages(
fflush ( stdout ) ;
fflush ( stdout ) ;
}
}
Sender = computeStatus . MPI_SOURCE ;
Sender = computeStatus . MPI_SOURCE ;
//cout << " ...from "<<Sender << endl;
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " )Received message from Process " < < Sender < < " Type= " < < Message [ 2 ] < < endl ;
cout < < " \n ( " < < myRank < < " )Received message from Process " < < Sender < < " Type= " < < Message [ 2 ] < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
# endif
# endif
if ( Message [ 2 ] = = SIZEINFO )
if ( Message [ 2 ] = = SIZEINFO ) {
{
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " )Received bundled message from Process " < < Sender < < " Size= " < < Message [ 0 ] < < endl ;
cout < < " \n ( " < < myRank < < " )Received bundled message from Process " < < Sender < < " Size= " < < Message [ 0 ] < < endl ;
@ -112,9 +113,9 @@ void processMessages(
fflush ( stdout ) ;
fflush ( stdout ) ;
# endif
# endif
// Receive the message
// Receive the message
//cout << myRank<<" Receiving from "<<Sender<<endl;
error_codeC = MPI_Recv ( & ReceiveBuffer [ 0 ] , bundleSize , TypeMap < MilanLongInt > ( ) , Sender , BundleTag , comm , & computeStatus ) ;
error_codeC = MPI_Recv ( & ReceiveBuffer [ 0 ] , bundleSize , TypeMap < MilanLongInt > ( ) , Sender , BundleTag , comm , & computeStatus ) ;
if ( error_codeC ! = MPI_SUCCESS )
if ( error_codeC ! = MPI_SUCCESS ) {
{
MPI_Error_string ( error_codeC , error_message , & message_length ) ;
MPI_Error_string ( error_codeC , error_message , & message_length ) ;
cout < < " \n *Error in call to MPI_Receive on processor " < < myRank < < " Error: " < < error_message < < " \n " ;
cout < < " \n *Error in call to MPI_Receive on processor " < < myRank < < " Error: " < < error_message < < " \n " ;
fflush ( stdout ) ;
fflush ( stdout ) ;
@ -126,9 +127,7 @@ void processMessages(
cout < < endl ;
cout < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
# endif
# endif
}
} else { // Just a single message:
else
{ // Just a single message:
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " )Received regular message from Process " < < Sender < < " u= " < < Message [ 0 ] < < " v= " < < Message [ 1 ] < < endl ;
cout < < " \n ( " < < myRank < < " )Received regular message from Process " < < Sender < < " u= " < < Message [ 0 ] < < " v= " < < Message [ 1 ] < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
@ -146,8 +145,7 @@ void processMessages(
}
}
# ifdef DEBUG_GHOST_
# ifdef DEBUG_GHOST_
if ( ( v < StartIndex ) | | ( v > EndIndex ) )
if ( ( v < StartIndex ) | | ( v > EndIndex ) ) {
{
cout < < " \n ( " < < myRank < < " ) From ReceiveBuffer: This should not happen: u= " < < u < < " v= " < < v < < " Type= " < < message_type < < " StartIndex " < < StartIndex < < " EndIndex " < < EndIndex < < endl ;
cout < < " \n ( " < < myRank < < " ) From ReceiveBuffer: This should not happen: u= " < < u < < " v= " < < v < < " Type= " < < message_type < < " StartIndex " < < StartIndex < < " EndIndex " < < EndIndex < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
}
}
@ -158,33 +156,29 @@ void processMessages(
# endif
# endif
// Most of the time bundleSize == 3, thus, it's not worth parallelizing thi loop
// Most of the time bundleSize == 3, thus, it's not worth parallelizing thi loop
for ( MilanLongInt bundleCounter = 3 ; bundleCounter < bundleSize + 3 ; bundleCounter + = 3 )
for ( MilanLongInt bundleCounter = 3 ; bundleCounter < bundleSize + 3 ; bundleCounter + = 3 ) {
{
u = ReceiveBuffer [ bundleCounter - 3 ] ; // GHOST
u = ReceiveBuffer [ bundleCounter - 3 ] ; // GHOST
v = ReceiveBuffer [ bundleCounter - 2 ] ; // LOCAL
v = ReceiveBuffer [ bundleCounter - 2 ] ; // LOCAL
message_type = ReceiveBuffer [ bundleCounter - 1 ] ; // TYPE
message_type = ReceiveBuffer [ bundleCounter - 1 ] ; // TYPE
// CASE I: REQUEST
// CASE I: REQUEST
if ( message_type = = REQUEST )
if ( message_type = = REQUEST ) {
{
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " )Message type is REQUEST " < < endl ;
cout < < " \n ( " < < myRank < < " )Message type is REQUEST " < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
# endif
# endif
# ifdef DEBUG_GHOST_
# ifdef DEBUG_GHOST_
if ( ( v < 0 ) | | ( v < StartIndex ) | | ( ( v - StartIndex ) > NLVer ) )
if ( ( v < 0 ) | | ( v < StartIndex ) | | ( ( v - StartIndex ) > NLVer ) ) {
{
cout < < " \n ( " < < myRank < < " ) case 1 Bad address " < < v < < " " < < StartIndex < < " " < < v - StartIndex < < " " < < NLVer < < endl ;
cout < < " \n ( " < < myRank < < " ) case 1 Bad address " < < v < < " " < < StartIndex < < " " < < v - StartIndex < < " " < < NLVer < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
}
}
# endif
# endif
if ( Mate [ v - StartIndex ] = = - 1 )
if ( Mate [ v - StartIndex ] = = - 1 ) {
{ // Process only if not already matched (v is local)
// Process only if not already matched (v is local)
candidateMate [ NLVer + Ghost2LocalMap [ u ] ] = v ; // Set CandidateMate for the ghost
candidateMate [ NLVer + Ghost2LocalMap [ u ] ] = v ; // Set CandidateMate for the ghost
if ( candidateMate [ v - StartIndex ] = = u )
if ( candidateMate [ v - StartIndex ] = = u ) {
{
GMate [ Ghost2LocalMap [ u ] ] = v ; // u is ghost
GMate [ Ghost2LocalMap [ u ] ] = v ; // u is ghost
Mate [ v - StartIndex ] = u ; // v is local
Mate [ v - StartIndex ] = u ; // v is local
U . push_back ( v ) ;
U . push_back ( v ) ;
@ -199,10 +193,8 @@ void processMessages(
} // End of if ( candidateMate[v-StartIndex] == u )e
} // End of if ( candidateMate[v-StartIndex] == u )e
} // End of if ( Mate[v] == -1 )
} // End of if ( Mate[v] == -1 )
} // End of REQUEST
} // End of REQUEST
else
else { // CASE II: SUCCESS
{ // CASE II: SUCCESS
if ( message_type = = SUCCESS ) {
if ( message_type = = SUCCESS )
{
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " )Message type is SUCCESS " < < endl ;
cout < < " \n ( " < < myRank < < " )Message type is SUCCESS " < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
@ -210,28 +202,26 @@ void processMessages(
GMate [ Ghost2LocalMap [ u ] ] = EndIndex + 1 ; // Set a Dummy Mate to make sure that we do not (u is a ghost) process it again
GMate [ Ghost2LocalMap [ u ] ] = EndIndex + 1 ; // Set a Dummy Mate to make sure that we do not (u is a ghost) process it again
PROCESS_CROSS_EDGE ( & Counter [ Ghost2LocalMap [ u ] ] , S ) ;
PROCESS_CROSS_EDGE ( & Counter [ Ghost2LocalMap [ u ] ] , S ) ;
# ifdef DEBUG_GHOST_
# ifdef DEBUG_GHOST_
if ( ( v < 0 ) | | ( v < StartIndex ) | | ( ( v - StartIndex ) > NLVer ) )
if ( ( v < 0 ) | | ( v < StartIndex ) | | ( ( v - StartIndex ) > NLVer ) ) {
{
cout < < " \n ( " < < myRank < < " ) case 2 Bad address " < < v < < " " < < StartIndex < < " " < < v - StartIndex < < " " < < NLVer < < endl ;
cout < < " \n ( " < < myRank < < " ) case 2 Bad address " < < v < < " " < < StartIndex < < " " < < v - StartIndex < < " " < < NLVer < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
}
}
# endif
# endif
if ( Mate [ v - StartIndex ] = = - 1 )
if ( Mate [ v - StartIndex ] = = - 1 ) {
{ // Process only if not already matched ( v is local)
// Process only if not already matched ( v is local)
if ( candidateMate [ v - StartIndex ] = = u )
if ( candidateMate [ v - StartIndex ] = = u ) {
{
// Start: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v)
// Start: PARALLEL_PROCESS_EXPOSED_VERTEX_B(v)
w = computeCandidateMate ( verLocPtr [ v - StartIndex ] , verLocPtr [ v - StartIndex + 1 ] , edgeLocWeight , k , verLocInd , StartIndex , EndIndex , GMate , Mate , Ghost2LocalMap ) ;
w = computeCandidateMate ( verLocPtr [ v - StartIndex ] , verLocPtr [ v - StartIndex + 1 ] , edgeLocWeight , k ,
verLocInd , StartIndex , EndIndex , GMate , Mate , Ghost2LocalMap ) ;
candidateMate [ v - StartIndex ] = w ;
candidateMate [ v - StartIndex ] = w ;
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " ) " < < v < < " Points to: " < < w < < endl ;
cout < < " \n ( " < < myRank < < " ) " < < v < < " Points to: " < < w < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;
# endif
# endif
// If found a dominating edge:
// If found a dominating edge:
if ( w > = 0 )
if ( w > = 0 ) {
{
if ( ( w < StartIndex ) | | ( w > EndIndex ) ) {
if ( ( w < StartIndex ) | | ( w > EndIndex ) )
// w is a ghost
{ // w is a ghost
// Build the Message Packet:
// Build the Message Packet:
Message [ 0 ] = v ; // LOCAL
Message [ 0 ] = v ; // LOCAL
Message [ 1 ] = w ; // GHOST
Message [ 1 ] = w ; // GHOST
@ -245,12 +235,11 @@ void processMessages(
ghostOwner = findOwnerOfGhost ( w , verDistance , myRank , numProcs ) ;
ghostOwner = findOwnerOfGhost ( w , verDistance , myRank , numProcs ) ;
//assert(ghostOwner != -1);
//assert(ghostOwner != -1);
//assert(ghostOwner != myRank);
//assert(ghostOwner != myRank);
//cout << myRank<<" Sending to "<<ghostOwner<<endl;
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 ) ;
@ -264,10 +253,8 @@ void processMessages(
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
else
else { // w is a local vertex
{ // w is a local vertex
if ( candidateMate [ w - StartIndex ] = = v ) {
if ( candidateMate [ w - StartIndex ] = = v )
{
Mate [ v - StartIndex ] = w ; // v is local
Mate [ v - StartIndex ] = w ; // v is local
Mate [ w - StartIndex ] = v ; // w is local
Mate [ w - StartIndex ] = v ; // w is local
// Q.push_back(u);
// Q.push_back(u);
@ -281,15 +268,13 @@ void processMessages(
} // End of if(CandidateMate(w) = v
} // End of if(CandidateMate(w) = v
} // End of Else
} // End of Else
} // End of if(w >=0)
} // End of if(w >=0)
else
else { // No dominant edge found
{ // No dominant edge found
adj11 = verLocPtr [ v - StartIndex ] ;
adj11 = verLocPtr [ v - StartIndex ] ;
adj12 = verLocPtr [ v - StartIndex + 1 ] ;
adj12 = verLocPtr [ v - StartIndex + 1 ] ;
for ( k1 = adj11 ; k1 < adj12 ; k1 + + )
for ( k1 = adj11 ; k1 < adj12 ; k1 + + ) {
{
w = verLocInd [ k1 ] ;
w = verLocInd [ k1 ] ;
if ( ( w < StartIndex ) | | ( w > EndIndex ) )
if ( ( w < StartIndex ) | | ( w > EndIndex ) ) {
{ // A ghost
// A ghost
// Build the Message Packet:
// Build the Message Packet:
Message [ 0 ] = v ; // LOCAL
Message [ 0 ] = v ; // LOCAL
Message [ 1 ] = w ; // GHOST
Message [ 1 ] = w ; // GHOST
@ -303,6 +288,7 @@ void processMessages(
ghostOwner = findOwnerOfGhost ( w , verDistance , myRank , numProcs ) ;
ghostOwner = findOwnerOfGhost ( w , verDistance , myRank , numProcs ) ;
//assert(ghostOwner != -1);
//assert(ghostOwner != -1);
//assert(ghostOwner != myRank);
//assert(ghostOwner != myRank);
//cout << myRank<<" Sending to "<<ghostOwner<<endl;
MPI_Bsend ( & Message [ 0 ] , 3 , TypeMap < MilanLongInt > ( ) , ghostOwner , ComputeTag , comm ) ;
MPI_Bsend ( & Message [ 0 ] , 3 , TypeMap < MilanLongInt > ( ) , ghostOwner , ComputeTag , comm ) ;
( * msgInd ) + + ;
( * msgInd ) + + ;
( * msgActual ) + + ;
( * msgActual ) + + ;
@ -313,8 +299,8 @@ void processMessages(
} // End of if ( candidateMate[v-StartIndex] == u )
} // End of if ( candidateMate[v-StartIndex] == u )
} // End of if ( Mate[v] == -1 )
} // End of if ( Mate[v] == -1 )
} // End of if ( message_type == SUCCESS )
} // End of if ( message_type == SUCCESS )
else
else {
{ // CASE III: FAILURE
// CASE III: FAILURE
# ifdef PRINT_DEBUG_INFO_
# ifdef PRINT_DEBUG_INFO_
cout < < " \n ( " < < myRank < < " )Message type is FAILURE " < < endl ;
cout < < " \n ( " < < myRank < < " )Message type is FAILURE " < < endl ;
fflush ( stdout ) ;
fflush ( stdout ) ;