source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.hpp @ 1960

Last change on this file since 1960 was 1956, checked in by ymipsl, 4 years ago

Xios coupling

  • fix problem when sending grid mask from client to server
  • remove methods about grid compression, which will be managed in other ways

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: 16.5 KB
Line 
1#ifndef __XIOS_CDomain__
2#define __XIOS_CDomain__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
9#include "declare_ref_func.hpp"
10#include "event_client.hpp"
11#include "event_server.hpp"
12#include "buffer_in.hpp"
13#include "array_new.hpp"
14#include "attribute_array.hpp"
15#include "attribute_enum.hpp"
16#include "transformation.hpp"
17#include "transformation_enum.hpp"
18#include "server_distribution_description.hpp"
19#include "mesh.hpp"
20#include "element.hpp"
21#include "local_connector.hpp"
22#include "scatterer_connector.hpp"
23#include "gatherer_connector.hpp"
24#include "distribution_type.hpp"
25
26
27namespace xios {
28
29   /// ////////////////////// Déclarations ////////////////////// ///
30
31   class CDomainGroup;
32   class CDomainAttributes;
33   class CDomain;
34   class CFile;
35
36   ///--------------------------------------------------------------
37
38   // Declare/Define CDomainAttribute
39   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
40#  include "domain_attribute.conf"
41#  include "domain_attribute_private.conf"
42   END_DECLARE_ATTRIBUTE_MAP(CDomain)
43
44   ///--------------------------------------------------------------
45
46   class CDomain
47      : public CObjectTemplate<CDomain>
48      , public CDomainAttributes
49   {
50     /// typedef ///
51     typedef CObjectTemplate<CDomain>   SuperClass;
52     typedef CDomainAttributes SuperClassAttribute;
53     public:
54         enum EEventId
55         {
56           EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, 
57           EVENT_ID_AREA,
58           EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT,
59           EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE
60         } ;
61
62      public:
63
64         typedef CDomainAttributes RelAttributes;
65         typedef CDomainGroup      RelGroup;
66         typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
67
68         /// Constructeurs ///
69         CDomain(void);
70         explicit CDomain(const StdString & id);
71         CDomain(const CDomain & domain);       // Not implemented yet.
72         CDomain(const CDomain * const domain); // Not implemented yet.
73
74         static CDomain* createDomain();
75         
76         CMesh* mesh;
77         void assignMesh(const StdString, const int);
78       
79         virtual void parse(xml::CXMLNode & node);
80
81         void setContextClient(CContextClient* contextClient);
82
83         /// Vérifications ///
84         void checkAttributes(void);
85         bool checkAttributes_done_ = false ;
86
87         void checkAttributesOnClient();
88         void checkAttributesOnClientAfterTransformation();
89
90         void sendCheckedAttributes();
91
92         bool hasTransformation();
93         void solveInheritanceTransformation();
94         TransMapTypes getAllTransformations();
95         void redistribute(int nbLocalDomain);
96         void duplicateTransformation(CDomain*);
97         CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
98
99      public:
100         const std::set<StdString> & getRelFiles(void) const;
101         bool IsWritten(const StdString & filename) const;
102         bool isWrittenCompressed(const StdString& filename) const;
103         
104         int getNumberWrittenIndexes(MPI_Comm writtenCom);
105         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
106         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
107         CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
108
109         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
110
111         bool isEmpty(void) const;
112         bool isDistributed(void) const;
113
114        public :
115         /*!
116            \brief return if the domain can be written or not in a compressed way.
117            ie if there are some masked or indexed point on the domain. Valid only on server side.
118            \return true if domain can be writtedn in a compressed way
119         */ 
120         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
121        private :
122         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
123         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
124         void computeIsCompressible() ;
125
126      public :
127         std::vector<int> getNbGlob();
128         bool isEqual(CDomain* domain);
129
130         static bool dispatchEvent(CEventServer& event);
131     
132      private:
133         /** define if the domain is completed or not ie all attributes have been received before in case
134             of grid reading from file or coupling */ 
135         bool isCompleted_=true ; 
136      public:     
137        /*!
138           \brief Check if a domain is completed
139           Before make any domain processing, we must be sure that all domain informations have
140           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
141           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
142           \return true if domain and domain reference are completed
143          */
144         bool isCompleted(void)
145         {
146           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
147           else return isCompleted_ ;
148         }
149         void setCompleted(void) { isCompleted_=true ; }
150         void unsetCompleted(void) { isCompleted_=false ; }
151
152      public:
153         /// Mutateur ///
154         void addRelFile(const StdString & filename);
155         void addRelFileCompressed(const StdString& filename);           
156         
157         void computeWrittenIndex();
158         void computeWrittenCompressedIndex(MPI_Comm);
159
160         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
161                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
162
163         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
164                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
165         
166         void fillInLonLat();
167         bool distributionAttributesHaveValue() const;
168
169         size_t getGlobalWrittenSize() ;
170         /// Destructeur ///
171         virtual ~CDomain(void);
172
173         /// Accesseurs statiques ///
174         static StdString GetName(void);
175         static StdString GetDefName(void);
176
177         static ENodeType GetType(void);       
178
179      public:
180         CArray<double, 1> lonvalue, latvalue;
181         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
182         CArray<double, 1> areavalue;
183
184         CArray<int,1> localIndexToWriteOnServer;
185
186         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
187         CArray<bool, 1> localMask; // domainMask + indexing
188         bool isCurvilinear ;
189         bool hasBounds ;
190         bool hasArea;
191         bool hasLonLat;
192         bool hasPole ;
193         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
194         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
195         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
196         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
197
198         void computeLocalMask(void) ;
199     
200         void computeConnectedClients(CContextClient* client); 
201         private: std::set<CContextClient*> computeConnectedClients_done_; public:
202         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
203         private: std::set<int> listNbServer_ ; public:
204         
205      private:
206         void checkDomain(void);
207         void checkLocalIDomain(void);
208         void checkLocalJDomain(void);
209
210         void checkMask(void);
211         void checkDomainData(void);
212         void checkCompression(void);
213
214         void checkBounds(void);
215         void checkArea(void);
216         void checkLonLat();
217
218         void setTransformations(const TransMapTypes&);         
219         void computeNGlobDomain();
220         
221       public:
222         void sendDomainToFileServer(CContextClient* client) ;
223       private:
224         std::set<CContextClient*> sendDomainToFileServer_done_ ;
225       public:
226         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
227       private:
228         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
229     
230       public:
231        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
232
233       private:
234
235         void sendDomainDistribution(CContextClient* client, const string& domainId="") ; //for testing
236         void sendAttributes(); // ym obsolete -> to be removed
237         void sendIndex(CContextClient* client, const string& domainId="");
238         void sendDistributionAttributes(CContextClient* client, const string& domainId="");
239         void sendArea(CContextClient* client, const string& domainId="");
240         void sendLonLat(CContextClient* client, const string& domainId="");         
241         void sendDataIndex(CContextClient* client, const string& domainId="");
242         void convertLonLatValue();
243         void fillInRectilinearLonLat();
244         void fillInCurvilinearLonLat();
245         void fillInUnstructuredLonLat();
246         
247         static void recvDistributionAttributes(CEventServer& event);
248         static void recvIndex(CEventServer& event);
249         static void recvLon(CEventServer& event);
250         static void recvLat(CEventServer& event);
251         static void recvArea(CEventServer& event);
252         static void recvDataIndex(CEventServer& event);
253         void recvDistributionAttributes(CBufferIn& buffer);                 
254         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
255         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
256         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
257         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
258         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
259
260         void completeLonLatClient(void); 
261         
262         
263       private:         
264
265/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
266         std::list<CContextClient*> clients;
267         std::set<CContextClient*> clientsSet;
268
269         bool isChecked, computedWrittenIndex_;
270         std::set<StdString> relFiles, relFilesCompressed;
271         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
272         bool isClientAfterTransformationChecked;
273
274/** global index of the domain on server side, sent by the clients. This is global index for lon, lat, mask elements (ie non masked elements)
275    indGlobs_[rank] -> array of global index received from the client of rank "rank"
276    indGlobs[rank](ind) -> global indices of the "ind" element sent.
277    Defined only on server side
278*/
279         std::map<int, CArray<int,1> > indGlob_;
280
281/** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes
282    nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient)
283    nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank"
284*/
285         std::map<int, map<int,int> > nbSenders; 
286
287/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
288    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
289    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
290    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
291*/
292         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
293         
294 /** make the mapping between the global index (the key) and the local index
295     globalLocalIndexMap_[global_index] --> get the local index
296 */       
297         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
298
299
300/** only on server side : get the rank of each clients which participate to a received message
301*   recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver"
302*/
303         std::vector<int> recvClientRanks_;
304
305         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
306         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
307         std::map<int, std::vector<int> > connectedServerRank_;
308
309         bool isRedistributed_;
310         TransMapTypes transformationMap_;         
311         bool isUnstructed_;
312
313       
314       private:
315         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
316         static std::map<StdString, ETranformationType> transformationMapList_;
317         static bool _dummyTransformationMapList;
318
319       //////////////////////////////////////////////////////////////////////////////////////
320       //  this part is related to distribution, element definition, views and connectors  //
321       //////////////////////////////////////////////////////////////////////////////////////
322       private:
323         CLocalElement* localElement_ = nullptr ;
324         void initializeLocalElement(void) ;
325       
326       public: 
327         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
328         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
329       
330       private: 
331         void addFullView(void) ;
332         void addWorkflowView(void) ;
333         void addModelView(void) ;
334       
335       private:
336         CLocalConnector* modelToWorkflowConnector_ ;
337         void computeModelToWorkflowConnector(void)  ;
338       public:
339         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
340
341       public:
342         void computeRemoteElement(CContextClient* client, EDistributionType) ;
343         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector,
344                                 const string& domainId="") ;
345
346         static void recvDomainDistribution(CEventServer& event) ;
347         void receivedDomainDistribution(CEventServer& event, int phasis) ;
348
349         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ;
350         static void recvDistributedAttributes(CEventServer& event) ;
351         void recvDistributedAttributes(CEventServer& event, const string& type) ;
352         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
353
354       private:
355         map<CContextClient*, CDistributedElement*> remoteElement_ ;
356       public: 
357         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
358       private:
359         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
360       public: 
361         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
362       
363       private:
364         CGathererConnector*  gathererConnector_ ;
365       public:
366         CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
367        private:
368         CGathererConnector* serverFromClientConnector_ ;
369         CDistributedElement* elementFrom_ ;
370       public:
371         CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
372
373       private:
374         CScattererConnector*  serverToClientConnector_ = nullptr ;
375       public: 
376         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
377
378       private:
379         map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
380       public: 
381         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
382         
383
384         DECLARE_REF_FUNC(Domain,domain)
385
386   }; // class CDomain
387
388   ///--------------------------------------------------------------
389
390   // Declare/Define CDomainGroup and CDomainDefinition
391   DECLARE_GROUP(CDomain);
392
393   ///--------------------------------------------------------------
394
395} // namespace xios
396
397#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.