source: XIOS/dev/branch_openmp/src/node/context.hpp @ 1460

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

branch_openmp merged with XIOS_DEV_CMIP6@1459

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