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

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

Solve issues for grid mask on server side.

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.0 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         void checkEligibilityForCompressedOutput(void);
90
91         void sendCheckedAttributes();
92
93         bool hasTransformation();
94         void solveInheritanceTransformation();
95         TransMapTypes getAllTransformations();
96         void redistribute(int nbLocalDomain);
97         void duplicateTransformation(CDomain*);
98         CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
99
100      public:
101         const std::set<StdString> & getRelFiles(void) const;
102         bool IsWritten(const StdString & filename) const;
103         bool isWrittenCompressed(const StdString& filename) const;
104         
105         int getNumberWrittenIndexes(MPI_Comm writtenCom);
106         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
107         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
108         CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
109
110         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
111
112         bool isEmpty(void) const;
113         bool isDistributed(void) const;
114         bool isCompressible(void) const; 
115 
116         std::vector<int> getNbGlob();
117         bool isEqual(CDomain* domain);
118
119         static bool dispatchEvent(CEventServer& event);
120     
121      private:
122         /** define if the domain is completed or not ie all attributes have been received before in case
123             of grid reading from file or coupling */ 
124         bool isCompleted_=true ; 
125      public:     
126        /*!
127           \brief Check if a domain is completed
128           Before make any domain processing, we must be sure that all domain informations have
129           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
130           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
131           \return true if domain and domain reference are completed
132          */
133         bool isCompleted(void)
134         {
135           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
136           else return isCompleted_ ;
137         }
138         void setCompleted(void) { isCompleted_=true ; }
139         void unsetCompleted(void) { isCompleted_=false ; }
140
141      public:
142         /// Mutateur ///
143         void addRelFile(const StdString & filename);
144         void addRelFileCompressed(const StdString& filename);           
145         
146         void computeWrittenIndex();
147         void computeWrittenCompressedIndex(MPI_Comm);
148
149         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
150                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
151
152         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
153                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
154         
155         void fillInLonLat();
156         bool distributionAttributesHaveValue() const;
157
158         size_t getGlobalWrittenSize() ;
159         /// Destructeur ///
160         virtual ~CDomain(void);
161
162         /// Accesseurs statiques ///
163         static StdString GetName(void);
164         static StdString GetDefName(void);
165
166         static ENodeType GetType(void);       
167
168      public:
169         CArray<double, 1> lonvalue, latvalue;
170         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
171         CArray<double, 1> areavalue;
172
173         CArray<int,1> localIndexToWriteOnServer;
174
175         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
176         CArray<bool, 1> localMask; // domainMask + indexing
177         bool isCurvilinear ;
178         bool hasBounds ;
179         bool hasArea;
180         bool hasLonLat;
181         bool hasPole ;
182         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
183         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
184         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
185         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
186
187         void computeLocalMask(void) ;
188     
189         void computeConnectedClients(CContextClient* client); 
190         private: std::set<CContextClient*> computeConnectedClients_done_; public:
191         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
192         private: std::set<int> listNbServer_ ; public:
193         
194      private:
195         void checkDomain(void);
196         void checkLocalIDomain(void);
197         void checkLocalJDomain(void);
198
199         void checkMask(void);
200         void checkDomainData(void);
201         void checkCompression(void);
202
203         void checkBounds(void);
204         void checkArea(void);
205         void checkLonLat();
206
207         void setTransformations(const TransMapTypes&);         
208         void computeNGlobDomain();
209         
210       public:
211         void sendDomainToFileServer(CContextClient* client) ;
212       private:
213         std::set<CContextClient*> sendDomainToFileServer_done_ ;
214       public:
215         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
216       private:
217         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
218     
219       public:
220        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
221
222       private:
223
224         void sendDomainDistribution(CContextClient* client, const string& domainId="") ; //for testing
225         void sendAttributes(); // ym obsolete -> to be removed
226         void sendIndex(CContextClient* client, const string& domainId="");
227         void sendDistributionAttributes(CContextClient* client, const string& domainId="");
228         void sendArea(CContextClient* client, const string& domainId="");
229         void sendLonLat(CContextClient* client, const string& domainId="");         
230         void sendDataIndex(CContextClient* client, const string& domainId="");
231         void convertLonLatValue();
232         void fillInRectilinearLonLat();
233         void fillInCurvilinearLonLat();
234         void fillInUnstructuredLonLat();
235         
236         static void recvDistributionAttributes(CEventServer& event);
237         static void recvIndex(CEventServer& event);
238         static void recvLon(CEventServer& event);
239         static void recvLat(CEventServer& event);
240         static void recvArea(CEventServer& event);
241         static void recvDataIndex(CEventServer& event);
242         void recvDistributionAttributes(CBufferIn& buffer);                 
243         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
244         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
245         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
246         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
247         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
248
249         void completeLonLatClient(void); 
250         
251         
252       private:         
253
254/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
255         std::list<CContextClient*> clients;
256         std::set<CContextClient*> clientsSet;
257
258         bool isChecked, computedWrittenIndex_;
259         std::set<StdString> relFiles, relFilesCompressed;
260         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
261         bool isClientAfterTransformationChecked;
262
263/** 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)
264    indGlobs_[rank] -> array of global index received from the client of rank "rank"
265    indGlobs[rank](ind) -> global indices of the "ind" element sent.
266    Defined only on server side
267*/
268         std::map<int, CArray<int,1> > indGlob_;
269
270/** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes
271    nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient)
272    nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank"
273*/
274         std::map<int, map<int,int> > nbSenders; 
275
276/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
277    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
278    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
279    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
280*/
281         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
282         
283 /** make the mapping between the global index (the key) and the local index
284     globalLocalIndexMap_[global_index] --> get the local index
285 */       
286         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
287
288
289/** only on server side : get the rank of each clients which participate to a received message
290*   recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver"
291*/
292         std::vector<int> recvClientRanks_;
293
294         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
295         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
296         std::map<int, std::vector<int> > connectedServerRank_;
297
298         //! True if and only if the data defined on the domain can be outputted in a compressed way
299         bool isCompressible_;
300         bool isRedistributed_;
301         TransMapTypes transformationMap_;         
302         bool isUnstructed_;
303
304       
305       private:
306         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
307         static std::map<StdString, ETranformationType> transformationMapList_;
308         static bool _dummyTransformationMapList;
309
310       //////////////////////////////////////////////////////////////////////////////////////
311       //  this part is related to distribution, element definition, views and connectors  //
312       //////////////////////////////////////////////////////////////////////////////////////
313       private:
314         CLocalElement* localElement_ = nullptr ;
315         void initializeLocalElement(void) ;
316       
317       public: 
318         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
319         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
320       
321       private: 
322         void addFullView(void) ;
323         void addWorkflowView(void) ;
324         void addModelView(void) ;
325       
326       private:
327         CLocalConnector* modelToWorkflowConnector_ ;
328         void computeModelToWorkflowConnector(void)  ;
329       public:
330         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
331
332       public:
333         void computeRemoteElement(CContextClient* client, EDistributionType) ;
334         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& domainId="") ;
335
336         static void recvDomainDistribution(CEventServer& event) ;
337         void receivedDomainDistribution(CEventServer& event, int phasis) ;
338
339         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ;
340         static void recvDistributedAttributes(CEventServer& event) ;
341         void recvDistributedAttributes(CEventServer& event, const string& type) ;
342         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
343
344       private:
345         map<CContextClient*, CDistributedElement*> remoteElement_ ;
346       public: 
347         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
348       private:
349         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
350       public: 
351         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
352       
353       private:
354         CGathererConnector*  gathererConnector_ ;
355       public:
356         CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
357        private:
358         CGathererConnector* serverFromClientConnector_ ;
359         CDistributedElement* elementFrom_ ;
360       public:
361         CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
362
363       private:
364         CScattererConnector*  serverToClientConnector_ = nullptr ;
365       public: 
366         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
367
368       private:
369         map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
370       public: 
371         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
372         
373
374         DECLARE_REF_FUNC(Domain,domain)
375
376   }; // class CDomain
377
378   ///--------------------------------------------------------------
379
380   // Declare/Define CDomainGroup and CDomainDefinition
381   DECLARE_GROUP(CDomain);
382
383   ///--------------------------------------------------------------
384
385} // namespace xios
386
387#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.