source: XIOS/dev/dev_trunk_graph/src/node/context.hpp @ 2019

Last change on this file since 2019 was 2019, checked in by yushan, 3 years ago

Graph intermedia commit to a tmp branch

  • 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: 15.3 KB
RevLine 
[591]1#ifndef __XIOS_CContext__
2#define __XIOS_CContext__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[352]6//#include "node_type.hpp"
[549]7#include "calendar_wrapper.hpp"
[219]8
9#include "declare_group.hpp"
[300]10#include "data_output.hpp"
[639]11#include "garbage_collector.hpp"
[697]12#include "registry.hpp"
[382]13#include "mpi.hpp"
[2019]14#include "services_manager.hpp"
15#include "server_context.hpp"
[300]16
[219]17
[335]18namespace xios {
[549]19   class CContextClient;
20   class CContextServer;
[509]21
22
[219]23   /// ////////////////////// Déclarations ////////////////////// ///
24   class CContextGroup;
25   class CContextAttributes;
26   class CContext;
[352]27   class CFile;
[2019]28   class CCouplerIn ;
29   class CCouplerOut ;
[219]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   ///--------------------------------------------------------------
[509]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  */
[219]46   class CContext
47      : public CObjectTemplate<CContext>
48      , public CContextAttributes
49   {
[300]50         public :
51         enum EEventId
52         {
53           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
[509]54           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
[2019]55           EVENT_ID_SEND_REGISTRY,
56           EVENT_ID_CONTEXT_FINALIZE_CLIENT,
57           EVENT_ID_COUPLER_IN_READY,
58           EVENT_ID_COUPLER_IN_CLOSE_DEFINITION,
59           EVENT_ID_COUPLER_IN_CONTEXT_FINALIZED,
[549]60         };
[509]61
[219]62         /// typedef ///
63         typedef CObjectTemplate<CContext>   SuperClass;
64         typedef CContextAttributes SuperClassAttribute;
65
66      public :
67
68         typedef CContextAttributes RelAttributes;
69         typedef CContext           RelGroup;
70
71         //---------------------------------------------------------
72
73      public :
74
75         /// Constructeurs ///
76         CContext(void);
77         explicit CContext(const StdString & id);
78         CContext(const CContext & context);       // Not implemented yet.
79         CContext(const CContext * const context); // Not implemented yet.
80
81         /// Destructeur ///
82         virtual ~CContext(void);
83
84         //---------------------------------------------------------
85
86      public :
[509]87
[219]88         /// Mutateurs ///
[1542]89         void setCalendar(std::shared_ptr<CCalendar> newCalendar);
[509]90
[219]91         /// Accesseurs ///
[1542]92         std::shared_ptr<CCalendar>      getCalendar(void) const;
[219]93
94      public :
[509]95         // Initialize server or client
[2019]96         void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
97         void initClient(MPI_Comm intraComm, int serviceType);
98         
99         void initServer(MPI_Comm intraComm, int serviceType );
100         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
101         void createServerInterComm(void)  ;
102
[549]103         bool isInitialized(void);
[219]104
[1612]105         StdString dumpClassAttributes(void);
106
[509]107         // Put sever or client into loop state
[2019]108         bool eventLoop(bool enableEventsProcessing=true);
109         void globalEventLoop(void);
[597]110
[509]111         // Finalize a context
[549]112         void finalize(void);
[2019]113
[1071]114         bool isFinalized(void);
[509]115
[1130]116         void closeDefinition(void);
117
[2019]118         // to be removed     
119         std::vector<CField*> findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
[509]120         // Some functions to process context
[2019]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);
[1232]125         // void findAllEnabledFields(void);
126         // void findAllEnabledFieldsInReadModeFiles(void);
[775]127         void readAttributesOfEnabledFieldsInReadModeFiles();
[549]128         void solveAllInheritance(bool apply=true);
[300]129         void findEnabledFiles(void);
[2019]130         void findEnabledCouplerIn(void);
131         void findEnabledCouplerOut(void);
132         void createCouplerInterCommunicator(void) ;
[1232]133         void findEnabledWriteModeFiles(void);
[598]134         void findEnabledReadModeFiles(void);
[549]135         void closeAllFile(void);
136         void updateCalendar(int step);
[1232]137         void createFileHeader(void);
138         void initReadFiles(void);
[711]139         void prepareTimeseries(void);
[1358]140         void postProcessFilterGraph();
[598]141         void startPrefetchingOfEnabledReadModeFiles();
[1358]142         void doPreTimestepOperationsForEnabledReadModeFiles();
[1318]143         void doPostTimestepOperationsForEnabledReadModeFiles();
[593]144         void findFieldsWithReadAccess(void);
[2019]145         void triggerLateFields(void) ;
146         
[1330]147         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
148         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
[2019]149         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false); // old interface to be removed
150         void setClientServerBuffer(vector<CField*>& fields, bool bufferForWriting) ; 
[509]151
[1212]152         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
[2019]153         void distributeFiles(const std::vector<CFile*>& files);
154         void distributeFileOverBandwith(const std::vector<CFile*>& files) ;
155         void distributeFileOverMemoryBandwith(const std::vector<CFile*>& files) ;
[1349]156         
[509]157         // Send context close definition
[549]158         void sendCloseDefinition(void);
[2019]159       public:
160         void sendCloseDefinition(CContextClient* client) ;
161       private:
162         set<CContextClient*> sendCloseDefinition_done_ ;
163       public:
[509]164         // There are something to send on closing context defintion
[549]165         void sendUpdateCalendar(int step);
166         void sendCreateFileHeader(void);
[1232]167         void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
168         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
169         void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles);
[983]170         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
171         void sendRegistry(void) ;
[2019]172         void sendFinalizeClient(CContextClient* contextClient, const string& contextClientId);
173         
174         public:
175         void sendContextToFileServer(CContextClient* client) ;
176         private:
177         std::set<CContextClient*> sendToFileServer_done_ ;
178         
179         public: 
180         std::string getContextId() {return contextId_;}
[983]181
[509]182         // Client side: Receive and process messages
[549]183         static void recvUpdateCalendar(CEventServer& event);
184         void recvUpdateCalendar(CBufferIn& buffer);
185         static void recvCloseDefinition(CEventServer& event);
186         static void recvCreateFileHeader(CEventServer& event);
187         void recvCreateFileHeader(CBufferIn& buffer);
[509]188         static void recvSolveInheritanceContext(CEventServer& event);
189         void recvSolveInheritanceContext(CBufferIn& buffer);
[697]190         static void recvRegistry(CEventServer& event) ;
[983]191         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
[2019]192         static void recvFinalizeClient(CEventServer& event) ;
193         void recvFinalizeClient(CBufferIn& buffer);
194       
195       public:
196         void sendCouplerInReady(CContextClient* client);
197       private:
198         set<CContextClient*> sendCouplerInReady_done_;
199       public:
200         static void recvCouplerInReady(CEventServer& event) ;
201         void recvCouplerInReady(CBufferIn& buffer) ; //!< coupler is ready to receive grid definition.
202         set<CContextClient*> couplerInReady_;
203         bool isCouplerInReady(CContextClient* client) { return couplerInReady_.count(client)!=0 ;}
[509]204
[2019]205       public:
206        void sendCouplerInCloseDefinition(CContextClient* client) ;
207        set<CContextClient*> sendCouplerInCloseDefinition_done_;
208        static void recvCouplerInCloseDefinition(CEventServer& event) ;
209        void recvCouplerInCloseDefinition(CBufferIn& buffer) ; //!< coupler has finished it defintion, data can be sent     
210        set<CContextClient*> couplerInCloseDefinition_ ;
211        bool isCouplerInCloseDefinition(CContextClient* client) { return couplerInCloseDefinition_.count(client)!=0 ;}
[1054]212
[2019]213       public:
214        void sendCouplerInContextFinalized(CContextClient* client) ;
215        set<CContextClient*> sendCouplerInContextFinalized_done_;
216        static void recvCouplerInContextFinalized(CEventServer& event) ;
217        void recvCouplerInContextFinalized(CBufferIn& buffer) ; //!< coupler has finished it defintion, data can be sent     
218        set<CContextClient*> couplerInContextFinalized_ ;
219        bool isCouplerInContextFinalized(CContextClient* client) { return couplerInContextFinalized_.count(client)!=0 ;}
220
221       public: 
222        void freeComms(void);                  //!< Free internally allcoated communicators
223        void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
224
[509]225         // dispatch event
[549]226         static bool dispatchEvent(CEventServer& event);
[509]227
228      public:
229        // Get current context
230        static CContext* getCurrent(void);
231
232        // Get context root
233        static CContextGroup* getRoot(void);
234
235        // Set current context
236        static void setCurrent(const string& id);
237
238        // Create new context
239        static CContext* create(const string& id = "");
240
241        /// Accesseurs statiques ///
242        static StdString GetName(void);
243        static StdString GetDefName(void);
244        static ENodeType GetType(void);
245
246        static CContextGroup* GetContextGroup(void);
247
248        // Some functions to visualize structure of current context
249        static void ShowTree(StdOStream & out = std::clog);
250        static void CleanTree(void);
[2019]251        int getServiceType(void) {return serviceType_;}
[509]252
[219]253      public :
[509]254         // Parse xml node and write all info into context
[219]255         virtual void parse(xml::CXMLNode & node);
256
[509]257         // Visualize a context
[219]258         virtual StdString toString(void) const;
[509]259
260
261         // Solve all inheritance relation in current context
262         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
263
264         // Verify if all root definition in a context have children
265         virtual bool hasChild(void) const;
266
[2019]267         bool isProcessingEvent(void) {return isProcessingEvent_;}
268         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
269         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
270         MPI_Comm getIntraComm(void) {return intraComm_ ;}
271         int getIntraCommRank(void) {return intraCommRank_;}
272         int getIntraCommSize(void) {return intraCommSize_;}
[1054]273
[2019]274         void addCouplingChanel(const std::string& contextId, bool out) ;
275
[300]276      public :
[509]277         // Calendar of context
[1542]278         std::shared_ptr<CCalendar>   calendar;
[509]279
[598]280         // List of all enabled files (files on which fields are written or read)
[347]281         std::vector<CFile*> enabledFiles;
[598]282         // List of all enabled files in read mode (files on which fields are read)
283         std::vector<CFile*> enabledReadModeFiles;
[1208]284         // List of all enabled files in write mode
285         std::vector<CFile*> enabledWriteModeFiles;
[509]286
[2019]287         std::vector<CCouplerIn*> enabledCouplerIn;
288         std::vector<CCouplerOut*> enabledCouplerOut;
289
290
[740]291         // List of all enabled fields whose instant data is accessible from the public API
292         // but which are not part of a file
[2019]293         std::vector<CField*> fieldsWithReadAccess_;
294         std::vector<CField*> couplerInFields_;
295         std::vector<CField*> fileInFields_;
[593]296
[2019]297
[509]298         // Context root
[1542]299         static std::shared_ptr<CContextGroup> root;
[219]300
[509]301         // Determine context on client or not
[549]302         bool hasClient;
[300]303
[509]304         // Determine context on server or not
[549]305         bool hasServer;
[509]306
[1130]307         CContextServer* server;    //!< Concrete context server
308         CContextClient* client;    //!< Concrete contex client
[1071]309         std::vector<CContextServer*> serverPrimServer;
310         std::vector<CContextClient*> clientPrimServer;
311
[2019]312         // list of slave servers (IO server or others)
313         set<CContextClient*> slaveServers_ ;
314      private:
315         // the map containing context client associated to it string id for coupling out ;
316         std::map<std::string, CContextClient*> couplerOutClient_ ;
317         // the map containing context server associated to it string id for coupling out ;
318         std::map<std::string, CContextServer*> couplerOutServer_ ;
319         // the map containing context client associated to it string id for coupling in ;
320         std::map<std::string, CContextClient*> couplerInClient_ ;
321         // the map containing context server associated to it string id for coupling in ;
322         std::map<std::string, CContextServer*> couplerInServer_ ;
323      public:
324         CContextClient* getCouplerInClient(const string& contextId) { return couplerInClient_[contextId] ;}
325         CContextServer* getCouplerInServer(const string& contextId) { return couplerInServer_[contextId] ;}
326         CContextClient* getCouplerOutClient(const string& contextId) { return couplerOutClient_[contextId] ;}
327         CContextServer* getCouplerOutServer(const string& contextId) { return couplerOutServer_[contextId] ;}
328     
329 
330         std::vector<std::string> primServerId_;
331
[1130]332         CRegistry* registryIn ;    //!< input registry which is read from file
333         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
[775]334
[2019]335
336        MPI_Comm intraComm_ ; //! context intra communicator
337        int intraCommRank_ ; //! context intra communicator rank
338        int intraCommSize_ ; //! context intra communicator size
339       
[509]340      private:
341         bool isPostProcessed;
[1025]342         bool allProcessed;
[1139]343         bool finalized;
[2019]344         int countChildContextFinalized_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
[639]345         CGarbageCollector garbageCollector;
[1071]346         std::list<MPI_Comm> comms; //!< Communicators allocated internally
[509]347
[2019]348         int serviceType_;  //!< service associated to the context
349         string contextId_ ; //!< context client id for the servers. For clients this is same as getId()
350         bool isProcessingEvent_ ;
351         CServerContext* parentServerContext_ ;
352
[509]353      public: // Some function maybe removed in the near future
354        // virtual void toBinary  (StdOStream & os) const;
355        // virtual void fromBinary(StdIStream & is);
[219]356   }; // class CContext
357
358   ///--------------------------------------------------------------
359
360   // Declare/Define CContextGroup and CContextDefinition
361   DECLARE_GROUP(CContext);
362
363   ///--------------------------------------------------------------
364
[335]365} // namespace xios
[219]366
[591]367#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.