Commit 13760c48 authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

allToAll and allToLower test for communication with unknown sender ranks

parent 5110ba9b
......@@ -129,6 +129,7 @@ public:
template<typename RankIter> void setReceiverInfo( RankIter begin, RankIter end, bool changingSize );
template<typename Range> void setReceiverInfo( const Range & range, bool changingSize );
void setReceiverInfo( const std::set<MPIRank> & ranksToRecvFrom, bool changingSize );
void setReceiverInfo( const int numReceives );
void setReceiverInfo( const std::map<MPIRank,MPISize> & ranksToRecvFrom );
void setReceiverInfoFromSendBufferState( bool useSizeFromSendBuffers, bool changingSize );
......
......@@ -219,6 +219,20 @@ void GenericBufferSystem<Rb, Sb>::setReceiverInfo( const std::set<MPIRank> & ran
//**********************************************************************************************************************
/*! Sets receiver information, when the number of receives is known but the ranks are unknown
*
* \param numReceives number of expected messages
*/
//**********************************************************************************************************************
template< typename Rb, typename Sb>
void GenericBufferSystem<Rb, Sb>::setReceiverInfo( const int numReceives )
{
WALBERLA_ABORT("NOT IMPLEMENTED!");
}
//**********************************************************************************************************************
/*! Sets receiver information, when message sizes are known
*
......
......@@ -301,6 +301,90 @@ void gatherUsingAsymmetricCommunication(const bool useIProbe)
}
/**
* Test for communication when only the number of receives is known but not the ranks.
*/
void unknownRanksAllToAll()
{
const int rank = MPIManager::instance()->worldRank();
const int numProcesses = MPIManager::instance()->numProcesses();
WALBERLA_CHECK_GREATER_EQUAL(numProcesses, 3);
BufferSystem bs(MPI_COMM_WORLD, 42);
for (auto targetRank = 0; targetRank < numProcesses; ++targetRank)
{
auto& sb = bs.sendBuffer(targetRank);
for (int i = 0; i < rank + 1; ++i)
sb << rank;
}
//we await numProcesses messages on every rank
bs.setReceiverInfo(numProcesses);
//equivalent to
//bs.setReceiverInfoFromSendBufferState(false, true);
bs.sendAll();
auto numReceives = 0;
for (auto it = bs.begin(); it != bs.end(); ++it)
{
WALBERLA_CHECK_EQUAL(it.buffer().size(), (it.rank() + 1) * 4);
for (int i = 0; i < it.rank() + 1; ++i)
{
int received = -1;
it.buffer() >> received;
WALBERLA_CHECK_EQUAL(received, it.rank());
}
++numReceives;
}
WALBERLA_CHECK_EQUAL(numReceives, numProcesses);
}
void unknownRanksAllToLower()
{
const int rank = MPIManager::instance()->worldRank();
const int numProcesses = MPIManager::instance()->numProcesses();
WALBERLA_CHECK_GREATER_EQUAL(numProcesses, 3);
BufferSystem bs(MPI_COMM_WORLD, 42);
for (auto targetRank = 0; targetRank < rank + 1; ++targetRank)
{
auto& sb = bs.sendBuffer(targetRank);
for (int i = 0; i < rank + 1; ++i)
sb << rank;
}
//we await numProcesses messages on every rank
bs.setReceiverInfo(numProcesses);
//equivalent to
//std::set<mpi::MPIRank> recvs;
//for (auto targetRank = numProcesses - 1; targetRank >=rank; --targetRank)
//{
// recvs.emplace(targetRank);
//}
//bs.setReceiverInfo(recvs, true);
bs.sendAll();
auto numReceives = 0;
for (auto it = bs.begin(); it != bs.end(); ++it)
{
WALBERLA_CHECK_EQUAL(it.buffer().size(), (it.rank() + 1) * 4);
for (int i = 0; i < it.rank() + 1; ++i)
{
int received = -1;
it.buffer() >> received;
WALBERLA_CHECK_EQUAL(received, it.rank());
}
++numReceives;
}
WALBERLA_CHECK_EQUAL(numReceives, numProcesses - rank);
}
void selfSend()
{
int rank = MPIManager::instance()->worldRank();
......@@ -395,6 +479,12 @@ int main(int argc, char**argv)
gatherUsingAsymmetricCommunication(false);
gatherUsingAsymmetricCommunication(true);
WALBERLA_LOG_INFO_ON_ROOT("Testing Unknown Sender Ranks...");
WALBERLA_LOG_INFO_ON_ROOT("AllToAll...");
unknownRanksAllToAll();
WALBERLA_LOG_INFO_ON_ROOT("AllToLower...");
unknownRanksAllToLower();
WALBERLA_LOG_INFO_ON_ROOT("Testing self-send...");
selfSend();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment