source: XIOS/dev/XIOS_DEV_CMIP6/src/node/context.hpp @ 1314

Last change on this file since 1314 was 1239, checked in by mhnguyen, 7 years ago

Correcting a minor bug on detecting server reading level

+) Reading server level should be 1 (for now). In the future, maybe level-2 server can be used
+) Correct nbReadSenders with the right ContextClient?

Test
+) On Curie
+) Work with toy

  • 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: 10.8 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 "calendar_wrapper.hpp"
8
9#include "declare_group.hpp"
10//#include "context_client.hpp"
11//#include "context_server.hpp"
12#include "data_output.hpp"
13#include "garbage_collector.hpp"
14#include "registry.hpp"
15#include "mpi.hpp"
16
17
18namespace xios {
19   class CContextClient;
20   class CContextServer;
21
22
23   /// ////////////////////// Déclarations ////////////////////// ///
24   class CContextGroup;
25   class CContextAttributes;
26   class CContext;
27   class CFile;
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   ///--------------------------------------------------------------
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  */
44   class CContext
45      : public CObjectTemplate<CContext>
46      , public CContextAttributes
47   {
48         public :
49         enum EEventId
50         {
51           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
52           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
53           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
54           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
55           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
56         };
57
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 :
83
84         /// Mutateurs ///
85         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
86
87         /// Accesseurs ///
88         boost::shared_ptr<CCalendar>      getCalendar(void) const;
89
90      public :
91         // Initialize server or client
92         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
93         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
94         bool isInitialized(void);
95
96         // Put sever or client into loop state
97         bool checkBuffersAndListen(void);
98
99         // Finalize a context
100         void finalize(void);
101         bool isFinalized(void);
102
103         void closeDefinition(void);
104
105         // Some functions to process context
106         void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
107         // void findAllEnabledFields(void);
108         // void findAllEnabledFieldsInReadModeFiles(void);
109         void readAttributesOfEnabledFieldsInReadModeFiles();
110         void solveAllInheritance(bool apply=true);
111         void findEnabledFiles(void);
112         void findEnabledWriteModeFiles(void);
113         void findEnabledReadModeFiles(void);
114         void closeAllFile(void);
115         void updateCalendar(int step);
116         void createFileHeader(void);
117         void initReadFiles(void);
118         void checkAxisDomainsGridsEligibilityForCompressedOutput();
119         void prepareTimeseries(void);
120         void solveOnlyRefOfEnabledFields(bool sendToServer);         
121         void buildFilterGraphOfEnabledFields();
122         void startPrefetchingOfEnabledReadModeFiles();
123         void checkPrefetchingOfEnabledReadModeFiles();
124         void findFieldsWithReadAccess(void);
125         void solveAllRefOfFieldsWithReadAccess();
126         void buildFilterGraphOfFieldsWithReadAccess();
127         void postProcessing();
128         void postProcessingGlobalAttributes();         
129
130         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
131         void checkGridEnabledFields();
132         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
133         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
134         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
135
136//         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize);
137//         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize);
138//         void setClientServerBuffer();
139         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient);
140         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient);
141         void setClientServerBuffer(CContextClient* contextClient);
142
143         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
144         void distributeFiles(void);
145
146         // Send context close definition
147         void sendCloseDefinition(void);
148         // There are something to send on closing context defintion
149         void sendUpdateCalendar(int step);
150         void sendCreateFileHeader(void);
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);
155         void sendPostProcessing();
156         void sendPostProcessingGlobalAttributes();
157         void sendProcessingGridOfEnabledFields();
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
161         const StdString& getIdServer();
162         const StdString& getIdServer(const int srvPoolNb);
163
164         // Client side: Receive and process messages
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);
170         static void recvSolveInheritanceContext(CEventServer& event);
171         void recvSolveInheritanceContext(CBufferIn& buffer);
172         static void recvPostProcessing(CEventServer& event);
173         void recvPostProcessing(CBufferIn& buffer);
174         static void recvProcessingGridOfEnabledFields(CEventServer& event);
175         static void recvPostProcessingGlobalAttributes(CEventServer& event);
176         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
177         static void recvRegistry(CEventServer& event) ;
178         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
179
180         void freeComms(void);                  //!< Free internally allcoated communicators
181         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
182
183         // dispatch event
184         static bool dispatchEvent(CEventServer& event);
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
210      public :
211         // Parse xml node and write all info into context
212         virtual void parse(xml::CXMLNode & node);
213
214         // Visualize a context
215         virtual StdString toString(void) const;
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
224
225      public :
226         // Calendar of context
227         boost::shared_ptr<CCalendar>   calendar;
228
229         // List of all enabled files (files on which fields are written or read)
230         std::vector<CFile*> enabledFiles;
231         // List of all enabled files in read mode (files on which fields are read)
232         std::vector<CFile*> enabledReadModeFiles;
233         // List of all enabled files in write mode
234         std::vector<CFile*> enabledWriteModeFiles;
235
236         // List of all enabled fields whose instant data is accessible from the public API
237         // but which are not part of a file
238         std::vector<CField*> fieldsWithReadAccess;
239
240         // Context root
241         static shared_ptr<CContextGroup> root;
242
243         // Determine context on client or not
244         bool hasClient;
245
246         // Determine context on server or not
247         bool hasServer;
248
249         CContextServer* server;    //!< Concrete context server
250         CContextClient* client;    //!< Concrete contex client
251         std::vector<CContextServer*> serverPrimServer;
252         std::vector<CContextClient*> clientPrimServer;
253
254         CRegistry* registryIn ;    //!< input registry which is read from file
255         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
256
257      private:
258         bool isPostProcessed;
259         bool allProcessed;
260         bool finalized;
261         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
262         StdString idServer_;
263         CGarbageCollector garbageCollector;
264         std::list<MPI_Comm> comms; //!< Communicators allocated internally
265
266      public: // Some function maybe removed in the near future
267        // virtual void toBinary  (StdOStream & os) const;
268        // virtual void fromBinary(StdIStream & is);
269   }; // class CContext
270
271   ///--------------------------------------------------------------
272
273   // Declare/Define CContextGroup and CContextDefinition
274   DECLARE_GROUP(CContext);
275
276   ///--------------------------------------------------------------
277
278} // namespace xios
279
280#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.