helics  3.3.0
MpiComms.h
1 /*
2 Copyright (c) 2017-2022,
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
helics::CommsInterface::brokerTargetAddress
std::string brokerTargetAddress
the base for the broker address
Definition: CommsInterface.hpp:125
helics::CommsInterface::propertyLock
bool propertyLock()
Definition: CommsInterface.cpp:153
helics::mpi::MpiComms::~MpiComms
~MpiComms()
Definition: MpiComms.cpp:29
helics::message_process_result::processed
@ processed
the message was used to update the current state
helics::mpi::MpiComms
Definition: MpiComms.h:24
helics::ActionMessage
Definition: ActionMessage.hpp:30
helics::mpi::MpiComms::MpiComms
MpiComms()
Definition: MpiComms.cpp:21
helics::CommsInterface::logError
void logError(std::string_view message) const
Definition: CommsInterface.cpp:581
helics::CommsInterface::txQueue
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:155
helics::isValidCommand
bool isValidCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:338
helics::isIgnoreableCommand
bool isIgnoreableCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:317
helics::CommsInterface::logMessage
void logMessage(std::string_view message) const
Definition: CommsInterface.cpp:563
helics::CommsInterface::ActionCallback
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:151
helics::CommsInterface::disconnect
void disconnect()
Definition: CommsInterface.cpp:385
helics::CommsInterface::ConnectionStatus::TERMINATED
@ TERMINATED
the connection has been TERMINATED
helics::CommsInterface::logWarning
void logWarning(std::string_view message) const
Definition: CommsInterface.cpp:572
helics::CommsInterface::localTargetAddress
std::string localTargetAddress
the base for the receive address
Definition: CommsInterface.hpp:124
helics::prettyPrintString
std::string prettyPrintString(const ActionMessage &command)
Definition: ActionMessage.cpp:846
helics::CommsInterface
Definition: CommsInterface.hpp:25
helics::isProtocolCommand
bool isProtocolCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:226
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::CommsInterface::ConnectionStatus::CONNECTED
@ CONNECTED
we are CONNECTED