source: XIOS/dev/branch_openmp/src/node/domain.hpp @ 1545

Last change on this file since 1545 was 1545, checked in by yushan, 6 years ago

branch_openmp merged with trunk r1544

  • 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: 9.3 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 "mpi_std.hpp"
20#include "mesh.hpp"
21
22namespace xios {
23
24   /// ////////////////////// Déclarations ////////////////////// ///
25
26   class CDomainGroup;
27   class CDomainAttributes;
28   class CDomain;
29   class CFile;
30
31   ///--------------------------------------------------------------
32
33   // Declare/Define CDomainAttribute
34   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
35#  include "domain_attribute.conf"
36#  include "domain_attribute_private.conf"
37   END_DECLARE_ATTRIBUTE_MAP(CDomain)
38
39   ///--------------------------------------------------------------
40
41   class CDomain
42      : public CObjectTemplate<CDomain>
43      , public CDomainAttributes
44   {
45     /// typedef ///
46     typedef CObjectTemplate<CDomain>   SuperClass;
47     typedef CDomainAttributes SuperClassAttribute;
48     public:
49         enum EEventId
50         {
51           EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, 
52           EVENT_ID_AREA, EVENT_ID_MASK,
53           EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT
54         } ;
55
56      public:
57
58         typedef CDomainAttributes RelAttributes;
59         typedef CDomainGroup      RelGroup;
60         typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
61
62         /// Constructeurs ///
63         CDomain(void);
64         explicit CDomain(const StdString & id);
65         CDomain(const CDomain & domain);       // Not implemented yet.
66         CDomain(const CDomain * const domain); // Not implemented yet.
67
68         static CDomain* createDomain();
69         
70         CMesh* mesh;
71         void assignMesh(const StdString, const int);
72       
73         virtual void parse(xml::CXMLNode & node);
74
75         void setContextClient(CContextClient* contextClient);
76
77         /// Vérifications ///
78         void checkAttributes(void);
79         void checkAttributesOnClient();
80         void checkAttributesOnClientAfterTransformation();
81         void checkEligibilityForCompressedOutput(void);
82
83         void sendCheckedAttributes();
84
85         bool hasTransformation();
86         void solveInheritanceTransformation();
87         TransMapTypes getAllTransformations();
88         void redistribute(int nbLocalDomain);
89         void duplicateTransformation(CDomain*);
90         CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
91
92      public:
93         const std::set<StdString> & getRelFiles(void) const;
94         bool IsWritten(const StdString & filename) const;
95         bool isWrittenCompressed(const StdString& filename) const;
96         
97         int getNumberWrittenIndexes(ep_lib::MPI_Comm writtenCom);
98         int getTotalNumberWrittenIndexes(ep_lib::MPI_Comm writtenCom);
99         int getOffsetWrittenIndexes(ep_lib::MPI_Comm writtenCom);
100         CArray<int,1>& getCompressedIndexToWriteOnServer(ep_lib::MPI_Comm writtenCom);
101
102         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
103
104         bool isEmpty(void) const;
105         bool isDistributed(void) const;
106         bool isCompressible(void) const; 
107 
108         std::vector<int> getNbGlob();
109         bool isEqual(CDomain* domain);
110
111         static bool dispatchEvent(CEventServer& event);
112
113      public:
114         /// Mutateur ///
115         void addRelFile(const StdString & filename);
116         void addRelFileCompressed(const StdString& filename);           
117         
118         void computeWrittenIndex();
119         void computeWrittenCompressedIndex(ep_lib::MPI_Comm);
120
121         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
122                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
123
124         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
125                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
126         
127         void fillInLonLat();
128         bool distributionAttributesHaveValue() const;
129
130         size_t getGlobalWrittenSize() ;
131         /// Destructeur ///
132         virtual ~CDomain(void);
133
134         /// Accesseurs statiques ///
135         static StdString GetName(void);
136         static StdString GetDefName(void);
137
138         static ENodeType GetType(void);       
139
140      public:
141         CArray<double, 1> lonvalue, latvalue;
142         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
143         CArray<double, 1> areavalue;
144
145         CArray<size_t,1> localIndexToWriteOnServer;         
146
147         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
148         CArray<bool, 1> localMask; // domainMask + indexing
149         bool isCurvilinear ;
150         bool hasBounds ;
151         bool hasArea;
152         bool hasLonLat;
153         bool hasPole ;
154
155         void computeLocalMask(void) ;
156      private:
157         void checkDomain(void);
158         void checkLocalIDomain(void);
159         void checkLocalJDomain(void);
160
161         void checkMask(void);
162         void checkDomainData(void);
163         void checkCompression(void);
164
165         void checkBounds(void);
166         void checkArea(void);
167         void checkLonLat();
168         void checkZoom(void);
169
170         void setTransformations(const TransMapTypes&);         
171         void computeNGlobDomain();
172         void sendAttributes();
173         void sendIndex();
174         void sendDistributionAttributes();
175         void sendMask();
176         void sendArea();
177         void sendLonLat();         
178         void sendDataIndex();
179         void convertLonLatValue();
180         void fillInRectilinearLonLat();
181         void fillInCurvilinearLonLat();
182         void fillInUnstructuredLonLat();
183         
184         static void recvDistributionAttributes(CEventServer& event);
185         static void recvIndex(CEventServer& event);
186         static void recvIndexZoom(CEventServer& event);
187         static void recvMask(CEventServer& event);         
188         static void recvLon(CEventServer& event);
189         static void recvLat(CEventServer& event);
190         static void recvArea(CEventServer& event);
191         static void recvDataIndex(CEventServer& event);
192         void recvDistributionAttributes(CBufferIn& buffer);                 
193         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
194         void recvMask(std::map<int, CBufferIn*>& rankBuffers);
195         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
196         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
197         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
198         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
199
200         void completeLonLatClient(void); 
201         void computeConnectedClients();   
202
203       private:
204
205/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
206         std::list<CContextClient*> clients;
207         std::set<CContextClient*> clientsSet;
208
209         bool doZoomByIndex_;
210         bool isChecked, computedWrittenIndex_;
211         std::set<StdString> relFiles, relFilesCompressed;
212         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
213         bool isClientAfterTransformationChecked;
214         std::map<int, CArray<int,1> > indGlob_;
215         std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server
216
217/** Global index of each client sent to server: map<serverSize, map<serverRank, indexes>> */
218         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
219         // std::map<CContextClient*, std::map<int, vector<int> > > indWrittenSrv_; // Global written index of each client sent to server
220         std::vector<int> indexesToWrite;
221         std::vector<int> recvClientRanks_;
222         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
223         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
224         std::map<int, std::map<int,size_t> > connectedDataSize_;
225         std::map<int, std::vector<int> > connectedServerRank_;
226
227         //! True if and only if the data defined on the domain can be outputted in a compressed way
228         bool isCompressible_;
229         bool isRedistributed_;
230         TransMapTypes transformationMap_;         
231         bool isUnstructed_;
232         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
233       
234       private:
235         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
236         static bool initializeTransformationMap();
237         static std::map<StdString, ETranformationType> *transformationMapList_ptr;
238         #pragma omp threadprivate(transformationMapList_ptr)
239         static bool _dummyTransformationMapList;
240         #pragma omp threadprivate(_dummyTransformationMapList)
241
242         DECLARE_REF_FUNC(Domain,domain)
243
244   }; // class CDomain
245
246   ///--------------------------------------------------------------
247
248   // Declare/Define CDomainGroup and CDomainDefinition
249   DECLARE_GROUP(CDomain);
250
251   ///--------------------------------------------------------------
252
253} // namespace xios
254
255#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.