source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.hpp @ 2270

Last change on this file since 2270 was 2270, checked in by ymipsl, 3 years ago

Tracking memory leak :
Tranformations and algorithms are now managed with shared_ptr.

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
  • Property svn:executable set to *
File size: 11.7 KB
Line 
1#ifndef __XIOS_CAxis__
2#define __XIOS_CAxis__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "group_factory.hpp"
7#include "virtual_node.hpp"
8
9#include "declare_group.hpp"
10#include "declare_ref_func.hpp"
11#include "declare_virtual_node.hpp"
12#include "attribute_array.hpp"
13#include "attribute_enum.hpp"
14#include "attribute_enum_impl.hpp"
15#include "server_distribution_description.hpp"
16#include "transformation.hpp"
17#include "transformation_enum.hpp"
18#include "transformation_path.hpp"
19#include "element.hpp"
20#include "local_connector.hpp"
21#include "scatterer_connector.hpp"
22#include "gatherer_connector.hpp"
23#include "distribution_type.hpp"
24#include "generic_algorithm_transformation.hpp"
25
26
27namespace xios
28{
29   /// ////////////////////// Déclarations ////////////////////// ///
30
31   class CAxisGroup;
32   class CAxisAttributes;
33   class CAxis;
34   class CField;
35
36   ///--------------------------------------------------------------
37
38   // Declare/Define CAxisAttribute
39   BEGIN_DECLARE_ATTRIBUTE_MAP(CAxis)
40#  include "axis_attribute.conf"
41   END_DECLARE_ATTRIBUTE_MAP(CAxis)
42
43   ///--------------------------------------------------------------
44
45   class CAxis
46      : public CObjectTemplate<CAxis>
47      , public CAxisAttributes
48   {
49               /// typedef ///
50         typedef CObjectTemplate<CAxis>   SuperClass;
51         typedef CAxisAttributes SuperClassAttribute;
52         
53      public:
54         enum EEventId
55         {
56           EVENT_ID_AXIS_DISTRIBUTION,
57           EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE
58         } ;
59
60      public:
61         typedef CAxisAttributes RelAttributes;
62         typedef CAxisGroup      RelGroup;
63
64      public:
65         /// Constructeurs ///
66         CAxis(void);
67         explicit CAxis(const StdString & id);
68         CAxis(const CAxis & axis);       // Not implemented yet.
69         CAxis(const CAxis * const axis); // Not implemented yet.
70
71         static CAxis* createAxis();
72         static CAxis* get(const string& id, bool noError=false) ; //<! return axis pointer using id
73         static bool has(const string& id) ; //<! return domain pointer using id
74         static CField*  getFieldFromId(const string& id) ;
75
76         /// Accesseurs ///
77         const std::set<StdString> & getRelFiles(void) const;
78 
79         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
80                                                        CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
81
82         /// Test ///
83         bool IsWritten(const StdString & filename) const;
84         bool isWrittenCompressed(const StdString& filename) const;
85         bool isDistributed(void) const;
86       
87      public:
88        /*!
89            \brief return if the axis can be written or not in a compressed way.
90            ie if there are some masked or indexed point on the domain. Valid only on server side.
91            \return true if domain can be writtedn in a compressed way
92         */ 
93         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
94      private:
95         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
96         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
97         void computeIsCompressible() ;
98       
99      public:
100
101         /// Mutateur ///
102         void addRelFile(const StdString & filename);
103         void addRelFileCompressed(const StdString& filename);
104
105         
106
107         /// Destructeur ///
108         virtual ~CAxis(void);
109
110         virtual void parse(xml::CXMLNode & node);
111
112         void setContextClient(CContextClient* contextClient);
113
114         /// Accesseurs statiques ///
115         static StdString GetName(void);
116         static StdString GetDefName(void);
117         static ENodeType GetType(void);
118
119         static bool dispatchEvent(CEventServer& event);         
120       
121         /// Vérifications ///
122         void checkAttributes(void);
123         bool checkAttributes_done_ = false ;
124
125         size_t getGlobalWrittenSize(void) ;
126
127      //////////////////////////
128      ///// transformations ////
129      //////////////////////////
130      public:
131        typedef CTransformation<CAxis>::TransformationMapTypes TransMapTypes;
132      private:
133        static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
134        static std::map<StdString, ETranformationType> transformationMapList_;
135        static bool dummyTransformationMapList_;
136        TransMapTypes transformationMap_;         
137
138      public:
139        CTransformation<CAxis>* addTransformation(ETranformationType transType, const StdString& id="");
140        CTransformation<CAxis>* addTransformation(ETranformationType transType, CTransformation<CAxis>* transformation) ;
141        void setTransformations(const TransMapTypes&);         
142        void duplicateTransformation(CAxis*);
143        TransMapTypes getAllTransformations();
144        bool hasTransformation();
145        void solveInheritanceTransformation_old(); // to remove later
146        void solveInheritanceTransformation();
147      private:
148        bool solveInheritanceTransformation_done_= false ;
149      public:
150        bool activateFieldWorkflow(CGarbageCollector& gc) ;
151      private:
152        bool activateFieldWorkflow_done_=false ;
153      private:
154        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
155      public:
156        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
157        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
158      private:
159        CTransformationPaths transformationPaths_ ;
160      public:
161        CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} 
162        void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;}
163
164      ////////////////////////////
165         bool isEqual(CAxis* axis);
166
167      public: 
168        bool hasValue;       
169        bool hasBounds;
170        bool hasLabel;
171
172      private:
173         void checkData();
174         void checkMask();
175         void checkBounds();
176         void checkLabel();
177     
178      public:
179         void sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) ;
180      private:
181         std::set<CContextClient*> sendAxisToCouplerOut_done_ ;
182   
183      public:
184         void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
185         string getCouplingAlias(const string& fieldId, int posInGrid) ;
186
187      private:
188
189/** Clients that have to send a axis. There can be multiple clients in case of secondary server, otherwise only one client. */
190         std::list<CContextClient*> clients;
191         std::set<CContextClient*> clientsSet;
192
193      private:
194         /** define if the axis is completed or not ie all attributes have been received before in case
195             of grid reading from file or coupling */ 
196         bool isCompleted_=true ; 
197      public:     
198         /*!
199           \brief Check if a axis is completed
200           Before make any axis processing, we must be sure that all axis informations have
201           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
202           other context (coupling). So all direct reference of the axis (axis_ref) must be also completed
203           \return true if axis and axis reference are completed
204          */
205         bool isCompleted(void)
206         {
207           if (hasDirectAxisReference()) if (!getDirectAxisReference()->isCompleted()) return false;
208           else return isCompleted_ ;
209         }
210         void setCompleted(void) { isCompleted_=true ; }
211         void unsetCompleted(void) { isCompleted_=false ; }
212     
213      private:
214         bool isChecked;
215         std::set<StdString> relFiles, relFilesCompressed;
216          std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server
217         std::map<int, std::vector<int> > connectedServerRank_;
218
219       //////////////////////////////////////////////////////////////////////////////////////
220       //  this part is related to distribution, element definition, views and connectors  //
221       //////////////////////////////////////////////////////////////////////////////////////
222         
223        private:
224         shared_ptr<CLocalElement> localElement_ ;
225         void initializeLocalElement(void) ;
226        public: 
227         shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
228         shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
229        private:
230         void addFullView(void) ;
231         void addWorkflowView(void) ;
232         void addModelView(void) ;
233
234        private:
235         shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
236         void computeModelToWorkflowConnector(void)  ;
237        public:
238         shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
239       
240       public:
241         void computeRemoteElement(CContextClient* client, EDistributionType) ;
242         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, shared_ptr<CScattererConnector>& scattererConnector,
243                                 const string& axisId="") ;
244
245         static void recvAxisDistribution(CEventServer& event) ;
246         void receivedAxisDistribution(CEventServer& event, int phasis) ;
247         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client ) ;
248         void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scattererConnector, const string& axisId) ;
249         static void recvDistributedAttributes(CEventServer& event) ;
250         void recvDistributedAttributes(CEventServer& event, const string& type) ;
251       private:
252         map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
253       public: 
254         shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
255       private:
256         map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
257       public: 
258         shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
259       private:
260         shared_ptr<CGathererConnector>  gathererConnector_ ;
261       public:
262         shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
263       private:
264         shared_ptr<CGathererConnector> serverFromClientConnector_ ;
265         shared_ptr<CDistributedElement> elementFrom_ ;
266       public:
267        shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
268
269       private:
270         shared_ptr<CScattererConnector> serverToClientConnector_ = nullptr ;
271       public: 
272         shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
273
274       private:
275          map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
276       public: 
277        shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
278
279         DECLARE_REF_FUNC(Axis,axis)
280   }; // class CAxis
281
282   ///--------------------------------------------------------------
283
284   // Declare/Define CAxisGroup and CAxisDefinition
285   DECLARE_GROUP(CAxis);
286} // namespace xios
287
288#endif // __XIOS_CAxis__
Note: See TracBrowser for help on using the repository browser.