[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" |
---|
[219] | 18 | |
---|
[335] | 19 | namespace xios { |
---|
[509] | 20 | |
---|
[1564] | 21 | /// ////////////////////// Declarations ////////////////////// /// |
---|
[219] | 22 | |
---|
| 23 | class CGridGroup; |
---|
| 24 | class CGridAttributes; |
---|
[540] | 25 | class CDomainGroup; |
---|
| 26 | class CAxisGroup; |
---|
[887] | 27 | class CScalarGroup; |
---|
[219] | 28 | class CGrid; |
---|
[551] | 29 | class CDistributionClient; |
---|
[552] | 30 | class CDistributionServer; |
---|
[553] | 31 | class CServerDistributionDescription; |
---|
| 32 | class CClientServerMapping; |
---|
[620] | 33 | class CGridTransformation; |
---|
[219] | 34 | |
---|
| 35 | ///-------------------------------------------------------------- |
---|
| 36 | |
---|
| 37 | // Declare/Define CGridAttribute |
---|
| 38 | BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid) |
---|
| 39 | # include "grid_attribute.conf" |
---|
| 40 | END_DECLARE_ATTRIBUTE_MAP(CGrid) |
---|
| 41 | |
---|
| 42 | ///-------------------------------------------------------------- |
---|
| 43 | |
---|
| 44 | class CGrid |
---|
| 45 | : public CObjectTemplate<CGrid> |
---|
| 46 | , public CGridAttributes |
---|
| 47 | { |
---|
| 48 | /// typedef /// |
---|
| 49 | typedef CObjectTemplate<CGrid> SuperClass; |
---|
| 50 | typedef CGridAttributes SuperClassAttribute; |
---|
| 51 | |
---|
[676] | 52 | public: |
---|
[219] | 53 | |
---|
| 54 | typedef CGridAttributes RelAttributes; |
---|
| 55 | typedef CGridGroup RelGroup; |
---|
| 56 | |
---|
[300] | 57 | enum EEventId |
---|
| 58 | { |
---|
[887] | 59 | EVENT_ID_INDEX, EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR |
---|
[650] | 60 | }; |
---|
[509] | 61 | |
---|
[219] | 62 | /// Constructeurs /// |
---|
| 63 | CGrid(void); |
---|
[650] | 64 | explicit CGrid(const StdString& id); |
---|
| 65 | CGrid(const CGrid& grid); // Not implemented yet. |
---|
| 66 | CGrid(const CGrid* const grid); // Not implemented yet. |
---|
[219] | 67 | |
---|
| 68 | /// Traitements /// |
---|
[509] | 69 | // void solveReference(void); |
---|
[219] | 70 | |
---|
[676] | 71 | void checkEligibilityForCompressedOutput(); |
---|
| 72 | |
---|
[509] | 73 | |
---|
[1869] | 74 | |
---|
[509] | 75 | void checkMaskIndex(bool doCalculateIndex); |
---|
| 76 | |
---|
[650] | 77 | // virtual void toBinary (StdOStream& os) const; |
---|
| 78 | // virtual void fromBinary(StdIStream& is); |
---|
[219] | 79 | |
---|
[676] | 80 | void addRelFileCompressed(const StdString& filename); |
---|
| 81 | |
---|
[219] | 82 | /// Tests /// |
---|
[676] | 83 | bool isCompressible(void) const; |
---|
| 84 | bool isWrittenCompressed(const StdString& filename) const; |
---|
[219] | 85 | |
---|
[676] | 86 | public: |
---|
[219] | 87 | |
---|
| 88 | /// Accesseurs /// |
---|
[1158] | 89 | StdSize getDimension(void); |
---|
[509] | 90 | |
---|
[1869] | 91 | StdSize getDataSize(void) ; |
---|
[219] | 92 | |
---|
[1564] | 93 | /// Entrees-sorties de champs |
---|
[369] | 94 | template <int n> |
---|
[1869] | 95 | void inputField(const CArray<double,n>& field, CArray<double,1>& stored) ; |
---|
[593] | 96 | template <int n> |
---|
[1869] | 97 | void maskField(const CArray<double,n>& field, CArray<double,1>& stored) ; |
---|
[1637] | 98 | template <int n> |
---|
[1869] | 99 | void outputField(const CArray<double,1>& stored, CArray<double,n>& field) ; |
---|
[1250] | 100 | template <int n> |
---|
[1869] | 101 | void uncompressField(const CArray<double,n>& data, CArray<double,1>& outData) ; |
---|
[509] | 102 | |
---|
[650] | 103 | virtual void parse(xml::CXMLNode& node); |
---|
[540] | 104 | |
---|
[219] | 105 | /// Destructeur /// |
---|
| 106 | virtual ~CGrid(void); |
---|
| 107 | |
---|
[676] | 108 | public: |
---|
[219] | 109 | |
---|
| 110 | /// Accesseurs statiques /// |
---|
| 111 | static StdString GetName(void); |
---|
| 112 | static StdString GetDefName(void); |
---|
[509] | 113 | |
---|
[219] | 114 | static ENodeType GetType(void); |
---|
| 115 | |
---|
| 116 | /// Instanciateurs Statiques /// |
---|
[347] | 117 | static CGrid* createGrid(CDomain* domain); |
---|
| 118 | static CGrid* createGrid(CDomain* domain, CAxis* axis); |
---|
[745] | 119 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 120 | const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[745] | 121 | static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 122 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
| 123 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 124 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder); |
---|
[745] | 125 | static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 126 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[823] | 127 | static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest); |
---|
| 128 | static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc); |
---|
[219] | 129 | |
---|
[1144] | 130 | public: |
---|
[219] | 131 | void computeIndexServer(void); |
---|
| 132 | void computeIndex(void); |
---|
[586] | 133 | void computeIndexScalarGrid(); |
---|
[1129] | 134 | void computeWrittenIndex(); |
---|
[1869] | 135 | void solveDomainAxisRef(bool areAttributesChecked); |
---|
| 136 | void checkElementsAttributes(void) ; |
---|
[219] | 137 | |
---|
[509] | 138 | void solveDomainRef(bool checkAtt); |
---|
| 139 | void solveAxisRef(bool checkAtt); |
---|
[887] | 140 | void solveScalarRef(bool checkAtt); |
---|
[1869] | 141 | void solveElementsRefInheritance(bool apply = true); |
---|
| 142 | // void solveTransformations(); |
---|
[775] | 143 | void solveDomainAxisBaseRef(); |
---|
[509] | 144 | |
---|
[835] | 145 | CDomain* addDomain(const std::string& id=StdString()); |
---|
| 146 | CAxis* addAxis(const std::string& id=StdString()); |
---|
[887] | 147 | CScalar* addScalar(const std::string& id=StdString()); |
---|
[1870] | 148 | |
---|
| 149 | public: |
---|
| 150 | void sendGridToFileServer(CContextClient* client) ; |
---|
| 151 | private: |
---|
| 152 | std::set<CContextClient*> sendGridToFileServer_done_ ; |
---|
| 153 | |
---|
| 154 | public: |
---|
[1784] | 155 | void sendAddDomain(const std::string& id,CContextClient* contextClient); |
---|
| 156 | void sendAddAxis(const std::string& id,CContextClient* contextClient); |
---|
| 157 | void sendAddScalar(const std::string& id,CContextClient* contextClient); |
---|
| 158 | void sendAllDomains(CContextClient* contextClient); |
---|
| 159 | void sendAllAxis(CContextClient* contextClient); |
---|
| 160 | void sendAllScalars(CContextClient* contextClient); |
---|
[540] | 161 | |
---|
[650] | 162 | static void recvAddDomain(CEventServer& event); |
---|
| 163 | void recvAddDomain(CBufferIn& buffer); |
---|
| 164 | static void recvAddAxis(CEventServer& event); |
---|
| 165 | void recvAddAxis(CBufferIn& buffer); |
---|
[887] | 166 | static void recvAddScalar(CEventServer& event); |
---|
| 167 | void recvAddScalar(CBufferIn& buffer); |
---|
[540] | 168 | |
---|
[650] | 169 | static bool dispatchEvent(CEventServer& event); |
---|
| 170 | static void recvIndex(CEventServer& event); |
---|
[1853] | 171 | void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers, CContextServer* server); |
---|
[650] | 172 | void sendIndex(void); |
---|
[586] | 173 | void sendIndexScalarGrid(); |
---|
[509] | 174 | |
---|
[1294] | 175 | void setContextClient(CContextClient* contextClient); |
---|
| 176 | |
---|
[509] | 177 | void computeDomConServer(); |
---|
| 178 | std::map<int, int> getDomConServerSide(); |
---|
[1330] | 179 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); |
---|
| 180 | std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false); |
---|
[540] | 181 | std::vector<StdString> getDomainList(); |
---|
| 182 | std::vector<StdString> getAxisList(); |
---|
[887] | 183 | std::vector<StdString> getScalarList(); |
---|
[540] | 184 | std::vector<CDomain*> getDomains(); |
---|
| 185 | std::vector<CAxis*> getAxis(); |
---|
[887] | 186 | std::vector<CScalar*> getScalars(); |
---|
[943] | 187 | CDomain* getDomain(int domainIndex); |
---|
| 188 | CAxis* getAxis(int axisIndex); |
---|
| 189 | CScalar* getScalar(int scalarIndex); |
---|
[551] | 190 | std::vector<int> getAxisOrder(); |
---|
[567] | 191 | std::vector<int> getGlobalDimension(); |
---|
[1236] | 192 | bool isScalarGrid() const; |
---|
[540] | 193 | |
---|
[567] | 194 | bool doGridHaveDataToWrite(); |
---|
[1235] | 195 | bool doGridHaveDataDistributed(CContextClient* client = 0); |
---|
[1871] | 196 | size_t getWrittenDataSize() ; |
---|
[676] | 197 | int getNumberWrittenIndexes() const; |
---|
| 198 | int getTotalNumberWrittenIndexes() const; |
---|
| 199 | int getOffsetWrittenIndexes() const; |
---|
[567] | 200 | |
---|
[620] | 201 | CGridTransformation* getTransformations(); |
---|
[567] | 202 | |
---|
[632] | 203 | void transformGrid(CGrid* transformGridSrc); |
---|
[1869] | 204 | |
---|
| 205 | void prepareTransformGrid(CGrid* transformGridSrc); |
---|
| 206 | bool prepareTransformGrid_done_ = false ; |
---|
| 207 | |
---|
| 208 | void makeTransformGrid(void); |
---|
| 209 | bool makeTransformGrid_done_ = false ; |
---|
| 210 | |
---|
| 211 | std::vector<std::string> getAuxInputTransformGrid(void) ; |
---|
| 212 | |
---|
[775] | 213 | void completeGrid(CGrid* transformGridSrc = 0); |
---|
[687] | 214 | void doAutoDistribution(CGrid* transformGridSrc); |
---|
[619] | 215 | bool isTransformed(); |
---|
| 216 | void setTransformed(); |
---|
[890] | 217 | bool isGenerated(); |
---|
| 218 | void setGenerated(); |
---|
[823] | 219 | void addTransGridSource(CGrid* gridSrc); |
---|
| 220 | std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource(); |
---|
[824] | 221 | bool hasTransform(); |
---|
[1215] | 222 | size_t getGlobalWrittenSize(void) ; |
---|
[1869] | 223 | bool checkIfCompleted(void) ; |
---|
[509] | 224 | |
---|
[1869] | 225 | |
---|
[1637] | 226 | bool hasMask(void) const; |
---|
[650] | 227 | void checkMask(void); |
---|
[821] | 228 | void createMask(void); |
---|
[1129] | 229 | void modifyMask(const CArray<int,1>& indexToModify, bool valueToModify = false); |
---|
| 230 | void modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue = false); |
---|
[509] | 231 | |
---|
[742] | 232 | void computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 233 | const std::vector<CAxis*>& axis, |
---|
[887] | 234 | const std::vector<CScalar*>& scalars, |
---|
| 235 | const CArray<int,1>& axisDomainOrder); |
---|
[742] | 236 | |
---|
[1869] | 237 | void computeGridIndexToFileServer(CContextClient* client) ; |
---|
[1870] | 238 | |
---|
| 239 | private: |
---|
| 240 | /** Client-like distribution calculated based on the knowledge of the entire grid */ |
---|
| 241 | CDistributionClient* clientDistribution_; |
---|
| 242 | public: |
---|
[1869] | 243 | void computeClientDistribution(void) ; |
---|
[1870] | 244 | private: |
---|
[1869] | 245 | bool computeClientDistribution_done_ = false ; |
---|
[1870] | 246 | public: |
---|
| 247 | CDistributionClient* getClientDistribution(void); |
---|
[1869] | 248 | |
---|
[1871] | 249 | private: |
---|
| 250 | /** Server-like distribution calculated upon receiving indexes */ |
---|
| 251 | CDistributionServer* serverDistribution_; |
---|
| 252 | void computeServerDistribution(void) ; |
---|
| 253 | bool computeServerDistribution_done_=false ; |
---|
| 254 | public: |
---|
[1872] | 255 | CDistributionServer* getServerDistribution(void) { if (!computeServerDistribution_done_) computeServerDistribution() ; return serverDistribution_ ;} |
---|
[1871] | 256 | |
---|
| 257 | |
---|
[1870] | 258 | private: |
---|
[567] | 259 | template<int N> |
---|
| 260 | void checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 261 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 262 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 263 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 264 | bool createMask = false); |
---|
[623] | 265 | template<int N> |
---|
[1129] | 266 | void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify); |
---|
[623] | 267 | |
---|
[1129] | 268 | template<int N> |
---|
| 269 | void modifyGridMaskSize(CArray<bool,N>& gridMask, const std::vector<int>& eachDimSize, bool newValue); |
---|
| 270 | |
---|
[1869] | 271 | void storeField_arr(const double* const data, CArray<double, 1>& stored) ; |
---|
| 272 | void restoreField_arr(const CArray<double, 1>& stored, double* const data) ; |
---|
| 273 | void uncompressField_arr(const double* const data, CArray<double, 1>& outData) ; |
---|
| 274 | void maskField_arr(const double* const data, CArray<double, 1>& stored) ; |
---|
[1144] | 275 | |
---|
[540] | 276 | void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); |
---|
| 277 | void setVirtualAxisGroup(CAxisGroup* newVAxisGroup); |
---|
[887] | 278 | void setVirtualScalarGroup(CScalarGroup* newVScalarGroup); |
---|
[567] | 279 | |
---|
[887] | 280 | void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>()); |
---|
[540] | 281 | void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>()); |
---|
[887] | 282 | void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>()); |
---|
[540] | 283 | |
---|
[887] | 284 | CDomainGroup* getVirtualDomainGroup() const; |
---|
[540] | 285 | CAxisGroup* getVirtualAxisGroup() const; |
---|
[887] | 286 | CScalarGroup* getVirtualScalarGroup() const; |
---|
[619] | 287 | |
---|
[657] | 288 | void checkAttributesAfterTransformation(); |
---|
[619] | 289 | void setTransformationAlgorithms(); |
---|
[1542] | 290 | void computeIndexByElement(const std::vector<std::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
[1263] | 291 | const CContextClient* client, |
---|
[865] | 292 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer); |
---|
[1158] | 293 | int computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 294 | const std::vector<CDomain*> domains, |
---|
| 295 | const std::vector<CAxis*> axis, |
---|
| 296 | const std::vector<CScalar*> scalars, |
---|
| 297 | const CArray<int,1>& axisDomainOrder); |
---|
| 298 | int getDistributedDimension(); |
---|
[619] | 299 | |
---|
[1869] | 300 | void computeConnectedClients(CContextClient* client); |
---|
| 301 | set<CContextClient*> computeConnectedClients_done_ ; |
---|
| 302 | |
---|
| 303 | void computeConnectedClientsScalarGrid(CContextClient* client); |
---|
| 304 | set<CContextClient*> computeConnectedClientsScalarGrid_done_ ; |
---|
[1794] | 305 | |
---|
| 306 | public: |
---|
| 307 | /** Array containing the local index of the grid |
---|
| 308 | * storeIndex_client[local_workflow_grid_index] -> local_model_grid_index. |
---|
| 309 | * Used to store field from model into the worklow, or to return field into models. |
---|
| 310 | * The size of the array is the number of local index of the workflow grid */ |
---|
[1869] | 311 | CArray<int, 1> storeIndex_client_; |
---|
| 312 | void computeStoreIndex_client(void) ; |
---|
| 313 | bool computeStoreIndex_client_done_ = false ; |
---|
| 314 | CArray<int, 1>& getStoreIndex_client(void) { if (!computeStoreIndex_client_done_) computeStoreIndex_client() ; return storeIndex_client_ ;} |
---|
[1794] | 315 | |
---|
| 316 | /** Array containing the grid mask masked defined by the mask_nd grid attribute. |
---|
| 317 | * The corresponding masked field value provided by the model will be replaced by a NaN value |
---|
| 318 | * in the workflow. */ |
---|
[1869] | 319 | CArray<bool, 1> storeMask_client_; |
---|
| 320 | void computeStoreMask_client(void) ; |
---|
| 321 | bool computeStoreMask_client_done_ = false ; |
---|
| 322 | CArray<bool, 1>& getStoreMask_client(void) { if (!computeStoreMask_client_done_) computeStoreMask_client() ; return storeMask_client_ ;} |
---|
[1794] | 323 | |
---|
| 324 | /** Map containing the indexes on client side that will be sent to each connected server. |
---|
| 325 | * storeIndex_toSrv[&contextClient] -> map concerning the contextClient for which the data will be sent (client side) |
---|
| 326 | * storeIndex_toSrv[&contextClient][rank] -> array of indexes that will be sent to each "rank" of the connected servers |
---|
| 327 | * storeIndex_toSrv[&contextClient][rank](index_of_buffer_sent_to_server) -> local index of the field of the workflow |
---|
| 328 | * grid that will be sent to server */ |
---|
| 329 | std::map<CContextClient*, map<int, CArray<int, 1> > > storeIndex_toSrv_; |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | /** Map containing the indexes on client side that will be received from each connected server. |
---|
| 333 | * This map is used to agreggate field data received from server (for reading) into a single array, which will be an entry |
---|
| 334 | * point of the worklow on client side. |
---|
| 335 | * storeIndex_toSrv[rank] -> array of indexes that will be received from each "rank" of the connected servers |
---|
| 336 | * storeIndex_toSrv[rank](index_of_buffer_received_from_server) -> local index of the field in the "workflow grid" |
---|
| 337 | * that has been received from server */ |
---|
| 338 | std::map<int, CArray<int, 1> > storeIndex_fromSrv_; // Support, for now, reading with level-1 server |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | /** Maps storing the number of participating clients for data sent a specific server for a given contextClient, identified |
---|
| 342 | * by the servers communicator size. In future must be direcly identified by context. |
---|
| 343 | * nbSender_[context_server_size] -> map the number of client sender by connected rank of servers |
---|
| 344 | * nbSender_[context_server_size] [rank_server] -> the number of client participating to a send message for a server of rank "rank_server" |
---|
| 345 | * Usefull to indicate in a message the number of participant needed by the transfer protocol */ |
---|
| 346 | std::map<int, std::map<int,int> > nbSenders_; |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | /** Maps storing the number of participating servers for data sent a specific client for a given contextClient. |
---|
| 350 | * Symetric of nbSenders_, but for server side which want to send data to client. |
---|
| 351 | * nbReadSender_[context_client_size] -> map the number of server sender by connected rank of clients |
---|
| 352 | * nbReadSender_[context_client_size] [rank_client] -> the number of serverq participating to a send message for a client of rank "rank_client" |
---|
| 353 | * Usefull to indicate in a message the number of participant needed by the transfer protocol */ |
---|
| 354 | std::map<CContextClient*, std::map<int,int> > nbReadSenders_; |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | // Manh Ha's comment: " A client receives global index from other clients (via recvIndex) |
---|
| 358 | // then does mapping these index into local index of STORE_CLIENTINDEX |
---|
| 359 | // In this way, store_clientIndex can be used as an input of a source filter |
---|
| 360 | // Maybe we need a flag to determine whether a client wants to write. TODO " |
---|
| 361 | |
---|
[1870] | 362 | private: |
---|
| 363 | /** Map storing received data on server side. This map is the equivalent to the storeIndex_client, but for data received from client |
---|
| 364 | * instead that from model. This map is used to concatenate data received from several clients into a single array on server side |
---|
| 365 | * which match the local workflow grid. |
---|
| 366 | * outLocalIndexStoreOnClient_[client_rank] -> Array of index from client of rank "client_rank" |
---|
| 367 | * outLocalIndexStoreOnClient_[client_rank](index of buffer from client) -> local index of the workflow grid |
---|
| 368 | * The map is created in CGrid::computeClientIndex and filled upon receiving data in CField::recvUpdateData(). |
---|
| 369 | * Symetrically it is also used to send data from a server to several client for reading case. */ |
---|
| 370 | map<int, CArray<size_t, 1>> outLocalIndexStoreOnClient_; |
---|
| 371 | public: |
---|
| 372 | void computeOutLocalIndexStoreOnClient(void) ; |
---|
| 373 | private: |
---|
| 374 | bool computeOutLocalIndexStoreOnClient_done_ = false ; |
---|
| 375 | public: |
---|
| 376 | map<int, CArray<size_t, 1>>& getOutLocalIndexStoreOnClient(void) |
---|
| 377 | { if (!computeOutLocalIndexStoreOnClient_done_) computeOutLocalIndexStoreOnClient(); return outLocalIndexStoreOnClient_ ; } |
---|
[1794] | 378 | |
---|
[1870] | 379 | public: |
---|
[1794] | 380 | /** Indexes calculated based on server-like distribution. |
---|
| 381 | * They are used for writing/reading data and only calculated for server level that does the writing/reading. |
---|
[1847] | 382 | * Along with localIndexToWriteOnClient, these indexes are used to correctly place incoming data. |
---|
| 383 | * size of the array : numberWrittenIndexes_ : number of index written in a compressed way |
---|
| 384 | * localIndexToWriteOnServer_(compressed_written_index) : -> local uncompressed index that will be written in the file */ |
---|
| 385 | CArray<size_t,1> localIndexToWriteOnServer_; |
---|
[1794] | 386 | |
---|
| 387 | /** Indexes calculated based on client-like distribution. |
---|
| 388 | * They are used for writing/reading data and only calculated for server level that does the writing/reading. |
---|
[1847] | 389 | * Along with localIndexToWriteOnServer, these indexes are used to correctly place incoming data. |
---|
| 390 | * size of the array : numberWrittenIndexes_ |
---|
| 391 | * localIndexToWriteOnClient_(compressed_written_index) -> local index of the workflow grid*/ |
---|
| 392 | CArray<size_t,1> localIndexToWriteOnClient_; |
---|
[1794] | 393 | |
---|
[1870] | 394 | public: |
---|
| 395 | bool isDataDistributed(void) ; |
---|
[540] | 396 | private: |
---|
[1236] | 397 | |
---|
[1294] | 398 | /** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
[1353] | 399 | std::list<CContextClient*> clients; |
---|
| 400 | std::set<CContextClient*> clientsSet; |
---|
[1294] | 401 | |
---|
[1870] | 402 | private: |
---|
| 403 | /** Map storing received indexes on server side sent by clients. Key = sender rank, value = global index array. |
---|
| 404 | Later, the global indexes received will be mapped onto local index computed with the local distribution. |
---|
| 405 | outGlobalIndexFromClient_[rank] -> array of global index send by client of rank "rank" |
---|
| 406 | outGlobalIndexFromClient_[rank](n) -> global index of datav n sent by client |
---|
| 407 | */ |
---|
[1847] | 408 | map<int, CArray<size_t, 1> > outGlobalIndexFromClient_; |
---|
[1870] | 409 | public: |
---|
| 410 | map<int, CArray<size_t, 1> >& getOutGlobalIndexFromClient() { return outGlobalIndexFromClient_ ;} |
---|
[1794] | 411 | |
---|
[1870] | 412 | private: |
---|
[1294] | 413 | bool isChecked; |
---|
| 414 | bool isDomainAxisChecked; |
---|
| 415 | bool isIndexSent; |
---|
| 416 | |
---|
[540] | 417 | CDomainGroup* vDomainGroup_; |
---|
| 418 | CAxisGroup* vAxisGroup_; |
---|
[887] | 419 | CScalarGroup* vScalarGroup_; |
---|
| 420 | std::vector<std::string> axisList_, domList_, scalarList_; |
---|
| 421 | bool isAxisListSet, isDomListSet, isScalarListSet; |
---|
[567] | 422 | |
---|
[568] | 423 | CClientServerMapping* clientServerMap_; |
---|
[676] | 424 | int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
[1243] | 425 | |
---|
[1330] | 426 | /** Map storing local ranks of connected receivers. Key = size of receiver's intracomm. |
---|
| 427 | * It is calculated in computeConnectedClients(). */ |
---|
[1263] | 428 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
[1243] | 429 | |
---|
[1330] | 430 | /** Map storing the size of data to be send. Key = size of receiver's intracomm |
---|
| 431 | * It is calculated in computeConnectedClients(). */ |
---|
[1263] | 432 | std::map<int, std::map<int,size_t> > connectedDataSize_; |
---|
[1243] | 433 | |
---|
[1330] | 434 | /** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */ |
---|
| 435 | std::vector<int> connectedServerRankRead_; |
---|
| 436 | |
---|
| 437 | /** Size of data to be send in case of reading. It is calculated in recvIndex(). */ |
---|
| 438 | std::map<int,size_t> connectedDataSizeRead_; |
---|
[1870] | 439 | |
---|
[676] | 440 | //! True if and only if the data defined on the grid can be outputted in a compressed way |
---|
| 441 | bool isCompressible_; |
---|
| 442 | std::set<std::string> relFilesCompressed; |
---|
[619] | 443 | |
---|
[1129] | 444 | bool isTransformed_, isGenerated_; |
---|
| 445 | bool computedWrittenIndex_; |
---|
[1870] | 446 | |
---|
[620] | 447 | std::vector<int> axisPositionInGrid_; |
---|
[1870] | 448 | void computeAxisPositionInGrid(void) ; |
---|
| 449 | bool computeAxisPositionInGrid_done_ = false ; |
---|
| 450 | std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;} |
---|
| 451 | |
---|
[620] | 452 | CGridTransformation* transformations_; |
---|
[1158] | 453 | bool hasDomainAxisBaseRef_; |
---|
[823] | 454 | std::map<CGrid*, std::pair<bool,StdString> > gridSrc_; |
---|
[824] | 455 | bool hasTransform_; |
---|
[1243] | 456 | |
---|
[1847] | 457 | /** Map storing global indexes of server-like (band-wise) distribution for sending to receivers (client side). |
---|
| 458 | * Key = size of receiver's intracomm (i.e. number of servers) |
---|
| 459 | * ~ map<int, umap<int, std::vector<size_t> >> globalIndexOnServer_ |
---|
| 460 | * globalIndexOnServer_[servers_size] -> map for a distribution of size "servers_size" (number of servers) |
---|
| 461 | * globalIndexOnServer_[servers_size][server_rank] -> array of global index managed by server of rank "server_rank" |
---|
| 462 | * globalIndexOnServer_[servers_size][server_rank][n] -> global index of data to be send to the server by client based on sub element of the grid. |
---|
| 463 | * -> grid masking is not included. |
---|
[1263] | 464 | */ |
---|
| 465 | // std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
| 466 | std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
[1243] | 467 | |
---|
[1263] | 468 | |
---|
[1784] | 469 | /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */ |
---|
[887] | 470 | std::vector<int> order_; |
---|
[1243] | 471 | |
---|
[219] | 472 | }; // class CGrid |
---|
| 473 | |
---|
| 474 | ///-------------------------------------------------------------- |
---|
| 475 | |
---|
[369] | 476 | template <int n> |
---|
[1869] | 477 | void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) |
---|
[1622] | 478 | TRY |
---|
[219] | 479 | { |
---|
[1294] | 480 | //#ifdef __XIOS_DEBUG |
---|
[369] | 481 | if (this->getDataSize() != field.numElements()) |
---|
| 482 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
[680] | 483 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
[421] | 484 | << "Received data size = " << field.numElements() << " ] " |
---|
[955] | 485 | << "The data array does not have the right size! " |
---|
[1343] | 486 | << "Grid = " << this->getId()) |
---|
[1294] | 487 | //#endif |
---|
[650] | 488 | this->storeField_arr(field.dataFirst(), stored); |
---|
[219] | 489 | } |
---|
[1622] | 490 | CATCH |
---|
[219] | 491 | |
---|
[593] | 492 | template <int n> |
---|
[1869] | 493 | void CGrid::maskField(const CArray<double,n>& field, CArray<double,1>& stored) |
---|
[1637] | 494 | { |
---|
| 495 | //#ifdef __XIOS_DEBUG |
---|
| 496 | if (this->getDataSize() != field.numElements()) |
---|
| 497 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
| 498 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
| 499 | << "Received data size = " << field.numElements() << " ] " |
---|
| 500 | << "The data array does not have the right size! " |
---|
| 501 | << "Grid = " << this->getId()) |
---|
| 502 | //#endif |
---|
| 503 | this->maskField_arr(field.dataFirst(), stored); |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | template <int n> |
---|
[1869] | 507 | void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) |
---|
[1622] | 508 | TRY |
---|
[593] | 509 | { |
---|
[1294] | 510 | //#ifdef __XIOS_DEBUG |
---|
[593] | 511 | if (this->getDataSize() != field.numElements()) |
---|
| 512 | ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const", |
---|
| 513 | << "[ Size of the data = " << this->getDataSize() << ", " |
---|
| 514 | << "Output data size = " << field.numElements() << " ] " |
---|
[955] | 515 | << "The ouput array does not have the right size! " |
---|
[1343] | 516 | << "Grid = " << this->getId()) |
---|
[1294] | 517 | //#endif |
---|
[593] | 518 | this->restoreField_arr(stored, field.dataFirst()); |
---|
| 519 | } |
---|
[1622] | 520 | CATCH |
---|
[593] | 521 | |
---|
[1250] | 522 | /*! |
---|
| 523 | This function removes the effect of mask on received data on the server. |
---|
| 524 | This function only serve for the checking purpose. TODO: Something must be done to seperate mask and data_index from each other in received data |
---|
| 525 | \data data received data with masking effect on the server |
---|
| 526 | \outData data without masking effect |
---|
| 527 | */ |
---|
| 528 | template <int N> |
---|
[1869] | 529 | void CGrid::uncompressField(const CArray<double,N>& data, CArray<double,1>& outData) |
---|
[1622] | 530 | TRY |
---|
[1250] | 531 | { |
---|
| 532 | uncompressField_arr(data.dataFirst(), outData); |
---|
| 533 | } |
---|
[1622] | 534 | CATCH |
---|
[1250] | 535 | |
---|
[567] | 536 | template<int N> |
---|
| 537 | void CGrid::checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 538 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 539 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 540 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 541 | bool createMask) |
---|
[1622] | 542 | TRY |
---|
[567] | 543 | { |
---|
[1637] | 544 | int idx = 0; |
---|
| 545 | int numElement = axisDomainOrder.numElements(); |
---|
| 546 | int dim = domainMasks.size() * 2 + axisMasks.size(); |
---|
| 547 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 548 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[567] | 549 | |
---|
[1637] | 550 | std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim); |
---|
| 551 | std::vector<int> currentIndex(dim); |
---|
| 552 | int idxDomain = 0, idxAxis = 0; |
---|
| 553 | for (int i = 0; i < numElement; ++i) |
---|
| 554 | { |
---|
| 555 | indexMap[i] = idx; |
---|
| 556 | if (2 == axisDomainOrder(i)) { |
---|
| 557 | eachDimSize[indexMap[i]] = domainP[idxDomain]->ni; |
---|
| 558 | eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj; |
---|
| 559 | idx += 2; ++idxDomain; |
---|
| 560 | } |
---|
| 561 | else if (1 == axisDomainOrder(i)) { |
---|
| 562 | // eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements(); |
---|
| 563 | eachDimSize[indexMap[i]] = axisP[idxAxis]->n; |
---|
| 564 | ++idx; ++idxAxis; |
---|
| 565 | } |
---|
| 566 | else {}; |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | if (!gridMask.isEmpty() && !createMask) |
---|
| 570 | { |
---|
| 571 | for (int i = 0; i < dim; ++i) |
---|
[567] | 572 | { |
---|
[1637] | 573 | if (gridMask.extent(i) != eachDimSize[i]) |
---|
| 574 | ERROR("CGrid::checkMask(void)", |
---|
| 575 | << "The mask has one dimension whose size is different from the one of the local grid." << std::endl |
---|
| 576 | << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl |
---|
| 577 | << "Mask size for dimension " << i << " is " << gridMask.extent(i) << "." << std::endl |
---|
| 578 | << "Grid = " << this->getId()) |
---|
[567] | 579 | } |
---|
[1637] | 580 | } |
---|
| 581 | else { |
---|
| 582 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 583 | gridMask = true; |
---|
| 584 | } |
---|
[567] | 585 | |
---|
[1637] | 586 | int ssize = gridMask.numElements(); |
---|
| 587 | idx = 0; |
---|
| 588 | while (idx < ssize) |
---|
| 589 | { |
---|
| 590 | for (int i = 0; i < dim-1; ++i) |
---|
[567] | 591 | { |
---|
[1637] | 592 | if (idxLoop[i] == eachDimSize[i]) |
---|
[567] | 593 | { |
---|
[1637] | 594 | idxLoop[i] = 0; |
---|
| 595 | ++idxLoop[i+1]; |
---|
[567] | 596 | } |
---|
| 597 | } |
---|
| 598 | |
---|
[1637] | 599 | // Find out outer index |
---|
| 600 | idxDomain = idxAxis = 0; |
---|
| 601 | bool maskValue = true; |
---|
| 602 | for (int i = 0; i < numElement; ++i) |
---|
[567] | 603 | { |
---|
[1637] | 604 | if (2 == axisDomainOrder(i)) |
---|
[567] | 605 | { |
---|
[1637] | 606 | int idxTmp = idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]]; |
---|
| 607 | if (idxTmp < (*domainMasks[idxDomain]).numElements()) |
---|
| 608 | maskValue = maskValue && (*domainMasks[idxDomain])(idxTmp); |
---|
| 609 | else |
---|
| 610 | maskValue = false; |
---|
| 611 | ++idxDomain; |
---|
[567] | 612 | } |
---|
[1637] | 613 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 614 | { |
---|
[1637] | 615 | int idxTmp = idxLoop[indexMap[i]]; |
---|
| 616 | if (idxTmp < (*axisMasks[idxAxis]).numElements()) |
---|
| 617 | maskValue = maskValue && (*axisMasks[idxAxis])(idxTmp); |
---|
| 618 | else |
---|
| 619 | maskValue = false; |
---|
[1421] | 620 | |
---|
[1637] | 621 | ++idxAxis; |
---|
[567] | 622 | } |
---|
[1637] | 623 | } |
---|
[567] | 624 | |
---|
[1637] | 625 | int maskIndex = idxLoop[0]; |
---|
| 626 | int mulDim = 1; |
---|
| 627 | for (int k = 1; k < dim; ++k) |
---|
| 628 | { |
---|
| 629 | mulDim *= eachDimSize[k-1]; |
---|
| 630 | maskIndex += idxLoop[k]*mulDim; |
---|
| 631 | } |
---|
| 632 | *(gridMask.dataFirst()+maskIndex) &= maskValue; |
---|
[1564] | 633 | |
---|
[1637] | 634 | ++idxLoop[0]; |
---|
| 635 | ++idx; |
---|
| 636 | } |
---|
[567] | 637 | } |
---|
[1622] | 638 | CATCH_DUMP_ATTR |
---|
[567] | 639 | |
---|
[1129] | 640 | template<int N> |
---|
| 641 | void CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 642 | const std::vector<int>& eachDimSize, |
---|
| 643 | bool newValue) |
---|
[1622] | 644 | TRY |
---|
[1129] | 645 | { |
---|
| 646 | if (N != eachDimSize.size()) |
---|
| 647 | { |
---|
| 648 | // ERROR("CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 649 | // const std::vector<int>& eachDimSize, |
---|
| 650 | // bool newValue)", |
---|
| 651 | // << "Dimension size of the mask is different from input dimension size." << std::endl |
---|
| 652 | // << "Mask dimension is " << N << "." << std::endl |
---|
| 653 | // << "Input dimension is " << eachDimSize.size() << "." << std::endl |
---|
[1343] | 654 | // << "Grid = " << this->getId()) |
---|
[1129] | 655 | } |
---|
| 656 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 657 | gridMask = newValue; |
---|
| 658 | } |
---|
[1622] | 659 | CATCH_DUMP_ATTR |
---|
[1129] | 660 | |
---|
| 661 | |
---|
[623] | 662 | /*! |
---|
| 663 | Modify the current mask of grid, the local index to be modified will take value false |
---|
| 664 | \param [in/out] gridMask current mask of grid |
---|
| 665 | \param [in] indexToModify local index to modify |
---|
| 666 | */ |
---|
| 667 | template<int N> |
---|
[1129] | 668 | void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify) |
---|
[1622] | 669 | TRY |
---|
[1129] | 670 | { |
---|
[623] | 671 | int num = indexToModify.numElements(); |
---|
| 672 | for (int idx = 0; idx < num; ++idx) |
---|
| 673 | { |
---|
| 674 | *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify; |
---|
| 675 | } |
---|
| 676 | } |
---|
[1622] | 677 | CATCH_DUMP_ATTR |
---|
| 678 | |
---|
[219] | 679 | ///-------------------------------------------------------------- |
---|
| 680 | |
---|
[1397] | 681 | |
---|
| 682 | |
---|
[219] | 683 | // Declare/Define CGridGroup and CGridDefinition |
---|
| 684 | DECLARE_GROUP(CGrid); |
---|
| 685 | |
---|
| 686 | ///-------------------------------------------------------------- |
---|
| 687 | |
---|
[335] | 688 | } // namespace xios |
---|
[219] | 689 | |
---|
[591] | 690 | #endif // __XIOS_CGrid__ |
---|