#pragma once #include #include "gsl/multi_span" #include #include "MpiEnvironment.hpp" #include "Util.hpp" #include "state.hpp" class Communicator { constexpr static std::size_t NoNeighbors{8}; std::vector _neighbors; std::vector _sizes; std::vector _sendTypes; const std::vector& _recvTypes{_sendTypes}; std::vector _sendDisplacements; std::vector _recvDisplacements; MPI_Comm _commDistGraph{MPI_COMM_NULL}; MPI_Datatype _haloRowType; MPI_Datatype _haloColumnType; MPI_Datatype _haloCornerType{MPI_CHAR}; public: Communicator() = default; Communicator(const MpiEnvironment& env, const Size& gridSize, const Size& tileSize); ~Communicator(); void swap(Communicator& first, Communicator& second); Communicator(Communicator&) = delete; Communicator& operator=(Communicator&) = delete; Communicator(Communicator&& other) noexcept; Communicator& operator=(Communicator&& other) noexcept; void Communicate(gsl::multi_span& model); class MpiRequest { MPI_Request _req{MPI_REQUEST_NULL}; bool finished{}; public: MpiRequest(MPI_Request req); void Wait(); ~MpiRequest(); }; MpiRequest AsyncCommunicate(gsl::multi_span& model); };