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

Last change on this file since 2338 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
RevLine 
[591]1#ifndef __XIOS_CAxis__
2#define __XIOS_CAxis__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "group_factory.hpp"
[619]7#include "virtual_node.hpp"
[219]8
9#include "declare_group.hpp"
[540]10#include "declare_ref_func.hpp"
[619]11#include "declare_virtual_node.hpp"
[369]12#include "attribute_array.hpp"
[399]13#include "attribute_enum.hpp"
14#include "attribute_enum_impl.hpp"
[567]15#include "server_distribution_description.hpp"
[619]16#include "transformation.hpp"
17#include "transformation_enum.hpp"
[1984]18#include "transformation_path.hpp"
[1918]19#include "element.hpp"
20#include "local_connector.hpp"
[1930]21#include "scatterer_connector.hpp"
22#include "gatherer_connector.hpp"
23#include "distribution_type.hpp"
[1984]24#include "generic_algorithm_transformation.hpp"
[2274]25#include "grid_transformation_factory_impl.hpp"
[219]26
[1930]27
[1984]28namespace xios
29{
[219]30   /// ////////////////////// Déclarations ////////////////////// ///
31
32   class CAxisGroup;
33   class CAxisAttributes;
34   class CAxis;
[2206]35   class CField;
[219]36
37   ///--------------------------------------------------------------
38
39   // Declare/Define CAxisAttribute
40   BEGIN_DECLARE_ATTRIBUTE_MAP(CAxis)
[231]41#  include "axis_attribute.conf"
[219]42   END_DECLARE_ATTRIBUTE_MAP(CAxis)
43
44   ///--------------------------------------------------------------
45
46   class CAxis
47      : public CObjectTemplate<CAxis>
48      , public CAxisAttributes
49   {
[987]50               /// typedef ///
51         typedef CObjectTemplate<CAxis>   SuperClass;
52         typedef CAxisAttributes SuperClassAttribute;
53         
[1235]54      public:
[567]55         enum EEventId
56         {
[2326]57           EVENT_ID_COLLECTIVE=100,
[1930]58           EVENT_ID_AXIS_DISTRIBUTION,
[2326]59           EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE,
60           EVENT_ID_NO_COLLECTIVE=1000,
[567]61         } ;
62
[1235]63      public:
[219]64         typedef CAxisAttributes RelAttributes;
65         typedef CAxisGroup      RelGroup;
66
[621]67      public:
[219]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.
[2274]73         static void releaseStaticAllocation(void) ; // release static allocation on heap
[219]74
[622]75         static CAxis* createAxis();
[2206]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) ;
[1158]79
80         /// Accesseurs ///
81         const std::set<StdString> & getRelFiles(void) const;
[1975]82 
[1371]83         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
84                                                        CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
[731]85
[219]86         /// Test ///
87         bool IsWritten(const StdString & filename) const;
[676]88         bool isWrittenCompressed(const StdString& filename) const;
[594]89         bool isDistributed(void) const;
[1956]90       
[1984]91      public:
[1956]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_ ;} 
[1984]98      private:
[1956]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       
[1984]103      public:
[219]104
105         /// Mutateur ///
106         void addRelFile(const StdString & filename);
[676]107         void addRelFileCompressed(const StdString& filename);
[219]108
[1869]109         
[219]110
111         /// Destructeur ///
112         virtual ~CAxis(void);
113
[619]114         virtual void parse(xml::CXMLNode & node);
115
[1345]116         void setContextClient(CContextClient* contextClient);
117
[219]118         /// Accesseurs statiques ///
119         static StdString GetName(void);
120         static StdString GetDefName(void);
121         static ENodeType GetType(void);
122
[1235]123         static bool dispatchEvent(CEventServer& event);         
[1869]124       
125         /// Vérifications ///
126         void checkAttributes(void);
127         bool checkAttributes_done_ = false ;
[2291]128         bool checkGeometricAttributes(bool generateError) ; 
129         void setGeometricAttributes(const CAxis& axisSrc) ;
130         void resetGeometricAttributes(void) ;
[619]131
[1215]132         size_t getGlobalWrittenSize(void) ;
[676]133
[1984]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 ;
[2206]156      public:
157        bool activateFieldWorkflow(CGarbageCollector& gc) ;
[1984]158      private:
[2206]159        bool activateFieldWorkflow_done_=false ;
160      private:
[2270]161        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
[1984]162      public:
[2270]163        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
164        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
[1984]165      private:
166        CTransformationPaths transformationPaths_ ;
167      public:
168        CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} 
169        void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;}
170
171      ////////////////////////////
[1158]172         bool isEqual(CAxis* axis);
[619]173
[1235]174      public: 
175        bool hasValue;       
[1558]176        bool hasBounds;
177        bool hasLabel;
178
[1984]179      private:
[2291]180         bool checkData(bool generateError);
181         bool checkMask(bool generateError);
182         bool checkBounds(bool generateError);
183         bool checkLabel(bool generateError);
[1870]184     
[1875]185      public:
186         void sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) ;
[1870]187      private:
[1875]188         std::set<CContextClient*> sendAxisToCouplerOut_done_ ;
189   
190      public:
191         void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
[2022]192         string getCouplingAlias(const string& fieldId, int posInGrid) ;
[1875]193
[567]194      private:
[1345]195
[1875]196/** Clients that have to send a axis. There can be multiple clients in case of secondary server, otherwise only one client. */
[1353]197         std::list<CContextClient*> clients;
198         std::set<CContextClient*> clientsSet;
[1345]199
[1875]200      private:
[1869]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 ; 
[1875]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_ ;
[2282]216
217           MISSING_RETURN( "bool CAxis::isCompleted() " );
218           return true;
[1875]219         }
220         void setCompleted(void) { isCompleted_=true ; }
221         void unsetCompleted(void) { isCompleted_=false ; }
222     
223      private:
[219]224         bool isChecked;
[676]225         std::set<StdString> relFiles, relFilesCompressed;
[1984]226          std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server
[1337]227         std::map<int, std::vector<int> > connectedServerRank_;
[1099]228
[1930]229       //////////////////////////////////////////////////////////////////////////////////////
230       //  this part is related to distribution, element definition, views and connectors  //
231       //////////////////////////////////////////////////////////////////////////////////////
[1918]232         
233        private:
[2267]234         shared_ptr<CLocalElement> localElement_ ;
[1918]235         void initializeLocalElement(void) ;
236        public: 
[2267]237         shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
238         shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
[1918]239        private:
240         void addFullView(void) ;
241         void addWorkflowView(void) ;
242         void addModelView(void) ;
243
244        private:
[2267]245         shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
[1918]246         void computeModelToWorkflowConnector(void)  ;
247        public:
[2267]248         shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
[1930]249       
250       public:
251         void computeRemoteElement(CContextClient* client, EDistributionType) ;
[2304]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="") ;
[1918]254
[1930]255         static void recvAxisDistribution(CEventServer& event) ;
256         void receivedAxisDistribution(CEventServer& event, int phasis) ;
[1943]257         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client ) ;
[2267]258         void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scattererConnector, const string& axisId) ;
[1930]259         static void recvDistributedAttributes(CEventServer& event) ;
260         void recvDistributedAttributes(CEventServer& event, const string& type) ;
261       private:
[2267]262         map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
[1930]263       public: 
[2267]264         shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
[1930]265       private:
[2267]266         map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
[1930]267       public: 
[2267]268         shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
[1930]269       private:
[2267]270         shared_ptr<CGathererConnector>  gathererConnector_ ;
[1943]271       public:
[2267]272         shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
[1943]273       private:
[2267]274         shared_ptr<CGathererConnector> serverFromClientConnector_ ;
275         shared_ptr<CDistributedElement> elementFrom_ ;
[1930]276       public:
[2267]277        shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
[1930]278
[1934]279       private:
[2267]280         shared_ptr<CScattererConnector> serverToClientConnector_ = nullptr ;
[2304]281         shared_ptr<CDistributedElement> elementTo_ ;
[1934]282       public: 
[2267]283         shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
[1930]284
[1934]285       private:
[2267]286          map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
[1934]287       public: 
[2267]288        shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
[1930]289
[540]290         DECLARE_REF_FUNC(Axis,axis)
[219]291   }; // class CAxis
292
293   ///--------------------------------------------------------------
294
295   // Declare/Define CAxisGroup and CAxisDefinition
296   DECLARE_GROUP(CAxis);
[335]297} // namespace xios
[219]298
[591]299#endif // __XIOS_CAxis__
Note: See TracBrowser for help on using the repository browser.