source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.hpp @ 1869

Last change on this file since 1869 was 1869, checked in by ymipsl, 4 years ago

Some update...

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: 13.4 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   class CCouplerIn ;
29   class CCouplerOut ;
30   ///--------------------------------------------------------------
31
32   // Declare/Define CFileAttribute
33   BEGIN_DECLARE_ATTRIBUTE_MAP(CContext)
34#  include "context_attribute.conf"
35   END_DECLARE_ATTRIBUTE_MAP(CContext)
36
37   ///--------------------------------------------------------------
38  /*!
39  \class CContext
40   This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS
41   Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which
42   we can have access to each element.
43   In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed,
44   object of the class is created and its contains all information of other elements in the xml file.
45  */
46   class CContext
47      : public CObjectTemplate<CContext>
48      , public CContextAttributes
49   {
50         public :
51         enum EEventId
52         {
53           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
54           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
55           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
56           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
57           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS,
58           EVENT_ID_CONTEXT_FINALIZE_CLIENT,
59         };
60
61         /// typedef ///
62         typedef CObjectTemplate<CContext>   SuperClass;
63         typedef CContextAttributes SuperClassAttribute;
64
65      public :
66
67         typedef CContextAttributes RelAttributes;
68         typedef CContext           RelGroup;
69
70         //---------------------------------------------------------
71
72      public :
73
74         /// Constructeurs ///
75         CContext(void);
76         explicit CContext(const StdString & id);
77         CContext(const CContext & context);       // Not implemented yet.
78         CContext(const CContext * const context); // Not implemented yet.
79
80         /// Destructeur ///
81         virtual ~CContext(void);
82
83         //---------------------------------------------------------
84
85      public :
86
87         /// Mutateurs ///
88         void setCalendar(std::shared_ptr<CCalendar> newCalendar);
89
90         /// Accesseurs ///
91         std::shared_ptr<CCalendar>      getCalendar(void) const;
92
93      public :
94         // Initialize server or client
95         void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
96         void initClient(MPI_Comm intraComm, int serviceType);
97         
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 eventLoop(bool enableEventsProcessing=true);
108         void globalEventLoop(void);
109
110         // Finalize a context
111         void finalize(void);
112
113         bool isFinalized(void);
114
115         void closeDefinition(void);
116         void closeDefinition_old(void);
117
118         // to be removed     
119         std::vector<CField*> findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
120         // Some functions to process context
121         std::vector<CField*> findAllEnabledFieldsInFileOut(const std::vector<CFile*>& activeFiles);
122         std::vector<CField*> findAllEnabledFieldsInFileIn(const std::vector<CFile*>& activeFiles);
123         std::vector<CField*> findAllEnabledFieldsCouplerOut(const std::vector<CCouplerOut*>& activeCouplerOut);
124         std::vector<CField*> findAllEnabledFieldsCouplerIn(const std::vector<CCouplerIn*>& activeCouplerIn);
125         // void findAllEnabledFields(void);
126         // void findAllEnabledFieldsInReadModeFiles(void);
127         void readAttributesOfEnabledFieldsInReadModeFiles();
128         void solveAllInheritance(bool apply=true);
129         void findEnabledFiles(void);
130         void findEnabledCouplerIn(void);
131         void findEnabledCouplerOut(void);
132         void createCouplerInterCommunicator(void) ;
133         void findEnabledWriteModeFiles(void);
134         void findEnabledReadModeFiles(void);
135         void closeAllFile(void);
136         void updateCalendar(int step);
137         void createFileHeader(void);
138         void initReadFiles(void);
139         void checkAxisDomainsGridsEligibilityForCompressedOutput();
140         void prepareTimeseries(void);
141         void solveOnlyRefOfEnabledFields(void);         
142         void buildFilterGraphOfEnabledFields();
143         void postProcessFilterGraph();
144         void startPrefetchingOfEnabledReadModeFiles();
145         void doPreTimestepOperationsForEnabledReadModeFiles();
146         void doPostTimestepOperationsForEnabledReadModeFiles();
147         void findFieldsWithReadAccess(void);
148         void solveAllRefOfFieldsWithReadAccess();
149         void buildFilterGraphOfFieldsWithReadAccess();
150         void postProcessing();
151         void postProcessingGlobalAttributes();         
152
153         void solveAllRefOfEnabledFieldsAndTransform(void);
154         void checkGridEnabledFields();
155         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
156         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
157         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
158
159         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
160         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
161         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false);
162
163         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
164         void distributeFiles(const std::vector<CFile*>& files);
165         void distributeFileOverBandwith(const std::vector<CFile*>& files) ;
166         void distributeFileOverMemoryBandwith(const std::vector<CFile*>& files) ;
167         
168         // Send context close definition
169         void sendCloseDefinition(void);
170         // There are something to send on closing context defintion
171         void sendUpdateCalendar(int step);
172         void sendCreateFileHeader(void);
173         void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
174         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
175         void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles);
176         void sendRefGrid(const std::vector<CFile*>& activeFiles);
177         void sendPostProcessing();
178         void sendPostProcessingGlobalAttributes();
179         void sendProcessingGridOfEnabledFields();
180         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
181         void sendRegistry(void) ;
182         void sendFinalizeClient(CContextClient* contextClient, const string& contextClientId);
183
184         std::string getContextId() {return contextId_;}
185
186         // Client side: Receive and process messages
187         static void recvUpdateCalendar(CEventServer& event);
188         void recvUpdateCalendar(CBufferIn& buffer);
189         static void recvCloseDefinition(CEventServer& event);
190         static void recvCreateFileHeader(CEventServer& event);
191         void recvCreateFileHeader(CBufferIn& buffer);
192         static void recvSolveInheritanceContext(CEventServer& event);
193         void recvSolveInheritanceContext(CBufferIn& buffer);
194         static void recvPostProcessing(CEventServer& event);
195         void recvPostProcessing(CBufferIn& buffer);
196         static void recvProcessingGridOfEnabledFields(CEventServer& event);
197         static void recvPostProcessingGlobalAttributes(CEventServer& event);
198         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
199         static void recvRegistry(CEventServer& event) ;
200         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
201         static void recvFinalizeClient(CEventServer& event) ;
202         void recvFinalizeClient(CBufferIn& buffer);
203         
204         void freeComms(void);                  //!< Free internally allcoated communicators
205         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
206
207         // dispatch event
208         static bool dispatchEvent(CEventServer& event);
209
210      public:
211        // Get current context
212        static CContext* getCurrent(void);
213
214        // Get context root
215        static CContextGroup* getRoot(void);
216
217        // Set current context
218        static void setCurrent(const string& id);
219
220        // Create new context
221        static CContext* create(const string& id = "");
222
223        /// Accesseurs statiques ///
224        static StdString GetName(void);
225        static StdString GetDefName(void);
226        static ENodeType GetType(void);
227
228        static CContextGroup* GetContextGroup(void);
229
230        // Some functions to visualize structure of current context
231        static void ShowTree(StdOStream & out = std::clog);
232        static void CleanTree(void);
233        int getServiceType(void) {return serviceType_;}
234
235      public :
236         // Parse xml node and write all info into context
237         virtual void parse(xml::CXMLNode & node);
238
239         // Visualize a context
240         virtual StdString toString(void) const;
241
242
243         // Solve all inheritance relation in current context
244         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
245
246         // Verify if all root definition in a context have children
247         virtual bool hasChild(void) const;
248
249         bool isProcessingEvent(void) {return isProcessingEvent_;}
250         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
251         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
252         MPI_Comm getIntraComm(void) {return intraComm_ ;}
253         int getIntraCommRank(void) {return intraCommRank_;}
254         int getIntraCommSize(void) {return intraCommSize_;}
255
256         void addCouplingChanel(const std::string& contextId, bool out) ;
257
258      public :
259         // Calendar of context
260         std::shared_ptr<CCalendar>   calendar;
261
262         // List of all enabled files (files on which fields are written or read)
263         std::vector<CFile*> enabledFiles;
264         // List of all enabled files in read mode (files on which fields are read)
265         std::vector<CFile*> enabledReadModeFiles;
266         // List of all enabled files in write mode
267         std::vector<CFile*> enabledWriteModeFiles;
268
269         std::vector<CCouplerIn*> enabledCouplerIn;
270         std::vector<CCouplerOut*> enabledCouplerOut;
271
272
273         // List of all enabled fields whose instant data is accessible from the public API
274         // but which are not part of a file
275         std::vector<CField*> fieldsWithReadAccess_;
276
277         // Context root
278         static std::shared_ptr<CContextGroup> root;
279
280         // Determine context on client or not
281         bool hasClient;
282
283         // Determine context on server or not
284         bool hasServer;
285
286         CContextServer* server;    //!< Concrete context server
287         CContextClient* client;    //!< Concrete contex client
288         std::vector<CContextServer*> serverPrimServer;
289         std::vector<CContextClient*> clientPrimServer;
290         std::map<std::string, CContextClient*> couplerClient_ ;
291         std::map<std::string, CContextServer*> couplerServer_ ;
292
293
294         std::vector<std::string> primServerId_;
295
296         CRegistry* registryIn ;    //!< input registry which is read from file
297         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
298
299
300        MPI_Comm intraComm_ ; //! context intra communicator
301        int intraCommRank_ ; //! context intra communicator rank
302        int intraCommSize_ ; //! context intra communicator size
303       
304      private:
305         bool isPostProcessed;
306         bool allProcessed;
307         bool finalized;
308         int countChildContextFinalized_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
309         CGarbageCollector garbageCollector;
310         std::list<MPI_Comm> comms; //!< Communicators allocated internally
311
312         int serviceType_;  //!< service associated to the context
313         string contextId_ ; //!< context client id for the servers. For clients this is same as getId()
314         bool isProcessingEvent_ ;
315         CServerContext* parentServerContext_ ;
316
317      public: // Some function maybe removed in the near future
318        // virtual void toBinary  (StdOStream & os) const;
319        // virtual void fromBinary(StdIStream & is);
320   }; // class CContext
321
322   ///--------------------------------------------------------------
323
324   // Declare/Define CContextGroup and CContextDefinition
325   DECLARE_GROUP(CContext);
326
327   ///--------------------------------------------------------------
328
329} // namespace xios
330
331#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.