11 #ifndef vtk_m_filter_flow_internal_Messenger_h
12 #define vtk_m_filter_flow_internal_Messenger_h
15 #include <vtkm/filter/flow/vtkm_filter_flow_export.h>
16 #include <vtkm/thirdparty/diy/diy.h>
23 #ifdef VTKM_ENABLE_MPI
36 class VTKM_FILTER_FLOW_EXPORT Messenger
39 VTKM_CONT Messenger(vtkmdiy::mpi::communicator& comm);
42 #ifdef VTKM_ENABLE_MPI
43 this->CleanupRequests();
47 int GetRank()
const {
return this->Rank; }
48 int GetNumRanks()
const {
return this->NumRanks; }
50 #ifdef VTKM_ENABLE_MPI
51 VTKM_CONT void RegisterTag(
int tag, std::size_t numRecvs, std::size_t size);
54 static std::size_t CalcMessageBufferSize(std::size_t msgSz);
56 void InitializeBuffers();
57 void CheckPendingSendRequests();
58 void CleanupRequests(
int tag = TAG_ANY);
59 void SendData(
int dst,
int tag,
const vtkmdiy::MemoryBuffer& buff);
60 bool RecvData(
const std::set<int>& tags,
61 std::vector<std::pair<int, vtkmdiy::MemoryBuffer>>& buffers,
62 bool blockAndWait =
false);
65 void PostRecv(
int tag);
66 void PostRecv(
int tag, std::size_t sz,
int src = -1);
73 std::size_t id, numPackets, packet, packetSz, dataSz;
76 bool RecvData(
int tag, std::vector<vtkmdiy::MemoryBuffer>& buffers,
bool blockAndWait =
false);
78 void PrepareForSend(
int tag,
const vtkmdiy::MemoryBuffer& buff, std::vector<char*>& buffList);
79 vtkm::Id GetMsgID() {
return this->MsgID++; }
80 static bool PacketCompare(
const char* a,
const char* b);
81 void ProcessReceivedBuffers(std::vector<char*>& incomingBuffers,
82 std::vector<std::pair<int, vtkmdiy::MemoryBuffer>>& buffers);
85 using RequestTagPair = std::pair<MPI_Request, int>;
86 using RankIdPair = std::pair<int, int>;
89 std::map<int, std::pair<std::size_t, std::size_t>> MessageTagInfo;
94 std::map<RequestTagPair, char*> RecvBuffers;
95 std::map<RankIdPair, std::list<char*>> RecvPackets;
96 std::map<RequestTagPair, char*> SendBuffers;
97 static constexpr
int TAG_ANY = -1;
99 void CheckRequests(
const std::map<RequestTagPair, char*>& buffer,
100 const std::set<int>& tags,
102 std::vector<RequestTagPair>& reqTags);
105 static constexpr
int NumRanks = 1;
106 static constexpr
int Rank = 0;
115 #endif // vtk_m_filter_flow_internal_Messenger_h