-
Notifications
You must be signed in to change notification settings - Fork 6
Adding AdiosGlobalComm for global data exchange #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
74b2678
cd07262
f6896de
3463800
5420fa3
f8cf322
1edd1c3
bff8f2c
a8230a5
8d3689f
c95c9aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ struct InMessageLayout { | |
| size_t start; | ||
| /** | ||
| * Number of items (of the user specified type passed to the template | ||
| * parameter of AdiosComm) that should be read from the messages array | ||
| * parameter of AdiosPtnComm) that should be read from the messages array | ||
| * (returned by Communicator::Recv). | ||
| */ | ||
| size_t count; | ||
|
|
@@ -131,13 +131,18 @@ class Communicator { | |
| */ | ||
| virtual void Send(T *msgs, Mode mode) = 0; | ||
| /** | ||
| * Receive an array. Use AdiosComm's GetInMessageLayout to retreive | ||
| * Receive an array. Use AdiosPtnComm's GetInMessageLayout to retreive | ||
| * an instance of the InMessageLayout struct containing the layout of | ||
| * the received array. | ||
| */ | ||
| virtual std::vector<T> Recv(Mode mode) = 0; | ||
|
|
||
| virtual InMessageLayout GetInMessageLayout() = 0; | ||
|
|
||
| virtual void SetCommParams(std::string VarName, size_t msgSize ) { | ||
| throw std::logic_error("Communicator::SetCommParams() called — must be overridden in the derived Comm class"); | ||
| } | ||
|
|
||
| virtual ~Communicator() = default; | ||
| }; | ||
|
|
||
|
|
@@ -151,40 +156,40 @@ class NoOpComm : public Communicator<T> { | |
|
|
||
|
|
||
| /** | ||
| * The AdiosComm class implements the Communicator interface to support sending | ||
| * The AdiosPtnComm class implements the Communicator interface to support sending | ||
| * messages between the clients and server via ADIOS2. The BP4 and SST ADIOS2 | ||
| * engines are currently supported. | ||
| * One AdiosComm object is required for each communication link direction. For | ||
| * One AdiosPtnComm object is required for each communication link direction. For | ||
| * example, for a client and server to both send and receive messages one | ||
| * AdiosComm for client->server messaging and another AdiosComm for | ||
| * AdiosPtnComm for client->server messaging and another AdiosPtnComm for | ||
| * server->client messaging are needed. Redev::BidirectionalComm is a helper | ||
| * class for this use case. | ||
| */ | ||
| template<typename T> | ||
| class AdiosComm : public Communicator<T> { | ||
| class AdiosPtnComm : public Communicator<T> { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public: | ||
| /** | ||
| * Create an AdiosComm object. Collective across sender and receiver ranks. | ||
| * Create an AdiosPtnComm object. Collective across sender and receiver ranks. | ||
| * Calls to the constructor from the sender and receiver ranks must be in | ||
| * the same order (i.e., first creating the client-to-server object then the | ||
| * server-to-client link). | ||
| * @param[in] comm_ MPI communicator for sender ranks | ||
| * @param[in] recvRanks_ number of ranks in the receivers MPI communicator | ||
| * @param[in] eng_ ADIOS2 engine for writing on the sender side | ||
| * @param[in] io_ ADIOS2 IO associated with eng_ | ||
| * @param[in] name_ unique name among AdiosComm objects | ||
| * @param[in] name_ unique name among AdiosPtnComm objects | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we now have the partitioned and global communicators, specify that this communicator works on the partitioned data. |
||
| */ | ||
| AdiosComm(MPI_Comm comm_, int recvRanks_, adios2::Engine& eng_, adios2::IO& io_, std::string name_) | ||
| AdiosPtnComm(MPI_Comm comm_, int recvRanks_, adios2::Engine& eng_, adios2::IO& io_, std::string name_) | ||
| : comm(comm_), recvRanks(recvRanks_), eng(eng_), io(io_), name(name_), verbose(0) { | ||
| inMsg.knownSizes = false; | ||
| } | ||
|
|
||
| /// We are explicitly not allowing copy/move constructor/assignment as we don't | ||
| /// know if the ADIOS2 Engine and IO objects can be safely copied/moved. | ||
| AdiosComm(const AdiosComm& other) = delete; | ||
| AdiosComm(AdiosComm&& other) = delete; | ||
| AdiosComm& operator=(const AdiosComm& other) = delete; | ||
| AdiosComm& operator=(AdiosComm&& other) = delete; | ||
| AdiosPtnComm(const AdiosPtnComm& other) = delete; | ||
| AdiosPtnComm(AdiosPtnComm&& other) = delete; | ||
| AdiosPtnComm& operator=(const AdiosPtnComm& other) = delete; | ||
| AdiosPtnComm& operator=(AdiosPtnComm&& other) = delete; | ||
|
|
||
| void SetOutMessageLayout(LOs& dest_, LOs& offsets_) { | ||
| REDEV_FUNCTION_TIMER; | ||
|
|
@@ -343,7 +348,7 @@ class AdiosComm : public Communicator<T> { | |
| return inMsg; | ||
| } | ||
| /** | ||
| * Control the amount of output from AdiosComm functions. The higher the value the more output is written. | ||
| * Control the amount of output from AdiosPtnComm functions. The higher the value the more output is written. | ||
| * @param[in] lvl valid values are [0:5] where 0 is silent and 5 is produces | ||
| * the most output | ||
| */ | ||
|
|
@@ -370,4 +375,74 @@ class AdiosComm : public Communicator<T> { | |
| InMessageLayout inMsg; | ||
| }; | ||
|
|
||
| /** | ||
| * The AdiosGlobalComm class implements the Communicator interface to enable | ||
| * message exchange between clients and the server through ADIOS2. | ||
| * Similar to AdiosPtnComm, it provides bidirectional communication, | ||
| * but the key distinction is that the global communicator is shared | ||
| * across all ranks and partitions. | ||
| * | ||
| * It is primarily used for transferring global data and metadata | ||
| * relevant to coupled applications. | ||
| * | ||
| * Currently, the BP4 and SST ADIOS2 engines are supported. | ||
| */ | ||
| template <typename T> | ||
| class AdiosGlobalComm : public Communicator<T> | ||
| { | ||
| public: | ||
| AdiosGlobalComm(MPI_Comm comm_, adios2::Engine& eng_, adios2::IO& io_, | ||
| std::string name_) | ||
| : comm(comm_), eng(eng_), io(io_), name(name_) | ||
| { | ||
| } | ||
|
|
||
| // copy/move of adios engine and io objects isn't safe. | ||
| AdiosGlobalComm(const AdiosGlobalComm& other) = delete; | ||
| AdiosGlobalComm(AdiosGlobalComm&& other) = delete; | ||
| AdiosGlobalComm& operator=(const AdiosGlobalComm& other) = delete; | ||
| AdiosGlobalComm& operator=(AdiosGlobalComm&& other) = delete; | ||
|
|
||
| void SetCommParams(std::string varName_, size_t msgSize_){ | ||
| varName = varName_; | ||
| msgSize = msgSize_; | ||
| } | ||
| void Send(T* ptr, Mode mode) | ||
| { | ||
| REDEV_FUNCTION_TIMER; | ||
| auto var = io.InquireVariable<T>(varName); | ||
| auto msg = std::vector<T>(ptr, ptr + msgSize); | ||
| if (!var) { | ||
| var = io.DefineVariable<T>(varName,{} ,{},{msgSize}); | ||
| } | ||
| assert(var); | ||
| eng.Put(var, msg.data()); | ||
| if(mode == Mode::Synchronous) { | ||
| eng.PerformPuts(); | ||
| } | ||
| } | ||
| std::vector<T> Recv(Mode mode) | ||
| { | ||
| REDEV_FUNCTION_TIMER; | ||
| std::vector<T> msg; | ||
| auto var = io.InquireVariable<T>(varName); | ||
| assert(var); | ||
| msg.resize(msgSize); | ||
| eng.Get(var, msg.data()); | ||
| if(mode == Mode::Synchronous) { | ||
| eng.PerformGets(); | ||
| } | ||
| return msg; | ||
| } | ||
| void SetOutMessageLayout(LOs& dest, LOs& offsets) {}; | ||
| InMessageLayout GetInMessageLayout() { return {}; } | ||
|
|
||
| private: | ||
| MPI_Comm comm; | ||
| adios2::Engine& eng; | ||
| adios2::IO& io; | ||
| std::string name; | ||
| std::string varName = ""; | ||
| std::size_t msgSize = 0; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,6 @@ using CVs = std::vector<CV>; | |
|
|
||
| enum class ProcessType { Client = 0, Server = 1 }; | ||
| enum class TransportType { BP4 = 0, SST = 1 }; | ||
|
|
||
| enum class CommType{ Ptn = 0, Global = 1 }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change this to Counter argument is we use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to move
ctypesince it's an enummovewill have no impact.