source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.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
  • Property svn:executable set to *
File size: 13.4 KB
Line 
1#ifndef __XIOS_CAxis__
2#define __XIOS_CAxis__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "group_factory.hpp"
7#include "virtual_node.hpp"
8
9#include "declare_group.hpp"
10#include "declare_ref_func.hpp"
11#include "declare_virtual_node.hpp"
12#include "attribute_array.hpp"
13#include "attribute_enum.hpp"
14#include "attribute_enum_impl.hpp"
15#include "server_distribution_description.hpp"
16#include "transformation.hpp"
17#include "transformation_enum.hpp"
18#include "element.hpp"
19#include "local_connector.hpp"
20#include "scatterer_connector.hpp"
21#include "gatherer_connector.hpp"
22#include "distribution_type.hpp"
23
24
25namespace xios {
26   /// ////////////////////// Déclarations ////////////////////// ///
27
28   class CAxisGroup;
29   class CAxisAttributes;
30   class CAxis;
31
32   ///--------------------------------------------------------------
33
34   // Declare/Define CAxisAttribute
35   BEGIN_DECLARE_ATTRIBUTE_MAP(CAxis)
36#  include "axis_attribute.conf"
37   END_DECLARE_ATTRIBUTE_MAP(CAxis)
38
39   ///--------------------------------------------------------------
40
41   class CAxis
42      : public CObjectTemplate<CAxis>
43      , public CAxisAttributes
44   {
45               /// typedef ///
46         typedef CObjectTemplate<CAxis>   SuperClass;
47         typedef CAxisAttributes SuperClassAttribute;
48         
49      public:
50         enum EEventId
51         {
52           EVENT_ID_DISTRIBUTION_ATTRIBUTE,           
53           EVENT_ID_DISTRIBUTED_VALUE,
54           EVENT_ID_NON_DISTRIBUTED_VALUE,
55           EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES,
56           EVENT_ID_DISTRIBUTED_ATTRIBUTES,
57           EVENT_ID_AXIS_DISTRIBUTION,
58           EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE
59         } ;
60
61      public:
62         typedef CAxisAttributes RelAttributes;
63         typedef CAxisGroup      RelGroup;
64         typedef CTransformation<CAxis>::TransformationMapTypes TransMapTypes;
65
66      public:
67         /// Constructeurs ///
68         CAxis(void);
69         explicit CAxis(const StdString & id);
70         CAxis(const CAxis & axis);       // Not implemented yet.
71         CAxis(const CAxis * const axis); // Not implemented yet.
72
73         static CAxis* createAxis();
74
75         /// Accesseurs ///
76         const std::set<StdString> & getRelFiles(void) const;
77
78         int getNumberWrittenIndexes(MPI_Comm writtenCom);
79         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
80         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
81         CArray<int, 1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
82
83         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
84                                                        CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
85
86         /// Test ///
87         bool IsWritten(const StdString & filename) const;
88         bool isWrittenCompressed(const StdString& filename) const;
89         bool isDistributed(void) const;
90       
91        public:
92        /*!
93            \brief return if the axis can be written or not in a compressed way.
94            ie if there are some masked or indexed point on the domain. Valid only on server side.
95            \return true if domain can be writtedn in a compressed way
96         */ 
97         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
98        private:
99         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
100         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
101         void computeIsCompressible() ;
102       
103        public:
104
105         /// Mutateur ///
106         void addRelFile(const StdString & filename);
107         void addRelFileCompressed(const StdString& filename);
108
109         
110
111         /// Destructeur ///
112         virtual ~CAxis(void);
113
114         virtual void parse(xml::CXMLNode & node);
115
116         void setContextClient(CContextClient* contextClient);
117
118         /// Accesseurs statiques ///
119         static StdString GetName(void);
120         static StdString GetDefName(void);
121         static ENodeType GetType(void);
122
123         static bool dispatchEvent(CEventServer& event);         
124       
125         /// Vérifications ///
126         void checkAttributes(void);
127         bool checkAttributes_done_ = false ;
128         
129         void checkAttributesOnClient();
130         void checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid,
131                                                         CServerDistributionDescription::ServerDistributionType distType = CServerDistributionDescription::BAND_DISTRIBUTION);
132         void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
133                                    CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
134
135         size_t getGlobalWrittenSize(void) ;
136
137         void computeWrittenIndex();
138         void computeWrittenCompressedIndex(MPI_Comm);
139         bool hasTransformation();
140         void solveInheritanceTransformation();
141         TransMapTypes getAllTransformations();         
142         void duplicateTransformation(CAxis*);
143         CTransformation<CAxis>* addTransformation(ETranformationType transType, const StdString& id="");
144         bool isEqual(CAxis* axis);
145
146      public: 
147        bool hasValue;       
148        bool hasBounds;
149        bool hasLabel;
150
151        CArray<int,1> localIndexToWriteOnServer;
152         
153         void computeConnectedClients(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid);
154         private: std::set<CContextClient*> computeConnectedClients_done_ ; public :
155         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
156         private: std::set<int> listNbServer_ ; public:
157
158      private:
159         void checkData();
160         void checkMask();
161         void checkBounds();
162         void checkLabel();
163      public:
164         void sendAxisToFileServer(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) ;
165      private:
166         std::set<CContextClient*> sendAxisToFileServer_done_ ;
167     
168      public:
169         void sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) ;
170      private:
171         std::set<CContextClient*> sendAxisToCouplerOut_done_ ;
172   
173      public:
174         void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
175
176      private:
177         void sendAttributes(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
178                             CServerDistributionDescription::ServerDistributionType distType, const string& axisId="");
179         void sendDistributionAttribute(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
180                                        CServerDistributionDescription::ServerDistributionType distType, const string& axisId="");
181         
182
183         void sendNonDistributedAttributes(CContextClient* client, const string& axisId="");
184         void sendDistributedAttributes_old(CContextClient* client, const string& axisId="");
185
186         static void recvNonDistributedAttributes(CEventServer& event);
187         static void recvDistributedAttributes_old(CEventServer& event);
188         static void recvDistributionAttribute(CEventServer& event);
189         void recvNonDistributedAttributes(int rank, CBufferIn& buffer);
190         void recvDistributedAttributes_old(vector<int>& rank, vector<CBufferIn*> buffers);
191         void recvDistributionAttribute(CBufferIn& buffer);
192
193         void setTransformations(const TransMapTypes&);
194
195      private:
196
197/** Clients that have to send a axis. There can be multiple clients in case of secondary server, otherwise only one client. */
198         std::list<CContextClient*> clients;
199         std::set<CContextClient*> clientsSet;
200
201      private:
202         /** define if the axis is completed or not ie all attributes have been received before in case
203             of grid reading from file or coupling */ 
204         bool isCompleted_=true ; 
205      public:     
206         /*!
207           \brief Check if a axis is completed
208           Before make any axis processing, we must be sure that all axis informations have
209           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
210           other context (coupling). So all direct reference of the axis (axis_ref) must be also completed
211           \return true if axis and axis reference are completed
212          */
213         bool isCompleted(void)
214         {
215           if (hasDirectAxisReference()) if (!getDirectAxisReference()->isCompleted()) return false;
216           else return isCompleted_ ;
217         }
218         void setCompleted(void) { isCompleted_=true ; }
219         void unsetCompleted(void) { isCompleted_=false ; }
220     
221      private:
222         bool isChecked;
223         bool areClientAttributesChecked_;
224         bool isClientAfterTransformationChecked;
225         std::set<StdString> relFiles, relFilesCompressed;
226         TransMapTypes transformationMap_;         
227
228         std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server
229         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server
230         // std::map<int, vector<int> > indWrittenSrv_; // Global written index of each client sent to server
231         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
232         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
233         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;
234         std::map<int, std::vector<int> > connectedServerRank_;
235         bool computedWrittenIndex_;                 
236
237       private:
238         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
239         static std::map<StdString, ETranformationType> transformationMapList_;
240         static bool dummyTransformationMapList_;
241
242
243       //////////////////////////////////////////////////////////////////////////////////////
244       //  this part is related to distribution, element definition, views and connectors  //
245       //////////////////////////////////////////////////////////////////////////////////////
246         
247        private:
248         CLocalElement* localElement_ = nullptr ;
249         void initializeLocalElement(void) ;
250        public: 
251         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
252         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
253        private:
254         void addFullView(void) ;
255         void addWorkflowView(void) ;
256         void addModelView(void) ;
257
258        private:
259         CLocalConnector* modelToWorkflowConnector_ ;
260         void computeModelToWorkflowConnector(void)  ;
261        public:
262         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
263       
264       public:
265         void computeRemoteElement(CContextClient* client, EDistributionType) ;
266         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector,
267                                 const string& axisId="") ;
268
269         static void recvAxisDistribution(CEventServer& event) ;
270         void receivedAxisDistribution(CEventServer& event, int phasis) ;
271         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client ) ;
272         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& axisId) ;
273         static void recvDistributedAttributes(CEventServer& event) ;
274         void recvDistributedAttributes(CEventServer& event, const string& type) ;
275       private:
276         map<CContextClient*, CDistributedElement*> remoteElement_ ;
277       public: 
278         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
279       private:
280         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
281       public: 
282         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
283       private:
284         CGathererConnector*  gathererConnector_ ;
285       public:
286         CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
287       private:
288         CGathererConnector* serverFromClientConnector_ ;
289         CDistributedElement* elementFrom_ ;
290       public:
291        CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
292
293       private:
294         CScattererConnector*  serverToClientConnector_ = nullptr ;
295       public: 
296         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
297
298       private:
299          map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
300       public: 
301         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
302
303         DECLARE_REF_FUNC(Axis,axis)
304   }; // class CAxis
305
306   ///--------------------------------------------------------------
307
308   // Declare/Define CAxisGroup and CAxisDefinition
309   DECLARE_GROUP(CAxis);
310} // namespace xios
311
312#endif // __XIOS_CAxis__
Note: See TracBrowser for help on using the repository browser.