source: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp @ 1766

Last change on this file since 1766 was 1766, checked in by ymipsl, 2 years ago

more cleaning...
YM

  • 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: 12.2 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 "data_output.hpp"
11#include "garbage_collector.hpp"
12#include "registry.hpp"
13#include "mpi.hpp"
14#include "services_manager.hpp"
15#include "server_context.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           EVENT_ID_CONTEXT_FINALIZE_CLIENT,
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(std::shared_ptr<CCalendar> newCalendar);
87
88         /// Accesseurs ///
89         std::shared_ptr<CCalendar>      getCalendar(void) const;
90
91      public :
92         // Initialize server or client
93         void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
94         void initClient(MPI_Comm intraComm, int serviceType);
95         
96         void initServer(MPI_Comm intraComm, int serviceType );
97         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
98         void createServerInterComm(void)  ;
99
100         bool isInitialized(void);
101
102         StdString dumpClassAttributes(void);
103
104         // Put sever or client into loop state
105         bool eventLoop(bool enableEventsProcessing=true);
106         void globalEventLoop(void);
107
108         // Finalize a context
109         void finalize(void);
110
111         bool isFinalized(void);
112
113         void closeDefinition(void);
114
115         // Some functions to process context
116         void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
117         // void findAllEnabledFields(void);
118         // void findAllEnabledFieldsInReadModeFiles(void);
119         void readAttributesOfEnabledFieldsInReadModeFiles();
120         void solveAllInheritance(bool apply=true);
121         void findEnabledFiles(void);
122         void findEnabledWriteModeFiles(void);
123         void findEnabledReadModeFiles(void);
124         void closeAllFile(void);
125         void updateCalendar(int step);
126         void createFileHeader(void);
127         void initReadFiles(void);
128         void checkAxisDomainsGridsEligibilityForCompressedOutput();
129         void prepareTimeseries(void);
130         void solveOnlyRefOfEnabledFields(bool sendToServer);         
131         void buildFilterGraphOfEnabledFields();
132         void postProcessFilterGraph();
133         void startPrefetchingOfEnabledReadModeFiles();
134         void doPreTimestepOperationsForEnabledReadModeFiles();
135         void doPostTimestepOperationsForEnabledReadModeFiles();
136         void findFieldsWithReadAccess(void);
137         void solveAllRefOfFieldsWithReadAccess();
138         void buildFilterGraphOfFieldsWithReadAccess();
139         void postProcessing();
140         void postProcessingGlobalAttributes();         
141
142         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
143         void checkGridEnabledFields();
144         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
145         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
146         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
147
148         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
149         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
150         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false);
151
152         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
153         void distributeFiles(void);
154         void distributeFileOverBandwith() ;
155         void distributeFileOverMemoryBandwith() ;
156         
157         // Send context close definition
158         void sendCloseDefinition(void);
159         // There are something to send on closing context defintion
160         void sendUpdateCalendar(int step);
161         void sendCreateFileHeader(void);
162         void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
163         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
164         void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles);
165         void sendRefGrid(const std::vector<CFile*>& activeFiles);
166         void sendPostProcessing();
167         void sendPostProcessingGlobalAttributes();
168         void sendProcessingGridOfEnabledFields();
169         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
170         void sendRegistry(void) ;
171         void sendFinalizeClient(CContextClient* contextClient, const string& contextClientId);
172
173
174         const StdString& getIdServer();
175         void setIdServer(const StdString& idServer);
176         const StdString& getIdServer(const int srvPoolNb);
177         std::string getContextId() {return contextId_;}
178
179         // Client side: Receive and process messages
180         static void recvUpdateCalendar(CEventServer& event);
181         void recvUpdateCalendar(CBufferIn& buffer);
182         static void recvCloseDefinition(CEventServer& event);
183         static void recvCreateFileHeader(CEventServer& event);
184         void recvCreateFileHeader(CBufferIn& buffer);
185         static void recvSolveInheritanceContext(CEventServer& event);
186         void recvSolveInheritanceContext(CBufferIn& buffer);
187         static void recvPostProcessing(CEventServer& event);
188         void recvPostProcessing(CBufferIn& buffer);
189         static void recvProcessingGridOfEnabledFields(CEventServer& event);
190         static void recvPostProcessingGlobalAttributes(CEventServer& event);
191         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
192         static void recvRegistry(CEventServer& event) ;
193         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
194         static void recvFinalizeClient(CEventServer& event) ;
195         void recvFinalizeClient(CBufferIn& buffer);
196         
197         void freeComms(void);                  //!< Free internally allcoated communicators
198         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
199
200         // dispatch event
201         static bool dispatchEvent(CEventServer& event);
202
203      public:
204        // Get current context
205        static CContext* getCurrent(void);
206
207        // Get context root
208        static CContextGroup* getRoot(void);
209
210        // Set current context
211        static void setCurrent(const string& id);
212
213        // Create new context
214        static CContext* create(const string& id = "");
215
216        /// Accesseurs statiques ///
217        static StdString GetName(void);
218        static StdString GetDefName(void);
219        static ENodeType GetType(void);
220
221        static CContextGroup* GetContextGroup(void);
222
223        // Some functions to visualize structure of current context
224        static void ShowTree(StdOStream & out = std::clog);
225        static void CleanTree(void);
226        int getServiceType(void) {return serviceType_;}
227
228      public :
229         // Parse xml node and write all info into context
230         virtual void parse(xml::CXMLNode & node);
231
232         // Visualize a context
233         virtual StdString toString(void) const;
234
235
236         // Solve all inheritance relation in current context
237         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
238
239         // Verify if all root definition in a context have children
240         virtual bool hasChild(void) const;
241
242         bool isProcessingEvent(void) {return isProcessingEvent_;}
243         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
244         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
245
246      public :
247         // Calendar of context
248         std::shared_ptr<CCalendar>   calendar;
249
250         // List of all enabled files (files on which fields are written or read)
251         std::vector<CFile*> enabledFiles;
252         // List of all enabled files in read mode (files on which fields are read)
253         std::vector<CFile*> enabledReadModeFiles;
254         // List of all enabled files in write mode
255         std::vector<CFile*> enabledWriteModeFiles;
256
257         // List of all enabled fields whose instant data is accessible from the public API
258         // but which are not part of a file
259         std::vector<CField*> fieldsWithReadAccess;
260
261         // Context root
262         static std::shared_ptr<CContextGroup> root;
263
264         // Determine context on client or not
265         bool hasClient;
266
267         // Determine context on server or not
268         bool hasServer;
269
270         CContextServer* server;    //!< Concrete context server
271         CContextClient* client;    //!< Concrete contex client
272         std::vector<CContextServer*> serverPrimServer;
273         std::vector<CContextClient*> clientPrimServer;
274         std::vector<std::string> primServerId_;
275
276         CRegistry* registryIn ;    //!< input registry which is read from file
277         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
278
279
280        MPI_Comm intraComm_ ; //! context intra communicator
281
282      private:
283         bool isPostProcessed;
284         bool allProcessed;
285         bool finalized;
286         int countChildContextFinalized_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
287         StdString idServer_;
288         CGarbageCollector garbageCollector;
289         std::list<MPI_Comm> comms; //!< Communicators allocated internally
290
291         int serviceType_;  //!< service associated to the context
292         string contextId_ ; //!< context client id for the servers. For clients this is same as getId()
293         bool isProcessingEvent_ ;
294         CServerContext* parentServerContext_ ;
295
296      public: // Some function maybe removed in the near future
297        // virtual void toBinary  (StdOStream & os) const;
298        // virtual void fromBinary(StdIStream & is);
299   }; // class CContext
300
301   ///--------------------------------------------------------------
302
303   // Declare/Define CContextGroup and CContextDefinition
304   DECLARE_GROUP(CContext);
305
306   ///--------------------------------------------------------------
307
308} // namespace xios
309
310#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.