source: XIOS/dev/dev_trunk_omp/src/node/context.hpp @ 1646

Last change on this file since 1646 was 1646, checked in by yushan, 5 years ago

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

  • 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: 11.0 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 "mpi_std.hpp"
8#include "calendar_wrapper.hpp"
9
10#include "declare_group.hpp"
11#include "data_output.hpp"
12#include "garbage_collector.hpp"
13#include "registry.hpp"
14
15
16namespace xios {
17   class CContextClient;
18   class CContextServer;
19
20
21   /// ////////////////////// Déclarations ////////////////////// ///
22   class CContextGroup;
23   class CContextAttributes;
24   class CContext;
25   class CFile;
26   ///--------------------------------------------------------------
27
28   // Declare/Define CFileAttribute
29   BEGIN_DECLARE_ATTRIBUTE_MAP(CContext)
30#  include "context_attribute.conf"
31   END_DECLARE_ATTRIBUTE_MAP(CContext)
32
33   ///--------------------------------------------------------------
34  /*!
35  \class CContext
36   This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS
37   Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which
38   we can have access to each element.
39   In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed,
40   object of the class is created and its contains all information of other elements in the xml file.
41  */
42   class CContext
43      : public CObjectTemplate<CContext>
44      , public CContextAttributes
45   {
46         public :
47         enum EEventId
48         {
49           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
50           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
51           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
52           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
53           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
54         };
55
56         /// typedef ///
57         typedef CObjectTemplate<CContext>   SuperClass;
58         typedef CContextAttributes SuperClassAttribute;
59
60      public :
61
62         typedef CContextAttributes RelAttributes;
63         typedef CContext           RelGroup;
64
65         //---------------------------------------------------------
66
67      public :
68
69         /// Constructeurs ///
70         CContext(void);
71         explicit CContext(const StdString & id);
72         CContext(const CContext & context);       // Not implemented yet.
73         CContext(const CContext * const context); // Not implemented yet.
74
75         /// Destructeur ///
76         virtual ~CContext(void);
77
78         //---------------------------------------------------------
79
80      public :
81
82         /// Mutateurs ///
83         void setCalendar(std::shared_ptr<CCalendar> newCalendar);
84
85         /// Accesseurs ///
86         std::shared_ptr<CCalendar>      getCalendar(void) const;
87
88      public :
89         // Initialize server or client
90         void initClient(ep_lib::MPI_Comm intraComm, ep_lib::MPI_Comm interComm, CContext* cxtServer = 0);
91         void initServer(ep_lib::MPI_Comm intraComm, ep_lib::MPI_Comm interComm, CContext* cxtClient = 0);
92         bool isInitialized(void);
93
94         StdString dumpClassAttributes(void);
95
96         // Put sever or client into loop state
97         bool checkBuffersAndListen(bool enableEventsProcessing=true);
98
99         // Finalize a context
100         void finalize(void);
101         bool isFinalized(void);
102
103         void closeDefinition(void);
104
105         // Some functions to process context
106         void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
107         // void findAllEnabledFields(void);
108         // void findAllEnabledFieldsInReadModeFiles(void);
109         void readAttributesOfEnabledFieldsInReadModeFiles();
110         void solveAllInheritance(bool apply=true);
111         void findEnabledFiles(void);
112         void findEnabledWriteModeFiles(void);
113         void findEnabledReadModeFiles(void);
114         void closeAllFile(void);
115         void updateCalendar(int step);
116         void createFileHeader(void);
117         void initReadFiles(void);
118         void checkAxisDomainsGridsEligibilityForCompressedOutput();
119         void prepareTimeseries(void);
120         void solveOnlyRefOfEnabledFields(bool sendToServer);         
121         void buildFilterGraphOfEnabledFields();
122         void postProcessFilterGraph();
123         void startPrefetchingOfEnabledReadModeFiles();
124         void doPreTimestepOperationsForEnabledReadModeFiles();
125         void doPostTimestepOperationsForEnabledReadModeFiles();
126         void findFieldsWithReadAccess(void);
127         void solveAllRefOfFieldsWithReadAccess();
128         void buildFilterGraphOfFieldsWithReadAccess();
129         void postProcessing();
130         void postProcessingGlobalAttributes();         
131
132         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
133         void checkGridEnabledFields();
134         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
135         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
136         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
137
138         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
139         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
140         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false);
141
142         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
143         void distributeFiles(void);
144         void distributeFileOverBandwith() ;
145         void distributeFileOverMemoryBandwith() ;
146         
147
148         // Send context close definition
149         void sendCloseDefinition(void);
150         // There are something to send on closing context defintion
151         void sendUpdateCalendar(int step);
152         void sendCreateFileHeader(void);
153         void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
154         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
155         void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles);
156         void sendRefGrid(const std::vector<CFile*>& activeFiles);
157         void sendPostProcessing();
158         void sendPostProcessingGlobalAttributes();
159         void sendProcessingGridOfEnabledFields();
160         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
161         void sendRegistry(void) ;
162
163         const StdString& getIdServer();
164         const StdString& getIdServer(const int srvPoolNb);
165
166         // Client side: Receive and process messages
167         static void recvUpdateCalendar(CEventServer& event);
168         void recvUpdateCalendar(CBufferIn& buffer);
169         static void recvCloseDefinition(CEventServer& event);
170         static void recvCreateFileHeader(CEventServer& event);
171         void recvCreateFileHeader(CBufferIn& buffer);
172         static void recvSolveInheritanceContext(CEventServer& event);
173         void recvSolveInheritanceContext(CBufferIn& buffer);
174         static void recvPostProcessing(CEventServer& event);
175         void recvPostProcessing(CBufferIn& buffer);
176         static void recvProcessingGridOfEnabledFields(CEventServer& event);
177         static void recvPostProcessingGlobalAttributes(CEventServer& event);
178         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
179         static void recvRegistry(CEventServer& event) ;
180         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
181
182         void freeComms(void);                  //!< Free internally allcoated communicators
183         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
184
185         // dispatch event
186         static bool dispatchEvent(CEventServer& event);
187
188      public:
189        // Get current context
190        static CContext* getCurrent(void);
191
192        // Get context root
193        static CContextGroup* getRoot(void);
194
195        // Set current context
196        static void setCurrent(const string& id);
197
198        // Create new context
199        static CContext* create(const string& id = "");
200
201        /// Accesseurs statiques ///
202        static StdString GetName(void);
203        static StdString GetDefName(void);
204        static ENodeType GetType(void);
205
206        static CContextGroup* GetContextGroup(void);
207
208        // Some functions to visualize structure of current context
209        static void ShowTree(StdOStream & out = std::clog);
210        static void CleanTree(void);
211
212      public :
213         // Parse xml node and write all info into context
214         virtual void parse(xml::CXMLNode & node);
215
216         // Visualize a context
217         virtual StdString toString(void) const;
218
219
220         // Solve all inheritance relation in current context
221         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
222
223         // Verify if all root definition in a context have children
224         virtual bool hasChild(void) const;
225
226
227      public :
228         // Calendar of context
229         std::shared_ptr<CCalendar>   calendar;
230
231         // List of all enabled files (files on which fields are written or read)
232         std::vector<CFile*> enabledFiles;
233         // List of all enabled files in read mode (files on which fields are read)
234         std::vector<CFile*> enabledReadModeFiles;
235         // List of all enabled files in write mode
236         std::vector<CFile*> enabledWriteModeFiles;
237
238         // List of all enabled fields whose instant data is accessible from the public API
239         // but which are not part of a file
240         std::vector<CField*> fieldsWithReadAccess;
241
242         // Context root
243         static std::shared_ptr<CContextGroup> *root_ptr;
244         #pragma omp threadprivate(root_ptr)
245
246         // Determine context on client or not
247         bool hasClient;
248
249         // Determine context on server or not
250         bool hasServer;
251
252         CContextServer* server;    //!< Concrete context server
253         CContextClient* client;    //!< Concrete contex client
254         std::vector<CContextServer*> serverPrimServer;
255         std::vector<CContextClient*> clientPrimServer;
256
257         CRegistry* registryIn ;    //!< input registry which is read from file
258         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
259
260      private:
261         bool isPostProcessed;
262         bool allProcessed;
263         bool finalized;
264         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
265         StdString idServer_;
266         CGarbageCollector garbageCollector;
267         std::list<ep_lib::MPI_Comm> comms; //!< Communicators allocated internally
268
269      public: // Some function maybe removed in the near future
270        // virtual void toBinary  (StdOStream & os) const;
271        // virtual void fromBinary(StdIStream & is);
272   }; // class CContext
273
274   ///--------------------------------------------------------------
275
276   // Declare/Define CContextGroup and CContextDefinition
277   DECLARE_GROUP(CContext);
278
279   ///--------------------------------------------------------------
280
281} // namespace xios
282
283#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.