helics  2.8.1
MpiComms.h
1 /*
2 Copyright (c) 2017-2020,
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:152
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::CommsInterface::connection_status::terminated
@ terminated
the connection has been terminated
helics::CommsInterface::logWarning
void logWarning(const std::string &message) const
Definition: CommsInterface.cpp:570
helics::mpi::MpiComms
Definition: MpiComms.h:24
helics::CommsInterface::logError
void logError(const std::string &message) const
Definition: CommsInterface.cpp:579
helics::ActionMessage
Definition: ActionMessage.hpp:29
helics::mpi::MpiComms::MpiComms
MpiComms()
Definition: MpiComms.cpp:21
helics::CommsInterface::txQueue
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:153
helics::isValidCommand
bool isValidCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:317
helics::CommsInterface::ActionCallback
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:149
helics::CommsInterface::disconnect
void disconnect()
Definition: CommsInterface.cpp:384
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:861
helics::isDisconnectCommand
bool isDisconnectCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:276
helics::CommsInterface
Definition: CommsInterface.hpp:26
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::connection_status::connected
@ connected
we are connected
helics::CommsInterface::logMessage
void logMessage(const std::string &message) const
Definition: CommsInterface.cpp:561