12 "toolbox::particles::"
13 "SieveParticles<T>::_"
33 for (
auto* p : list) {
46 logDebug(
"exchangeSieveListsGlobally()",
"there are " << _particlesThatHaveToBeSieved.size() <<
" sieve sets (each tied to one tree or the global sorting, respectively)");
48 deleteParticles(_particlesThatHaveToBeSieved);
51 const int numberOfParticlesToSend = _particlesThatCanNotBeLiftedWithinTheirTree.size();
52 logDebug(
"exchangeSieveListsGlobally()",
"inform all other ranks that I host " << numberOfParticlesToSend <<
" particles that cannot be sorted locally. Use tag " << _SieveReductionTag);
60 logDebug(
"exchangeSieveListsGlobally()",
"pack send information (vector of pointers) into array");
61 std::vector<T> sendBuffer;
62 sendBuffer.resize(numberOfParticlesToSend);
64 for (
auto& p : _particlesThatCanNotBeLiftedWithinTheirTree) {
71 logDebug(
"exchangeSieveListsGlobally()",
"ask rank " << rank <<
" how many messages have to be received");
74 logDebug(
"exchangeSieveListsGlobally()",
"will receive " << numberOfReceivedMessages.
getValue() <<
" particles from rank " << rank);
76 MPI_Request* sendRequest =
nullptr;
77 MPI_Request* receiveRequest =
nullptr;
79 std::vector<T> receiveBuffer;
80 if (numberOfReceivedMessages.
getValue() > 0) {
81 receiveRequest =
new MPI_Request();
82 receiveBuffer.resize(numberOfReceivedMessages.
getValue());
86 T::getGlobalCommunciationDatatype(),
94 if (numberOfParticlesToSend > 0) {
95 sendRequest =
new MPI_Request();
98 numberOfParticlesToSend,
99 T::getGlobalCommunciationDatatype(),
107 logDebug(
"exchangeSieveListsGlobally()",
"issued my sends and receives");
114 if (sendRequest !=
nullptr)
115 MPI_Test(sendRequest, &sendFlag, MPI_STATUS_IGNORE);
116 if (receiveRequest !=
nullptr)
117 MPI_Test(receiveRequest, &receiveFlag, MPI_STATUS_IGNORE);
118 flag = sendFlag and receiveFlag;
125 logDebug(
"exchangeSieveListsGlobally()",
"append " << receiveBuffer.size() <<
" messages to local sieve particle list");
126 for (
int i = 0; i < numberOfReceivedMessages.
getValue(); i++) {
127 _particlesThatHaveToBeSieved.push_back(
new T(receiveBuffer[i]));
130 if (sendRequest !=
nullptr)
132 if (receiveRequest !=
nullptr)
133 delete receiveRequest;
138 _particlesThatHaveToBeSieved.insert(
139 _particlesThatHaveToBeSieved.end(), _particlesThatCanNotBeLiftedWithinTheirTree.begin(), _particlesThatCanNotBeLiftedWithinTheirTree.end()
143 _particlesThatCanNotBeLiftedWithinTheirTree.clear();
146 for (
auto p: _particlesThatHaveToBeSieved){
155 std::ostringstream msg;
157 msg <<
"(#particles-that-cannot-be-lifted=" << _particlesThatCanNotBeLiftedWithinTheirTree.size()
158 <<
",#particles-that-have-to-be-sieved=" << _particlesThatHaveToBeSieved.size()
167 deleteParticles(_particlesThatCanNotBeLiftedWithinTheirTree);
168 deleteParticles(_particlesThatHaveToBeSieved);
170 _particlesThatCanNotBeLiftedWithinTheirTree.clear();
171 _particlesThatHaveToBeSieved.clear();
179 for (
auto p: _particlesThatHaveToBeSieved) {
183 logDebug(
"cloneParticlesToBeSieved()",
"created a clone of the particle set: " << this->
toString() <<
"->" << result.
toString() );
191 logDebug(
"addParticleThatCanNotBeLiftedWithinItsTree(T* p)",
"particle cannot be lifted: " << p->toString() );
192 _particlesThatCanNotBeLiftedWithinTheirTree.push_back(p);
198 return _particlesThatHaveToBeSieved.size();
204 return not _particlesThatHaveToBeSieved.empty();
211 bool removeReturnedParticlesFromSet,
212 bool onlyReturnParticlesThatWillBeLocal,
215 tarch::multicore::Lock lock(_particlesToBeSievedSemaphore, removeReturnedParticlesFromSet and lockSemaphore);
218 typename ParticleList::iterator p = _particlesThatHaveToBeSieved.begin();
219 while (p != _particlesThatHaveToBeSieved.end()) {
224 (willBeLocal or not onlyReturnParticlesThatWillBeLocal)
226 logDebug(
"getParticlesToBeSievedIntoVertex(...)",
"drop particle " << (*p)->toString() <<
" from global sieve list into vertex " << marker.toString());
228 (*p)->setCellH(marker.h());
230 result.push_back(*p);
231 if (removeReturnedParticlesFromSet) {
232 p = _particlesThatHaveToBeSieved.erase(p);
#define logDebug(methodName, logMacroMessageStream)
std::bitset< Dimensions > periodicBC
int getNumberOfRanks() const
void triggerDeadlockTimeOut(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1, const std::string &comment="")
Triggers a time out and shuts down the cluster if a timeout is violated.
void setDeadlockWarningTimeStamp()
Memorise global timeout.
void writeTimeOutWarning(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1)
Writes a warning if relevant.
void setDeadlockTimeOutTimeStamp()
static Rank & getInstance()
This operation returns the singleton instance.
int getRank() const
Return rank of this node.
static int reserveFreeTag(const std::string &fullQualifiedMessageName, int numberOfTags=1)
Return a Free Tag.
MPI_Comm getCommunicator() const
Create a lock around a boolean semaphore region.
virtual void receiveDanglingMessages() override
Answer to MPI Messages.
static ServiceRepository & getInstance()
Utility class for global sorting for all flavours of particle sets.
std::string toString() const
std::list< T * > ParticleList
SieveParticles< T > cloneParticlesToBeSieved()
Clone object, but let it contain only the delivering part, i.e.
virtual ~SieveParticles()
Destructor.
ParticleList getParticlesToBeSievedIntoVertex(const peano4::datamanagement::VertexMarker &marker, bool removeReturnedParticlesFromSet, bool onlyReturnParticlesThatWillBeLocal, bool lockSemaphore)
Get particles that are to be sieved into one vertex.
void addParticleThatCanNotBeLiftedWithinItsTree(T *)
Add a particle to the list of particles which cannot be lifted.
int getNumberOfParticlesThatHaveBeSievedIntoVertices() const
hasParticlesToBeSievedIntoVertices() is equivalent to checking if this routine returns something grea...
void deleteParticles()
Deep clear.
void exchangeSieveListsGlobally(const tarch::la::Vector< Dimensions, double > domainOffset, const tarch::la::Vector< Dimensions, double > domainSize, const std::bitset< Dimensions > periodicBC)
Get all the global sieve data consistent.
bool hasParticlesToBeSievedIntoVertices() const
Fine out how many particles still to sieve.
static tarch::logging::Log _log
ParticleList _particlesThatHaveToBeSieved
Particles that should be sieved.
std::string toString(Filter filter)
bool sieveParticle(const Particle &particle, const peano4::datamanagement::VertexMarker &marker)
A particle is to be sieved into a vertex if.
bool particleAssignedToVertexWillBeLocal(const tarch::la::Vector< Dimensions, double > &x, const peano4::datamanagement::VertexMarker &marker)
tarch::la::Vector< Dimensions, double > applyPeriodicBoundaryConditions(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > domainOffset, const tarch::la::Vector< Dimensions, double > domainSize, const std::bitset< Dimensions > periodicBC)
Applies the periodic boundary condition on particle coordinates x.
Vertex marker to provide information about selected vertex.
static void sendAndPollDanglingMessages(const tarch::mpi::IntegerMessage &message, int destination, int tag, MPI_Comm communicator=tarch::mpi::Rank::getInstance().getCommunicator())
static void receiveAndPollDanglingMessages(tarch::mpi::IntegerMessage &message, int source, int tag, MPI_Comm communicator=tarch::mpi::Rank::getInstance().getCommunicator())