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 | |
---|
27 | namespace 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 | private: |
---|
215 | public: |
---|
216 | void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ; |
---|
217 | private: |
---|
218 | std::set<CContextClient*> sendDomainToCouplerOut_done_ ; |
---|
219 | |
---|
220 | public: |
---|
221 | void makeAliasForCoupling(const string& fieldId, int posInGrid) ; |
---|
222 | |
---|
223 | private: |
---|
224 | |
---|
225 | void sendDomainDistribution(CContextClient* client, const string& domainId="") ; //for testing |
---|
226 | void sendAttributes(); // ym obsolete -> to be removed |
---|
227 | void sendIndex(CContextClient* client, const string& domainId=""); |
---|
228 | void sendDistributionAttributes(CContextClient* client, const string& domainId=""); |
---|
229 | void sendArea(CContextClient* client, const string& domainId=""); |
---|
230 | void sendLonLat(CContextClient* client, const string& domainId=""); |
---|
231 | void sendDataIndex(CContextClient* client, const string& domainId=""); |
---|
232 | void convertLonLatValue(); |
---|
233 | void fillInRectilinearLonLat(); |
---|
234 | void fillInCurvilinearLonLat(); |
---|
235 | void fillInUnstructuredLonLat(); |
---|
236 | |
---|
237 | static void recvDistributionAttributes(CEventServer& event); |
---|
238 | static void recvIndex(CEventServer& event); |
---|
239 | static void recvLon(CEventServer& event); |
---|
240 | static void recvLat(CEventServer& event); |
---|
241 | static void recvArea(CEventServer& event); |
---|
242 | static void recvDataIndex(CEventServer& event); |
---|
243 | void recvDistributionAttributes(CBufferIn& buffer); |
---|
244 | void recvIndex(std::map<int, CBufferIn*>& rankBuffers); |
---|
245 | void recvLon(std::map<int, CBufferIn*>& rankBuffers); |
---|
246 | void recvLat(std::map<int, CBufferIn*>& rankBuffers); |
---|
247 | void recvArea(std::map<int, CBufferIn*>& rankBuffers); |
---|
248 | void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers); |
---|
249 | |
---|
250 | void completeLonLatClient(void); |
---|
251 | |
---|
252 | |
---|
253 | private: |
---|
254 | |
---|
255 | /** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
256 | std::list<CContextClient*> clients; |
---|
257 | std::set<CContextClient*> clientsSet; |
---|
258 | |
---|
259 | bool isChecked, computedWrittenIndex_; |
---|
260 | std::set<StdString> relFiles, relFilesCompressed; |
---|
261 | bool isClientChecked; // Verify whether all attributes of domain on the client side are good |
---|
262 | bool isClientAfterTransformationChecked; |
---|
263 | |
---|
264 | /** 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) |
---|
265 | indGlobs_[rank] -> array of global index received from the client of rank "rank" |
---|
266 | indGlobs[rank](ind) -> global indices of the "ind" element sent. |
---|
267 | Defined only on server side |
---|
268 | */ |
---|
269 | std::map<int, CArray<int,1> > indGlob_; |
---|
270 | |
---|
271 | /** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes |
---|
272 | nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient) |
---|
273 | nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank" |
---|
274 | */ |
---|
275 | std::map<int, map<int,int> > nbSenders; |
---|
276 | |
---|
277 | /** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>> |
---|
278 | indSrv_[nbServers] --> first map is related to the server distribution (ie associated with the contextClient) |
---|
279 | indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank" |
---|
280 | indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...) |
---|
281 | */ |
---|
282 | std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; |
---|
283 | |
---|
284 | /** make the mapping between the global index (the key) and the local index |
---|
285 | globalLocalIndexMap_[global_index] --> get the local index |
---|
286 | */ |
---|
287 | std::unordered_map<size_t,size_t> globalLocalIndexMap_; |
---|
288 | |
---|
289 | |
---|
290 | /** only on server side : get the rank of each clients which participate to a received message |
---|
291 | * recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver" |
---|
292 | */ |
---|
293 | std::vector<int> recvClientRanks_; |
---|
294 | |
---|
295 | std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
296 | std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer; |
---|
297 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
298 | |
---|
299 | //! True if and only if the data defined on the domain can be outputted in a compressed way |
---|
300 | bool isCompressible_; |
---|
301 | bool isRedistributed_; |
---|
302 | TransMapTypes transformationMap_; |
---|
303 | bool isUnstructed_; |
---|
304 | |
---|
305 | |
---|
306 | private: |
---|
307 | static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m); |
---|
308 | static std::map<StdString, ETranformationType> transformationMapList_; |
---|
309 | static bool _dummyTransformationMapList; |
---|
310 | |
---|
311 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
312 | // this part is related to distribution, element definition, views and connectors // |
---|
313 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
314 | private: |
---|
315 | CLocalElement* localElement_ = nullptr ; |
---|
316 | void initializeLocalElement(void) ; |
---|
317 | |
---|
318 | public: |
---|
319 | CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; } |
---|
320 | CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;} |
---|
321 | |
---|
322 | private: |
---|
323 | void addFullView(void) ; |
---|
324 | void addWorkflowView(void) ; |
---|
325 | void addModelView(void) ; |
---|
326 | |
---|
327 | private: |
---|
328 | CLocalConnector* modelToWorkflowConnector_ ; |
---|
329 | void computeModelToWorkflowConnector(void) ; |
---|
330 | public: |
---|
331 | CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} |
---|
332 | |
---|
333 | public: |
---|
334 | void computeRemoteElement(CContextClient* client, EDistributionType) ; |
---|
335 | void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& domainId="") ; |
---|
336 | |
---|
337 | static void recvDomainDistribution(CEventServer& event) ; |
---|
338 | void receivedDomainDistribution(CEventServer& event, int phasis) ; |
---|
339 | |
---|
340 | void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ; |
---|
341 | static void recvDistributedAttributes(CEventServer& event) ; |
---|
342 | void recvDistributedAttributes(CEventServer& event, const string& type) ; |
---|
343 | private: |
---|
344 | map<CContextClient*, CDistributedElement*> remoteElement_ ; |
---|
345 | public: |
---|
346 | CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} |
---|
347 | private: |
---|
348 | map<CContextClient*, CScattererConnector*> clientToServerConnector_ ; |
---|
349 | public: |
---|
350 | CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} |
---|
351 | |
---|
352 | private: |
---|
353 | CGathererConnector* gathererConnector_ ; |
---|
354 | CGathererConnector* serverFromClientConnector_ ; |
---|
355 | CDistributedElement* elementFrom_ ; |
---|
356 | public: |
---|
357 | CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} |
---|
358 | |
---|
359 | private: |
---|
360 | CScattererConnector* serverToClientConnector_ = nullptr ; |
---|
361 | public: |
---|
362 | CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} |
---|
363 | |
---|
364 | private: |
---|
365 | map<CContextClient*,CGathererConnector*> clientFromServerConnector_ ; |
---|
366 | public: |
---|
367 | CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} |
---|
368 | |
---|
369 | |
---|
370 | DECLARE_REF_FUNC(Domain,domain) |
---|
371 | |
---|
372 | }; // class CDomain |
---|
373 | |
---|
374 | ///-------------------------------------------------------------- |
---|
375 | |
---|
376 | // Declare/Define CDomainGroup and CDomainDefinition |
---|
377 | DECLARE_GROUP(CDomain); |
---|
378 | |
---|
379 | ///-------------------------------------------------------------- |
---|
380 | |
---|
381 | } // namespace xios |
---|
382 | |
---|
383 | #endif //__XIOS_CDomain__ |
---|