[6607] | 1 | #ifndef __XIOS_CDomain__ |
---|
| 2 | #define __XIOS_CDomain__ |
---|
| 3 | |
---|
| 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
| 6 | #include "group_factory.hpp" |
---|
| 7 | |
---|
| 8 | #include "declare_group.hpp" |
---|
| 9 | #include "declare_ref_func.hpp" |
---|
| 10 | #include "event_client.hpp" |
---|
| 11 | #include "event_server.hpp" |
---|
| 12 | #include "buffer_in.hpp" |
---|
| 13 | #include "array_new.hpp" |
---|
| 14 | #include "attribute_array.hpp" |
---|
| 15 | #include "attribute_enum.hpp" |
---|
| 16 | #include "transformation.hpp" |
---|
| 17 | #include "transformation_enum.hpp" |
---|
| 18 | #include "server_distribution_description.hpp" |
---|
| 19 | #include "mesh.hpp" |
---|
| 20 | |
---|
| 21 | namespace xios { |
---|
| 22 | |
---|
| 23 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 24 | |
---|
| 25 | class CDomainGroup; |
---|
| 26 | class CDomainAttributes; |
---|
| 27 | class CDomain; |
---|
| 28 | class CFile; |
---|
| 29 | |
---|
| 30 | ///-------------------------------------------------------------- |
---|
| 31 | |
---|
| 32 | // Declare/Define CDomainAttribute |
---|
| 33 | BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain) |
---|
| 34 | # include "domain_attribute.conf" |
---|
| 35 | # include "domain_attribute_private.conf" |
---|
| 36 | END_DECLARE_ATTRIBUTE_MAP(CDomain) |
---|
| 37 | |
---|
| 38 | ///-------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | class CDomain |
---|
| 41 | : public CObjectTemplate<CDomain> |
---|
| 42 | , public CDomainAttributes |
---|
| 43 | { |
---|
| 44 | /// typedef /// |
---|
| 45 | typedef CObjectTemplate<CDomain> SuperClass; |
---|
| 46 | typedef CDomainAttributes SuperClassAttribute; |
---|
| 47 | public: |
---|
| 48 | enum EEventId |
---|
| 49 | { |
---|
| 50 | EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, |
---|
| 51 | EVENT_ID_AREA, |
---|
| 52 | EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT |
---|
| 53 | } ; |
---|
| 54 | |
---|
| 55 | public: |
---|
| 56 | |
---|
| 57 | typedef CDomainAttributes RelAttributes; |
---|
| 58 | typedef CDomainGroup RelGroup; |
---|
| 59 | typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes; |
---|
| 60 | |
---|
| 61 | /// Constructeurs /// |
---|
| 62 | CDomain(void); |
---|
| 63 | explicit CDomain(const StdString & id); |
---|
| 64 | CDomain(const CDomain & domain); // Not implemented yet. |
---|
| 65 | CDomain(const CDomain * const domain); // Not implemented yet. |
---|
| 66 | |
---|
| 67 | static CDomain* createDomain(); |
---|
| 68 | |
---|
| 69 | CMesh* mesh; |
---|
| 70 | void assignMesh(const StdString, const int); |
---|
| 71 | |
---|
| 72 | virtual void parse(xml::CXMLNode & node); |
---|
| 73 | |
---|
| 74 | void setContextClient(CContextClient* contextClient); |
---|
| 75 | |
---|
| 76 | /// Vérifications /// |
---|
| 77 | void checkAttributes(void); |
---|
| 78 | void checkAttributesOnClient(); |
---|
| 79 | void checkAttributesOnClientAfterTransformation(); |
---|
| 80 | void checkEligibilityForCompressedOutput(void); |
---|
| 81 | |
---|
| 82 | void sendCheckedAttributes(); |
---|
| 83 | |
---|
| 84 | bool hasTransformation(); |
---|
| 85 | void solveInheritanceTransformation(); |
---|
| 86 | TransMapTypes getAllTransformations(); |
---|
| 87 | void redistribute(int nbLocalDomain); |
---|
| 88 | void duplicateTransformation(CDomain*); |
---|
| 89 | CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id=""); |
---|
| 90 | |
---|
| 91 | public: |
---|
| 92 | const std::set<StdString> & getRelFiles(void) const; |
---|
| 93 | bool IsWritten(const StdString & filename) const; |
---|
| 94 | bool isWrittenCompressed(const StdString& filename) const; |
---|
| 95 | |
---|
| 96 | int getNumberWrittenIndexes(MPI_Comm writtenCom); |
---|
| 97 | int getTotalNumberWrittenIndexes(MPI_Comm writtenCom); |
---|
| 98 | int getOffsetWrittenIndexes(MPI_Comm writtenCom); |
---|
| 99 | CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom); |
---|
| 100 | |
---|
| 101 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); |
---|
| 102 | |
---|
| 103 | bool isEmpty(void) const; |
---|
| 104 | bool isDistributed(void) const; |
---|
| 105 | bool isCompressible(void) const; |
---|
| 106 | |
---|
| 107 | bool isTiled(void) const; |
---|
| 108 | bool isTiledOnly(void) const; |
---|
| 109 | int getTileId(int i, int j) const; |
---|
| 110 | int getTileDataISize(int tileId) const; |
---|
| 111 | int getTileDataJSize(int tileId) const; |
---|
| 112 | void computeCompressionTiled(CArray<int,1>& dataIndexI, CArray<int,1>& dataIndexJ, |
---|
| 113 | CArray<int,1>& infoIndexI, CArray<int,1>& infoIndexJ); |
---|
| 114 | |
---|
| 115 | std::vector<int> getNbGlob(); |
---|
| 116 | bool isEqual(CDomain* domain); |
---|
| 117 | |
---|
| 118 | static bool dispatchEvent(CEventServer& event); |
---|
| 119 | |
---|
| 120 | public: |
---|
| 121 | /// Mutateur /// |
---|
| 122 | void addRelFile(const StdString & filename); |
---|
| 123 | void addRelFileCompressed(const StdString& filename); |
---|
| 124 | |
---|
| 125 | void computeWrittenIndex(); |
---|
| 126 | void computeWrittenCompressedIndex(MPI_Comm); |
---|
| 127 | |
---|
| 128 | void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat, |
---|
| 129 | CArray<double,1>& lon_g, CArray<double,1>& lat_g); |
---|
| 130 | |
---|
| 131 | void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat, |
---|
| 132 | CArray<double,2>& boundsLon, CArray<double,2>& boundsLat); |
---|
| 133 | |
---|
| 134 | void fillInLonLat(); |
---|
| 135 | void initLonLatValue(); |
---|
| 136 | bool distributionAttributesHaveValue() const; |
---|
| 137 | |
---|
| 138 | size_t getGlobalWrittenSize() ; |
---|
| 139 | /// Destructeur /// |
---|
| 140 | virtual ~CDomain(void); |
---|
| 141 | |
---|
| 142 | /// Accesseurs statiques /// |
---|
| 143 | static StdString GetName(void); |
---|
| 144 | static StdString GetDefName(void); |
---|
| 145 | |
---|
| 146 | static ENodeType GetType(void); |
---|
| 147 | |
---|
| 148 | public: |
---|
| 149 | CArray<double, 1> lonvalue, latvalue; |
---|
| 150 | CArray<double, 2> bounds_lonvalue, bounds_latvalue; |
---|
| 151 | CArray<double, 1> areavalue; |
---|
| 152 | |
---|
| 153 | CArray<int,1> localIndexToWriteOnServer; |
---|
| 154 | |
---|
| 155 | CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask |
---|
| 156 | CArray<bool, 1> localMask; // domainMask + indexing |
---|
| 157 | bool isCurvilinear ; |
---|
| 158 | bool hasBounds ; |
---|
| 159 | bool hasArea; |
---|
| 160 | bool hasLonLat; |
---|
| 161 | bool hasPole ; |
---|
| 162 | bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined |
---|
| 163 | bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined |
---|
| 164 | bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined |
---|
| 165 | bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined |
---|
| 166 | |
---|
| 167 | void computeLocalMask(void) ; |
---|
| 168 | private: |
---|
| 169 | void checkDomain(void); |
---|
| 170 | void checkLocalIDomain(void); |
---|
| 171 | void checkLocalJDomain(void); |
---|
| 172 | |
---|
| 173 | void checkMask(void); |
---|
| 174 | void checkDomainData(void); |
---|
| 175 | void checkCompression(void); |
---|
| 176 | |
---|
| 177 | void checkBounds(void); |
---|
| 178 | void checkArea(void); |
---|
| 179 | void checkLonLat(); |
---|
| 180 | void checkTiles(); |
---|
| 181 | |
---|
| 182 | void setTransformations(const TransMapTypes&); |
---|
| 183 | void computeNGlobDomain(); |
---|
| 184 | void sendAttributes(); |
---|
| 185 | void sendIndex(); |
---|
| 186 | void sendDistributionAttributes(); |
---|
| 187 | void sendArea(); |
---|
| 188 | void sendLonLat(); |
---|
| 189 | void sendDataIndex(); |
---|
| 190 | void convertLonLatValue(); |
---|
| 191 | void fillInRectilinearLonLat(); |
---|
| 192 | void fillInCurvilinearLonLat(); |
---|
| 193 | void fillInUnstructuredLonLat(); |
---|
| 194 | |
---|
| 195 | static void recvDistributionAttributes(CEventServer& event); |
---|
| 196 | static void recvIndex(CEventServer& event); |
---|
| 197 | static void recvLon(CEventServer& event); |
---|
| 198 | static void recvLat(CEventServer& event); |
---|
| 199 | static void recvArea(CEventServer& event); |
---|
| 200 | static void recvDataIndex(CEventServer& event); |
---|
| 201 | void recvDistributionAttributes(CBufferIn& buffer); |
---|
| 202 | void recvIndex(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 203 | void recvLon(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 204 | void recvLat(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 205 | void recvArea(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 206 | void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 207 | |
---|
| 208 | void completeLonLatClient(void); |
---|
| 209 | void computeConnectedClients(); |
---|
| 210 | |
---|
| 211 | private: |
---|
| 212 | |
---|
| 213 | /** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
| 214 | std::list<CContextClient*> clients; |
---|
| 215 | std::set<CContextClient*> clientsSet; |
---|
| 216 | |
---|
| 217 | bool isChecked, computedWrittenIndex_; |
---|
| 218 | std::set<StdString> relFiles, relFilesCompressed; |
---|
| 219 | bool isClientChecked; // Verify whether all attributes of domain on the client side are good |
---|
| 220 | bool isClientAfterTransformationChecked; |
---|
| 221 | std::map<int, CArray<int,1> > indGlob_; |
---|
| 222 | std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server |
---|
| 223 | |
---|
| 224 | /** Global index of each client sent to server: map<serverSize, map<serverRank, indexes>> */ |
---|
| 225 | std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; |
---|
| 226 | // std::map<CContextClient*, std::map<int, vector<int> > > indWrittenSrv_; // Global written index of each client sent to server |
---|
| 227 | std::vector<int> indexesToWrite; |
---|
| 228 | std::vector<int> recvClientRanks_; |
---|
| 229 | std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
| 230 | std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer; |
---|
| 231 | std::map<int, std::map<int,size_t> > connectedDataSize_; |
---|
| 232 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
| 233 | |
---|
| 234 | //! True if and only if the data defined on the domain can be outputted in a compressed way |
---|
| 235 | bool isCompressible_; |
---|
| 236 | bool isRedistributed_; |
---|
| 237 | TransMapTypes transformationMap_; |
---|
| 238 | bool isUnstructed_; |
---|
| 239 | std::unordered_map<size_t,size_t> globalLocalIndexMap_; |
---|
| 240 | |
---|
| 241 | //! True if tiled data is defined on the domain |
---|
| 242 | bool isTiled_; |
---|
| 243 | //! True if ONLY tiled data is defined on the domain |
---|
| 244 | bool isTiledOnly_; |
---|
| 245 | |
---|
| 246 | private: |
---|
| 247 | static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m); |
---|
| 248 | static std::map<StdString, ETranformationType> transformationMapList_; |
---|
| 249 | static bool _dummyTransformationMapList; |
---|
| 250 | |
---|
| 251 | DECLARE_REF_FUNC(Domain,domain) |
---|
| 252 | |
---|
| 253 | }; // class CDomain |
---|
| 254 | |
---|
| 255 | ///-------------------------------------------------------------- |
---|
| 256 | |
---|
| 257 | // Declare/Define CDomainGroup and CDomainDefinition |
---|
| 258 | DECLARE_GROUP(CDomain); |
---|
| 259 | |
---|
| 260 | ///-------------------------------------------------------------- |
---|
| 261 | |
---|
| 262 | } // namespace xios |
---|
| 263 | |
---|
| 264 | #endif //__XIOS_CDomain__ |
---|