source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.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
File size: 14.3 KB
RevLine 
[591]1#ifndef __XIOS_CDomain__
2#define __XIOS_CDomain__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
[540]9#include "declare_ref_func.hpp"
[300]10#include "event_client.hpp"
11#include "event_server.hpp"
12#include "buffer_in.hpp"
[369]13#include "array_new.hpp"
14#include "attribute_array.hpp"
[449]15#include "attribute_enum.hpp"
[631]16#include "transformation.hpp"
17#include "transformation_enum.hpp"
[1984]18#include "transformation_path.hpp"
[1025]19#include "server_distribution_description.hpp"
[878]20#include "mesh.hpp"
[1918]21#include "element.hpp"
22#include "local_connector.hpp"
[1930]23#include "scatterer_connector.hpp"
[1918]24#include "gatherer_connector.hpp"
[1930]25#include "distribution_type.hpp"
[1984]26#include "generic_algorithm_transformation.hpp"
[878]27
[1930]28
[1984]29namespace xios
30{
[509]31
[219]32   /// ////////////////////// Déclarations ////////////////////// ///
33
34   class CDomainGroup;
35   class CDomainAttributes;
36   class CDomain;
[878]37   class CFile;
[2206]38   class CField ;
[219]39
40   ///--------------------------------------------------------------
41
42   // Declare/Define CDomainAttribute
43   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
44#  include "domain_attribute.conf"
[775]45#  include "domain_attribute_private.conf"
[219]46   END_DECLARE_ATTRIBUTE_MAP(CDomain)
47
48   ///--------------------------------------------------------------
49
50   class CDomain
51      : public CObjectTemplate<CDomain>
52      , public CDomainAttributes
53   {
[1158]54     /// typedef ///
55     typedef CObjectTemplate<CDomain>   SuperClass;
56     typedef CDomainAttributes SuperClassAttribute;
57     public:
[300]58         enum EEventId
59         {
[2326]60           EVENT_ID_COLLECTIVE=100,
61           EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE,
62           EVENT_ID_NO_COLLECTIVE=100,
[300]63         } ;
[509]64
[676]65      public:
[219]66
67         typedef CDomainAttributes RelAttributes;
68         typedef CDomainGroup      RelGroup;
[1984]69         
[219]70         /// Constructeurs ///
71         CDomain(void);
72         explicit CDomain(const StdString & id);
73         CDomain(const CDomain & domain);       // Not implemented yet.
74         CDomain(const CDomain * const domain); // Not implemented yet.
[2274]75         static void releaseStaticAllocation(void) ; // release static allocation on heap
76
[2203]77         static CDomain* createDomain();
[2206]78         static CDomain* get(const string& id, bool noError=false) ; //<! return domain pointer using id
79         static bool has(const string& id) ; //<! return domain pointer using id
80         static CField*  getFieldFromId(const string& id) ;
[219]81
[878]82         CMesh* mesh;
[924]83         void assignMesh(const StdString, const int);
[878]84       
[631]85         virtual void parse(xml::CXMLNode & node);
86
[1345]87         void setContextClient(CContextClient* contextClient);
88
[219]89         /// Vérifications ///
90         void checkAttributes(void);
[1869]91         bool checkAttributes_done_ = false ;
92
[1984]93         
94      //////////////////////////
95      ///// transformations ////
96      //////////////////////////
97      public:
98        typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
99      private:
100        static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
101        static std::map<StdString, ETranformationType> transformationMapList_;
102        static bool dummyTransformationMapList_;
103        TransMapTypes transformationMap_;         
104
105      public:
106        CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
107        CTransformation<CDomain>* addTransformation(ETranformationType transType, CTransformation<CDomain>* transformation) ;
108        void setTransformations(const TransMapTypes&);         
109        void duplicateTransformation(CDomain*);
110        TransMapTypes getAllTransformations();
111        bool hasTransformation();
112        void solveInheritanceTransformation_old(); // to remove later
113        void solveInheritanceTransformation();
114      private:
115        bool solveInheritanceTransformation_done_= false ;
[2206]116      public:
117        bool activateFieldWorkflow(CGarbageCollector& gc) ;
[1984]118      private:
[2206]119        bool activateFieldWorkflow_done_=false ;
120
121      private:
[2270]122        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
[1984]123      public:
[2270]124        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
125        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
[1984]126      private:
127        CTransformationPaths transformationPaths_ ;
128      public:
129        CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} 
130        void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;}
131
132      ////////////////////////////
133
[687]134         void redistribute(int nbLocalDomain);
[631]135
[1158]136      public:
137         const std::set<StdString> & getRelFiles(void) const;
[219]138         bool IsWritten(const StdString & filename) const;
[676]139         bool isWrittenCompressed(const StdString& filename) const;
[1144]140         
[1330]141         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
[731]142
[219]143         bool isEmpty(void) const;
[594]144         bool isDistributed(void) const;
[1956]145
146        public :
147         /*!
148            \brief return if the domain can be written or not in a compressed way.
149            ie if there are some masked or indexed point on the domain. Valid only on server side.
150            \return true if domain can be writtedn in a compressed way
151         */ 
152         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
153        private :
154         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
155         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
156         void computeIsCompressible() ;
157
158      public :
[1158]159         bool isEqual(CDomain* domain);
[1236]160
161         static bool dispatchEvent(CEventServer& event);
[1875]162     
163      private:
164         /** define if the domain is completed or not ie all attributes have been received before in case
165             of grid reading from file or coupling */ 
166         bool isCompleted_=true ; 
167      public:     
168        /*!
169           \brief Check if a domain is completed
170           Before make any domain processing, we must be sure that all domain informations have
171           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
172           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
173           \return true if domain and domain reference are completed
174          */
175         bool isCompleted(void)
176         {
177           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
178           else return isCompleted_ ;
[2282]179
180           MISSING_RETURN( "bool CDomain::isCompleted() " );
181           return true;
[1875]182         }
183         void setCompleted(void) { isCompleted_=true ; }
184         void unsetCompleted(void) { isCompleted_=false ; }
[1236]185
[676]186      public:
[219]187         /// Mutateur ///
188         void addRelFile(const StdString & filename);
[1236]189         void addRelFileCompressed(const StdString& filename);           
190         
[821]191         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
[809]192                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
[821]193
194         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
[809]195                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
[1158]196         
197         void fillInLonLat();
198         bool distributionAttributesHaveValue() const;
[611]199
[1215]200         size_t getGlobalWrittenSize() ;
[219]201         /// Destructeur ///
202         virtual ~CDomain(void);
203
204         /// Accesseurs statiques ///
205         static StdString GetName(void);
206         static StdString GetDefName(void);
[509]207
[1236]208         static ENodeType GetType(void);       
209
210      public:
211         CArray<double, 1> lonvalue, latvalue;
212         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
213         CArray<double, 1> areavalue;
214
215
[1311]216         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
217         CArray<bool, 1> localMask; // domainMask + indexing
[384]218         bool isCurvilinear ;
[449]219         bool hasBounds ;
[611]220         bool hasArea;
[665]221         bool hasLonLat;
[953]222         bool hasPole ;
[2312]223       
[1291]224         void computeLocalMask(void) ;
[1869]225     
226         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
[1974]227         private: std::set<int> listNbServer_ ;
[1869]228         
[631]229      private:
[667]230         void checkDomain(void);
231         void checkLocalIDomain(void);
232         void checkLocalJDomain(void);
233
234         void checkMask(void);
235         void checkDomainData(void);
236         void checkCompression(void);
237
238         void checkBounds(void);
239         void checkArea(void);
240         void checkLonLat();
[1870]241         
242       public:
243         void sendDomainToFileServer(CContextClient* client) ;
244       private:
245         std::set<CContextClient*> sendDomainToFileServer_done_ ;
[1943]246       public:
[1875]247         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
248       private:
249         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
250     
251       public:
252        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
[2022]253        string getCouplingAlias(const string& fieldId, int posInGrid) ;
[1875]254       private:
255
[1129]256         void convertLonLatValue();
[1158]257         void fillInRectilinearLonLat();
258         void fillInCurvilinearLonLat();
259         void fillInUnstructuredLonLat();
[1236]260         void completeLonLatClient(void); 
[1869]261         
262         
[1025]263       private:         
[1345]264
265/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
[1353]266         std::list<CContextClient*> clients;
267         std::set<CContextClient*> clientsSet;
[1345]268
[1974]269         bool isChecked ;
[676]270         std::set<StdString> relFiles, relFilesCompressed;
[1847]271
272/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
273    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
274    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
275    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
276*/
[1542]277         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
[1847]278
[1337]279         std::map<int, std::vector<int> > connectedServerRank_;
[1236]280
[715]281         bool isRedistributed_;
[657]282         bool isUnstructed_;
[1847]283
[953]284       
[1930]285       //////////////////////////////////////////////////////////////////////////////////////
286       //  this part is related to distribution, element definition, views and connectors  //
287       //////////////////////////////////////////////////////////////////////////////////////
[1918]288       private:
[2267]289         shared_ptr<CLocalElement> localElement_ = nullptr ;
[1918]290         void initializeLocalElement(void) ;
291       
292       public: 
[2267]293         shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
294         shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
[1918]295       
296       private: 
297         void addFullView(void) ;
298         void addWorkflowView(void) ;
299         void addModelView(void) ;
300       
301       private:
[2267]302         shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
[1918]303         void computeModelToWorkflowConnector(void)  ;
[1930]304       public:
[2267]305         shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
[1930]306
307       public:
308         void computeRemoteElement(CContextClient* client, EDistributionType) ;
[2304]309         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndexOut, std::map<int, CArray<size_t,1>>& globalIndexIn, 
310                                 shared_ptr<CScattererConnector> &scattererConnector, const string& domainId="") ;
[1930]311
312         static void recvDomainDistribution(CEventServer& event) ;
313         void receivedDomainDistribution(CEventServer& event, int phasis) ;
314
[2267]315         void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scaterrerConnector, const string& domainId) ;
[1930]316         static void recvDistributedAttributes(CEventServer& event) ;
317         void recvDistributedAttributes(CEventServer& event, const string& type) ;
[1943]318         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
319
[1930]320       private:
[2267]321         map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
[1930]322       public: 
[2267]323         shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
[1930]324       private:
[2267]325         map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
[1930]326       public: 
[2267]327         shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
[1934]328       
[1930]329       private:
[2267]330         shared_ptr<CGathererConnector>  gathererConnector_ ;
[1943]331       public:
[2267]332         shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
[1943]333        private:
[2267]334         shared_ptr<CGathererConnector> serverFromClientConnector_ ;
335         shared_ptr<CDistributedElement> elementFrom_ ;
[1930]336       public:
[2267]337         shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
[1918]338
[1934]339       private:
[2304]340         shared_ptr<CScattererConnector> serverToClientConnector_ = nullptr ;
341         shared_ptr<CDistributedElement> elementTo_ ;
[1934]342       public: 
[2267]343         shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
[1934]344
345       private:
[2267]346         map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
[1934]347       public: 
[2267]348         shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
[1918]349         
[1930]350
[540]351         DECLARE_REF_FUNC(Domain,domain)
352
[219]353   }; // class CDomain
354
355   ///--------------------------------------------------------------
356
357   // Declare/Define CDomainGroup and CDomainDefinition
358   DECLARE_GROUP(CDomain);
359
360   ///--------------------------------------------------------------
361
[335]362} // namespace xios
[219]363
[878]364#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.