[591] | 1 | #ifndef __XIOS_CContext__ |
---|
| 2 | #define __XIOS_CContext__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[352] | 6 | //#include "node_type.hpp" |
---|
[549] | 7 | #include "calendar_wrapper.hpp" |
---|
[219] | 8 | |
---|
| 9 | #include "declare_group.hpp" |
---|
[300] | 10 | #include "data_output.hpp" |
---|
[639] | 11 | #include "garbage_collector.hpp" |
---|
[697] | 12 | #include "registry.hpp" |
---|
[382] | 13 | #include "mpi.hpp" |
---|
[1761] | 14 | #include "services_manager.hpp" |
---|
| 15 | #include "server_context.hpp" |
---|
[300] | 16 | |
---|
[219] | 17 | |
---|
[335] | 18 | namespace xios { |
---|
[549] | 19 | class CContextClient; |
---|
| 20 | class CContextServer; |
---|
[509] | 21 | |
---|
| 22 | |
---|
[219] | 23 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 24 | class CContextGroup; |
---|
| 25 | class CContextAttributes; |
---|
| 26 | class CContext; |
---|
[352] | 27 | class CFile; |
---|
[1784] | 28 | class CCouplerIn ; |
---|
| 29 | class CCouplerOut ; |
---|
[219] | 30 | ///-------------------------------------------------------------- |
---|
| 31 | |
---|
| 32 | // Declare/Define CFileAttribute |
---|
| 33 | BEGIN_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 34 | # include "context_attribute.conf" |
---|
| 35 | END_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 36 | |
---|
| 37 | ///-------------------------------------------------------------- |
---|
[509] | 38 | /*! |
---|
| 39 | \class CContext |
---|
| 40 | This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS |
---|
| 41 | Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which |
---|
| 42 | we can have access to each element. |
---|
| 43 | In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed, |
---|
| 44 | object of the class is created and its contains all information of other elements in the xml file. |
---|
| 45 | */ |
---|
[219] | 46 | class CContext |
---|
| 47 | : public CObjectTemplate<CContext> |
---|
| 48 | , public CContextAttributes |
---|
| 49 | { |
---|
[300] | 50 | public : |
---|
| 51 | enum EEventId |
---|
| 52 | { |
---|
| 53 | EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, |
---|
[509] | 54 | EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, |
---|
[1025] | 55 | EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY, |
---|
| 56 | EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES, |
---|
[1764] | 57 | EVENT_ID_PROCESS_GRID_ENABLED_FIELDS, |
---|
| 58 | EVENT_ID_CONTEXT_FINALIZE_CLIENT, |
---|
[549] | 59 | }; |
---|
[509] | 60 | |
---|
[219] | 61 | /// typedef /// |
---|
| 62 | typedef CObjectTemplate<CContext> SuperClass; |
---|
| 63 | typedef CContextAttributes SuperClassAttribute; |
---|
| 64 | |
---|
| 65 | public : |
---|
| 66 | |
---|
| 67 | typedef CContextAttributes RelAttributes; |
---|
| 68 | typedef CContext RelGroup; |
---|
| 69 | |
---|
| 70 | //--------------------------------------------------------- |
---|
| 71 | |
---|
| 72 | public : |
---|
| 73 | |
---|
| 74 | /// Constructeurs /// |
---|
| 75 | CContext(void); |
---|
| 76 | explicit CContext(const StdString & id); |
---|
| 77 | CContext(const CContext & context); // Not implemented yet. |
---|
| 78 | CContext(const CContext * const context); // Not implemented yet. |
---|
| 79 | |
---|
| 80 | /// Destructeur /// |
---|
| 81 | virtual ~CContext(void); |
---|
| 82 | |
---|
| 83 | //--------------------------------------------------------- |
---|
| 84 | |
---|
| 85 | public : |
---|
[509] | 86 | |
---|
[219] | 87 | /// Mutateurs /// |
---|
[1542] | 88 | void setCalendar(std::shared_ptr<CCalendar> newCalendar); |
---|
[509] | 89 | |
---|
[219] | 90 | /// Accesseurs /// |
---|
[1542] | 91 | std::shared_ptr<CCalendar> getCalendar(void) const; |
---|
[219] | 92 | |
---|
| 93 | public : |
---|
[509] | 94 | // Initialize server or client |
---|
[1761] | 95 | void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType); |
---|
| 96 | void initClient(MPI_Comm intraComm, int serviceType); |
---|
| 97 | |
---|
| 98 | void initServer(MPI_Comm intraComm, int serviceType ); |
---|
| 99 | void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer) ; |
---|
| 100 | void createServerInterComm(void) ; |
---|
| 101 | |
---|
[549] | 102 | bool isInitialized(void); |
---|
[219] | 103 | |
---|
[1622] | 104 | StdString dumpClassAttributes(void); |
---|
| 105 | |
---|
[509] | 106 | // Put sever or client into loop state |
---|
[1761] | 107 | bool eventLoop(bool enableEventsProcessing=true); |
---|
[1764] | 108 | void globalEventLoop(void); |
---|
[597] | 109 | |
---|
[509] | 110 | // Finalize a context |
---|
[549] | 111 | void finalize(void); |
---|
[1764] | 112 | |
---|
[1071] | 113 | bool isFinalized(void); |
---|
[509] | 114 | |
---|
[1130] | 115 | void closeDefinition(void); |
---|
| 116 | |
---|
[509] | 117 | // Some functions to process context |
---|
[1232] | 118 | void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); |
---|
| 119 | // void findAllEnabledFields(void); |
---|
| 120 | // void findAllEnabledFieldsInReadModeFiles(void); |
---|
[775] | 121 | void readAttributesOfEnabledFieldsInReadModeFiles(); |
---|
[549] | 122 | void solveAllInheritance(bool apply=true); |
---|
[300] | 123 | void findEnabledFiles(void); |
---|
[1784] | 124 | void findEnabledCouplerIn(void); |
---|
| 125 | void findEnabledCouplerOut(void); |
---|
| 126 | void createCouplerInterCommunicator(void) ; |
---|
[1232] | 127 | void findEnabledWriteModeFiles(void); |
---|
[598] | 128 | void findEnabledReadModeFiles(void); |
---|
[549] | 129 | void closeAllFile(void); |
---|
| 130 | void updateCalendar(int step); |
---|
[1232] | 131 | void createFileHeader(void); |
---|
| 132 | void initReadFiles(void); |
---|
[676] | 133 | void checkAxisDomainsGridsEligibilityForCompressedOutput(); |
---|
[711] | 134 | void prepareTimeseries(void); |
---|
[1784] | 135 | void solveOnlyRefOfEnabledFields(void); |
---|
[640] | 136 | void buildFilterGraphOfEnabledFields(); |
---|
[1358] | 137 | void postProcessFilterGraph(); |
---|
[598] | 138 | void startPrefetchingOfEnabledReadModeFiles(); |
---|
[1358] | 139 | void doPreTimestepOperationsForEnabledReadModeFiles(); |
---|
[1318] | 140 | void doPostTimestepOperationsForEnabledReadModeFiles(); |
---|
[593] | 141 | void findFieldsWithReadAccess(void); |
---|
| 142 | void solveAllRefOfFieldsWithReadAccess(); |
---|
[640] | 143 | void buildFilterGraphOfFieldsWithReadAccess(); |
---|
[509] | 144 | void postProcessing(); |
---|
[1025] | 145 | void postProcessingGlobalAttributes(); |
---|
[509] | 146 | |
---|
[1784] | 147 | void solveAllRefOfEnabledFieldsAndTransform(void); |
---|
[1099] | 148 | void checkGridEnabledFields(); |
---|
[1232] | 149 | void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); |
---|
[1239] | 150 | void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); |
---|
| 151 | void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles) ; |
---|
[1025] | 152 | |
---|
[1330] | 153 | std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false); |
---|
| 154 | std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false); |
---|
| 155 | void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false); |
---|
[509] | 156 | |
---|
[1212] | 157 | // Distribute files (in write mode) among secondary-server pools according to the estimated data flux |
---|
[1208] | 158 | void distributeFiles(void); |
---|
[1349] | 159 | void distributeFileOverBandwith() ; |
---|
| 160 | void distributeFileOverMemoryBandwith() ; |
---|
| 161 | |
---|
[509] | 162 | // Send context close definition |
---|
[549] | 163 | void sendCloseDefinition(void); |
---|
[509] | 164 | // There are something to send on closing context defintion |
---|
[549] | 165 | void sendUpdateCalendar(int step); |
---|
| 166 | void sendCreateFileHeader(void); |
---|
[1232] | 167 | void sendEnabledFiles(const std::vector<CFile*>& activeFiles); |
---|
| 168 | void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); |
---|
| 169 | void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles); |
---|
| 170 | void sendRefGrid(const std::vector<CFile*>& activeFiles); |
---|
[509] | 171 | void sendPostProcessing(); |
---|
[1025] | 172 | void sendPostProcessingGlobalAttributes(); |
---|
| 173 | void sendProcessingGridOfEnabledFields(); |
---|
[983] | 174 | //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers |
---|
| 175 | void sendRegistry(void) ; |
---|
[1764] | 176 | void sendFinalizeClient(CContextClient* contextClient, const string& contextClientId); |
---|
[983] | 177 | |
---|
[1761] | 178 | std::string getContextId() {return contextId_;} |
---|
[511] | 179 | |
---|
[509] | 180 | // Client side: Receive and process messages |
---|
[549] | 181 | static void recvUpdateCalendar(CEventServer& event); |
---|
| 182 | void recvUpdateCalendar(CBufferIn& buffer); |
---|
| 183 | static void recvCloseDefinition(CEventServer& event); |
---|
| 184 | static void recvCreateFileHeader(CEventServer& event); |
---|
| 185 | void recvCreateFileHeader(CBufferIn& buffer); |
---|
[509] | 186 | static void recvSolveInheritanceContext(CEventServer& event); |
---|
| 187 | void recvSolveInheritanceContext(CBufferIn& buffer); |
---|
| 188 | static void recvPostProcessing(CEventServer& event); |
---|
| 189 | void recvPostProcessing(CBufferIn& buffer); |
---|
[1025] | 190 | static void recvProcessingGridOfEnabledFields(CEventServer& event); |
---|
| 191 | static void recvPostProcessingGlobalAttributes(CEventServer& event); |
---|
| 192 | void recvPostProcessingGlobalAttributes(CBufferIn& buffer); |
---|
[697] | 193 | static void recvRegistry(CEventServer& event) ; |
---|
[983] | 194 | void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers |
---|
[1764] | 195 | static void recvFinalizeClient(CEventServer& event) ; |
---|
| 196 | void recvFinalizeClient(CBufferIn& buffer); |
---|
| 197 | |
---|
[1130] | 198 | void freeComms(void); //!< Free internally allcoated communicators |
---|
| 199 | void releaseClientBuffers(void); //! Deallocate buffers allocated by clientContexts |
---|
[1054] | 200 | |
---|
[509] | 201 | // dispatch event |
---|
[549] | 202 | static bool dispatchEvent(CEventServer& event); |
---|
[509] | 203 | |
---|
| 204 | public: |
---|
| 205 | // Get current context |
---|
| 206 | static CContext* getCurrent(void); |
---|
| 207 | |
---|
| 208 | // Get context root |
---|
| 209 | static CContextGroup* getRoot(void); |
---|
| 210 | |
---|
| 211 | // Set current context |
---|
| 212 | static void setCurrent(const string& id); |
---|
| 213 | |
---|
| 214 | // Create new context |
---|
| 215 | static CContext* create(const string& id = ""); |
---|
| 216 | |
---|
| 217 | /// Accesseurs statiques /// |
---|
| 218 | static StdString GetName(void); |
---|
| 219 | static StdString GetDefName(void); |
---|
| 220 | static ENodeType GetType(void); |
---|
| 221 | |
---|
| 222 | static CContextGroup* GetContextGroup(void); |
---|
| 223 | |
---|
| 224 | // Some functions to visualize structure of current context |
---|
| 225 | static void ShowTree(StdOStream & out = std::clog); |
---|
| 226 | static void CleanTree(void); |
---|
[1761] | 227 | int getServiceType(void) {return serviceType_;} |
---|
[509] | 228 | |
---|
[219] | 229 | public : |
---|
[509] | 230 | // Parse xml node and write all info into context |
---|
[219] | 231 | virtual void parse(xml::CXMLNode & node); |
---|
| 232 | |
---|
[509] | 233 | // Visualize a context |
---|
[219] | 234 | virtual StdString toString(void) const; |
---|
[509] | 235 | |
---|
| 236 | |
---|
| 237 | // Solve all inheritance relation in current context |
---|
| 238 | virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); |
---|
| 239 | |
---|
| 240 | // Verify if all root definition in a context have children |
---|
| 241 | virtual bool hasChild(void) const; |
---|
| 242 | |
---|
[1761] | 243 | bool isProcessingEvent(void) {return isProcessingEvent_;} |
---|
| 244 | bool setProcessingEvent(void) {isProcessingEvent_=true ;} |
---|
| 245 | bool unsetProcessingEvent(void) {isProcessingEvent_=false ;} |
---|
[1784] | 246 | MPI_Comm getIntraComm(void) { return intraComm_ ;} |
---|
[1054] | 247 | |
---|
[1784] | 248 | void addCouplingChanel(const std::string& contextId, bool out) ; |
---|
| 249 | |
---|
[300] | 250 | public : |
---|
[509] | 251 | // Calendar of context |
---|
[1542] | 252 | std::shared_ptr<CCalendar> calendar; |
---|
[509] | 253 | |
---|
[598] | 254 | // List of all enabled files (files on which fields are written or read) |
---|
[347] | 255 | std::vector<CFile*> enabledFiles; |
---|
[598] | 256 | // List of all enabled files in read mode (files on which fields are read) |
---|
| 257 | std::vector<CFile*> enabledReadModeFiles; |
---|
[1208] | 258 | // List of all enabled files in write mode |
---|
| 259 | std::vector<CFile*> enabledWriteModeFiles; |
---|
[509] | 260 | |
---|
[1784] | 261 | std::vector<CCouplerIn*> enabledCouplerIn; |
---|
| 262 | std::vector<CCouplerOut*> enabledCouplerOut; |
---|
| 263 | |
---|
| 264 | |
---|
[740] | 265 | // List of all enabled fields whose instant data is accessible from the public API |
---|
| 266 | // but which are not part of a file |
---|
[593] | 267 | std::vector<CField*> fieldsWithReadAccess; |
---|
| 268 | |
---|
[509] | 269 | // Context root |
---|
[1542] | 270 | static std::shared_ptr<CContextGroup> root; |
---|
[219] | 271 | |
---|
[509] | 272 | // Determine context on client or not |
---|
[549] | 273 | bool hasClient; |
---|
[300] | 274 | |
---|
[509] | 275 | // Determine context on server or not |
---|
[549] | 276 | bool hasServer; |
---|
[509] | 277 | |
---|
[1130] | 278 | CContextServer* server; //!< Concrete context server |
---|
| 279 | CContextClient* client; //!< Concrete contex client |
---|
[1071] | 280 | std::vector<CContextServer*> serverPrimServer; |
---|
| 281 | std::vector<CContextClient*> clientPrimServer; |
---|
[1784] | 282 | std::map<std::string, CContextClient*> couplerClient_ ; |
---|
| 283 | std::map<std::string, CContextServer*> couplerServer_ ; |
---|
| 284 | |
---|
| 285 | |
---|
[1761] | 286 | std::vector<std::string> primServerId_; |
---|
[1071] | 287 | |
---|
[1130] | 288 | CRegistry* registryIn ; //!< input registry which is read from file |
---|
| 289 | CRegistry* registryOut ; //!< output registry which will be written into file at the finalize |
---|
[775] | 290 | |
---|
[1761] | 291 | |
---|
| 292 | MPI_Comm intraComm_ ; //! context intra communicator |
---|
[1784] | 293 | int intraCommRank_ ; //! context intra communicator rank |
---|
| 294 | int intraCommSize_ ; //! context intra communicator size |
---|
| 295 | |
---|
[509] | 296 | private: |
---|
| 297 | bool isPostProcessed; |
---|
[1025] | 298 | bool allProcessed; |
---|
[1139] | 299 | bool finalized; |
---|
[1764] | 300 | int countChildContextFinalized_; //!< Counter of child contexts (for now it is the number of secondary server pools) |
---|
[639] | 301 | CGarbageCollector garbageCollector; |
---|
[1639] | 302 | std::list<MPI_Comm> comms; //!< Communicators allocated internally |
---|
[509] | 303 | |
---|
[1761] | 304 | int serviceType_; //!< service associated to the context |
---|
| 305 | string contextId_ ; //!< context client id for the servers. For clients this is same as getId() |
---|
| 306 | bool isProcessingEvent_ ; |
---|
| 307 | CServerContext* parentServerContext_ ; |
---|
| 308 | |
---|
[509] | 309 | public: // Some function maybe removed in the near future |
---|
| 310 | // virtual void toBinary (StdOStream & os) const; |
---|
| 311 | // virtual void fromBinary(StdIStream & is); |
---|
[219] | 312 | }; // class CContext |
---|
| 313 | |
---|
| 314 | ///-------------------------------------------------------------- |
---|
| 315 | |
---|
| 316 | // Declare/Define CContextGroup and CContextDefinition |
---|
| 317 | DECLARE_GROUP(CContext); |
---|
| 318 | |
---|
| 319 | ///-------------------------------------------------------------- |
---|
| 320 | |
---|
[335] | 321 | } // namespace xios |
---|
[219] | 322 | |
---|
[591] | 323 | #endif // __XIOS_CContext__ |
---|