source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.hpp @ 1934

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

Big update on on going work related to data distribution and transfer between clients and servers.
Revisite of the source and store filter using "connectors".

-> inputs work again

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: 12.7 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         bool isCompressible(void) const;
91
92         /// Mutateur ///
93         void addRelFile(const StdString & filename);
94         void addRelFileCompressed(const StdString& filename);
95
96         
97
98         /// Destructeur ///
99         virtual ~CAxis(void);
100
101         virtual void parse(xml::CXMLNode & node);
102
103         void setContextClient(CContextClient* contextClient);
104
105         /// Accesseurs statiques ///
106         static StdString GetName(void);
107         static StdString GetDefName(void);
108         static ENodeType GetType(void);
109
110         static bool dispatchEvent(CEventServer& event);         
111       
112         /// Vérifications ///
113         void checkAttributes(void);
114         bool checkAttributes_done_ = false ;
115         
116         void checkAttributesOnClient();
117         void checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid,
118                                                         CServerDistributionDescription::ServerDistributionType distType = CServerDistributionDescription::BAND_DISTRIBUTION);
119         void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
120                                    CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
121
122         void checkEligibilityForCompressedOutput();
123         size_t getGlobalWrittenSize(void) ;
124
125         void computeWrittenIndex();
126         void computeWrittenCompressedIndex(MPI_Comm);
127         bool hasTransformation();
128         void solveInheritanceTransformation();
129         TransMapTypes getAllTransformations();         
130         void duplicateTransformation(CAxis*);
131         CTransformation<CAxis>* addTransformation(ETranformationType transType, const StdString& id="");
132         bool isEqual(CAxis* axis);
133
134      public: 
135        bool hasValue;       
136        bool hasBounds;
137        bool hasLabel;
138
139        CArray<int,1> localIndexToWriteOnServer;
140         
141         void computeConnectedClients(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid);
142         private: std::set<CContextClient*> computeConnectedClients_done_ ; public :
143         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
144         private: std::set<int> listNbServer_ ; public:
145
146      private:
147         void checkData();
148         void checkMask();
149         void checkBounds();
150         void checkLabel();
151      public:
152         void sendAxisToFileServer(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) ;
153      private:
154         std::set<CContextClient*> sendAxisToFileServer_done_ ;
155     
156      public:
157         void sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) ;
158      private:
159         std::set<CContextClient*> sendAxisToCouplerOut_done_ ;
160   
161      public:
162         void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
163
164      private:
165         void sendAttributes(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
166                             CServerDistributionDescription::ServerDistributionType distType, const string& axisId="");
167         void sendDistributionAttribute(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
168                                        CServerDistributionDescription::ServerDistributionType distType, const string& axisId="");
169         
170
171         void sendNonDistributedAttributes(CContextClient* client, const string& axisId="");
172         void sendDistributedAttributes_old(CContextClient* client, const string& axisId="");
173
174         static void recvNonDistributedAttributes(CEventServer& event);
175         static void recvDistributedAttributes_old(CEventServer& event);
176         static void recvDistributionAttribute(CEventServer& event);
177         void recvNonDistributedAttributes(int rank, CBufferIn& buffer);
178         void recvDistributedAttributes_old(vector<int>& rank, vector<CBufferIn*> buffers);
179         void recvDistributionAttribute(CBufferIn& buffer);
180
181         void setTransformations(const TransMapTypes&);
182
183      private:
184
185/** Clients that have to send a axis. There can be multiple clients in case of secondary server, otherwise only one client. */
186         std::list<CContextClient*> clients;
187         std::set<CContextClient*> clientsSet;
188
189      private:
190         /** define if the axis is completed or not ie all attributes have been received before in case
191             of grid reading from file or coupling */ 
192         bool isCompleted_=true ; 
193      public:     
194         /*!
195           \brief Check if a axis is completed
196           Before make any axis processing, we must be sure that all axis informations have
197           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
198           other context (coupling). So all direct reference of the axis (axis_ref) must be also completed
199           \return true if axis and axis reference are completed
200          */
201         bool isCompleted(void)
202         {
203           if (hasDirectAxisReference()) if (!getDirectAxisReference()->isCompleted()) return false;
204           else return isCompleted_ ;
205         }
206         void setCompleted(void) { isCompleted_=true ; }
207         void unsetCompleted(void) { isCompleted_=false ; }
208     
209      private:
210         bool isChecked;
211         bool areClientAttributesChecked_;
212         bool isClientAfterTransformationChecked;
213         std::set<StdString> relFiles, relFilesCompressed;
214         TransMapTypes transformationMap_;         
215         //! True if and only if the data defined on the axis can be outputted in a compressed way
216         bool isCompressible_;
217
218         std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server
219         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server
220         // std::map<int, vector<int> > indWrittenSrv_; // Global written index of each client sent to server
221         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
222         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
223         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;
224         std::map<int, std::vector<int> > connectedServerRank_;
225         bool computedWrittenIndex_;                 
226
227       private:
228         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
229         static std::map<StdString, ETranformationType> transformationMapList_;
230         static bool dummyTransformationMapList_;
231
232
233       //////////////////////////////////////////////////////////////////////////////////////
234       //  this part is related to distribution, element definition, views and connectors  //
235       //////////////////////////////////////////////////////////////////////////////////////
236         
237        private:
238         CLocalElement* localElement_ = nullptr ;
239         void initializeLocalElement(void) ;
240        public: 
241         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
242         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
243        private:
244         void addFullView(void) ;
245         void addWorkflowView(void) ;
246         void addModelView(void) ;
247
248        private:
249         CLocalConnector* modelToWorkflowConnector_ ;
250         void computeModelToWorkflowConnector(void)  ;
251        public:
252         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
253       
254       public:
255         void computeRemoteElement(CContextClient* client, EDistributionType) ;
256         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& axisId="") ;
257
258         static void recvAxisDistribution(CEventServer& event) ;
259         void receivedAxisDistribution(CEventServer& event, int phasis) ;
260
261         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& axisId) ;
262         static void recvDistributedAttributes(CEventServer& event) ;
263         void recvDistributedAttributes(CEventServer& event, const string& type) ;
264       private:
265         map<CContextClient*, CDistributedElement*> remoteElement_ ;
266       public: 
267         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
268       private:
269         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
270       public: 
271         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
272       private:
273         CGathererConnector*  gathererConnector_ ;
274         CGathererConnector* serverFromClientConnector_ ;
275         CDistributedElement* elementFrom_ ;
276       public:
277        CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
278
279       private:
280         CScattererConnector*  serverToClientConnector_ = nullptr ;
281       public: 
282         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
283
284       private:
285          map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
286       public: 
287         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
288
289         DECLARE_REF_FUNC(Axis,axis)
290   }; // class CAxis
291
292   ///--------------------------------------------------------------
293
294   // Declare/Define CAxisGroup and CAxisDefinition
295   DECLARE_GROUP(CAxis);
296} // namespace xios
297
298#endif // __XIOS_CAxis__
Note: See TracBrowser for help on using the repository browser.