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

Last change on this file since 2326 was 2326, checked in by ymipsl, 2 years ago

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