helics  3.5.2
MpiComms.h
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include "../CommsInterface.hpp"
10 #include "gmlc/containers/BlockingQueue.hpp"
11 #include "helics/helics-config.h"
12 
13 #include <atomic>
14 #include <future>
15 #include <mutex>
16 #include <set>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace helics {
22 namespace mpi {
24  class MpiComms final: public CommsInterface {
25  public:
27  MpiComms();
29  ~MpiComms();
30 
31  private:
32  std::atomic<bool> shutdown{false};
33  virtual void queue_rx_function() override;
34  virtual void queue_tx_function() override;
35 
38  int processIncomingMessage(ActionMessage& cmd);
39 
41  gmlc::containers::BlockingQueue<ActionMessage> rxMessageQueue;
43  gmlc::containers::BlockingQueue<std::pair<std::pair<int, int>, std::vector<char>>>
44  txMessageQueue;
45 
46  std::atomic<bool> hasBroker{false};
47  virtual void closeReceiver() override;
48 
49  public:
50  void setBrokerAddress(const std::string& address);
51 
52  std::string getAddress() { return localTargetAddress; }
53  gmlc::containers::BlockingQueue<ActionMessage>& getRxMessageQueue()
54  {
55  return rxMessageQueue;
56  }
57  gmlc::containers::BlockingQueue<std::pair<std::pair<int, int>, std::vector<char>>>&
58  getTxMessageQueue()
59  {
60  return txMessageQueue;
61  }
62  };
63 
64 } // namespace mpi
65 } // namespace helics
Definition: ActionMessage.hpp:30
Definition: CommsInterface.hpp:25
std::string localTargetAddress
the base for the receive address
Definition: CommsInterface.hpp:124
Definition: MpiComms.h:24
~MpiComms()
Definition: MpiComms.cpp:29
MpiComms()
Definition: MpiComms.cpp:21
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14