source: XIOS/dev/dev_trunk_omp/src/node/context.hpp @ 1601

Last change on this file since 1601 was 1601, checked in by yushan, 6 years ago

branch_openmp merged with trunk r1597

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