src/NFscheduler/Scheduler.cpp
//Transmitting all buffers to the master node
Transmitting all buffers to the master node
Transmitting all buffers to the master node
string ConvergeAllData(int Rank,int Size,string Buffer) {
	int OtherNode = 1;
	int CurrentRank = Rank;
	int CurrentMessageSize = int(Buffer.length());
	char* CurrentMessage = ConvertStringToCString(Buffer);
	int CurrentMultiplier = 1;
	bool Done = false;
	while (!Done) {
		if (CurrentRank % 2 == 0) {
			OtherNode = CurrentMultiplier*(CurrentRank+1);
			if (OtherNode >= Size) {
				if (CurrentRank == 0) {
					Done = true;
				}
			} else {			
				#ifdef NF_MPI
				MPI_Status status;
				int MessageSize;
				MPI_Recv(&MessageSize,1, MPI_INT, OtherNode, TAG_DATA, MPI_COMM_WORLD, &status);
				if (MessageSize > 0) {
					char* OldMessage = CurrentMessage;
					CurrentMessage = new char[CurrentMessageSize+MessageSize];
					MPI_Recv(CurrentMessage,MessageSize, MPI_CHAR, OtherNode, TAG_DATA, MPI_COMM_WORLD, &status);
					if (OldMessage != NULL) {
						for (int i=MessageSize; i < (MessageSize+CurrentMessageSize); i++) {
							CurrentMessage[i] = OldMessage[i-MessageSize];
						}
						delete [] OldMessage;
					}
					CurrentMessageSize += MessageSize;
				}
				#endif
			}
		} else {
			OtherNode = CurrentMultiplier*(CurrentRank-1);
			if (!Done) {
				#ifdef NF_MPI
				MPI_Send(&CurrentMessageSize,1, MPI_INT, OtherNode, TAG_DATA, MPI_COMM_WORLD);
				if (CurrentMessageSize > 0) {
					MPI_Send(CurrentMessage,CurrentMessageSize, MPI_CHAR, OtherNode, TAG_DATA, MPI_COMM_WORLD);
				}
				Done = true;
				delete [] CurrentMessage;
				CurrentMessage = NULL;
				#endif
			}
		}
		CurrentMultiplier = CurrentMultiplier*2;
		CurrentRank = CurrentRank/2;
	}
	if (Rank == 0) {
		Buffer.assign(CurrentMessage);
		delete [] CurrentMessage;
	}
	return Buffer;
}
string ConvergeAllData ( int Rank , int Size , string Buffer ) { int OtherNode = 1 ; int CurrentRank = Rank ; int CurrentMessageSize = int ( Buffer . length ( ) ) ; char * CurrentMessage = ConvertStringToCString ( Buffer ) ; int CurrentMultiplier = 1 ; bool Done = false ; while ( ! Done ) { if ( CurrentRank % 2 == 0 ) { OtherNode = CurrentMultiplier * ( CurrentRank + 1 ) ; if ( OtherNode >= Size ) { if ( CurrentRank == 0 ) { Done = true ; } } else { #ifdef NF_MPI MPI_Status status ; int MessageSize ; MPI_Recv ( & MessageSize , 1 , MPI_INT , OtherNode , TAG_DATA , MPI_COMM_WORLD , & status ) ; if ( MessageSize > 0 ) { char * OldMessage = CurrentMessage ; CurrentMessage = new char [ CurrentMessageSize + MessageSize ] ; MPI_Recv ( CurrentMessage , MessageSize , MPI_CHAR , OtherNode , TAG_DATA , MPI_COMM_WORLD , & status ) ; if ( OldMessage != NULL ) { for ( int i = MessageSize ; i < ( MessageSize + CurrentMessageSize ) ; i ++ ) { CurrentMessage [ i ] = OldMessage [ i - MessageSize ] ; } delete [ ] OldMessage ; } CurrentMessageSize += MessageSize ; } #endif } } else { OtherNode = CurrentMultiplier * ( CurrentRank - 1 ) ; if ( ! Done ) { #ifdef NF_MPI MPI_Send ( & CurrentMessageSize , 1 , MPI_INT , OtherNode , TAG_DATA , MPI_COMM_WORLD ) ; if ( CurrentMessageSize > 0 ) { MPI_Send ( CurrentMessage , CurrentMessageSize , MPI_CHAR , OtherNode , TAG_DATA , MPI_COMM_WORLD ) ; } Done = true ; delete [ ] CurrentMessage ; CurrentMessage = NULL ; #endif } } CurrentMultiplier = CurrentMultiplier * 2 ; CurrentRank = CurrentRank / 2 ; } if ( Rank == 0 ) { Buffer . assign ( CurrentMessage ) ; delete [ ] CurrentMessage ; } return Buffer ; }
Transmitting all buffers to the master node
Transmitting all buffers to the master node
//Indicating when the master node is done //Doubling the current multiplier //Changing the rank