[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; |
---|
[1853] | 16 | class CContextServer ; |
---|
[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 |
---|
[1639] | 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); |
---|
| 33 | void waitEvent(list<int>& ranks); |
---|
[1761] | 34 | void waitEvent_old(list<int>& ranks); |
---|
[300] | 35 | |
---|
[1054] | 36 | // Functions to set/get buffers |
---|
[1757] | 37 | bool getBuffers(const size_t timeLine, 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); |
---|
[2324] | 41 | void eventLoop(void) ; |
---|
| 42 | void callGlobalEventLoop() ; |
---|
[595] | 43 | void releaseBuffers(void); |
---|
[1130] | 44 | bool havePendingRequests(void); |
---|
[2260] | 45 | bool havePendingRequests(list<int>& ranks) ; |
---|
[512] | 46 | |
---|
[595] | 47 | bool isServerLeader(void) const; |
---|
[1021] | 48 | bool isServerNotLeader(void) const; |
---|
[595] | 49 | const std::list<int>& getRanksServerLeader(void) const; |
---|
[1021] | 50 | const std::list<int>& getRanksServerNotLeader(void) const; |
---|
[512] | 51 | |
---|
[1761] | 52 | /*! |
---|
| 53 | * Check if the attached mode is used. |
---|
| 54 | * |
---|
| 55 | * \return true if and only if attached mode is used |
---|
| 56 | */ |
---|
| 57 | bool isAttachedModeEnabled() const { return isAttached_ ; } |
---|
[704] | 58 | |
---|
[1232] | 59 | static void computeLeader(int clientRank, int clientSize, int serverSize, |
---|
| 60 | std::list<int>& rankRecvLeader, |
---|
| 61 | std::list<int>& rankRecvNotLeader); |
---|
| 62 | |
---|
[595] | 63 | // Close and finalize context client |
---|
[1054] | 64 | // void closeContext(void); Never been implemented. |
---|
[1757] | 65 | bool isNotifiedFinalized(void) ; |
---|
[595] | 66 | void finalize(void); |
---|
[300] | 67 | |
---|
[2130] | 68 | void setBufferSize(const std::map<int,StdSize>& mapSize); |
---|
[726] | 69 | |
---|
[1784] | 70 | int getRemoteSize(void) {return serverSize;} |
---|
| 71 | int getServerSize(void) {return serverSize;} |
---|
[1918] | 72 | MPI_Comm getIntraComm(void) {return intraComm ;} |
---|
| 73 | int getIntraCommSize(void) {return clientSize ;} |
---|
| 74 | int getIntraCommRank(void) {return clientRank ;} |
---|
[1853] | 75 | |
---|
| 76 | /*! set the associated server (dual chanel client/server) */ |
---|
| 77 | void setAssociatedServer(CContextServer* associatedServer) { associatedServer=associatedServer_;} |
---|
| 78 | /*! get the associated server (dual chanel client/server) */ |
---|
| 79 | CContextServer* getAssociatedServer(void) { return associatedServer_;} |
---|
[2130] | 80 | void setGrowableBuffer(void) { isGrowableBuffer_=true;} |
---|
| 81 | void setFixedBuffer(void) { isGrowableBuffer_=false;} |
---|
[512] | 82 | public: |
---|
[2130] | 83 | CContext* context_; //!< Context for client |
---|
[509] | 84 | |
---|
[595] | 85 | size_t timeLine; //!< Timeline of each event |
---|
[509] | 86 | |
---|
[595] | 87 | int clientRank; //!< Rank of current client |
---|
[300] | 88 | |
---|
[595] | 89 | int clientSize; //!< Size of client group |
---|
[300] | 90 | |
---|
[595] | 91 | int serverSize; //!< Size of server group |
---|
[300] | 92 | |
---|
[1757] | 93 | MPI_Comm interComm; //!< Communicator of server group (interCommunicator) |
---|
[300] | 94 | |
---|
[2259] | 95 | MPI_Comm interCommMerged_; //!< Communicator of the client group + server group (intraCommunicator) needed for one sided communication. |
---|
| 96 | MPI_Comm commSelf_ ; //!< Communicator for proc alone from interCommMerged |
---|
[1757] | 97 | |
---|
[1639] | 98 | MPI_Comm intraComm; //!< Communicator of client group |
---|
[300] | 99 | |
---|
[1158] | 100 | map<int,CClientBuffer*> buffers; //!< Buffers for connection to servers |
---|
[300] | 101 | |
---|
[1757] | 102 | bool pureOneSided ; //!< if true, client will communicated with servers only trough one sided communication. Otherwise the hybrid mode P2P /One sided is used. |
---|
| 103 | |
---|
[2130] | 104 | size_t hashId_ ; //!< hash id on the context client that will be used for context server to identify the remote calling context client. |
---|
| 105 | |
---|
[512] | 106 | private: |
---|
[1757] | 107 | void lockBuffers(list<int>& ranks) ; |
---|
| 108 | void unlockBuffers(list<int>& ranks) ; |
---|
| 109 | |
---|
[512] | 110 | //! Mapping of server and buffer size for each connection to server |
---|
[595] | 111 | std::map<int,StdSize> mapBufferSize_; |
---|
[1201] | 112 | //! Maximum event sizes estimated for each connection to server |
---|
| 113 | std::map<int,StdSize> maxEventSizes; |
---|
[917] | 114 | //! Maximum number of events that can be buffered |
---|
| 115 | StdSize maxBufferedEvents; |
---|
[300] | 116 | |
---|
[512] | 117 | //! Context for server (Only used in attached mode) |
---|
| 118 | CContext* parentServer; |
---|
| 119 | |
---|
[595] | 120 | //! List of server ranks for which the client is leader |
---|
| 121 | std::list<int> ranksServerLeader; |
---|
| 122 | |
---|
[1021] | 123 | //! List of server ranks for which the client is not leader |
---|
| 124 | std::list<int> ranksServerNotLeader; |
---|
| 125 | |
---|
[2259] | 126 | std::map<int, MPI_Comm> winComm_ ; //! Window communicators |
---|
| 127 | std::map<int, std::vector<MPI_Win> >windows_ ; //! one sided mpi windows to expose client buffers to servers == windows[nbServers][2] |
---|
[1761] | 128 | bool isAttached_ ; |
---|
[1853] | 129 | CContextServer* associatedServer_ ; //!< The server associated to the pair client/server |
---|
[2130] | 130 | bool isGrowableBuffer_ = true ; |
---|
[2246] | 131 | |
---|
[2260] | 132 | double latency_=0e-2 ; |
---|
[2324] | 133 | |
---|
| 134 | bool locked_ = false ; //!< The context client is locked to avoid recursive checkBuffer |
---|
[595] | 135 | }; |
---|
[512] | 136 | } |
---|
| 137 | |
---|
| 138 | #endif // __CONTEXT_CLIENT_HPP__ |
---|