source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp @ 2326

Last change on this file since 2326 was 2326, checked in by ymipsl, 2 years ago

Fix Deadlock from reading phase.
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: 17.2 KB
RevLine 
[591]1#ifndef __XIOS_CGrid__
2#define __XIOS_CGrid__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
9#include "domain.hpp"
10#include "axis.hpp"
[887]11#include "scalar.hpp"
[369]12#include "array_new.hpp"
13#include "attribute_array.hpp"
[552]14#include "distribution_server.hpp"
[553]15#include "client_server_mapping.hpp"
[567]16#include "utils.hpp"
[619]17#include "transformation_enum.hpp"
[1918]18#include "grid_local_connector.hpp"
19#include "grid_elements.hpp"
[1930]20#include "grid_scatterer_connector.hpp"
21#include "grid_gatherer_connector.hpp"
[1984]22#include "transformation_path.hpp"
23#include "filter.hpp"
[1999]24#include "grid_algorithm.hpp"
[219]25
[1930]26
[335]27namespace xios {
[509]28
[1564]29   /// ////////////////////// Declarations ////////////////////// ///
[219]30
31   class CGridGroup;
32   class CGridAttributes;
[540]33   class CDomainGroup;
34   class CAxisGroup;
[887]35   class CScalarGroup;
[219]36   class CGrid;
[551]37   class CDistributionClient;
[552]38   class CDistributionServer;
[553]39   class CServerDistributionDescription;
40   class CClientServerMapping;
[2011]41 
[219]42   ///--------------------------------------------------------------
43
44   // Declare/Define CGridAttribute
45   BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid)
46#  include "grid_attribute.conf"
47   END_DECLARE_ATTRIBUTE_MAP(CGrid)
48
49   ///--------------------------------------------------------------
50
51   class CGrid
52      : public CObjectTemplate<CGrid>
53      , public CGridAttributes
54   {
55         /// typedef ///
56         typedef CObjectTemplate<CGrid>   SuperClass;
57         typedef CGridAttributes SuperClassAttribute;
58
[1930]59      private:
60       
61        // define a structure to store elements (CDomain, CAxis, CScalar) using a void* and a type to cast the pointer
62         enum EElementType { TYPE_SCALAR, TYPE_AXIS, TYPE_DOMAIN } ;
63         struct SElement {void* ptr ; EElementType type ; CScalar* scalar ;  CAxis* axis ; CDomain* domain ; } ;
64         vector<SElement> elements_ ;
65         bool elementsComputed_ = false ; 
66         /** retrieve the vector of elements as a structure containing a void* and the type of pointer */
67         vector<SElement>& getElements(void) { if (!elementsComputed_) computeElements() ; return elements_ ; } 
68         void computeElements(void) ;
69         /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */
70         std::vector<int> order_;
71
[676]72      public:
[219]73
74         typedef CGridAttributes RelAttributes;
75         typedef CGridGroup      RelGroup;
76
[300]77         enum EEventId
78         {
[2326]79           EVENT_ID_COLLECTIVE=100,
[1973]80           EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR,
[1943]81           EVENT_ID_SEND_MASK,
[2326]82           EVENT_ID_NO_COLLECTIVE=1000,
[1943]83
[650]84         };
[509]85
[219]86         /// Constructeurs ///
87         CGrid(void);
[650]88         explicit CGrid(const StdString& id);
89         CGrid(const CGrid& grid);       // Not implemented yet.
90         CGrid(const CGrid* const grid); // Not implemented yet.
[219]91
92         /// Traitements ///
[509]93//         void solveReference(void);
[219]94
[676]95         void checkEligibilityForCompressedOutput();
[1930]96         
[676]97
[509]98
99         void checkMaskIndex(bool doCalculateIndex);
100
[650]101 //        virtual void toBinary  (StdOStream& os) const;
102//         virtual void fromBinary(StdIStream& is);
[219]103
[676]104         void addRelFileCompressed(const StdString& filename);
105
[219]106         /// Tests ///
[676]107         bool isCompressible(void) const;
108         bool isWrittenCompressed(const StdString& filename) const;
[219]109
[676]110      public:
[219]111
112         /// Accesseurs ///
[1158]113         StdSize getDimension(void);
[509]114
[1869]115         StdSize  getDataSize(void) ;
[219]116
[1875]117         /**
118          * Get the local data grid size, ie the size of the compressed grid (inside the workflow)
119          * \return The size od the compressed grid
120          */
121         StdSize  getLocalDataSize(void) ;
122
[1973]123 
[650]124         virtual void parse(xml::CXMLNode& node);
[540]125
[219]126         /// Destructeur ///
127         virtual ~CGrid(void);
128
[676]129      public:
[219]130
131         /// Accesseurs statiques ///
132         static StdString GetName(void);
133         static StdString GetDefName(void);
[509]134
[219]135         static ENodeType GetType(void);
136
137         /// Instanciateurs Statiques ///
[347]138         static CGrid* createGrid(CDomain* domain);
139         static CGrid* createGrid(CDomain* domain, CAxis* axis);
[745]140         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]141                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
[745]142         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]143                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
144         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
145                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder);
[2311]146         static CGrid* get(const string& id, bool noError=false) ; //<! return grid pointer using id
147         static bool has(const string& id) ; //<! return if grid exist using id
[2315]148         static CField* getFieldFromId(const string& id) ; //<! return field id if used in grid reference
[745]149         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]150                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
[823]151         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
152         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
[219]153
[2206]154         CDomain* getAssociatedDomain(const string& domainId, bool noError=false) ;
155         CAxis*   getAssociatedAxis(const string& axisId, bool noError=false) ;
156         CScalar* getAssociatedScalar(const string& scalarId, bool noError=false) ;
[1144]157      public:           
[1869]158         void solveDomainAxisRef(bool areAttributesChecked);
159         void checkElementsAttributes(void) ;
[219]160
[509]161         void solveDomainRef(bool checkAtt);
162         void solveAxisRef(bool checkAtt);
[887]163         void solveScalarRef(bool checkAtt);
[1869]164         void solveElementsRefInheritance(bool apply = true);
[2206]165         bool activateFieldWorkflow(CGarbageCollector& gc) ;
[1869]166        // void solveTransformations();
[775]167         void solveDomainAxisBaseRef();
[509]168
[835]169         CDomain* addDomain(const std::string& id=StdString());
170         CAxis* addAxis(const std::string& id=StdString());
[887]171         CScalar* addScalar(const std::string& id=StdString());
[1870]172
173      public:
174         void sendGridToFileServer(CContextClient* client) ;
175      private:
176         std::set<CContextClient*> sendGridToFileServer_done_ ;
[1875]177     
[1870]178      public:
[1875]179         void sendGridToCouplerOut(CContextClient* client, const string& fieldId) ;
180      private:
181         std::set<CContextClient*> sendGridToCouplerOut_done_ ;
182
183      public:
184         void makeAliasForCoupling(const string& fieldId) ;
[2022]185         string getCouplingAlias(const string& fieldId) ;
[1875]186
187      public:
[1784]188         void sendAddDomain(const std::string& id,CContextClient* contextClient);
189         void sendAddAxis(const std::string& id,CContextClient* contextClient);
190         void sendAddScalar(const std::string& id,CContextClient* contextClient);
[1974]191       
[650]192         static void recvAddDomain(CEventServer& event);
193         void recvAddDomain(CBufferIn& buffer);
194         static void recvAddAxis(CEventServer& event);
195         void recvAddAxis(CBufferIn& buffer);
[887]196         static void recvAddScalar(CEventServer& event);
197         void recvAddScalar(CBufferIn& buffer);
[540]198
[650]199         static bool dispatchEvent(CEventServer& event);
[1875]200       
201       public:
[1294]202         void setContextClient(CContextClient* contextClient);
203
[1330]204         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
205         std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false);
[540]206         std::vector<StdString> getDomainList();
207         std::vector<StdString> getAxisList();
[887]208         std::vector<StdString> getScalarList();
[540]209         std::vector<CDomain*> getDomains();
210         std::vector<CAxis*> getAxis();
[887]211         std::vector<CScalar*> getScalars();
[943]212         CDomain* getDomain(int domainIndex);
213         CAxis* getAxis(int axisIndex);
214         CScalar* getScalar(int scalarIndex);
[551]215         std::vector<int> getAxisOrder();
[567]216         std::vector<int> getGlobalDimension();
[1236]217         bool isScalarGrid() const;         
[540]218
[567]219         bool doGridHaveDataToWrite();
[1235]220         bool doGridHaveDataDistributed(CContextClient* client = 0);
[567]221
[1984]222         ///////////////////////////////////////////
223         ////////    TRANSFORMATIONS           /////
224         ///////////////////////////////////////////
225      public:
[1988]226         pair<shared_ptr<CFilter>, shared_ptr<CFilter> > buildTransformationGraph(CGarbageCollector& gc, bool isSource, CGrid* gridSrc, double detectMissingValues,
[2144]227                                                                                  double defaultValue, CGrid*& newGrid, bool graphEnabled=false, CField* field=0) ;
[1984]228      private:
[2270]229        shared_ptr<CGridAlgorithm> gridAlgorithm_ = nullptr ;
[1999]230      public:
[2270]231        void setGridAlgorithm(shared_ptr<CGridAlgorithm> gridAlgorithm) {gridAlgorithm_ = gridAlgorithm;}
232        shared_ptr<CGridAlgorithm> getGridAlgorithm(void) { return gridAlgorithm_ ;}
[1984]233       
234        ///////////////////////////////////////////
235      public:
236
237        size_t getGlobalWrittenSize(void) ;
[1875]238         
239         bool isCompleted(void) ;
240         void setCompleted(void) ;
241         void unsetCompleted(void) ;
[509]242
[1869]243
[1637]244         bool hasMask(void) const;
[1918]245        /** get mask pointer stored in mask_1d, or mask_2d, or..., or mask_7d */
246         CArray<bool,1> mask_ ;
247         CArray<bool,1>& getMask(void) ;
[509]248
[1973]249      private:
[1870]250        /** Client-like distribution calculated based on the knowledge of the entire grid */
251       CDistributionClient* clientDistribution_;
252     public: 
[1869]253       void computeClientDistribution(void) ;
[1870]254     private:
[1869]255       bool computeClientDistribution_done_ = false ;
[1870]256     public:
257       CDistributionClient* getClientDistribution(void); 
[1869]258
[1871]259     private:   
[540]260        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
261        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
[887]262        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
[567]263
[887]264        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
[540]265        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
[887]266        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
[540]267
[887]268        CDomainGroup* getVirtualDomainGroup() const;
[540]269        CAxisGroup* getVirtualAxisGroup() const;
[887]270        CScalarGroup* getVirtualScalarGroup() const;
[619]271
[1158]272        int computeGridGlobalDimension(std::vector<int>& globalDim,
273                                       const std::vector<CDomain*> domains,
274                                       const std::vector<CAxis*> axis,
275                                       const std::vector<CScalar*> scalars,
276                                       const CArray<int,1>& axisDomainOrder);
277        int getDistributedDimension();
[1794]278      public:
279
[1870]280        bool isDataDistributed(void) ; 
[540]281      private:
[1236]282
[1294]283/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
[1353]284        std::list<CContextClient*> clients;
285        std::set<CContextClient*> clientsSet;
[1294]286
[1870]287      private:
[1294]288        bool isChecked;
289        bool isDomainAxisChecked;
290        bool isIndexSent;
291
[540]292        CDomainGroup* vDomainGroup_;
293        CAxisGroup* vAxisGroup_;
[887]294        CScalarGroup* vScalarGroup_;
295        std::vector<std::string> axisList_, domList_, scalarList_;
296        bool isAxisListSet, isDomListSet, isScalarListSet;
[567]297
[1330]298/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
299  * It is calculated in computeConnectedClients(). */
[1263]300        std::map<int, std::vector<int> > connectedServerRank_;
[1243]301
[1330]302/** Map storing the size of data to be send. Key = size of receiver's intracomm
303  * It is calculated in computeConnectedClients(). */
[1263]304        std::map<int, std::map<int,size_t> > connectedDataSize_;
[1243]305
[1330]306/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
307        std::vector<int> connectedServerRankRead_;
308
309/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
310        std::map<int,size_t> connectedDataSizeRead_;
[1870]311     
[676]312         //! True if and only if the data defined on the grid can be outputted in a compressed way
313        bool isCompressible_;
314        std::set<std::string> relFilesCompressed;
[619]315
[1870]316       
[620]317        std::vector<int> axisPositionInGrid_;
[1870]318        void computeAxisPositionInGrid(void) ;
319        bool computeAxisPositionInGrid_done_ = false ;
320        std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;}
321
[1158]322        bool hasDomainAxisBaseRef_;       
[823]323        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
[1243]324
[1930]325     //////////////////////////////////////////////////////////////////////////////////////
326     //  this part is related to distribution, element definition, views and connectors  //
327     //////////////////////////////////////////////////////////////////////////////////////
[1984]328      public:
329       CGrid* duplicateSentGrid(void) ;
[1943]330      private:
331       static void recvMask(CEventServer& event) ;
332       void receiveMask(CEventServer& event) ;
[1243]333
[1918]334      private: 
[2267]335       shared_ptr<CGridLocalElements> gridLocalElements_= nullptr ;
[1918]336        void computeGridLocalElements(void) ;
337      public:
[2267]338        shared_ptr<CGridLocalElements> getGridLocalElements(void) { if (gridLocalElements_==nullptr) computeGridLocalElements() ; return gridLocalElements_ ;}
[1918]339
340      private:
[2267]341        shared_ptr<CGridLocalConnector> modelToWorkflowConnector_ = nullptr ;
[1918]342      public:
343        void computeModelToWorkflowConnector(void) ;
[2267]344        shared_ptr<CGridLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;}
[1918]345
[1930]346      private:
[2267]347        shared_ptr<CGridLocalConnector> workflowToModelConnector_ = nullptr;
[1930]348      public:
349        void computeWorkflowToModelConnector(void) ;
[2267]350        shared_ptr<CGridLocalConnector> getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;}
[1930]351
352      public: //?
[2022]353        void distributeGridToServer(CContextClient* client, const string& fieldId="");
[1930]354     
[1934]355           
[1930]356      private:
[2267]357        shared_ptr<CGridLocalConnector> workflowToFullConnector_ = nullptr;
[1930]358      public:
359        void computeWorkflowToFullConnector(void) ;
[2267]360        shared_ptr<CGridLocalConnector> getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;}
[1930]361
362      private:
[2267]363        shared_ptr<CGridLocalConnector> fullToWorkflowConnector_ = nullptr;
[1930]364      public:
365        void computeFullToWorkflowConnector(void) ;
[2267]366        shared_ptr<CGridLocalConnector> getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;}
[1930]367
[1934]368   
369
[1930]370      private:
[2267]371         shared_ptr<CGridGathererConnector> clientFromClientConnector_ = nullptr ;
[1930]372      public:
[2267]373         shared_ptr<CGridGathererConnector> getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;}
[1930]374         void computeClientFromClientConnector(void) ;
375
376      private:
[2267]377         map<CContextClient*, shared_ptr<CGridScattererConnector>> clientToClientConnector_ ;
[1930]378      public:
[2267]379         shared_ptr<CGridScattererConnector> getClientToClientConnector(CContextClient* client) { return clientToClientConnector_[client] ;} // make some test to see if connector exits for the given client
[1930]380 
381
382      private:
[2267]383         map<CContextClient*,shared_ptr<CGridGathererConnector>> clientFromServerConnector_  ;
[1930]384      public:
[2267]385         shared_ptr<CGridGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
[1930]386         void computeClientFromServerConnector(void) ;
387
[1934]388      private:
[2267]389         shared_ptr<CGridScattererConnector> serverToClientConnector_=nullptr ;
[1934]390      public:
[2267]391         shared_ptr<CGridScattererConnector> getServerToClientConnector(void) { if (serverToClientConnector_==nullptr) computeServerToClientConnector() ; return serverToClientConnector_;}
[1934]392         void computeServerToClientConnector(void) ;
393      private:
[2267]394         map<CContextClient*, shared_ptr<CGridScattererConnector>> clientToServerConnector_ ;
[1934]395      public:
[2267]396         shared_ptr<CGridScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client
[1934]397         
398      private:
[2267]399         shared_ptr<CGridGathererConnector> serverFromClientConnector_ = nullptr ;
[1934]400      public:
[2267]401         shared_ptr<CGridGathererConnector> getServerFromClientConnector(void) { if (serverFromClientConnector_==nullptr) computeServerFromClientConnector() ; return serverFromClientConnector_;}
[1934]402         void computeServerFromClientConnector(void) ;
403
[219]404   }; // class CGrid
405
406   // Declare/Define CGridGroup and CGridDefinition
407   DECLARE_GROUP(CGrid);
408
409   ///--------------------------------------------------------------
410
[335]411} // namespace xios
[219]412
[591]413#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.