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

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

Big update on on going work related to data distribution and transfer between clients and servers.

  • move all related file into distribution directorie
  • implement the concept of data "View"
  • implement the concept of "connector" which make the data transfer between 2 differents "Views"

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