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

Last change on this file since 1764 was 1764, checked in by ymipsl, 5 years ago

Some Update on XIOS services
Seems to work on Irène for :

  • first level of servers
  • fisrt + second level of servers
  • attached mode

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