source: XIOS/dev/dev_olga/src/node/axis.hpp @ 1577

Last change on this file since 1577 was 1571, checked in by oabramkina, 6 years ago

Taking care of cases when a process doesn't possess a grid (its domain or axe size is zero).

Tested with CMIP6 toy models and IPSL model.

To do: remove grid mask from transformations.

  • 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: 8.6 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
19namespace xios {
20   /// ////////////////////// Déclarations ////////////////////// ///
21
22   class CAxisGroup;
23   class CAxisAttributes;
24   class CAxis;
25
26   ///--------------------------------------------------------------
27
28   // Declare/Define CAxisAttribute
29   BEGIN_DECLARE_ATTRIBUTE_MAP(CAxis)
30#  include "axis_attribute.conf"
31   END_DECLARE_ATTRIBUTE_MAP(CAxis)
32
33   ///--------------------------------------------------------------
34
35   class CAxis
36      : public CObjectTemplate<CAxis>
37      , public CAxisAttributes
38   {
39               /// typedef ///
40         typedef CObjectTemplate<CAxis>   SuperClass;
41         typedef CAxisAttributes SuperClassAttribute;
42         
43      public:
44         enum EEventId
45         {
46           EVENT_ID_DISTRIBUTION_ATTRIBUTE,           
47           EVENT_ID_DISTRIBUTED_VALUE,
48           EVENT_ID_NON_DISTRIBUTED_VALUE,
49           EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES,
50           EVENT_ID_DISTRIBUTED_ATTRIBUTES
51         } ;
52
53      public:
54         typedef CAxisAttributes RelAttributes;
55         typedef CAxisGroup      RelGroup;
56         typedef CTransformation<CAxis>::TransformationMapTypes TransMapTypes;
57
58      public:
59         /// Constructeurs ///
60         CAxis(void);
61         explicit CAxis(const StdString & id);
62         CAxis(const CAxis & axis);       // Not implemented yet.
63         CAxis(const CAxis * const axis); // Not implemented yet.
64
65         static CAxis* createAxis();
66
67         /// Accesseurs ///
68         const std::set<StdString> & getRelFiles(void) const;
69
70         int getNumberWrittenIndexes(MPI_Comm writtenCom);
71         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
72         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
73         CArray<int, 1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
74
75         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid,
76                                                        CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
77
78         /// Test ///
79         bool IsWritten(const StdString & filename) const;
80         bool isWrittenCompressed(const StdString& filename) const;
81         bool isDistributed(void) const;
82         bool isCompressible(void) const;
83
84         /// Mutateur ///
85         void addRelFile(const StdString & filename);
86         void addRelFileCompressed(const StdString& filename);
87
88         /// Vérifications ///
89         void checkAttributes(void);
90
91         /// Destructeur ///
92         virtual ~CAxis(void);
93
94         virtual void parse(xml::CXMLNode & node);
95
96         void setContextClient(CContextClient* contextClient);
97
98         /// Accesseurs statiques ///
99         static StdString GetName(void);
100         static StdString GetDefName(void);
101         static ENodeType GetType(void);
102
103         static bool dispatchEvent(CEventServer& event);         
104         
105         void checkAttributesOnClient();
106         void checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid,
107                                                         CServerDistributionDescription::ServerDistributionType distType = CServerDistributionDescription::BAND_DISTRIBUTION);
108         void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
109                                    CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
110
111         void checkEligibilityForCompressedOutput();
112         size_t getGlobalWrittenSize(void) ;
113
114         void computeWrittenIndex();
115         void computeWrittenCompressedIndex(MPI_Comm);
116
117         template <class T> void outputAxis(CArray<T,1>& valueIn, CArray<T,1>& valueOut);
118
119         bool hasTransformation();
120         void solveInheritanceTransformation();
121         TransMapTypes getAllTransformations();         
122         void duplicateTransformation(CAxis*);
123         CTransformation<CAxis>* addTransformation(ETranformationType transType, const StdString& id="");
124         bool isEqual(CAxis* axis);
125
126      public: 
127        bool hasValue;       
128        bool hasBounds;
129        bool hasLabel;
130
131//        CArray<size_t,1> localIndexToWriteOnServer;
132        CArray<int,1> localIndexToWriteOnServer;
133        CArray<size_t,1> localIndexToWriteOnClient;
134
135      private:
136         void checkData();
137         void checkMask();
138         void checkBounds();
139         void checkLabel();
140         void sendAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
141                             CServerDistributionDescription::ServerDistributionType distType);
142         void sendDistributionAttribute(const std::vector<int>& globalDim, int orderPositionInGrid,
143                                        CServerDistributionDescription::ServerDistributionType distType);
144         void computeConnectedClients(const std::vector<int>& globalDim, int orderPositionInGrid,
145                                     CServerDistributionDescription::ServerDistributionType distType);
146
147         void sendNonDistributedAttributes(void);
148         void sendDistributedAttributes(void);
149
150         static void recvNonDistributedAttributes(CEventServer& event);
151         static void recvDistributedAttributes(CEventServer& event);
152         static void recvDistributionAttribute(CEventServer& event);
153         void recvNonDistributedAttributes(int rank, CBufferIn& buffer);
154         void recvDistributedAttributes(vector<int>& rank, vector<CBufferIn*> buffers);
155         void recvDistributionAttribute(CBufferIn& buffer);
156
157         void setTransformations(const TransMapTypes&);
158
159      private:
160
161/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
162         std::list<CContextClient*> clients;
163         std::set<CContextClient*> clientsSet;
164
165         bool isChecked;
166         bool areClientAttributesChecked_;
167         bool isClientAfterTransformationChecked;
168         std::set<StdString> relFiles, relFilesCompressed;
169         TransMapTypes transformationMap_;         
170         //! True if and only if the data defined on the axis can be outputted in a compressed way
171         bool isCompressible_;
172         std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server
173         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server
174         // std::map<int, vector<int> > indWrittenSrv_; // Global written index of each client sent to server
175         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
176         std::vector<int> indexesToWrite;
177         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
178         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;
179         std::map<int, std::vector<int> > connectedServerRank_;
180         bool computedWrittenIndex_;                 
181
182       private:
183         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
184         static std::map<StdString, ETranformationType> transformationMapList_;
185         static bool dummyTransformationMapList_;
186
187         DECLARE_REF_FUNC(Axis,axis)
188   }; // class CAxis
189
190   ///--------------------------------------------------------------
191
192   template <class T> void CAxis::outputAxis(CArray<T,1>& valueIn, CArray<T,1>& valueOut)
193   {
194     int sizeServer = localIndexToWriteOnServer.numElements();
195     int sizeClient = localIndexToWriteOnClient.numElements();
196     valueOut.resize(sizeClient);
197
198     if (sizeServer == sizeClient)
199     {
200       valueOut = valueIn;
201     }
202     else
203     // a hole
204     {
205       valueOut = valueIn;
206       //valueOut = -1; initialize here to some value ????
207     }
208//      CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient;
209//      CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer;
210//      for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx)
211//      {
212//        fieldOut(outIndexServer(idx)) = recvDataSrv(outIndexClient(idx));
213//      }
214   }
215
216   // Declare/Define CAxisGroup and CAxisDefinition
217   DECLARE_GROUP(CAxis);
218} // namespace xios
219
220#endif // __XIOS_CAxis__
Note: See TracBrowser for help on using the repository browser.