[300] | 1 | #ifndef __CONTEXT_CLIENT_HPP__ |
---|
| 2 | #define __CONTEXT_CLIENT_HPP__ |
---|
| 3 | |
---|
[591] | 4 | #include "xios_spl.hpp" |
---|
[300] | 5 | #include "buffer_out.hpp" |
---|
[697] | 6 | #include "buffer_in.hpp" |
---|
[300] | 7 | #include "buffer_client.hpp" |
---|
| 8 | #include "event_client.hpp" |
---|
[697] | 9 | #include "event_server.hpp" |
---|
[382] | 10 | #include "mpi.hpp" |
---|
[697] | 11 | #include "registry.hpp" |
---|
[300] | 12 | |
---|
[335] | 13 | namespace xios |
---|
[300] | 14 | { |
---|
[595] | 15 | class CContext; |
---|
[509] | 16 | |
---|
[512] | 17 | /*! |
---|
| 18 | \class CContextClient |
---|
| 19 | A context can be both on client and on server side. In order to differenciate the role of |
---|
| 20 | context on each side, e.x client sending events, server receiving and processing events, there is a need of |
---|
| 21 | concrete "context" classes for both sides. |
---|
| 22 | CContextClient processes and sends events from client to server where CContextServer receives these events |
---|
| 23 | and processes them. |
---|
| 24 | */ |
---|
[300] | 25 | class CContextClient |
---|
| 26 | { |
---|
| 27 | public: |
---|
[595] | 28 | // Contructor |
---|
| 29 | CContextClient(CContext* parent, MPI_Comm intraComm, MPI_Comm interComm, CContext* parentServer = 0); |
---|
[300] | 30 | |
---|
[595] | 31 | // Send event to server |
---|
| 32 | void sendEvent(CEventClient& event); |
---|
[1054] | 33 | bool sendTemporarilyBufferedEvent(); |
---|
[595] | 34 | void waitEvent(list<int>& ranks); |
---|
[300] | 35 | |
---|
[1054] | 36 | // Functions to set/get buffers |
---|
| 37 | bool getBuffers(const list<int>& serverList, const list<int>& sizeList, list<CBufferOut*>& retBuffers, bool nonBlocking = false); |
---|
[595] | 38 | void newBuffer(int rank); |
---|
| 39 | bool checkBuffers(list<int>& ranks); |
---|
| 40 | bool checkBuffers(void); |
---|
| 41 | void releaseBuffers(void); |
---|
[1130] | 42 | bool havePendingRequests(void); |
---|
[512] | 43 | |
---|
[595] | 44 | bool isServerLeader(void) const; |
---|
[1021] | 45 | bool isServerNotLeader(void) const; |
---|
[595] | 46 | const std::list<int>& getRanksServerLeader(void) const; |
---|
[1021] | 47 | const std::list<int>& getRanksServerNotLeader(void) const; |
---|
[512] | 48 | |
---|
[704] | 49 | bool isAttachedModeEnabled() const; |
---|
[1054] | 50 | bool hasTemporarilyBufferedEvent() const { return !tmpBufferedEvent.isEmpty(); }; |
---|
[704] | 51 | |
---|
[1232] | 52 | static void computeLeader(int clientRank, int clientSize, int serverSize, |
---|
| 53 | std::list<int>& rankRecvLeader, |
---|
| 54 | std::list<int>& rankRecvNotLeader); |
---|
| 55 | |
---|
[595] | 56 | // Close and finalize context client |
---|
[1054] | 57 | // void closeContext(void); Never been implemented. |
---|
[595] | 58 | void finalize(void); |
---|
[300] | 59 | |
---|
[917] | 60 | void setBufferSize(const std::map<int,StdSize>& mapSize, const std::map<int,StdSize>& maxEventSize); |
---|
[726] | 61 | |
---|
[512] | 62 | public: |
---|
[595] | 63 | CContext* context; //!< Context for client |
---|
[509] | 64 | |
---|
[595] | 65 | size_t timeLine; //!< Timeline of each event |
---|
[509] | 66 | |
---|
[595] | 67 | int clientRank; //!< Rank of current client |
---|
[300] | 68 | |
---|
[595] | 69 | int clientSize; //!< Size of client group |
---|
[300] | 70 | |
---|
[595] | 71 | int serverSize; //!< Size of server group |
---|
[300] | 72 | |
---|
[595] | 73 | MPI_Comm interComm; //!< Communicator of server group |
---|
[300] | 74 | |
---|
[595] | 75 | MPI_Comm intraComm; //!< Communicator of client group |
---|
[300] | 76 | |
---|
[1158] | 77 | map<int,CClientBuffer*> buffers; //!< Buffers for connection to servers |
---|
[300] | 78 | |
---|
[512] | 79 | private: |
---|
| 80 | //! Mapping of server and buffer size for each connection to server |
---|
[595] | 81 | std::map<int,StdSize> mapBufferSize_; |
---|
[1201] | 82 | //! Maximum event sizes estimated for each connection to server |
---|
| 83 | std::map<int,StdSize> maxEventSizes; |
---|
[917] | 84 | //! Maximum number of events that can be buffered |
---|
| 85 | StdSize maxBufferedEvents; |
---|
[300] | 86 | |
---|
[1054] | 87 | struct { |
---|
| 88 | std::list<int> ranks, sizes; |
---|
| 89 | std::list<CBufferOut*> buffers; |
---|
| 90 | |
---|
| 91 | bool isEmpty() const { return ranks.empty(); }; |
---|
| 92 | void clear() { |
---|
| 93 | ranks.clear(); |
---|
| 94 | sizes.clear(); |
---|
| 95 | |
---|
| 96 | for (std::list<CBufferOut*>::iterator it = buffers.begin(); it != buffers.end(); it++) |
---|
| 97 | delete *it; |
---|
| 98 | |
---|
| 99 | buffers.clear(); |
---|
| 100 | }; |
---|
| 101 | } tmpBufferedEvent; //! Event temporarily buffered (used only on the server) |
---|
| 102 | |
---|
[512] | 103 | //! Context for server (Only used in attached mode) |
---|
| 104 | CContext* parentServer; |
---|
| 105 | |
---|
[595] | 106 | //! List of server ranks for which the client is leader |
---|
| 107 | std::list<int> ranksServerLeader; |
---|
| 108 | |
---|
[1021] | 109 | //! List of server ranks for which the client is not leader |
---|
| 110 | std::list<int> ranksServerNotLeader; |
---|
| 111 | |
---|
[595] | 112 | }; |
---|
[512] | 113 | } |
---|
| 114 | |
---|
| 115 | #endif // __CONTEXT_CLIENT_HPP__ |
---|