Commit 2d1ff10d authored by dpugmire's avatar dpugmire
Browse files

Code cleanup

parent 5c453769
......@@ -120,45 +120,42 @@ void Messenger::PostRecv(int tag, std::size_t sz, int src)
void Messenger::CheckPendingSendRequests()
{
std::vector<RequestTagPair> reqTags;
this->CheckRequests(this->SendBuffers, {}, false, reqTags);
//Cleanup any send buffers that have completed.
for (auto&& rt : reqTags)
std::vector<std::pair<RequestTagPair, char*>> req;
if (this->CheckRequests(this->SendBuffers, {}, false, req))
{
auto entry = this->SendBuffers.find(rt);
if (entry != this->SendBuffers.end())
for (const auto& it : req)
{
delete[] entry->second;
this->SendBuffers.erase(entry);
delete[] it.second;
this->SendBuffers.erase(it.first);
}
}
}
void Messenger::CheckRequests(const std::map<RequestTagPair, char*>& buffers,
bool Messenger::CheckRequests(const std::map<RequestTagPair, char*>& buffers,
const std::set<int>& tagsToCheck,
bool BlockAndWait,
std::vector<RequestTagPair>& reqTags)
std::vector<std::pair<RequestTagPair, char*>>& ret)
{
std::vector<MPI_Request> req, copy;
std::vector<int> tags;
reqTags.resize(0);
//Check the buffers for the specified tags.
for (auto&& it : buffers)
req.reserve(buffers.size());
tags.reserve(buffers.size());
for (const auto& it : buffers)
{
if (tagsToCheck.empty() || tagsToCheck.find(it.first.second) != tagsToCheck.end())
{
req.push_back(it.first.first);
copy.push_back(it.first.first);
tags.push_back(it.first.second);
}
}
//Nothing..
if (req.empty())
return;
{
ret.resize(0);
return false;
}
//Check the outstanding requests.
std::vector<MPI_Status> status(req.size());
......@@ -171,12 +168,23 @@ void Messenger::CheckRequests(const std::map<RequestTagPair, char*>& buffers,
else
err = MPI_Testsome(req.size(), req.data(), &num, indices.data(), status.data());
if (err != MPI_SUCCESS)
throw vtkm::cont::ErrorFilterExecution("Error with MPI_Testsome in Messenger::RecvData");
throw vtkm::cont::ErrorFilterExecution(
"Error with MPI_Testsome/MPI_Waitsome in Messenger::CheckRequests");
if (num == 0)
return false;
//Add the req/tag to the return vector.
for (int i = 0; i < num; i++)
reqTags.push_back(RequestTagPair(copy[indices[i]], tags[indices[i]]));
std::size_t sz = static_cast<std::size_t>(num);
ret.reserve(sz);
for (std::size_t i = 0; i < sz; i++)
{
RequestTagPair key(req[indices[i]], tags[indices[i]]);
const auto& it = buffers.find(key);
ret.push_back(std::make_pair(key, it->second));
}
return true;
}
bool Messenger::PacketCompare(const char* a, const char* b)
......@@ -286,31 +294,25 @@ bool Messenger::RecvData(const std::set<int>& tags,
buffers.resize(0);
std::vector<RequestTagPair> reqTags;
this->CheckRequests(this->RecvBuffers, tags, blockAndWait, reqTags);
//Nothing came in.
if (reqTags.empty())
std::vector<std::pair<RequestTagPair, char*>> req;
if (!this->CheckRequests(this->RecvBuffers, tags, blockAndWait, req))
return false;
std::vector<char*> incomingBuffers;
incomingBuffers.reserve(reqTags.size());
for (auto&& rt : reqTags)
incomingBuffers.reserve(req.size());
for (const auto& r : req)
{
auto it = this->RecvBuffers.find(rt);
if (it == this->RecvBuffers.end())
throw vtkm::cont::ErrorFilterExecution("receive buffer not found");
incomingBuffers.push_back(it->second);
this->RecvBuffers.erase(it);
incomingBuffers.push_back(r.second);
this->RecvBuffers.erase(r.first);
}
this->ProcessReceivedBuffers(incomingBuffers, buffers);
//Re-post receives
for (auto&& rt : reqTags)
this->PostRecv(rt.second);
for (const auto& rt : req)
this->PostRecv(rt.first.second);
return !buffers.empty();
return true;
}
void Messenger::ProcessReceivedBuffers(std::vector<char*>& incomingBuffers,
......
......@@ -44,8 +44,8 @@ public:
#endif
}
int GetRank() const { return this->Rank; }
int GetNumRanks() const { return this->NumRanks; }
inline int GetRank() const { return this->Rank; }
inline int GetNumRanks() const { return this->NumRanks; }
#ifdef VTKM_ENABLE_MPI
VTKM_CONT void RegisterTag(int tag, std::size_t numRecvs, std::size_t size);
......@@ -96,10 +96,10 @@ private:
std::map<RequestTagPair, char*> SendBuffers;
static constexpr int TAG_ANY = -1;
void CheckRequests(const std::map<RequestTagPair, char*>& buffer,
bool CheckRequests(const std::map<RequestTagPair, char*>& buffer,
const std::set<int>& tags,
bool BlockAndWait,
std::vector<RequestTagPair>& reqTags);
std::vector<std::pair<RequestTagPair, char*>>& ret);
#else
protected:
static constexpr int NumRanks = 1;
......
......@@ -133,7 +133,7 @@ template <typename P, template <typename, typename> class Container, typename Al
inline void ParticleMessenger::SendParticles(
const std::unordered_map<int, Container<P, Allocator>>& m)
{
for (auto&& mit : m)
for (const auto& mit : m)
if (!mit.second.empty())
this->SendParticles(mit.first, mit.second);
}
......
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