source: XIOS/dev/dev_olga/src/node/context.hpp @ 1184

Last change on this file since 1184 was 1184, checked in by oabramkina, 7 years ago

Two server levels: correcting buffer allocations on client side of primary server. The buffer size is calculated according to the number of files sent to each secondary server.

  • 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.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 "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_CONTEXT_POST_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(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
94         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
95         bool isInitialized(void);
96
97         // Put sever or client into loop state
98         bool checkBuffersAndListen(void);
99
100         // Finalize a context
101         void finalize(void);
102         void postFinalize(void);
103         bool isFinalized(void);
104
105         void closeDefinition(void);
106
107         // Some functions to process context
108         void findAllEnabledFields(void);
109         void findAllEnabledFieldsInReadModeFiles(void);
110         void readAttributesOfEnabledFieldsInReadModeFiles();
111         void solveAllInheritance(bool apply=true);
112         void findEnabledFiles(void);
113         void findEnabledReadModeFiles(void);
114         void closeAllFile(void);
115         void updateCalendar(int step);
116         void createFileHeader(void );
117         void checkAxisDomainsGridsEligibilityForCompressedOutput();
118         void prepareTimeseries(void);
119         void solveOnlyRefOfEnabledFields(bool sendToServer);         
120         void buildFilterGraphOfEnabledFields();
121         void startPrefetchingOfEnabledReadModeFiles();
122         void checkPrefetchingOfEnabledReadModeFiles();
123         void findFieldsWithReadAccess(void);
124         void solveAllRefOfFieldsWithReadAccess();
125         void buildFilterGraphOfFieldsWithReadAccess();
126         void postProcessing();
127         void postProcessingGlobalAttributes();         
128
129         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
130         void checkGridEnabledFields();
131         void sendGridEnabledFields();
132
133//         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize);
134//         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize);
135//         void setClientServerBuffer();
136         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient);
137         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient);
138         void setClientServerBuffer(CContextClient* contextClient);
139
140         // Send context close definition
141         void sendCloseDefinition(void);
142         // There are something to send on closing context defintion
143         void sendUpdateCalendar(int step);
144         void sendCreateFileHeader(void);
145         void sendEnabledFiles();
146         void sendEnabledFields();
147         void sendRefDomainsAxis();
148         void sendRefGrid();
149         void sendPostProcessing();
150         void sendPostProcessingGlobalAttributes();
151         void sendProcessingGridOfEnabledFields();
152         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
153         void sendRegistry(void) ;
154
155         const StdString& getIdServer();
156         const StdString& getIdServer(const int srvPoolNb);
157
158         // Client side: Receive and process messages
159         static void recvUpdateCalendar(CEventServer& event);
160         void recvUpdateCalendar(CBufferIn& buffer);
161         static void recvCloseDefinition(CEventServer& event);
162         static void recvCreateFileHeader(CEventServer& event);
163         void recvCreateFileHeader(CBufferIn& buffer);
164         static void recvSolveInheritanceContext(CEventServer& event);
165         void recvSolveInheritanceContext(CBufferIn& buffer);
166         static void recvPostProcessing(CEventServer& event);
167         void recvPostProcessing(CBufferIn& buffer);
168         static void recvProcessingGridOfEnabledFields(CEventServer& event);
169         static void recvPostProcessingGlobalAttributes(CEventServer& event);
170         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
171         static void recvRegistry(CEventServer& event) ;
172         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
173
174         void freeComms(void);                  //!< Free internally allcoated communicators
175         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
176
177         // dispatch event
178         static bool dispatchEvent(CEventServer& event);
179
180      public:
181        // Get current context
182        static CContext* getCurrent(void);
183
184        // Get context root
185        static CContextGroup* getRoot(void);
186
187        // Set current context
188        static void setCurrent(const string& id);
189
190        // Create new context
191        static CContext* create(const string& id = "");
192
193        /// Accesseurs statiques ///
194        static StdString GetName(void);
195        static StdString GetDefName(void);
196        static ENodeType GetType(void);
197
198        static CContextGroup* GetContextGroup(void);
199
200        // Some functions to visualize structure of current context
201        static void ShowTree(StdOStream & out = std::clog);
202        static void CleanTree(void);
203
204      public :
205         // Parse xml node and write all info into context
206         virtual void parse(xml::CXMLNode & node);
207
208         // Visualize a context
209         virtual StdString toString(void) const;
210
211
212         // Solve all inheritance relation in current context
213         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
214
215         // Verify if all root definition in a context have children
216         virtual bool hasChild(void) const;
217
218
219      public :
220         // Calendar of context
221         boost::shared_ptr<CCalendar>   calendar;
222
223         // List of all enabled files (files on which fields are written or read)
224         std::vector<CFile*> enabledFiles;
225         // List of all enabled files in read mode (files on which fields are read)
226         std::vector<CFile*> enabledReadModeFiles;
227
228         // List of all enabled fields whose instant data is accessible from the public API
229         // but which are not part of a file
230         std::vector<CField*> fieldsWithReadAccess;
231
232         // Context root
233         static shared_ptr<CContextGroup> root;
234
235         // Determine context on client or not
236         bool hasClient;
237
238         // Determine context on server or not
239         bool hasServer;
240
241         CContextServer* server;    //!< Concrete context server
242         CContextClient* client;    //!< Concrete contex client
243         std::vector<CContextServer*> serverPrimServer;
244         std::vector<CContextClient*> clientPrimServer;
245
246         CRegistry* registryIn ;    //!< input registry which is read from file
247         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
248
249      private:
250         bool isPostProcessed;
251         bool allProcessed;
252         bool finalized;
253         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
254         StdString idServer_;
255         CGarbageCollector garbageCollector;
256         std::list<MPI_Comm> comms; //!< Communicators allocated internally
257
258      public: // Some function maybe removed in the near future
259        // virtual void toBinary  (StdOStream & os) const;
260        // virtual void fromBinary(StdIStream & is);
261   }; // class CContext
262
263   ///--------------------------------------------------------------
264
265   // Declare/Define CContextGroup and CContextDefinition
266   DECLARE_GROUP(CContext);
267
268   ///--------------------------------------------------------------
269
270} // namespace xios
271
272#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.