source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.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
  • Property svn:executable set to *
File size: 10.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
21namespace xios {
22   /// ////////////////////// Déclarations ////////////////////// ///
23
24   class CAxisGroup;
25   class CAxisAttributes;
26   class CAxis;
27
28   ///--------------------------------------------------------------
29
30   // Declare/Define CAxisAttribute
31   BEGIN_DECLARE_ATTRIBUTE_MAP(CAxis)
32#  include "axis_attribute.conf"
33   END_DECLARE_ATTRIBUTE_MAP(CAxis)
34
35   ///--------------------------------------------------------------
36
37   class CAxis
38      : public CObjectTemplate<CAxis>
39      , public CAxisAttributes
40   {
41               /// typedef ///
42         typedef CObjectTemplate<CAxis>   SuperClass;
43         typedef CAxisAttributes SuperClassAttribute;
44         
45      public:
46         enum EEventId
47         {
48           EVENT_ID_DISTRIBUTION_ATTRIBUTE,           
49           EVENT_ID_DISTRIBUTED_VALUE,
50           EVENT_ID_NON_DISTRIBUTED_VALUE,
51           EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES,
52           EVENT_ID_DISTRIBUTED_ATTRIBUTES
53         } ;
54
55      public:
56         typedef CAxisAttributes RelAttributes;
57         typedef CAxisGroup      RelGroup;
58         typedef CTransformation<CAxis>::TransformationMapTypes TransMapTypes;
59
60      public:
61         /// Constructeurs ///
62         CAxis(void);
63         explicit CAxis(const StdString & id);
64         CAxis(const CAxis & axis);       // Not implemented yet.
65         CAxis(const CAxis * const axis); // Not implemented yet.
66
67         static CAxis* createAxis();
68
69         /// Accesseurs ///
70         const std::set<StdString> & getRelFiles(void) const;
71
72         int getNumberWrittenIndexes(MPI_Comm writtenCom);
73         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
74         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
75         CArray<int, 1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
76
77         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
78                                                        CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
79
80         /// Test ///
81         bool IsWritten(const StdString & filename) const;
82         bool isWrittenCompressed(const StdString& filename) const;
83         bool isDistributed(void) const;
84         bool isCompressible(void) const;
85
86         /// Mutateur ///
87         void addRelFile(const StdString & filename);
88         void addRelFileCompressed(const StdString& filename);
89
90         
91
92         /// Destructeur ///
93         virtual ~CAxis(void);
94
95         virtual void parse(xml::CXMLNode & node);
96
97         void setContextClient(CContextClient* contextClient);
98
99         /// Accesseurs statiques ///
100         static StdString GetName(void);
101         static StdString GetDefName(void);
102         static ENodeType GetType(void);
103
104         static bool dispatchEvent(CEventServer& event);         
105       
106         /// Vérifications ///
107         void checkAttributes(void);
108         bool checkAttributes_done_ = false ;
109         
110         void checkAttributesOnClient();
111         void checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid,
112                                                         CServerDistributionDescription::ServerDistributionType distType = CServerDistributionDescription::BAND_DISTRIBUTION);
113         void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
114                                    CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
115
116         void checkEligibilityForCompressedOutput();
117         size_t getGlobalWrittenSize(void) ;
118
119         void computeWrittenIndex();
120         void computeWrittenCompressedIndex(MPI_Comm);
121         bool hasTransformation();
122         void solveInheritanceTransformation();
123         TransMapTypes getAllTransformations();         
124         void duplicateTransformation(CAxis*);
125         CTransformation<CAxis>* addTransformation(ETranformationType transType, const StdString& id="");
126         bool isEqual(CAxis* axis);
127
128      public: 
129        bool hasValue;       
130        bool hasBounds;
131        bool hasLabel;
132
133        CArray<int,1> localIndexToWriteOnServer;
134         
135         void computeConnectedClients(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid);
136         private: std::set<CContextClient*> computeConnectedClients_done_ ; public :
137         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
138         private: std::set<int> listNbServer_ ; public:
139
140      private:
141         void checkData();
142         void checkMask();
143         void checkBounds();
144         void checkLabel();
145      public:
146         void sendAxisToFileServer(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) ;
147      private:
148         std::set<CContextClient*> sendAxisToFileServer_done_ ;
149     
150      public:
151         void sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) ;
152      private:
153         std::set<CContextClient*> sendAxisToCouplerOut_done_ ;
154   
155      public:
156         void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
157
158      private:
159         void sendAttributes(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
160                             CServerDistributionDescription::ServerDistributionType distType, const string& axisId="");
161         void sendDistributionAttribute(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
162                                        CServerDistributionDescription::ServerDistributionType distType, const string& axisId="");
163         
164
165         void sendNonDistributedAttributes(CContextClient* client, const string& axisId="");
166         void sendDistributedAttributes(CContextClient* client, const string& axisId="");
167
168         static void recvNonDistributedAttributes(CEventServer& event);
169         static void recvDistributedAttributes(CEventServer& event);
170         static void recvDistributionAttribute(CEventServer& event);
171         void recvNonDistributedAttributes(int rank, CBufferIn& buffer);
172         void recvDistributedAttributes(vector<int>& rank, vector<CBufferIn*> buffers);
173         void recvDistributionAttribute(CBufferIn& buffer);
174
175         void setTransformations(const TransMapTypes&);
176
177      private:
178
179/** Clients that have to send a axis. There can be multiple clients in case of secondary server, otherwise only one client. */
180         std::list<CContextClient*> clients;
181         std::set<CContextClient*> clientsSet;
182
183      private:
184         /** define if the axis is completed or not ie all attributes have been received before in case
185             of grid reading from file or coupling */ 
186         bool isCompleted_=true ; 
187      public:     
188         /*!
189           \brief Check if a axis is completed
190           Before make any axis processing, we must be sure that all axis informations have
191           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
192           other context (coupling). So all direct reference of the axis (axis_ref) must be also completed
193           \return true if axis and axis reference are completed
194          */
195         bool isCompleted(void)
196         {
197           if (hasDirectAxisReference()) if (!getDirectAxisReference()->isCompleted()) return false;
198           else return isCompleted_ ;
199         }
200         void setCompleted(void) { isCompleted_=true ; }
201         void unsetCompleted(void) { isCompleted_=false ; }
202     
203      private:
204         bool isChecked;
205         bool areClientAttributesChecked_;
206         bool isClientAfterTransformationChecked;
207         std::set<StdString> relFiles, relFilesCompressed;
208         TransMapTypes transformationMap_;         
209         //! True if and only if the data defined on the axis can be outputted in a compressed way
210         bool isCompressible_;
211
212         std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server
213         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server
214         // std::map<int, vector<int> > indWrittenSrv_; // Global written index of each client sent to server
215         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
216         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
217         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;
218         std::map<int, std::vector<int> > connectedServerRank_;
219         bool computedWrittenIndex_;                 
220
221       private:
222         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
223         static std::map<StdString, ETranformationType> transformationMapList_;
224         static bool dummyTransformationMapList_;
225
226
227         
228        private:
229         CLocalElement* localElement_ = nullptr ;
230         void initializeLocalElement(void) ;
231        public: 
232         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
233         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
234        private:
235         void addFullView(void) ;
236         void addWorkflowView(void) ;
237         void addModelView(void) ;
238
239        private:
240         CLocalConnector* modelToWorkflowConnector_ ;
241         void computeModelToWorkflowConnector(void)  ;
242        public:
243         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
244
245
246         DECLARE_REF_FUNC(Axis,axis)
247   }; // class CAxis
248
249   ///--------------------------------------------------------------
250
251   // Declare/Define CAxisGroup and CAxisDefinition
252   DECLARE_GROUP(CAxis);
253} // namespace xios
254
255#endif // __XIOS_CAxis__
Note: See TracBrowser for help on using the repository browser.