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