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

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

Two-level server: merging new grid functionalities and changes in the communication protocol (e.g. non-blocking context finalize, registries, oasis).

Tests on curie: test_client, test_complete, nemo (test_xios2_cmip6.exe).

To do: non-structured grid, check reading, possible bug in client/server initialization (?).

  • 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: 9.8 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 "context_client.hpp"
11//#include "context_server.hpp"
12#include "data_output.hpp"
[639]13#include "garbage_collector.hpp"
[697]14#include "registry.hpp"
[382]15#include "mpi.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;
[219]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   ///--------------------------------------------------------------
[509]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  */
[219]44   class CContext
45      : public CObjectTemplate<CContext>
46      , public CContextAttributes
47   {
[300]48         public :
49         enum EEventId
50         {
51           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
[509]52           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
[1025]53           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
54           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
55           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
[549]56         };
[509]57
[219]58         /// typedef ///
59         typedef CObjectTemplate<CContext>   SuperClass;
60         typedef CContextAttributes SuperClassAttribute;
61
62      public :
63
64         typedef CContextAttributes RelAttributes;
65         typedef CContext           RelGroup;
66
67         //---------------------------------------------------------
68
69      public :
70
71         /// Constructeurs ///
72         CContext(void);
73         explicit CContext(const StdString & id);
74         CContext(const CContext & context);       // Not implemented yet.
75         CContext(const CContext * const context); // Not implemented yet.
76
77         /// Destructeur ///
78         virtual ~CContext(void);
79
80         //---------------------------------------------------------
81
82      public :
[509]83
[219]84         /// Mutateurs ///
[343]85         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
[509]86
[219]87         /// Accesseurs ///
[343]88         boost::shared_ptr<CCalendar>      getCalendar(void) const;
[219]89
90      public :
[509]91         // Initialize server or client
[983]92         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
[597]93         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
[549]94         bool isInitialized(void);
[219]95
[509]96         // Put sever or client into loop state
[597]97         bool checkBuffersAndListen(void);
98
[509]99         // Finalize a context
[549]100         void finalize(void);
[1130]101         void postFinalize(void);
[1071]102         bool isFinalized(void);
[509]103
[1130]104         void closeDefinition(void);
105
[509]106         // Some functions to process context
[300]107         void findAllEnabledFields(void);
[775]108         void findAllEnabledFieldsInReadModeFiles(void);
109         void readAttributesOfEnabledFieldsInReadModeFiles();
[549]110         void solveAllInheritance(bool apply=true);
[300]111         void findEnabledFiles(void);
[598]112         void findEnabledReadModeFiles(void);
[549]113         void closeAllFile(void);
114         void updateCalendar(int step);
115         void createFileHeader(void );
[676]116         void checkAxisDomainsGridsEligibilityForCompressedOutput();
[711]117         void prepareTimeseries(void);
[1129]118         void solveOnlyRefOfEnabledFields(bool sendToServer);         
[640]119         void buildFilterGraphOfEnabledFields();
[598]120         void startPrefetchingOfEnabledReadModeFiles();
121         void checkPrefetchingOfEnabledReadModeFiles();
[593]122         void findFieldsWithReadAccess(void);
123         void solveAllRefOfFieldsWithReadAccess();
[640]124         void buildFilterGraphOfFieldsWithReadAccess();
[509]125         void postProcessing();
[1025]126         void postProcessingGlobalAttributes();         
[509]127
[1129]128         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
[1025]129         void solveAllEnabledFields();
[1099]130         void checkGridEnabledFields();
131         void sendGridEnabledFields();
[1025]132
[917]133         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize);
134         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize);
[509]135         void setClientServerBuffer();
136
137         // Send context close definition
[549]138         void sendCloseDefinition(void);
[509]139         // There are something to send on closing context defintion
[549]140         void sendUpdateCalendar(int step);
141         void sendCreateFileHeader(void);
[509]142         void sendEnabledFiles();
143         void sendEnabledFields();
144         void sendRefDomainsAxis();
145         void sendRefGrid();
146         void sendPostProcessing();
[1025]147         void sendPostProcessingGlobalAttributes();
148         void sendProcessingGridOfEnabledFields();
[983]149         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
150         void sendRegistry(void) ;
151
[511]152         const StdString& getIdServer();
[1009]153         const StdString& getIdServer(const int srvPoolNb);
[511]154
[509]155         // Client side: Receive and process messages
[549]156         static void recvUpdateCalendar(CEventServer& event);
157         void recvUpdateCalendar(CBufferIn& buffer);
158         static void recvCloseDefinition(CEventServer& event);
159         static void recvCreateFileHeader(CEventServer& event);
160         void recvCreateFileHeader(CBufferIn& buffer);
[509]161         static void recvSolveInheritanceContext(CEventServer& event);
162         void recvSolveInheritanceContext(CBufferIn& buffer);
163         static void recvPostProcessing(CEventServer& event);
164         void recvPostProcessing(CBufferIn& buffer);
[1025]165         static void recvProcessingGridOfEnabledFields(CEventServer& event);
166         static void recvPostProcessingGlobalAttributes(CEventServer& event);
167         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
[697]168         static void recvRegistry(CEventServer& event) ;
[983]169         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
[509]170
[1130]171         void freeComms(void);                  //!< Free internally allcoated communicators
172         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
[1054]173
[509]174         // dispatch event
[549]175         static bool dispatchEvent(CEventServer& event);
[509]176
177      public:
178        // Get current context
179        static CContext* getCurrent(void);
180
181        // Get context root
182        static CContextGroup* getRoot(void);
183
184        // Set current context
185        static void setCurrent(const string& id);
186
187        // Create new context
188        static CContext* create(const string& id = "");
189
190        /// Accesseurs statiques ///
191        static StdString GetName(void);
192        static StdString GetDefName(void);
193        static ENodeType GetType(void);
194
195        static CContextGroup* GetContextGroup(void);
196
197        // Some functions to visualize structure of current context
198        static void ShowTree(StdOStream & out = std::clog);
199        static void CleanTree(void);
200
[219]201      public :
[509]202         // Parse xml node and write all info into context
[219]203         virtual void parse(xml::CXMLNode & node);
204
[509]205         // Visualize a context
[219]206         virtual StdString toString(void) const;
[509]207
208
209         // Solve all inheritance relation in current context
210         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
211
212         // Verify if all root definition in a context have children
213         virtual bool hasChild(void) const;
214
[1054]215
[300]216      public :
[509]217         // Calendar of context
218         boost::shared_ptr<CCalendar>   calendar;
219
[598]220         // List of all enabled files (files on which fields are written or read)
[347]221         std::vector<CFile*> enabledFiles;
[598]222         // List of all enabled files in read mode (files on which fields are read)
223         std::vector<CFile*> enabledReadModeFiles;
[509]224
[740]225         // List of all enabled fields whose instant data is accessible from the public API
226         // but which are not part of a file
[593]227         std::vector<CField*> fieldsWithReadAccess;
228
[509]229         // Context root
[549]230         static shared_ptr<CContextGroup> root;
[219]231
[509]232         // Determine context on client or not
[549]233         bool hasClient;
[300]234
[509]235         // Determine context on server or not
[549]236         bool hasServer;
[509]237
[1130]238         CContextServer* server;    //!< Concrete context server
239         CContextClient* client;    //!< Concrete contex client
[1071]240         std::vector<CContextServer*> serverPrimServer;
241         std::vector<CContextClient*> clientPrimServer;
242
[1130]243         CRegistry* registryIn ;    //!< input registry which is read from file
244         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
[775]245
[509]246      private:
247         bool isPostProcessed;
[1025]248         bool allProcessed;
[1130]249//         bool finalized;
250         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
[511]251         StdString idServer_;
[639]252         CGarbageCollector garbageCollector;
[1071]253         std::list<MPI_Comm> comms; //!< Communicators allocated internally
[509]254
255      public: // Some function maybe removed in the near future
256        // virtual void toBinary  (StdOStream & os) const;
257        // virtual void fromBinary(StdIStream & is);
[219]258   }; // class CContext
259
260   ///--------------------------------------------------------------
261
262   // Declare/Define CContextGroup and CContextDefinition
263   DECLARE_GROUP(CContext);
264
265   ///--------------------------------------------------------------
266
[335]267} // namespace xios
[219]268
[591]269#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.