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