[266] | 1 | |
---|
[219] | 2 | #include "grid.hpp" |
---|
| 3 | |
---|
[352] | 4 | #include "attribute_template.hpp" |
---|
| 5 | #include "object_template.hpp" |
---|
| 6 | #include "group_template.hpp" |
---|
| 7 | #include "message.hpp" |
---|
[286] | 8 | #include <iostream> |
---|
[591] | 9 | #include "xios_spl.hpp" |
---|
[352] | 10 | #include "type.hpp" |
---|
| 11 | #include "context.hpp" |
---|
| 12 | #include "context_client.hpp" |
---|
[552] | 13 | #include "context_server.hpp" |
---|
[369] | 14 | #include "array_new.hpp" |
---|
[657] | 15 | #include "server_distribution_description.hpp" |
---|
[568] | 16 | #include "client_server_mapping_distributed.hpp" |
---|
[660] | 17 | #include "distribution_client.hpp" |
---|
| 18 | #include "grid_transformation.hpp" |
---|
[687] | 19 | #include "grid_generate.hpp" |
---|
[1340] | 20 | #include "server.hpp" |
---|
[1930] | 21 | #include "distribution_type.hpp" |
---|
| 22 | #include "grid_remote_connector.hpp" |
---|
| 23 | #include "grid_elements.hpp" |
---|
| 24 | #include "grid_local_view.hpp" |
---|
[1943] | 25 | #include "grid_mask_connector.hpp" |
---|
[219] | 26 | |
---|
[1930] | 27 | |
---|
[335] | 28 | namespace xios { |
---|
[219] | 29 | |
---|
[742] | 30 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
[219] | 31 | |
---|
| 32 | CGrid::CGrid(void) |
---|
| 33 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
[650] | 34 | , isChecked(false), isDomainAxisChecked(false) |
---|
[887] | 35 | , vDomainGroup_(), domList_(), isDomListSet(false) |
---|
| 36 | , vAxisGroup_(), axisList_(), isAxisListSet(false) |
---|
| 37 | , vScalarGroup_(), scalarList_(), isScalarListSet(false) |
---|
[676] | 38 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
[1871] | 39 | , numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
[1330] | 40 | , connectedDataSize_(), connectedServerRank_(), connectedServerRankRead_(), connectedDataSizeRead_() |
---|
[1870] | 41 | , isCompressible_(false) |
---|
[676] | 42 | , transformations_(0), isTransformed_(false) |
---|
[1158] | 43 | , axisPositionInGrid_(), hasDomainAxisBaseRef_(false) |
---|
[890] | 44 | , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_() |
---|
[1129] | 45 | , computedWrittenIndex_(false) |
---|
[1294] | 46 | , clients() |
---|
[540] | 47 | { |
---|
[957] | 48 | setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group")); |
---|
| 49 | setVirtualAxisGroup(CAxisGroup::create(getId() + "_virtual_axis_group")); |
---|
| 50 | setVirtualScalarGroup(CScalarGroup::create(getId() + "_virtual_scalar_group")); |
---|
[540] | 51 | } |
---|
[219] | 52 | |
---|
[650] | 53 | CGrid::CGrid(const StdString& id) |
---|
[219] | 54 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
[650] | 55 | , isChecked(false), isDomainAxisChecked(false) |
---|
[887] | 56 | , vDomainGroup_(), domList_(), isDomListSet(false) |
---|
| 57 | , vAxisGroup_(), axisList_(), isAxisListSet(false) |
---|
| 58 | , vScalarGroup_(), scalarList_(), isScalarListSet(false) |
---|
[676] | 59 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
[1871] | 60 | , numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
[1330] | 61 | , connectedDataSize_(), connectedServerRank_(), connectedServerRankRead_(), connectedDataSizeRead_() |
---|
[1870] | 62 | , isCompressible_(false) |
---|
[676] | 63 | , transformations_(0), isTransformed_(false) |
---|
[1158] | 64 | , axisPositionInGrid_(), hasDomainAxisBaseRef_(false) |
---|
[890] | 65 | , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_() |
---|
[1129] | 66 | , computedWrittenIndex_(false) |
---|
[1294] | 67 | , clients() |
---|
[540] | 68 | { |
---|
[957] | 69 | setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group")); |
---|
| 70 | setVirtualAxisGroup(CAxisGroup::create(getId() + "_virtual_axis_group")); |
---|
| 71 | setVirtualScalarGroup(CScalarGroup::create(getId() + "_virtual_scalar_group")); |
---|
[540] | 72 | } |
---|
[219] | 73 | |
---|
| 74 | CGrid::~CGrid(void) |
---|
[509] | 75 | { |
---|
[551] | 76 | if (0 != clientDistribution_) delete clientDistribution_; |
---|
[552] | 77 | if (0 != serverDistribution_) delete serverDistribution_; |
---|
[656] | 78 | if (0 != clientServerMap_) delete clientServerMap_; |
---|
[620] | 79 | if (0 != transformations_) delete transformations_; |
---|
[219] | 80 | } |
---|
| 81 | |
---|
| 82 | ///--------------------------------------------------------------- |
---|
| 83 | |
---|
[650] | 84 | StdString CGrid::GetName(void) { return StdString("grid"); } |
---|
| 85 | StdString CGrid::GetDefName(void) { return CGrid::GetName(); } |
---|
| 86 | ENodeType CGrid::GetType(void) { return eGrid; } |
---|
[219] | 87 | |
---|
| 88 | |
---|
[1930] | 89 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 90 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 91 | ///////// MEMBER FUNCTION RELATED TO GRID CONSTRUCTION by ELEMNTS AND MANAGEMENT ///// |
---|
| 92 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 93 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
| 97 | TRY |
---|
| 98 | { |
---|
| 99 | std::vector<CDomain*> vecDom(1, domain); |
---|
| 100 | std::vector<CAxis*> vecAxis; |
---|
| 101 | return createGrid(vecDom, vecAxis); |
---|
| 102 | } |
---|
| 103 | CATCH |
---|
| 104 | |
---|
| 105 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
| 106 | TRY |
---|
| 107 | { |
---|
| 108 | std::vector<CDomain*> vecDom(1, domain); |
---|
| 109 | std::vector<CAxis*> vecAxis(1, axis); |
---|
| 110 | |
---|
| 111 | return createGrid(vecDom, vecAxis); |
---|
| 112 | } |
---|
| 113 | CATCH |
---|
| 114 | |
---|
| 115 | CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 116 | const CArray<int,1>& axisDomainOrder) |
---|
| 117 | TRY |
---|
| 118 | { |
---|
| 119 | std::vector<CScalar*> vecScalar; |
---|
| 120 | return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); |
---|
| 121 | } |
---|
| 122 | CATCH |
---|
| 123 | |
---|
| 124 | CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 125 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
| 126 | TRY |
---|
| 127 | { |
---|
| 128 | return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); |
---|
| 129 | } |
---|
| 130 | CATCH |
---|
| 131 | |
---|
| 132 | CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 133 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
| 134 | TRY |
---|
| 135 | { |
---|
| 136 | if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) |
---|
| 137 | ERROR("CGrid* CGrid::createGrid(...)", |
---|
| 138 | << "The size of axisDomainOrder (" << axisDomainOrder.numElements() |
---|
| 139 | << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); |
---|
| 140 | |
---|
| 141 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); |
---|
| 142 | grid->setDomainList(domains); |
---|
| 143 | grid->setAxisList(axis); |
---|
| 144 | grid->setScalarList(scalars); |
---|
| 145 | |
---|
| 146 | // By default, domains are always the first elements of a grid |
---|
| 147 | if (0 == axisDomainOrder.numElements()) |
---|
| 148 | { |
---|
| 149 | int size = domains.size() + axis.size() + scalars.size(); |
---|
| 150 | int nb = 0; |
---|
| 151 | grid->axis_domain_order.resize(size); |
---|
| 152 | for (int i = 0; i < size; ++i) |
---|
| 153 | { |
---|
[1934] | 154 | if (i < domains.size()) |
---|
| 155 | { |
---|
[1930] | 156 | grid->axis_domain_order(i) = 2; |
---|
[1934] | 157 | grid->order_.push_back(2) ; |
---|
[1930] | 158 | } |
---|
[1934] | 159 | else if ((scalars.size() < (size-nb)) < size) |
---|
| 160 | { |
---|
[1930] | 161 | grid->axis_domain_order(i) = 1; |
---|
[1934] | 162 | grid->order_.push_back(1) ; |
---|
[1930] | 163 | } |
---|
| 164 | else |
---|
[1934] | 165 | { |
---|
[1930] | 166 | grid->axis_domain_order(i) = 0; |
---|
[1934] | 167 | grid->order_.push_back(0) ; |
---|
| 168 | } |
---|
[1930] | 169 | ++nb; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | else |
---|
| 173 | { |
---|
| 174 | grid->axis_domain_order.resize(axisDomainOrder.numElements()); |
---|
| 175 | grid->axis_domain_order = axisDomainOrder; |
---|
[1934] | 176 | grid->order_.clear() ; |
---|
| 177 | for(int i=0; i<axisDomainOrder.numElements();i++) grid->order_.push_back(axisDomainOrder(i)) ; |
---|
| 178 | |
---|
[1930] | 179 | } |
---|
| 180 | |
---|
| 181 | // grid->solveElementsRefInheritance(true); |
---|
| 182 | |
---|
| 183 | return grid; |
---|
| 184 | } |
---|
| 185 | CATCH |
---|
| 186 | |
---|
| 187 | //---------------------------------------------------------------- |
---|
| 188 | |
---|
| 189 | //! Change virtual field group to a new one |
---|
| 190 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
| 191 | TRY |
---|
| 192 | { |
---|
| 193 | this->vDomainGroup_ = newVDomainGroup; |
---|
| 194 | } |
---|
| 195 | CATCH_DUMP_ATTR |
---|
| 196 | |
---|
| 197 | //! Change virtual variable group to new one |
---|
| 198 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
| 199 | TRY |
---|
| 200 | { |
---|
| 201 | this->vAxisGroup_ = newVAxisGroup; |
---|
| 202 | } |
---|
| 203 | CATCH_DUMP_ATTR |
---|
| 204 | |
---|
| 205 | //! Change virtual variable group to new one |
---|
| 206 | void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) |
---|
| 207 | TRY |
---|
| 208 | { |
---|
| 209 | this->vScalarGroup_ = newVScalarGroup; |
---|
| 210 | } |
---|
| 211 | CATCH_DUMP_ATTR |
---|
| 212 | |
---|
| 213 | //---------------------------------------------------------------- |
---|
| 214 | |
---|
| 215 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
| 216 | TRY |
---|
| 217 | { |
---|
| 218 | return this->vDomainGroup_; |
---|
| 219 | } |
---|
| 220 | CATCH |
---|
| 221 | |
---|
| 222 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
| 223 | TRY |
---|
| 224 | { |
---|
| 225 | return this->vAxisGroup_; |
---|
| 226 | } |
---|
| 227 | CATCH |
---|
| 228 | |
---|
| 229 | CScalarGroup* CGrid::getVirtualScalarGroup() const |
---|
| 230 | TRY |
---|
| 231 | { |
---|
| 232 | return this->vScalarGroup_; |
---|
| 233 | } |
---|
| 234 | CATCH |
---|
| 235 | |
---|
| 236 | ///--------------------------------------------------------------- |
---|
| 237 | |
---|
| 238 | CDomain* CGrid::addDomain(const std::string& id) |
---|
| 239 | TRY |
---|
| 240 | { |
---|
| 241 | order_.push_back(2); |
---|
| 242 | axis_domain_order.resize(order_.size()); |
---|
| 243 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
| 244 | return vDomainGroup_->createChild(id); |
---|
| 245 | } |
---|
| 246 | CATCH_DUMP_ATTR |
---|
| 247 | |
---|
| 248 | CAxis* CGrid::addAxis(const std::string& id) |
---|
| 249 | TRY |
---|
| 250 | { |
---|
| 251 | order_.push_back(1); |
---|
| 252 | axis_domain_order.resize(order_.size()); |
---|
| 253 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
| 254 | return vAxisGroup_->createChild(id); |
---|
| 255 | } |
---|
| 256 | CATCH_DUMP_ATTR |
---|
| 257 | |
---|
| 258 | CScalar* CGrid::addScalar(const std::string& id) |
---|
| 259 | TRY |
---|
| 260 | { |
---|
| 261 | order_.push_back(0); |
---|
| 262 | axis_domain_order.resize(order_.size()); |
---|
| 263 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
| 264 | return vScalarGroup_->createChild(id); |
---|
| 265 | } |
---|
| 266 | CATCH_DUMP_ATTR |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | /*! |
---|
| 272 | \brief Get the list of domain pointers |
---|
| 273 | \return list of domain pointers |
---|
| 274 | */ |
---|
| 275 | std::vector<CDomain*> CGrid::getDomains() |
---|
| 276 | TRY |
---|
| 277 | { |
---|
[1943] | 278 | setDomainList(); |
---|
[1930] | 279 | std::vector<CDomain*> domList; |
---|
| 280 | if (!domList_.empty()) |
---|
| 281 | { |
---|
| 282 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
| 283 | } |
---|
| 284 | return domList; |
---|
| 285 | } |
---|
| 286 | CATCH_DUMP_ATTR |
---|
| 287 | |
---|
| 288 | /*! |
---|
| 289 | \brief Get the list of axis pointers |
---|
| 290 | \return list of axis pointers |
---|
| 291 | */ |
---|
| 292 | std::vector<CAxis*> CGrid::getAxis() |
---|
| 293 | TRY |
---|
| 294 | { |
---|
[1943] | 295 | setAxisList(); |
---|
[1930] | 296 | std::vector<CAxis*> aList; |
---|
| 297 | if (!axisList_.empty()) |
---|
| 298 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
| 299 | |
---|
| 300 | return aList; |
---|
| 301 | } |
---|
| 302 | CATCH_DUMP_ATTR |
---|
| 303 | |
---|
| 304 | /*! |
---|
| 305 | \brief Get the list of axis pointers |
---|
| 306 | \return list of axis pointers |
---|
| 307 | */ |
---|
| 308 | std::vector<CScalar*> CGrid::getScalars() |
---|
| 309 | TRY |
---|
| 310 | { |
---|
[1943] | 311 | setScalarList() ; |
---|
[1930] | 312 | std::vector<CScalar*> sList; |
---|
| 313 | if (!scalarList_.empty()) |
---|
| 314 | for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); |
---|
| 315 | |
---|
| 316 | return sList; |
---|
| 317 | } |
---|
| 318 | CATCH_DUMP_ATTR |
---|
| 319 | |
---|
| 320 | /*! |
---|
| 321 | \brief Get domain pointer with index |
---|
| 322 | \return domain pointer |
---|
| 323 | */ |
---|
| 324 | CDomain* CGrid::getDomain(int domainIndex) |
---|
| 325 | TRY |
---|
| 326 | { |
---|
| 327 | std::vector<CDomain*> domainListP = this->getDomains(); |
---|
| 328 | if (domainListP.empty()) |
---|
| 329 | { |
---|
| 330 | ERROR("CGrid::getDomain(int domainIndex)", |
---|
| 331 | << "No domain associated to this grid. " << std::endl |
---|
| 332 | << "Grid id = " << this->getId()); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | if (domainIndex >= domainListP.size() || (domainIndex < 0)) |
---|
| 336 | ERROR("CGrid::getDomain(int domainIndex)", |
---|
| 337 | << "Domain with the index doesn't exist " << std::endl |
---|
| 338 | << "Grid id = " << this->getId() << std::endl |
---|
| 339 | << "Grid has only " << domainListP.size() << " domain but domain index required is " << domainIndex << std::endl); |
---|
| 340 | |
---|
| 341 | return domainListP[domainIndex]; |
---|
| 342 | } |
---|
| 343 | CATCH_DUMP_ATTR |
---|
| 344 | |
---|
| 345 | /*! |
---|
| 346 | \brief Get the axis pointer with index |
---|
| 347 | \return axis pointer |
---|
| 348 | */ |
---|
| 349 | CAxis* CGrid::getAxis(int axisIndex) |
---|
| 350 | TRY |
---|
| 351 | { |
---|
| 352 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 353 | if (axisListP.empty()) |
---|
| 354 | { |
---|
| 355 | ERROR("CGrid::getDomain(int axisIndex)", |
---|
| 356 | << "No axis associated to this grid. " << std::endl |
---|
| 357 | << "Grid id = " << this->getId()); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | if (axisIndex >= axisListP.size() || (axisIndex < 0)) |
---|
| 361 | ERROR("CGrid::getDomain(int axisIndex)", |
---|
| 362 | << "Domain with the index doesn't exist " << std::endl |
---|
| 363 | << "Grid id = " << this->getId() << std::endl |
---|
| 364 | << "Grid has only " << axisListP.size() << " axis but axis index required is " << axisIndex << std::endl); |
---|
| 365 | |
---|
| 366 | return axisListP[axisIndex]; |
---|
| 367 | } |
---|
| 368 | CATCH_DUMP_ATTR |
---|
| 369 | |
---|
| 370 | /*! |
---|
| 371 | \brief Get the a scalar pointer |
---|
| 372 | \return scalar pointer |
---|
| 373 | */ |
---|
| 374 | CScalar* CGrid::getScalar(int scalarIndex) |
---|
| 375 | TRY |
---|
| 376 | { |
---|
| 377 | std::vector<CScalar*> scalarListP = this->getScalars(); |
---|
| 378 | if (scalarListP.empty()) |
---|
| 379 | { |
---|
| 380 | ERROR("CGrid::getScalar(int scalarIndex)", |
---|
| 381 | << "No scalar associated to this grid. " << std::endl |
---|
| 382 | << "Grid id = " << this->getId()); |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | if (scalarIndex >= scalarListP.size() || (scalarIndex < 0)) |
---|
| 386 | ERROR("CGrid::getScalar(int scalarIndex)", |
---|
| 387 | << "Scalar with the index doesn't exist " << std::endl |
---|
| 388 | << "Grid id = " << this->getId() << std::endl |
---|
| 389 | << "Grid has only " << scalarListP.size() << " scalar but scalar index required is " << scalarIndex << std::endl); |
---|
| 390 | |
---|
| 391 | return scalarListP[scalarIndex]; |
---|
| 392 | } |
---|
| 393 | CATCH_DUMP_ATTR |
---|
| 394 | |
---|
| 395 | /*! |
---|
| 396 | \brief Set domain(s) of a grid from a list |
---|
| 397 | \param[in] domains list of domains |
---|
| 398 | */ |
---|
| 399 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
| 400 | TRY |
---|
| 401 | { |
---|
| 402 | if (isDomListSet) return; |
---|
| 403 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 404 | if (!domains.empty() && domList.empty()) |
---|
| 405 | { |
---|
| 406 | for (int i = 0; i < domains.size(); ++i) |
---|
| 407 | this->getVirtualDomainGroup()->addChild(domains[i]); |
---|
| 408 | domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | if (!domList.empty()) |
---|
| 412 | { |
---|
| 413 | int sizeDom = domList.size(); |
---|
| 414 | domList_.resize(sizeDom); |
---|
| 415 | for (int i = 0; i < sizeDom; ++i) |
---|
| 416 | { |
---|
| 417 | domList_[i] = domList[i]->getId(); |
---|
| 418 | } |
---|
| 419 | isDomListSet = true; |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | CATCH_DUMP_ATTR |
---|
| 423 | |
---|
| 424 | /*! |
---|
| 425 | \brief Set axis(s) of a grid from a list |
---|
| 426 | \param[in] axis list of axis |
---|
| 427 | */ |
---|
| 428 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
| 429 | TRY |
---|
| 430 | { |
---|
| 431 | if (isAxisListSet) return; |
---|
| 432 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 433 | if (!axis.empty() && aList.empty()) |
---|
| 434 | { |
---|
| 435 | for (int i = 0; i < axis.size(); ++i) |
---|
| 436 | this->getVirtualAxisGroup()->addChild(axis[i]); |
---|
| 437 | aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | if (!aList.empty()) |
---|
| 441 | { |
---|
| 442 | int sizeAxis = aList.size(); |
---|
| 443 | axisList_.resize(sizeAxis); |
---|
| 444 | for (int i = 0; i < sizeAxis; ++i) |
---|
| 445 | { |
---|
| 446 | axisList_[i] = aList[i]->getId(); |
---|
| 447 | } |
---|
| 448 | isAxisListSet = true; |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | CATCH_DUMP_ATTR |
---|
| 452 | |
---|
| 453 | /*! |
---|
| 454 | \brief Set scalar(s) of a grid from a list |
---|
| 455 | \param[in] scalars list of scalars |
---|
| 456 | */ |
---|
| 457 | void CGrid::setScalarList(const std::vector<CScalar*> scalars) |
---|
| 458 | TRY |
---|
| 459 | { |
---|
| 460 | if (isScalarListSet) return; |
---|
| 461 | std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 462 | if (!scalars.empty() && sList.empty()) |
---|
| 463 | { |
---|
| 464 | for (int i = 0; i < scalars.size(); ++i) |
---|
| 465 | this->getVirtualScalarGroup()->addChild(scalars[i]); |
---|
| 466 | sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | if (!sList.empty()) |
---|
| 470 | { |
---|
| 471 | int sizeScalar = sList.size(); |
---|
| 472 | scalarList_.resize(sizeScalar); |
---|
| 473 | for (int i = 0; i < sizeScalar; ++i) |
---|
| 474 | { |
---|
| 475 | scalarList_[i] = sList[i]->getId(); |
---|
| 476 | } |
---|
| 477 | isScalarListSet = true; |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | CATCH_DUMP_ATTR |
---|
| 481 | |
---|
| 482 | /*! |
---|
| 483 | \brief Get list of id of domains |
---|
| 484 | \return id list of domains |
---|
| 485 | */ |
---|
| 486 | std::vector<StdString> CGrid::getDomainList() |
---|
| 487 | TRY |
---|
| 488 | { |
---|
| 489 | setDomainList(); |
---|
| 490 | return domList_; |
---|
| 491 | } |
---|
| 492 | CATCH |
---|
| 493 | |
---|
| 494 | /*! |
---|
| 495 | \brief Get list of id of axis |
---|
| 496 | \return id list of axis |
---|
| 497 | */ |
---|
| 498 | std::vector<StdString> CGrid::getAxisList() |
---|
| 499 | TRY |
---|
| 500 | { |
---|
| 501 | setAxisList(); |
---|
| 502 | return axisList_; |
---|
| 503 | } |
---|
| 504 | CATCH |
---|
| 505 | |
---|
| 506 | /*! |
---|
| 507 | \brief Get list of id of scalar |
---|
| 508 | \return id list of scalar |
---|
| 509 | */ |
---|
| 510 | std::vector<StdString> CGrid::getScalarList() |
---|
| 511 | TRY |
---|
| 512 | { |
---|
| 513 | setScalarList(); |
---|
| 514 | return scalarList_; |
---|
| 515 | } |
---|
| 516 | CATCH |
---|
| 517 | |
---|
| 518 | |
---|
| 519 | void CGrid::computeElements(void) |
---|
| 520 | { |
---|
| 521 | const auto& domains = getDomains() ; |
---|
| 522 | const auto& axis = getAxis() ; |
---|
| 523 | const auto& scalars = getScalars() ; |
---|
| 524 | int idxDomain = 0, idxAxis=0 , idxScalar=0 ; |
---|
| 525 | |
---|
| 526 | for(auto type : order_) |
---|
| 527 | { |
---|
| 528 | if (type == 0) { elements_.push_back({scalars[idxScalar], TYPE_SCALAR, scalars[idxScalar], nullptr, nullptr } ) ; idxScalar++;} |
---|
| 529 | else if (type == 1) { elements_.push_back({axis[idxAxis], TYPE_AXIS, nullptr, axis[idxAxis], nullptr}) ; idxAxis++;} |
---|
| 530 | else if (type == 2) { elements_.push_back({domains[idxDomain], TYPE_DOMAIN, nullptr, nullptr, domains[idxDomain] }) ; idxDomain++;} |
---|
| 531 | } |
---|
| 532 | elementsComputed_ = true ; |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | |
---|
| 536 | /*! |
---|
| 537 | Parse a grid, for now, it contains only domain, axis and scalar |
---|
| 538 | */ |
---|
| 539 | void CGrid::parse(xml::CXMLNode& node) |
---|
| 540 | TRY |
---|
| 541 | { |
---|
| 542 | SuperClass::parse(node); |
---|
| 543 | |
---|
| 544 | if (node.goToChildElement()) |
---|
| 545 | { |
---|
| 546 | StdString domainName("domain"); |
---|
| 547 | StdString axisName("axis"); |
---|
| 548 | StdString scalarName("scalar"); |
---|
| 549 | do |
---|
| 550 | { |
---|
| 551 | if (node.getElementName() == domainName) { |
---|
| 552 | order_.push_back(2); |
---|
| 553 | this->getVirtualDomainGroup()->parseChild(node); |
---|
| 554 | } |
---|
| 555 | if (node.getElementName() == axisName) { |
---|
| 556 | order_.push_back(1); |
---|
| 557 | this->getVirtualAxisGroup()->parseChild(node); |
---|
| 558 | } |
---|
| 559 | if (node.getElementName() == scalarName) { |
---|
| 560 | order_.push_back(0); |
---|
| 561 | this->getVirtualScalarGroup()->parseChild(node); |
---|
| 562 | } |
---|
| 563 | } while (node.goToNextElement()); |
---|
| 564 | node.goToParentElement(); |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | if (!order_.empty()) |
---|
| 568 | { |
---|
| 569 | int sizeOrd = order_.size(); |
---|
| 570 | axis_domain_order.resize(sizeOrd); |
---|
| 571 | for (int i = 0; i < sizeOrd; ++i) |
---|
| 572 | { |
---|
| 573 | axis_domain_order(i) = order_[i]; |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | setDomainList(); |
---|
| 578 | setAxisList(); |
---|
| 579 | setScalarList(); |
---|
| 580 | } |
---|
| 581 | CATCH_DUMP_ATTR |
---|
| 582 | |
---|
| 583 | |
---|
| 584 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 585 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 586 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 587 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 588 | |
---|
| 589 | |
---|
| 590 | |
---|
[1158] | 591 | StdSize CGrid::getDimension(void) |
---|
[1622] | 592 | TRY |
---|
[219] | 593 | { |
---|
[1158] | 594 | return getGlobalDimension().size(); |
---|
[219] | 595 | } |
---|
[1622] | 596 | CATCH_DUMP_ATTR |
---|
[219] | 597 | |
---|
| 598 | //--------------------------------------------------------------- |
---|
| 599 | |
---|
[1869] | 600 | StdSize CGrid::getDataSize(void) |
---|
[1622] | 601 | TRY |
---|
[286] | 602 | { |
---|
[586] | 603 | StdSize retvalue = 1; |
---|
[600] | 604 | if (!isScalarGrid()) |
---|
| 605 | { |
---|
[1870] | 606 | std::vector<int> dataNindex = getClientDistribution()->getDataNIndex(); |
---|
[1250] | 607 | for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; |
---|
[600] | 608 | } |
---|
| 609 | return retvalue; |
---|
[286] | 610 | } |
---|
[1622] | 611 | CATCH |
---|
[1875] | 612 | |
---|
| 613 | /*! |
---|
| 614 | * Get the local data grid size, ie the size of the compressed grid (inside the workflow) |
---|
| 615 | * \return The size od the compressed grid |
---|
| 616 | */ |
---|
| 617 | StdSize CGrid::getLocalDataSize(void) { return getClientDistribution()->getLocalDataSize();} |
---|
[286] | 618 | |
---|
[1875] | 619 | |
---|
[731] | 620 | /*! |
---|
| 621 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 622 | * |
---|
| 623 | * \return A map associating the server rank with its minimum buffer size. |
---|
[1099] | 624 | * TODO: Refactor code |
---|
[731] | 625 | */ |
---|
[1330] | 626 | std::map<int, StdSize> CGrid::getAttributesBufferSize(CContextClient* client, bool bufferForWriting) |
---|
[1622] | 627 | TRY |
---|
[509] | 628 | { |
---|
[1330] | 629 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(client); |
---|
[586] | 630 | |
---|
[731] | 631 | // The grid indexes require a similar size as the actual data |
---|
[1330] | 632 | std::map<int, StdSize> dataSizes = getDataBufferSize(client, "", bufferForWriting); |
---|
[1371] | 633 | std::map<int, StdSize>::iterator it, itE = dataSizes.end(); |
---|
| 634 | for (it = dataSizes.begin(); it != itE; ++it) |
---|
| 635 | { |
---|
| 636 | it->second += 2 * sizeof(bool); |
---|
| 637 | if (it->second > attributesSizes[it->first]) |
---|
| 638 | attributesSizes[it->first] = it->second; |
---|
| 639 | } |
---|
[1236] | 640 | |
---|
[731] | 641 | // Account for the axis attributes |
---|
| 642 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 643 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
[586] | 644 | { |
---|
[1870] | 645 | std::map<int, StdSize> axisAttBuffSize = axisList[i]->getAttributesBufferSize(client, getGlobalDimension(),getAxisPositionInGrid()[i]); |
---|
[731] | 646 | for (it = axisAttBuffSize.begin(), itE = axisAttBuffSize.end(); it != itE; ++it) |
---|
[586] | 647 | { |
---|
[1371] | 648 | it->second += 2 * sizeof(bool); |
---|
[731] | 649 | if (it->second > attributesSizes[it->first]) |
---|
| 650 | attributesSizes[it->first] = it->second; |
---|
[586] | 651 | } |
---|
| 652 | } |
---|
| 653 | |
---|
[731] | 654 | // Account for the domain attributes |
---|
| 655 | std::vector<CDomain*> domList = getDomains(); |
---|
| 656 | for (size_t i = 0; i < domList.size(); ++i) |
---|
[657] | 657 | { |
---|
[1236] | 658 | std::map<int, StdSize> domAttBuffSize = domList[i]->getAttributesBufferSize(client); |
---|
[731] | 659 | for (it = domAttBuffSize.begin(), itE = domAttBuffSize.end(); it != itE; ++it) |
---|
[657] | 660 | { |
---|
[1371] | 661 | it->second += 2 * sizeof(bool); |
---|
[731] | 662 | if (it->second > attributesSizes[it->first]) |
---|
| 663 | attributesSizes[it->first] = it->second; |
---|
[657] | 664 | } |
---|
| 665 | } |
---|
[742] | 666 | |
---|
[731] | 667 | return attributesSizes; |
---|
[1236] | 668 | } |
---|
[1622] | 669 | CATCH_DUMP_ATTR |
---|
[657] | 670 | |
---|
[731] | 671 | /*! |
---|
[1263] | 672 | * Compute the minimum buffer size required to send the data. |
---|
| 673 | * \param client contextClient used to determine the size of connected receivers |
---|
[731] | 674 | * \param id the id used to tag the data |
---|
[1330] | 675 | * \param bufferForWriting flag indicating if a buffer is used to send data for writing |
---|
[1263] | 676 | * \return A map associating the sender rank with its minimum buffer size. |
---|
[731] | 677 | */ |
---|
[1330] | 678 | std::map<int, StdSize> CGrid::getDataBufferSize(CContextClient* client, const std::string& id /*= ""*/, bool bufferForWriting /*= "false"*/) |
---|
[1622] | 679 | TRY |
---|
[1099] | 680 | { |
---|
[739] | 681 | // The record index is sometimes sent along with the data but we always |
---|
| 682 | // include it in the size calculation for the sake of simplicity |
---|
[1232] | 683 | const size_t extraSize = CEventClient::headerSize + (id.empty() ? getId() : id).size() |
---|
| 684 | + 2 * sizeof(size_t) |
---|
| 685 | + sizeof(size_t); |
---|
[1236] | 686 | |
---|
| 687 | std::map<int, StdSize> dataSizes; |
---|
[1263] | 688 | int receiverSize = client->serverSize; |
---|
[1330] | 689 | std::map<int,size_t>& dataSizeMap = bufferForWriting ? connectedDataSize_[receiverSize]: connectedDataSizeRead_; |
---|
| 690 | std::vector<int>& connectedServerRanks = bufferForWriting ? connectedServerRank_[receiverSize] : connectedServerRankRead_; |
---|
| 691 | |
---|
| 692 | std::map<int, size_t>::const_iterator itEnd = dataSizeMap.end(); |
---|
| 693 | for (size_t k = 0; k < connectedServerRanks.size(); ++k) |
---|
[764] | 694 | { |
---|
[1330] | 695 | int rank = connectedServerRanks[k]; |
---|
| 696 | std::map<int, size_t>::const_iterator it = dataSizeMap.find(rank); |
---|
[1236] | 697 | size_t count = (it != itEnd) ? it->second : 0; |
---|
[731] | 698 | |
---|
[1236] | 699 | dataSizes.insert(std::make_pair(rank, extraSize + CArray<double,1>::size(count))); |
---|
[764] | 700 | } |
---|
| 701 | |
---|
[731] | 702 | return dataSizes; |
---|
[509] | 703 | } |
---|
[1622] | 704 | CATCH_DUMP_ATTR |
---|
[509] | 705 | |
---|
[1215] | 706 | size_t CGrid::getGlobalWrittenSize(void) |
---|
[1622] | 707 | TRY |
---|
[1215] | 708 | { |
---|
| 709 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 710 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 711 | |
---|
| 712 | size_t globalGridSize=1 ; |
---|
| 713 | for (std::vector<CDomain*>::iterator it=domainP.begin(); it!=domainP.end();++it) globalGridSize*=(*it)->getGlobalWrittenSize() ; |
---|
| 714 | for (std::vector<CAxis*>::iterator it=axisP.begin(); it!=axisP.end();++it) globalGridSize*=(*it)->getGlobalWrittenSize() ; |
---|
| 715 | return globalGridSize ; |
---|
| 716 | } |
---|
[1622] | 717 | CATCH_DUMP_ATTR |
---|
[1215] | 718 | |
---|
[1870] | 719 | |
---|
| 720 | void CGrid::computeAxisPositionInGrid(void) |
---|
| 721 | { |
---|
| 722 | axisPositionInGrid_.resize(0); |
---|
| 723 | int idx = 0; |
---|
| 724 | for (int i = 0; i < axis_domain_order.numElements(); ++i) |
---|
| 725 | { |
---|
| 726 | int elementDimension = axis_domain_order(i); |
---|
| 727 | if (1 == elementDimension) |
---|
| 728 | { |
---|
| 729 | axisPositionInGrid_.push_back(idx); |
---|
| 730 | ++idx; |
---|
| 731 | } |
---|
| 732 | else if (2 == elementDimension) idx += 2; |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | |
---|
[657] | 736 | void CGrid::checkAttributesAfterTransformation() |
---|
[1622] | 737 | TRY |
---|
[657] | 738 | { |
---|
[927] | 739 | setAxisList(); |
---|
| 740 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
[1870] | 741 | for (int i = 0; i < axisListP.size(); ++i) |
---|
| 742 | axisListP[i]->checkAttributesOnClientAfterTransformation(getGlobalDimension(), getAxisPositionInGrid()[i]); |
---|
| 743 | |
---|
[927] | 744 | setDomainList(); |
---|
| 745 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 746 | if (!domListP.empty()) |
---|
| 747 | { |
---|
| 748 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 749 | { |
---|
| 750 | domListP[i]->checkAttributesOnClientAfterTransformation(); |
---|
| 751 | } |
---|
| 752 | } |
---|
[657] | 753 | } |
---|
[1622] | 754 | CATCH_DUMP_ATTR |
---|
[509] | 755 | |
---|
[676] | 756 | //--------------------------------------------------------------- |
---|
| 757 | |
---|
| 758 | /*! |
---|
| 759 | * Test whether the data defined on the grid can be outputted in a compressed way. |
---|
[720] | 760 | * |
---|
[676] | 761 | * \return true if and only if a mask was defined for this grid |
---|
| 762 | */ |
---|
| 763 | bool CGrid::isCompressible(void) const |
---|
[1622] | 764 | TRY |
---|
[676] | 765 | { |
---|
| 766 | return isCompressible_; |
---|
| 767 | } |
---|
[1622] | 768 | CATCH |
---|
[676] | 769 | |
---|
| 770 | //--------------------------------------------------------------- |
---|
| 771 | |
---|
| 772 | void CGrid::addRelFileCompressed(const StdString& filename) |
---|
[1622] | 773 | TRY |
---|
[676] | 774 | { |
---|
| 775 | this->relFilesCompressed.insert(filename); |
---|
| 776 | } |
---|
[1622] | 777 | CATCH_DUMP_ATTR |
---|
[676] | 778 | |
---|
| 779 | bool CGrid::isWrittenCompressed(const StdString& filename) const |
---|
[1622] | 780 | TRY |
---|
[676] | 781 | { |
---|
| 782 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 783 | } |
---|
[1622] | 784 | CATCH |
---|
[676] | 785 | |
---|
| 786 | //--------------------------------------------------------------- |
---|
[1236] | 787 | /* |
---|
| 788 | Find all reference of grid's components and inherite attributes if necessary |
---|
| 789 | */ |
---|
[509] | 790 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
[1622] | 791 | TRY |
---|
[219] | 792 | { |
---|
[509] | 793 | if (this->isDomainAxisChecked) return; |
---|
[369] | 794 | |
---|
[887] | 795 | this->solveScalarRef(areAttributesChecked); |
---|
[584] | 796 | this->solveAxisRef(areAttributesChecked); |
---|
[1158] | 797 | this->solveDomainRef(areAttributesChecked); |
---|
[509] | 798 | this->isDomainAxisChecked = areAttributesChecked; |
---|
| 799 | } |
---|
[1622] | 800 | CATCH_DUMP_ATTR |
---|
[509] | 801 | |
---|
[1236] | 802 | /* |
---|
| 803 | Go up hierachy reference and fill in the base reference with attributes of the children |
---|
| 804 | This function should be only used after reading component's attributes from file |
---|
| 805 | */ |
---|
[775] | 806 | void CGrid::solveDomainAxisBaseRef() |
---|
[1622] | 807 | TRY |
---|
[775] | 808 | { |
---|
| 809 | if (this->hasDomainAxisBaseRef_) return; |
---|
[887] | 810 | // Account for the scalar attributes |
---|
| 811 | std::vector<CScalar*> scalarList = getScalars(); |
---|
| 812 | for (size_t i = 0; i < scalarList.size(); ++i) |
---|
| 813 | { |
---|
| 814 | scalarList[i]->setAttributesReference(); |
---|
| 815 | } |
---|
| 816 | |
---|
[775] | 817 | // Account for the axis attributes |
---|
| 818 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 819 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
| 820 | { |
---|
[777] | 821 | axisList[i]->setAttributesReference(); |
---|
[775] | 822 | } |
---|
| 823 | |
---|
| 824 | // Account for the domain attributes |
---|
| 825 | std::vector<CDomain*> domList = getDomains(); |
---|
| 826 | for (size_t i = 0; i < domList.size(); ++i) |
---|
| 827 | { |
---|
[777] | 828 | domList[i]->setAttributesReference(); |
---|
[775] | 829 | } |
---|
[887] | 830 | |
---|
[775] | 831 | this->hasDomainAxisBaseRef_ = true; |
---|
| 832 | } |
---|
[1622] | 833 | CATCH_DUMP_ATTR |
---|
[775] | 834 | |
---|
[676] | 835 | void CGrid::checkEligibilityForCompressedOutput() |
---|
[1622] | 836 | TRY |
---|
[676] | 837 | { |
---|
| 838 | // We don't check if the mask is valid here, just if a mask has been defined at this point. |
---|
[817] | 839 | isCompressible_ = !mask_1d.isEmpty() || !mask_2d.isEmpty() || !mask_3d.isEmpty(); |
---|
[676] | 840 | } |
---|
[1622] | 841 | CATCH_DUMP_ATTR |
---|
[676] | 842 | |
---|
[1875] | 843 | //ym obsolete -> to be removed later |
---|
[509] | 844 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
[1622] | 845 | TRY |
---|
[509] | 846 | { |
---|
[650] | 847 | CContext* context = CContext::getCurrent(); |
---|
[1853] | 848 | if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) |
---|
| 849 | { |
---|
| 850 | if (this->isChecked && doSendingIndex && !isIndexSent) |
---|
| 851 | { |
---|
[1875] | 852 | if (isScalarGrid()) /*sendIndexScalarGrid()*/; |
---|
| 853 | else /*sendIndex()*/; |
---|
[1853] | 854 | this->isIndexSent = true; |
---|
| 855 | } |
---|
[1784] | 856 | } |
---|
[1027] | 857 | |
---|
[1030] | 858 | if (this->isChecked) return; |
---|
| 859 | this->checkAttributesAfterTransformation(); |
---|
[1099] | 860 | |
---|
| 861 | // TODO: Transfer grid attributes |
---|
[1250] | 862 | //if (!context->hasClient && context->hasServer) this->createMask(); |
---|
[1030] | 863 | this->computeIndex(); |
---|
[1027] | 864 | |
---|
[1030] | 865 | if (!(this->hasTransform() && !this->isTransformed())) |
---|
| 866 | this->isChecked = true; |
---|
[1009] | 867 | |
---|
[1030] | 868 | if (!(this->hasTransform() && (!this->isGenerated()))) |
---|
| 869 | this->isChecked = true; |
---|
[219] | 870 | } |
---|
[1622] | 871 | CATCH_DUMP_ATTR |
---|
[1784] | 872 | |
---|
| 873 | |
---|
[1637] | 874 | bool CGrid::hasMask() const |
---|
| 875 | TRY |
---|
| 876 | { |
---|
| 877 | return (!mask_1d.isEmpty() || !mask_2d.isEmpty() || !mask_3d.isEmpty() || |
---|
| 878 | !mask_4d.isEmpty() || !mask_5d.isEmpty() || !mask_6d.isEmpty() || !mask_7d.isEmpty()); |
---|
| 879 | } |
---|
| 880 | CATCH |
---|
[219] | 881 | |
---|
[1918] | 882 | |
---|
| 883 | CArray<bool,1>& CGrid::getMask(void) |
---|
| 884 | { |
---|
| 885 | |
---|
| 886 | if (mask_.isEmpty()) |
---|
| 887 | { |
---|
| 888 | if (!mask_0d.isEmpty()) mask_.reference(CArray<bool,1>(mask_0d.dataFirst(),shape(mask_0d.numElements()), neverDeleteData)) ; |
---|
| 889 | if (!mask_1d.isEmpty()) mask_.reference(CArray<bool,1>(mask_1d.dataFirst(),shape(mask_1d.numElements()), neverDeleteData)) ; |
---|
| 890 | if (!mask_2d.isEmpty()) mask_.reference(CArray<bool,1>(mask_2d.dataFirst(),shape(mask_2d.numElements()), neverDeleteData)) ; |
---|
| 891 | if (!mask_3d.isEmpty()) mask_.reference(CArray<bool,1>(mask_3d.dataFirst(),shape(mask_3d.numElements()), neverDeleteData)) ; |
---|
| 892 | if (!mask_4d.isEmpty()) mask_.reference(CArray<bool,1>(mask_4d.dataFirst(),shape(mask_4d.numElements()), neverDeleteData)) ; |
---|
| 893 | if (!mask_5d.isEmpty()) mask_.reference(CArray<bool,1>(mask_5d.dataFirst(),shape(mask_5d.numElements()), neverDeleteData)) ; |
---|
| 894 | if (!mask_6d.isEmpty()) mask_.reference(CArray<bool,1>(mask_6d.dataFirst(),shape(mask_6d.numElements()), neverDeleteData)) ; |
---|
| 895 | if (!mask_7d.isEmpty()) mask_.reference(CArray<bool,1>(mask_7d.dataFirst(),shape(mask_7d.numElements()), neverDeleteData)) ; |
---|
| 896 | } |
---|
| 897 | return mask_ ; |
---|
| 898 | } |
---|
[1236] | 899 | /* |
---|
| 900 | Create mask of grid from mask of its components |
---|
| 901 | */ |
---|
[821] | 902 | void CGrid::createMask(void) |
---|
[1622] | 903 | TRY |
---|
[821] | 904 | { |
---|
| 905 | using namespace std; |
---|
| 906 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 907 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 908 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 909 | |
---|
| 910 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
[1311] | 911 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->domainMask); |
---|
[821] | 912 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 913 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
| 914 | |
---|
| 915 | switch (dim) { |
---|
| 916 | case 1: |
---|
| 917 | checkGridMask(mask_1d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 918 | break; |
---|
| 919 | case 2: |
---|
| 920 | checkGridMask(mask_2d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 921 | break; |
---|
| 922 | case 3: |
---|
| 923 | checkGridMask(mask_3d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 924 | break; |
---|
[968] | 925 | case 4: |
---|
| 926 | checkGridMask(mask_4d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 927 | break; |
---|
| 928 | case 5: |
---|
| 929 | checkGridMask(mask_5d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 930 | break; |
---|
| 931 | case 6: |
---|
| 932 | checkGridMask(mask_6d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 933 | break; |
---|
| 934 | case 7: |
---|
| 935 | checkGridMask(mask_7d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 936 | break; |
---|
[821] | 937 | default: |
---|
| 938 | break; |
---|
| 939 | } |
---|
| 940 | } |
---|
[1622] | 941 | CATCH_DUMP_ATTR |
---|
[821] | 942 | |
---|
[1236] | 943 | /* |
---|
| 944 | Check validity of grid's mask by using the masks of its components |
---|
| 945 | */ |
---|
[415] | 946 | void CGrid::checkMask(void) |
---|
[1622] | 947 | TRY |
---|
[415] | 948 | { |
---|
| 949 | using namespace std; |
---|
[567] | 950 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 951 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 952 | int dim = domainP.size() * 2 + axisP.size(); |
---|
[415] | 953 | |
---|
[664] | 954 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
[1311] | 955 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->domainMask); |
---|
[567] | 956 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 957 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
[415] | 958 | |
---|
[567] | 959 | switch (dim) { |
---|
| 960 | case 1: |
---|
[817] | 961 | checkGridMask(mask_1d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 962 | break; |
---|
| 963 | case 2: |
---|
[817] | 964 | checkGridMask(mask_2d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 965 | break; |
---|
| 966 | case 3: |
---|
[817] | 967 | checkGridMask(mask_3d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 968 | break; |
---|
[932] | 969 | case 4: |
---|
| 970 | checkGridMask(mask_4d, domainMasks, axisMasks, axis_domain_order); |
---|
| 971 | break; |
---|
| 972 | case 5: |
---|
| 973 | checkGridMask(mask_5d, domainMasks, axisMasks, axis_domain_order); |
---|
| 974 | break; |
---|
| 975 | case 6: |
---|
| 976 | checkGridMask(mask_6d, domainMasks, axisMasks, axis_domain_order); |
---|
| 977 | break; |
---|
| 978 | case 7: |
---|
| 979 | checkGridMask(mask_7d, domainMasks, axisMasks, axis_domain_order); |
---|
| 980 | break; |
---|
[567] | 981 | default: |
---|
| 982 | break; |
---|
[415] | 983 | } |
---|
| 984 | } |
---|
[1622] | 985 | CATCH_DUMP_ATTR |
---|
[623] | 986 | |
---|
[1236] | 987 | /* |
---|
| 988 | Modify value of mask in a certain index |
---|
| 989 | This function can be used to correct the mask of grid after being constructed with createMask |
---|
| 990 | \param [in] indexToModify |
---|
| 991 | \param [in] modifyValue |
---|
| 992 | */ |
---|
[1129] | 993 | void CGrid::modifyMask(const CArray<int,1>& indexToModify, bool modifyValue) |
---|
[1622] | 994 | TRY |
---|
[623] | 995 | { |
---|
| 996 | using namespace std; |
---|
| 997 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
[1158] | 998 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[623] | 999 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 1000 | |
---|
| 1001 | switch (dim) { |
---|
[1250] | 1002 | case 0: |
---|
| 1003 | modifyGridMask(mask_0d, indexToModify, modifyValue); |
---|
| 1004 | break; |
---|
[623] | 1005 | case 1: |
---|
[1129] | 1006 | modifyGridMask(mask_1d, indexToModify, modifyValue); |
---|
[623] | 1007 | break; |
---|
| 1008 | case 2: |
---|
[1129] | 1009 | modifyGridMask(mask_2d, indexToModify, modifyValue); |
---|
[623] | 1010 | break; |
---|
| 1011 | case 3: |
---|
[1129] | 1012 | modifyGridMask(mask_3d, indexToModify, modifyValue); |
---|
[623] | 1013 | break; |
---|
[932] | 1014 | case 4: |
---|
[1129] | 1015 | modifyGridMask(mask_4d, indexToModify, modifyValue); |
---|
[932] | 1016 | break; |
---|
| 1017 | case 5: |
---|
[1129] | 1018 | modifyGridMask(mask_5d, indexToModify, modifyValue); |
---|
[932] | 1019 | break; |
---|
| 1020 | case 6: |
---|
[1129] | 1021 | modifyGridMask(mask_6d, indexToModify, modifyValue); |
---|
[932] | 1022 | break; |
---|
| 1023 | case 7: |
---|
[1129] | 1024 | modifyGridMask(mask_7d, indexToModify, modifyValue); |
---|
[932] | 1025 | break; |
---|
[623] | 1026 | default: |
---|
| 1027 | break; |
---|
| 1028 | } |
---|
| 1029 | } |
---|
[1622] | 1030 | CATCH_DUMP_ATTR |
---|
[623] | 1031 | |
---|
[1236] | 1032 | /* |
---|
| 1033 | Change the mask size. This function is used on reconstructing mask in server side |
---|
| 1034 | \param [in] newDimensionSize |
---|
| 1035 | \param [in] newValue |
---|
| 1036 | */ |
---|
[1129] | 1037 | void CGrid::modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue) |
---|
[1622] | 1038 | TRY |
---|
[1129] | 1039 | { |
---|
| 1040 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
[1136] | 1041 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[1129] | 1042 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 1043 | |
---|
| 1044 | switch (dim) { |
---|
[1250] | 1045 | case 0: |
---|
| 1046 | modifyGridMaskSize(mask_0d, newDimensionSize, newValue); |
---|
| 1047 | break; |
---|
[1129] | 1048 | case 1: |
---|
| 1049 | modifyGridMaskSize(mask_1d, newDimensionSize, newValue); |
---|
| 1050 | break; |
---|
| 1051 | case 2: |
---|
| 1052 | modifyGridMaskSize(mask_2d, newDimensionSize, newValue); |
---|
| 1053 | break; |
---|
| 1054 | case 3: |
---|
| 1055 | modifyGridMaskSize(mask_3d, newDimensionSize, newValue); |
---|
| 1056 | break; |
---|
| 1057 | case 4: |
---|
| 1058 | modifyGridMaskSize(mask_4d, newDimensionSize, newValue); |
---|
| 1059 | break; |
---|
| 1060 | case 5: |
---|
| 1061 | modifyGridMaskSize(mask_5d, newDimensionSize, newValue); |
---|
| 1062 | break; |
---|
| 1063 | case 6: |
---|
| 1064 | modifyGridMaskSize(mask_6d, newDimensionSize, newValue); |
---|
| 1065 | break; |
---|
| 1066 | case 7: |
---|
| 1067 | modifyGridMaskSize(mask_7d, newDimensionSize, newValue); |
---|
| 1068 | break; |
---|
| 1069 | default: |
---|
| 1070 | break; |
---|
| 1071 | } |
---|
| 1072 | } |
---|
[1622] | 1073 | CATCH_DUMP_ATTR |
---|
[1129] | 1074 | |
---|
[219] | 1075 | //--------------------------------------------------------------- |
---|
| 1076 | |
---|
[509] | 1077 | void CGrid::solveDomainRef(bool sendAtt) |
---|
[1622] | 1078 | TRY |
---|
[219] | 1079 | { |
---|
[540] | 1080 | setDomainList(); |
---|
[567] | 1081 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 1082 | if (!domListP.empty()) |
---|
[219] | 1083 | { |
---|
[567] | 1084 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 1085 | { |
---|
| 1086 | if (sendAtt) domListP[i]->sendCheckedAttributes(); |
---|
| 1087 | else domListP[i]->checkAttributesOnClient(); |
---|
| 1088 | } |
---|
[219] | 1089 | } |
---|
| 1090 | } |
---|
[1622] | 1091 | CATCH_DUMP_ATTR |
---|
[219] | 1092 | |
---|
| 1093 | //--------------------------------------------------------------- |
---|
| 1094 | |
---|
[567] | 1095 | void CGrid::solveAxisRef(bool sendAtt) |
---|
[1622] | 1096 | TRY |
---|
[219] | 1097 | { |
---|
[540] | 1098 | setAxisList(); |
---|
[567] | 1099 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 1100 | if (!axisListP.empty()) |
---|
[219] | 1101 | { |
---|
[567] | 1102 | for (int i = 0; i < axisListP.size(); ++i) |
---|
[540] | 1103 | { |
---|
[567] | 1104 | if (sendAtt) |
---|
[1870] | 1105 | axisListP[i]->sendCheckedAttributes(getGlobalDimension(),getAxisPositionInGrid()[i]); |
---|
[567] | 1106 | else |
---|
[742] | 1107 | axisListP[i]->checkAttributesOnClient(); |
---|
[540] | 1108 | } |
---|
[219] | 1109 | } |
---|
| 1110 | } |
---|
[1622] | 1111 | CATCH_DUMP_ATTR |
---|
[219] | 1112 | |
---|
[887] | 1113 | //--------------------------------------------------------------- |
---|
| 1114 | |
---|
| 1115 | void CGrid::solveScalarRef(bool sendAtt) |
---|
[1622] | 1116 | TRY |
---|
[887] | 1117 | { |
---|
| 1118 | setScalarList(); |
---|
| 1119 | std::vector<CScalar*> scalarListP = this->getScalars(); |
---|
| 1120 | if (!scalarListP.empty()) |
---|
| 1121 | { |
---|
| 1122 | for (int i = 0; i < scalarListP.size(); ++i) |
---|
| 1123 | { |
---|
| 1124 | /*Nothing to do for now */ |
---|
| 1125 | // if (sendAtt) scalarListP[i]->sendCheckedAttributes(); |
---|
| 1126 | // else scalarListP[i]->checkAttributesOnClient(); |
---|
| 1127 | } |
---|
| 1128 | } |
---|
| 1129 | } |
---|
[1622] | 1130 | CATCH_DUMP_ATTR |
---|
[887] | 1131 | |
---|
[1144] | 1132 | /*! |
---|
| 1133 | Compute the index to for write data into a file |
---|
| 1134 | */ |
---|
[1129] | 1135 | void CGrid::computeWrittenIndex() |
---|
[1622] | 1136 | TRY |
---|
[1129] | 1137 | { |
---|
| 1138 | if (computedWrittenIndex_) return; |
---|
| 1139 | computedWrittenIndex_ = true; |
---|
| 1140 | |
---|
[1202] | 1141 | if (isScalarGrid()) |
---|
| 1142 | { |
---|
| 1143 | size_t nbWritten = 1; |
---|
| 1144 | int writtenIndex = 0; |
---|
| 1145 | |
---|
[1847] | 1146 | localIndexToWriteOnClient_.resize(nbWritten); |
---|
| 1147 | localIndexToWriteOnServer_.resize(nbWritten); |
---|
| 1148 | localIndexToWriteOnServer_(0) = writtenIndex; |
---|
| 1149 | localIndexToWriteOnClient_(0) = writtenIndex; |
---|
[1202] | 1150 | |
---|
| 1151 | return; |
---|
| 1152 | } |
---|
| 1153 | |
---|
[1129] | 1154 | size_t nbWritten = 0, indGlo; |
---|
[1870] | 1155 | CDistributionClient::GlobalLocalDataMap& globalDataIndex = getClientDistribution()->getGlobalDataIndexOnClient(); |
---|
[1129] | 1156 | CDistributionClient::GlobalLocalDataMap::const_iterator itb = globalDataIndex.begin(), |
---|
| 1157 | ite = globalDataIndex.end(), it; |
---|
| 1158 | const CDistributionServer::GlobalLocalMap& globalLocalIndex = serverDistribution_->getGlobalLocalIndex(); |
---|
| 1159 | CDistributionServer::GlobalLocalMap::const_iterator itSrvb = globalLocalIndex.begin(), |
---|
| 1160 | itSrve = globalLocalIndex.end(), itSrv; |
---|
| 1161 | for (it = itb; it != ite; ++it) |
---|
| 1162 | { |
---|
| 1163 | indGlo = it->first; |
---|
| 1164 | if (globalLocalIndex.end() != globalLocalIndex.find(indGlo)) ++nbWritten; |
---|
| 1165 | } |
---|
| 1166 | |
---|
[1847] | 1167 | localIndexToWriteOnClient_.resize(nbWritten); |
---|
| 1168 | localIndexToWriteOnServer_.resize(nbWritten); |
---|
[1144] | 1169 | |
---|
[1143] | 1170 | { |
---|
| 1171 | numberWrittenIndexes_ = nbWritten; |
---|
[1870] | 1172 | if (isDataDistributed()) |
---|
[1143] | 1173 | { |
---|
[1847] | 1174 | CContext* context = CContext::getCurrent(); |
---|
| 1175 | MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, context->intraComm_); |
---|
| 1176 | MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, context->intraComm_); |
---|
[1143] | 1177 | offsetWrittenIndexes_ -= numberWrittenIndexes_; |
---|
| 1178 | } |
---|
| 1179 | else |
---|
| 1180 | totalNumberWrittenIndexes_ = numberWrittenIndexes_; |
---|
| 1181 | } |
---|
| 1182 | |
---|
[1129] | 1183 | nbWritten = 0; |
---|
| 1184 | for (it = itb; it != ite; ++it) |
---|
| 1185 | { |
---|
| 1186 | indGlo = it->first; |
---|
| 1187 | itSrv = globalLocalIndex.find(indGlo); |
---|
| 1188 | if (itSrve != itSrv) |
---|
| 1189 | { |
---|
[1847] | 1190 | localIndexToWriteOnServer_(nbWritten) = itSrv->second; |
---|
| 1191 | localIndexToWriteOnClient_(nbWritten) = it->second; |
---|
[1129] | 1192 | ++nbWritten; |
---|
| 1193 | } |
---|
| 1194 | } |
---|
| 1195 | } |
---|
[1622] | 1196 | CATCH_DUMP_ATTR |
---|
[1129] | 1197 | |
---|
[1869] | 1198 | |
---|
| 1199 | |
---|
| 1200 | /*! |
---|
| 1201 | Compute the global index of grid to send to server as well as the connected server of the current client. |
---|
| 1202 | First of all, from the local data on each element of grid, we can calculate their local index which also allows us to know |
---|
| 1203 | their global index. We can have a map of global index of grid and local index that each client holds |
---|
| 1204 | Then, each client holds a piece of information about the distribution of servers, which permits to compute the connected server(s) |
---|
| 1205 | of the current client. |
---|
| 1206 | */ |
---|
| 1207 | void CGrid::computeGridIndexToFileServer(CContextClient* client) |
---|
| 1208 | { |
---|
[1870] | 1209 | if (isScalarGrid()) computeConnectedClientsScalarGrid(client); |
---|
| 1210 | else computeConnectedClients(client); |
---|
| 1211 | |
---|
[1869] | 1212 | // compute indices for client/server transfer for domain |
---|
| 1213 | for (const auto& domainId : domList_) CDomain::get(domainId)->computeConnectedClients(client); |
---|
| 1214 | |
---|
| 1215 | |
---|
| 1216 | // compute indices for client/server transfer for axis |
---|
| 1217 | std::vector<CAxis*> axisList = this->getAxis(); |
---|
[1870] | 1218 | for(int i=0 ; i<axisList.size(); i++) axisList[i] -> computeConnectedClients(client, getGlobalDimension(),getAxisPositionInGrid()[i]) ; |
---|
[1869] | 1219 | } |
---|
[219] | 1220 | //--------------------------------------------------------------- |
---|
| 1221 | |
---|
[1869] | 1222 | |
---|
| 1223 | void CGrid::computeClientDistribution(void) |
---|
| 1224 | { |
---|
| 1225 | if (computeClientDistribution_done_) return ; |
---|
| 1226 | else computeClientDistribution_done_ = true ; |
---|
| 1227 | |
---|
| 1228 | CContext* context = CContext::getCurrent(); |
---|
| 1229 | int rank = context-> getIntraCommRank(); |
---|
| 1230 | clientDistribution_ = new CDistributionClient(rank, this); |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | void CGrid::computeStoreIndex_client(void) |
---|
| 1234 | { |
---|
| 1235 | if (computeStoreIndex_client_done_) return ; |
---|
| 1236 | else computeStoreIndex_client_done_ = true ; |
---|
| 1237 | if (isScalarGrid()) |
---|
| 1238 | { |
---|
| 1239 | storeIndex_client_.resize(1); |
---|
| 1240 | storeIndex_client_(0) = 0; |
---|
| 1241 | } |
---|
| 1242 | else |
---|
| 1243 | { |
---|
[1870] | 1244 | CDistributionClient* clientDistribution = getClientDistribution() ; |
---|
[1869] | 1245 | const std::vector<int>& localDataIndex = clientDistribution->getLocalDataIndexOnClient() ; |
---|
| 1246 | int nbStoreIndex = localDataIndex.size() ; |
---|
| 1247 | storeIndex_client_.resize(nbStoreIndex); |
---|
| 1248 | for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client_(idx) = localDataIndex[idx]; |
---|
| 1249 | } |
---|
| 1250 | } |
---|
| 1251 | |
---|
| 1252 | void CGrid::computeStoreMask_client(void) |
---|
| 1253 | { |
---|
| 1254 | if (computeStoreMask_client_done_) return ; |
---|
| 1255 | else computeStoreMask_client_done_ = true ; |
---|
| 1256 | if (isScalarGrid()) |
---|
| 1257 | { |
---|
| 1258 | storeMask_client_.resize(1); |
---|
| 1259 | storeMask_client_(0) = true; |
---|
| 1260 | } |
---|
| 1261 | else |
---|
| 1262 | { |
---|
[1870] | 1263 | CDistributionClient* clientDistribution = getClientDistribution() ; |
---|
[1869] | 1264 | const std::vector<bool>& localMaskIndex = clientDistribution->getLocalMaskIndexOnClient() ; |
---|
| 1265 | int nbMaskIndex = localMaskIndex.size() ; |
---|
| 1266 | storeMask_client_.resize(nbMaskIndex); |
---|
| 1267 | for (int idx = 0; idx < nbMaskIndex; ++idx) storeMask_client_(idx) = localMaskIndex[idx]; |
---|
| 1268 | } |
---|
| 1269 | } |
---|
| 1270 | |
---|
| 1271 | |
---|
[1870] | 1272 | void CGrid::computeOutLocalIndexStoreOnClient(void) |
---|
| 1273 | { |
---|
| 1274 | if (computeOutLocalIndexStoreOnClient_done_) return ; |
---|
| 1275 | else computeOutLocalIndexStoreOnClient_done_=true ; |
---|
[1023] | 1276 | |
---|
[1870] | 1277 | if (isScalarGrid()) |
---|
| 1278 | { |
---|
| 1279 | auto& outGlobalIndexFromClient = getOutGlobalIndexFromClient(); |
---|
| 1280 | auto itb = outGlobalIndexFromClient.begin(), ite = outGlobalIndexFromClient.end() ; |
---|
| 1281 | for (auto it = itb; it != ite; ++it) |
---|
[1263] | 1282 | { |
---|
| 1283 | int rank = it->first; |
---|
[1870] | 1284 | CArray<size_t,1>& globalIndex = outGlobalIndexFromClient[rank]; |
---|
[1794] | 1285 | outLocalIndexStoreOnClient_.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); |
---|
| 1286 | CArray<size_t,1>& localIndex = outLocalIndexStoreOnClient_[rank]; |
---|
[1870] | 1287 | if (1 != globalIndex.numElements()) |
---|
| 1288 | ERROR("void CGrid::computeClientIndexScalarGrid()", |
---|
| 1289 | << "Something wrong happened. " |
---|
| 1290 | << "Number of received global index on scalar grid should equal to 1" |
---|
| 1291 | << "Number of received global index " << globalIndex.numElements() << "."); |
---|
[1263] | 1292 | |
---|
[1870] | 1293 | localIndex(0) = globalIndex(0); |
---|
| 1294 | } |
---|
| 1295 | } |
---|
| 1296 | else |
---|
| 1297 | { |
---|
| 1298 | CDistributionClient::GlobalLocalDataMap& globalDataIndex = getClientDistribution()->getGlobalDataIndexOnClient(); |
---|
| 1299 | CDistributionClient::GlobalLocalDataMap::const_iterator itGloe = globalDataIndex.end(); |
---|
| 1300 | auto& outGlobalIndexFromClient = getOutGlobalIndexFromClient(); |
---|
| 1301 | auto itb = outGlobalIndexFromClient.begin(), ite = outGlobalIndexFromClient.end() ; |
---|
| 1302 | |
---|
| 1303 | for (auto it = itb; it != ite; ++it) |
---|
| 1304 | { |
---|
| 1305 | int rank = it->first; |
---|
| 1306 | CArray<size_t,1>& globalIndex = outGlobalIndexFromClient[rank]; |
---|
| 1307 | outLocalIndexStoreOnClient_.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); |
---|
| 1308 | CArray<size_t,1>& localIndex = outLocalIndexStoreOnClient_[rank]; |
---|
| 1309 | size_t nbIndex = 0; |
---|
[1129] | 1310 | |
---|
[1870] | 1311 | // Keep this code for this moment but it should be removed (or moved to DEBUG) to improve performance |
---|
| 1312 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 1313 | if (itGloe != globalDataIndex.find(globalIndex(idx))) ++nbIndex; |
---|
[1129] | 1314 | |
---|
[1870] | 1315 | if (nbIndex != localIndex.numElements()) |
---|
| 1316 | ERROR("void CGrid::computeClientIndex()", |
---|
| 1317 | << "Number of local index on client is different from number of received global index" |
---|
| 1318 | << "Rank of sent client " << rank <<"." |
---|
| 1319 | << "Number of local index " << nbIndex << ". " |
---|
| 1320 | << "Number of received global index " << localIndex.numElements() << "."); |
---|
| 1321 | |
---|
| 1322 | nbIndex = 0; |
---|
| 1323 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 1324 | if (itGloe != globalDataIndex.find(globalIndex(idx))) |
---|
| 1325 | localIndex(idx) = globalDataIndex[globalIndex(idx)]; |
---|
[1030] | 1326 | } |
---|
[1870] | 1327 | } |
---|
| 1328 | } |
---|
[1023] | 1329 | |
---|
[1870] | 1330 | bool CGrid::isDataDistributed(void) |
---|
| 1331 | { |
---|
| 1332 | return getClientDistribution()->isDataDistributed() ; |
---|
| 1333 | } |
---|
| 1334 | |
---|
[1136] | 1335 | /*! |
---|
[1263] | 1336 | Compute connected receivers and indexes to be sent to these receivers. |
---|
[1136] | 1337 | */ |
---|
[1869] | 1338 | void CGrid::computeConnectedClients(CContextClient* client) |
---|
[1622] | 1339 | TRY |
---|
[1023] | 1340 | { |
---|
[1869] | 1341 | if (computeConnectedClients_done_.count(client)!=0) return ; |
---|
[1870] | 1342 | else computeConnectedClients_done_.insert(client) ; |
---|
[1869] | 1343 | |
---|
[1023] | 1344 | CContext* context = CContext::getCurrent(); |
---|
[1784] | 1345 | |
---|
| 1346 | set<int> listReceiverSize ; |
---|
[1869] | 1347 | int receiverSize = client->serverSize; |
---|
| 1348 | |
---|
| 1349 | if (listReceiverSize.find(receiverSize)==listReceiverSize.end()) |
---|
[1784] | 1350 | { |
---|
[1869] | 1351 | listReceiverSize.insert(receiverSize) ; |
---|
| 1352 | if (connectedServerRank_.find(receiverSize) != connectedServerRank_.end()) |
---|
| 1353 | { |
---|
| 1354 | // delete corresponding map in case of recompute, probably because a grid could has been modifiedd |
---|
| 1355 | // by a transformation |
---|
| 1356 | connectedServerRank_.erase(receiverSize); |
---|
| 1357 | connectedDataSize_.erase(receiverSize); |
---|
| 1358 | globalIndexOnServer_.erase(receiverSize); |
---|
| 1359 | nbSenders_.erase(receiverSize); |
---|
| 1360 | } |
---|
[1099] | 1361 | |
---|
[1869] | 1362 | if (!doGridHaveDataDistributed(client)) |
---|
[1027] | 1363 | { |
---|
[1869] | 1364 | if (client->isServerLeader()) |
---|
| 1365 | { |
---|
[1870] | 1366 | size_t ssize = getClientDistribution()->getLocalDataIndexOnClient().size(); |
---|
[1869] | 1367 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1368 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1027] | 1369 | { |
---|
[1869] | 1370 | connectedServerRank_[receiverSize].push_back(*itRank); |
---|
| 1371 | connectedDataSize_[receiverSize][*itRank] = ssize; |
---|
[1027] | 1372 | } |
---|
[1869] | 1373 | } |
---|
| 1374 | return; |
---|
| 1375 | } |
---|
[1023] | 1376 | |
---|
[1869] | 1377 | // Compute mapping between client and server |
---|
| 1378 | std::vector<std::unordered_map<size_t,std::vector<int> > > indexServerOnElement; |
---|
| 1379 | CServerDistributionDescription serverDistributionDescription(getGlobalDimension(), client->serverSize); |
---|
| 1380 | std::vector<int> serverZeroIndex = serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, |
---|
[1263] | 1381 | client->clientRank, |
---|
| 1382 | client->clientSize, |
---|
| 1383 | axis_domain_order, |
---|
| 1384 | getDistributedDimension()); |
---|
[1232] | 1385 | |
---|
[1869] | 1386 | // Even if servers have no index, they must received something from client |
---|
| 1387 | // We only use several client to send "empty" message to these servers |
---|
| 1388 | std::list<int> serverZeroIndexLeader; |
---|
| 1389 | std::list<int> serverZeroIndexNotLeader; |
---|
| 1390 | CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); |
---|
| 1391 | for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 1392 | *it = serverZeroIndex[*it]; |
---|
[1232] | 1393 | |
---|
[1869] | 1394 | if (globalIndexOnServer_.find(receiverSize) == globalIndexOnServer_.end()) |
---|
| 1395 | computeIndexByElement(indexServerOnElement, client, globalIndexOnServer_[receiverSize]); |
---|
[1023] | 1396 | |
---|
[1870] | 1397 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = getClientDistribution()->getGlobalLocalDataSendToServer(); |
---|
[1869] | 1398 | CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; |
---|
| 1399 | CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
| 1400 | itbGlobalMap = globalIndexOnServer_[receiverSize].begin(); |
---|
| 1401 | iteGlobalMap = globalIndexOnServer_[receiverSize].end(); |
---|
[1023] | 1402 | |
---|
[1869] | 1403 | for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 1404 | { |
---|
| 1405 | int serverRank = itGlobalMap->first; |
---|
| 1406 | int indexSize = itGlobalMap->second.size(); |
---|
| 1407 | const std::vector<size_t>& indexVec = itGlobalMap->second; |
---|
| 1408 | for (int idx = 0; idx < indexSize; ++idx) |
---|
[1027] | 1409 | { |
---|
[1869] | 1410 | itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); |
---|
| 1411 | if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) |
---|
| 1412 | { |
---|
| 1413 | if (connectedDataSize_[receiverSize].end() == connectedDataSize_[receiverSize].find(serverRank)) |
---|
| 1414 | connectedDataSize_[receiverSize][serverRank] = 1; |
---|
| 1415 | else |
---|
| 1416 | ++connectedDataSize_[receiverSize][serverRank]; |
---|
| 1417 | } |
---|
[1027] | 1418 | } |
---|
[1869] | 1419 | } |
---|
[1023] | 1420 | |
---|
[1869] | 1421 | // Connected servers which really have index |
---|
| 1422 | for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 1423 | connectedServerRank_[receiverSize].push_back(itGlobalMap->first); |
---|
| 1424 | |
---|
| 1425 | // Connected servers which have no index at all |
---|
| 1426 | for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 1427 | connectedServerRank_[receiverSize].push_back(*it); |
---|
[1027] | 1428 | |
---|
[1869] | 1429 | // Even if a client has no index, it must connect to at least one server and |
---|
| 1430 | // send an "empty" data to this server |
---|
| 1431 | if (connectedServerRank_[receiverSize].empty()) |
---|
| 1432 | connectedServerRank_[receiverSize].push_back(client->clientRank % client->serverSize); |
---|
| 1433 | |
---|
| 1434 | // Now check if all servers have data to receive. If not, master client will send empty data. |
---|
| 1435 | // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. |
---|
| 1436 | std::vector<int> counts (client->clientSize); |
---|
| 1437 | std::vector<int> displs (client->clientSize); |
---|
| 1438 | displs[0] = 0; |
---|
| 1439 | int localCount = connectedServerRank_[receiverSize].size() ; |
---|
| 1440 | MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ; |
---|
| 1441 | for (int i = 0; i < client->clientSize-1; ++i) displs[i+1] = displs[i] + counts[i]; |
---|
| 1442 | std::vector<int> allConnectedServers(displs[client->clientSize-1]+counts[client->clientSize-1]); |
---|
| 1443 | MPI_Gatherv(&(connectedServerRank_[receiverSize])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm); |
---|
[1232] | 1444 | |
---|
[1869] | 1445 | if ((allConnectedServers.size() != receiverSize) && (client->clientRank == 0)) |
---|
| 1446 | { |
---|
| 1447 | std::vector<bool> isSrvConnected (receiverSize, false); |
---|
| 1448 | for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; |
---|
| 1449 | for (int i = 0; i < receiverSize; ++i) if (!isSrvConnected[i]) connectedServerRank_[receiverSize].push_back(i); |
---|
| 1450 | } |
---|
[1235] | 1451 | |
---|
[1869] | 1452 | nbSenders_[receiverSize] = CClientServerMapping::computeConnectedClients(receiverSize, client->clientSize, client->intraComm, connectedServerRank_[receiverSize]); |
---|
[1023] | 1453 | } |
---|
| 1454 | } |
---|
[1622] | 1455 | CATCH_DUMP_ATTR |
---|
[1023] | 1456 | |
---|
[865] | 1457 | /*! |
---|
| 1458 | Compute the global index of grid to send to server as well as the connected server of the current client. |
---|
| 1459 | First of all, from the local data on each element of grid, we can calculate their local index which also allows us to know |
---|
| 1460 | their global index. We can have a map of global index of grid and local index that each client holds |
---|
| 1461 | Then, each client holds a piece of information about the distribution of servers, which permits to compute the connected server(s) |
---|
| 1462 | of the current client. |
---|
| 1463 | */ |
---|
[1869] | 1464 | // ym obsolete : to be removed.... |
---|
[219] | 1465 | void CGrid::computeIndex(void) |
---|
[1622] | 1466 | TRY |
---|
[509] | 1467 | { |
---|
[1869] | 1468 | // old interface |
---|
[650] | 1469 | CContext* context = CContext::getCurrent(); |
---|
[1202] | 1470 | if (isScalarGrid()) |
---|
[1054] | 1471 | { |
---|
[1870] | 1472 | //computeClientIndexScalarGrid(); |
---|
[1853] | 1473 | if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) |
---|
[1202] | 1474 | { |
---|
[1869] | 1475 | // ym computeConnectedClientsScalarGrid(); |
---|
[1202] | 1476 | } |
---|
[1054] | 1477 | } |
---|
[1202] | 1478 | else |
---|
| 1479 | { |
---|
[1870] | 1480 | //computeClientIndex(); |
---|
[1853] | 1481 | if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) |
---|
[1202] | 1482 | { |
---|
[1869] | 1483 | //computeConnectedClients(); |
---|
[1202] | 1484 | } |
---|
| 1485 | } |
---|
[1761] | 1486 | //ym if (CServer::serverLevel==2) |
---|
| 1487 | if (context->getServiceType()==CServicesManager::OUT_SERVER) |
---|
[1340] | 1488 | { |
---|
| 1489 | computeWrittenIndex() ; |
---|
| 1490 | if (serverDistribution_!=0) serverDistribution_->partialClear() ; |
---|
| 1491 | if (clientDistribution_!=0) clientDistribution_->partialClear() ; |
---|
[1794] | 1492 | outGlobalIndexFromClient_.clear() ; |
---|
[1340] | 1493 | } |
---|
[219] | 1494 | } |
---|
[1622] | 1495 | CATCH_DUMP_ATTR |
---|
[219] | 1496 | |
---|
[865] | 1497 | /*! |
---|
| 1498 | Compute the global of (client) grid to send to server with the global index of each element of grid |
---|
| 1499 | Each element of grid has its own global index associated to a groups of server. We only search for the global index of each element whose |
---|
| 1500 | server is the same, then calculate the global index of grid. This way can reduce so much the time for executing DHT, which only needs to run |
---|
| 1501 | on each element whose size is much smaller than one of whole grid. |
---|
| 1502 | \param [in] indexServerOnElement global index of each element and the rank of server associated with these index |
---|
[1263] | 1503 | \param [in] client contextClient |
---|
[865] | 1504 | \param [out] globalIndexOnServer global index of grid and its corresponding rank of server. |
---|
| 1505 | */ |
---|
[1542] | 1506 | void CGrid::computeIndexByElement(const std::vector<std::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
[1263] | 1507 | const CContextClient* client, |
---|
[865] | 1508 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer) |
---|
[1622] | 1509 | TRY |
---|
[865] | 1510 | { |
---|
[1263] | 1511 | int serverSize = client->serverSize; |
---|
| 1512 | |
---|
| 1513 | std::vector<CDomain*> domList = getDomains(); |
---|
| 1514 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 1515 | |
---|
| 1516 | // Some pre-calculations of global index on each element of current grid. |
---|
| 1517 | int nbElement = axis_domain_order.numElements(); |
---|
| 1518 | std::vector<CArray<size_t,1> > globalIndexElement(nbElement); |
---|
| 1519 | int domainIdx = 0, axisIdx = 0, scalarIdx = 0; |
---|
| 1520 | std::vector<size_t> elementNGlobal(nbElement); |
---|
| 1521 | elementNGlobal[0] = 1; |
---|
| 1522 | size_t globalSize = 1; |
---|
| 1523 | for (int idx = 0; idx < nbElement; ++idx) |
---|
[1009] | 1524 | { |
---|
[1263] | 1525 | elementNGlobal[idx] = globalSize; |
---|
| 1526 | size_t elementSize; |
---|
| 1527 | size_t elementGlobalSize = 1; |
---|
| 1528 | if (2 == axis_domain_order(idx)) // This is domain |
---|
[865] | 1529 | { |
---|
[1263] | 1530 | elementSize = domList[domainIdx]->i_index.numElements(); |
---|
| 1531 | globalIndexElement[idx].resize(elementSize); |
---|
| 1532 | for (int jdx = 0; jdx < elementSize; ++jdx) |
---|
[865] | 1533 | { |
---|
[1263] | 1534 | globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); |
---|
[865] | 1535 | } |
---|
[1263] | 1536 | elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); |
---|
| 1537 | ++domainIdx; |
---|
| 1538 | } |
---|
| 1539 | else if (1 == axis_domain_order(idx)) // This is axis |
---|
| 1540 | { |
---|
| 1541 | elementSize = axisList[axisIdx]->index.numElements(); |
---|
| 1542 | globalIndexElement[idx].resize(elementSize); |
---|
| 1543 | for (int jdx = 0; jdx < elementSize; ++jdx) |
---|
[865] | 1544 | { |
---|
[1263] | 1545 | globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); |
---|
[865] | 1546 | } |
---|
[1263] | 1547 | elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); |
---|
| 1548 | ++axisIdx; |
---|
[865] | 1549 | } |
---|
[1263] | 1550 | else // Of course, this is scalar |
---|
| 1551 | { |
---|
| 1552 | globalIndexElement[idx].resize(1); |
---|
| 1553 | globalIndexElement[idx](0) = 0; |
---|
| 1554 | elementGlobalSize = 1; |
---|
| 1555 | } |
---|
| 1556 | globalSize *= elementGlobalSize; |
---|
| 1557 | } |
---|
[865] | 1558 | |
---|
[1263] | 1559 | std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); |
---|
[1542] | 1560 | std::vector<std::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); |
---|
[1263] | 1561 | CArray<int,1> nbIndexOnServer(serverSize); // Number of distributed global index held by each client for each server |
---|
| 1562 | // Number of temporary distributed global index held by each client for each server |
---|
| 1563 | // We have this variable for the case of non-distributed element (often axis) to check the duplicate server rank |
---|
| 1564 | CArray<int,1> nbIndexOnServerTmp(serverSize); |
---|
| 1565 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 1566 | { |
---|
| 1567 | nbIndexOnServer = 0; |
---|
[1542] | 1568 | const std::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; |
---|
[1263] | 1569 | const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; |
---|
| 1570 | CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); |
---|
| 1571 | clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); |
---|
| 1572 | const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); |
---|
| 1573 | CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), |
---|
| 1574 | ite = globalIndexElementOnServerMap.end(), it; |
---|
| 1575 | for (it = itb; it != ite; ++it) |
---|
[865] | 1576 | { |
---|
[1263] | 1577 | const std::vector<int>& tmp = it->second; |
---|
| 1578 | nbIndexOnServerTmp = 0; |
---|
| 1579 | for (int i = 0; i < tmp.size(); ++i) |
---|
[865] | 1580 | { |
---|
[1263] | 1581 | if (0 == nbIndexOnServerTmp(tmp[i])) ++nbIndexOnServerTmp(tmp[i]); |
---|
[865] | 1582 | } |
---|
[1263] | 1583 | nbIndexOnServer += nbIndexOnServerTmp; |
---|
| 1584 | } |
---|
[865] | 1585 | |
---|
[1263] | 1586 | for (int i = 0; i < serverSize; ++i) |
---|
| 1587 | { |
---|
| 1588 | if (0 != nbIndexOnServer(i)) |
---|
[865] | 1589 | { |
---|
[1263] | 1590 | globalElementIndexOnServer[idx][i].resize(nbIndexOnServer(i)); |
---|
| 1591 | elementOnServer[idx][i] = true; |
---|
[865] | 1592 | } |
---|
[1263] | 1593 | } |
---|
[865] | 1594 | |
---|
[1263] | 1595 | nbIndexOnServer = 0; |
---|
| 1596 | for (size_t j = 0; j < globalIndexElementOnServerMap.size(); ++j) |
---|
| 1597 | { |
---|
| 1598 | it = globalIndexElementOnServerMap.find(globalIndexElementOnClient(j)); |
---|
| 1599 | if (it != ite) |
---|
[1054] | 1600 | { |
---|
[1263] | 1601 | const std::vector<int>& tmp = it->second; |
---|
| 1602 | nbIndexOnServerTmp = 0; |
---|
| 1603 | for (int i = 0; i < tmp.size(); ++i) |
---|
[865] | 1604 | { |
---|
[1263] | 1605 | if (0 == nbIndexOnServerTmp(tmp[i])) |
---|
[914] | 1606 | { |
---|
[1263] | 1607 | globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer(tmp[i])] = it->first; |
---|
| 1608 | ++nbIndexOnServerTmp(tmp[i]); |
---|
[914] | 1609 | } |
---|
[865] | 1610 | } |
---|
[1263] | 1611 | nbIndexOnServer += nbIndexOnServerTmp; |
---|
[865] | 1612 | } |
---|
[1054] | 1613 | } |
---|
[1263] | 1614 | } |
---|
[865] | 1615 | |
---|
[1263] | 1616 | // Determine server which contain global source index |
---|
| 1617 | std::vector<bool> intersectedProc(serverSize, true); |
---|
| 1618 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 1619 | { |
---|
| 1620 | std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), |
---|
| 1621 | intersectedProc.begin(), intersectedProc.begin(), |
---|
| 1622 | std::logical_and<bool>()); |
---|
| 1623 | } |
---|
| 1624 | |
---|
| 1625 | std::vector<int> srcRank; |
---|
| 1626 | for (int idx = 0; idx < serverSize; ++idx) |
---|
| 1627 | { |
---|
| 1628 | if (intersectedProc[idx]) srcRank.push_back(idx); |
---|
| 1629 | } |
---|
| 1630 | |
---|
| 1631 | // Compute the global index of grid from global index of each element. |
---|
| 1632 | for (int i = 0; i < srcRank.size(); ++i) |
---|
| 1633 | { |
---|
| 1634 | size_t ssize = 1; |
---|
| 1635 | int rankSrc = srcRank[i]; |
---|
| 1636 | std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); |
---|
| 1637 | std::vector<size_t> currentIndex(nbElement,0); |
---|
[865] | 1638 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 1639 | { |
---|
[1263] | 1640 | ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); |
---|
| 1641 | globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); |
---|
[865] | 1642 | } |
---|
[1263] | 1643 | globalIndexOnServer[rankSrc].resize(ssize); |
---|
[865] | 1644 | |
---|
[1263] | 1645 | std::vector<int> idxLoop(nbElement,0); |
---|
| 1646 | int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); |
---|
| 1647 | size_t idx = 0; |
---|
| 1648 | while (idx < ssize) |
---|
[865] | 1649 | { |
---|
[1263] | 1650 | for (int ind = 0; ind < nbElement; ++ind) |
---|
| 1651 | { |
---|
| 1652 | if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) |
---|
| 1653 | { |
---|
| 1654 | idxLoop[ind] = 0; |
---|
| 1655 | ++idxLoop[ind+1]; |
---|
| 1656 | } |
---|
[1009] | 1657 | |
---|
[1263] | 1658 | currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; |
---|
[865] | 1659 | } |
---|
| 1660 | |
---|
[1263] | 1661 | for (int ind = 0; ind < innnerLoopSize; ++ind) |
---|
[865] | 1662 | { |
---|
[1263] | 1663 | currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; |
---|
| 1664 | size_t globalSrcIndex = 0; |
---|
| 1665 | for (int idxElement = 0; idxElement < nbElement; ++idxElement) |
---|
[865] | 1666 | { |
---|
[1263] | 1667 | globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; |
---|
[865] | 1668 | } |
---|
[1263] | 1669 | globalIndexOnServer[rankSrc][idx] = globalSrcIndex; |
---|
| 1670 | ++idx; |
---|
| 1671 | ++idxLoop[0]; |
---|
[865] | 1672 | } |
---|
| 1673 | } |
---|
[1158] | 1674 | } |
---|
[865] | 1675 | } |
---|
[1622] | 1676 | CATCH_DUMP_ATTR |
---|
| 1677 | //---------------------------------------------------------------- |
---|
[219] | 1678 | |
---|
[540] | 1679 | |
---|
[219] | 1680 | |
---|
[823] | 1681 | CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc) |
---|
[1622] | 1682 | TRY |
---|
[823] | 1683 | { |
---|
[887] | 1684 | std::vector<CDomain*> domainSrcTmp = gridSrc->getDomains(), domainSrc; |
---|
[823] | 1685 | std::vector<CAxis*> axisSrcTmp = gridSrc->getAxis(), axisSrc; |
---|
[887] | 1686 | std::vector<CScalar*> scalarSrcTmp = gridSrc->getScalars(), scalarSrc; |
---|
| 1687 | |
---|
| 1688 | for (int idx = 0; idx < domainSrcTmp.size(); ++idx) |
---|
| 1689 | { |
---|
| 1690 | CDomain* domain = CDomain::createDomain(); |
---|
| 1691 | domain->duplicateAttributes(domainSrcTmp[idx]); |
---|
| 1692 | domain->duplicateTransformation(domainSrcTmp[idx]); |
---|
| 1693 | domain->solveRefInheritance(true); |
---|
| 1694 | domain->solveInheritanceTransformation(); |
---|
| 1695 | domainSrc.push_back(domain); |
---|
| 1696 | } |
---|
| 1697 | |
---|
[823] | 1698 | for (int idx = 0; idx < axisSrcTmp.size(); ++idx) |
---|
| 1699 | { |
---|
| 1700 | CAxis* axis = CAxis::createAxis(); |
---|
| 1701 | axis->duplicateAttributes(axisSrcTmp[idx]); |
---|
| 1702 | axis->duplicateTransformation(axisSrcTmp[idx]); |
---|
| 1703 | axis->solveRefInheritance(true); |
---|
| 1704 | axis->solveInheritanceTransformation(); |
---|
| 1705 | axisSrc.push_back(axis); |
---|
| 1706 | } |
---|
| 1707 | |
---|
[887] | 1708 | for (int idx = 0; idx < scalarSrcTmp.size(); ++idx) |
---|
[823] | 1709 | { |
---|
[887] | 1710 | CScalar* scalar = CScalar::createScalar(); |
---|
| 1711 | scalar->duplicateAttributes(scalarSrcTmp[idx]); |
---|
| 1712 | scalar->duplicateTransformation(scalarSrcTmp[idx]); |
---|
| 1713 | scalar->solveRefInheritance(true); |
---|
| 1714 | scalar->solveInheritanceTransformation(); |
---|
| 1715 | scalarSrc.push_back(scalar); |
---|
[823] | 1716 | } |
---|
| 1717 | |
---|
[887] | 1718 | CGrid* grid = CGrid::createGrid(idNewGrid, domainSrc, axisSrc, scalarSrc, gridSrc->axis_domain_order); |
---|
[823] | 1719 | |
---|
| 1720 | return grid; |
---|
| 1721 | } |
---|
[1622] | 1722 | CATCH |
---|
[823] | 1723 | |
---|
[745] | 1724 | StdString CGrid::generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 1725 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 1726 | TRY |
---|
[745] | 1727 | { |
---|
[887] | 1728 | if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 1729 | ERROR("CGrid* CGrid::generateId(...)", |
---|
| 1730 | << "The size of axisDomainOrder (" << axisDomainOrder.numElements() |
---|
| 1731 | << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); |
---|
| 1732 | |
---|
| 1733 | std::ostringstream id; |
---|
| 1734 | |
---|
[887] | 1735 | if (domains.empty() && axis.empty() && !scalars.empty()) |
---|
| 1736 | id << "__scalar_"; |
---|
| 1737 | |
---|
| 1738 | if (0 != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 1739 | { |
---|
| 1740 | id << "__grid"; |
---|
| 1741 | |
---|
| 1742 | if (0 == axisDomainOrder.numElements()) |
---|
| 1743 | { |
---|
| 1744 | for (size_t i = 0; i < domains.size(); ++i) id << "_" << domains[i]->getId(); |
---|
| 1745 | for (size_t i = 0; i < axis.size(); ++i) id << "_" << axis[i]->getId(); |
---|
[887] | 1746 | for (size_t i = 0; i < scalars.size(); ++i) id << "_" << scalars[i]->getId(); |
---|
[745] | 1747 | } |
---|
| 1748 | else |
---|
| 1749 | { |
---|
[887] | 1750 | size_t iDomain = 0, iAxis = 0, iScalar = 0; |
---|
[745] | 1751 | for (size_t i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 1752 | { |
---|
[887] | 1753 | if (2 == axisDomainOrder(i)) |
---|
[745] | 1754 | id << "_" << domains[iDomain++]->getId(); |
---|
[887] | 1755 | else if (1 == axisDomainOrder(i)) |
---|
| 1756 | id << "_" << axis[iAxis++]->getId(); |
---|
[745] | 1757 | else |
---|
[887] | 1758 | id << "_" << scalars[iScalar++]->getId(); |
---|
[745] | 1759 | } |
---|
| 1760 | } |
---|
| 1761 | |
---|
| 1762 | id << "__"; |
---|
| 1763 | } |
---|
| 1764 | |
---|
| 1765 | return id.str(); |
---|
| 1766 | } |
---|
[1622] | 1767 | CATCH |
---|
[745] | 1768 | |
---|
[823] | 1769 | StdString CGrid::generateId(const CGrid* gridSrc, const CGrid* gridDest) |
---|
[1622] | 1770 | TRY |
---|
[823] | 1771 | { |
---|
| 1772 | StdString idSrc = gridSrc->getId(); |
---|
| 1773 | StdString idDest = gridDest->getId(); |
---|
| 1774 | |
---|
| 1775 | std::ostringstream id; |
---|
| 1776 | id << idSrc << "__" << idDest; |
---|
| 1777 | |
---|
| 1778 | return id.str(); |
---|
| 1779 | } |
---|
[1622] | 1780 | CATCH |
---|
[823] | 1781 | |
---|
[745] | 1782 | |
---|
[1158] | 1783 | //---------------------------------------------------------------- |
---|
| 1784 | |
---|
[1869] | 1785 | void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored) |
---|
[1622] | 1786 | TRY |
---|
[219] | 1787 | { |
---|
[1869] | 1788 | auto& storeIndex_client = getStoreIndex_client() ; |
---|
| 1789 | const StdSize size = storeIndex_client.numElements(); |
---|
[300] | 1790 | |
---|
[650] | 1791 | stored.resize(size); |
---|
[1869] | 1792 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; |
---|
[219] | 1793 | } |
---|
[1622] | 1794 | CATCH |
---|
[509] | 1795 | |
---|
[1869] | 1796 | void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data) |
---|
[1622] | 1797 | TRY |
---|
[593] | 1798 | { |
---|
[1869] | 1799 | auto& storeIndex_client=getStoreIndex_client() ; |
---|
| 1800 | const StdSize size = storeIndex_client.numElements(); |
---|
[593] | 1801 | |
---|
[1869] | 1802 | for(StdSize i = 0; i < size; i++) data[storeIndex_client(i)] = stored(i); |
---|
[593] | 1803 | } |
---|
[1622] | 1804 | CATCH |
---|
[593] | 1805 | |
---|
[1869] | 1806 | void CGrid::maskField_arr(const double* const data, CArray<double, 1>& stored) |
---|
[1637] | 1807 | { |
---|
[1869] | 1808 | auto& storeIndex_client=getStoreIndex_client() ; |
---|
| 1809 | auto& storeMask_client=getStoreMask_client() ; |
---|
| 1810 | |
---|
| 1811 | const StdSize size = storeIndex_client.numElements(); |
---|
[1637] | 1812 | stored.resize(size); |
---|
| 1813 | const double nanValue = std::numeric_limits<double>::quiet_NaN(); |
---|
| 1814 | |
---|
[1869] | 1815 | if (storeMask_client.numElements() != 0) |
---|
| 1816 | for(StdSize i = 0; i < size; i++) stored(i) = (storeMask_client(i)) ? data[storeIndex_client(i)] : nanValue; |
---|
[1637] | 1817 | else |
---|
[1869] | 1818 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; |
---|
[1637] | 1819 | } |
---|
| 1820 | |
---|
[1869] | 1821 | void CGrid::uncompressField_arr(const double* const data, CArray<double, 1>& out) |
---|
[1622] | 1822 | TRY |
---|
[1250] | 1823 | { |
---|
[1870] | 1824 | const std::vector<int>& localMaskedDataIndex = getClientDistribution()->getLocalMaskedDataIndexOnClient(); |
---|
[1250] | 1825 | const int size = localMaskedDataIndex.size(); |
---|
| 1826 | for(int i = 0; i < size; ++i) out(localMaskedDataIndex[i]) = data[i]; |
---|
| 1827 | } |
---|
[1622] | 1828 | CATCH |
---|
[1250] | 1829 | |
---|
[1870] | 1830 | |
---|
[1869] | 1831 | void CGrid::computeConnectedClientsScalarGrid(CContextClient* client) |
---|
[1622] | 1832 | TRY |
---|
[1202] | 1833 | { |
---|
[1869] | 1834 | if (computeConnectedClientsScalarGrid_done_.count(client)!=0) return ; |
---|
[1099] | 1835 | |
---|
[1784] | 1836 | CContext* context = CContext::getCurrent(); |
---|
| 1837 | |
---|
| 1838 | set<int> listReceiverSize ; |
---|
| 1839 | |
---|
[1869] | 1840 | int receiverSize = client->serverSize; |
---|
[1784] | 1841 | |
---|
[1869] | 1842 | if (listReceiverSize.find(receiverSize)==listReceiverSize.end()) |
---|
| 1843 | { |
---|
| 1844 | listReceiverSize.insert(receiverSize) ; |
---|
| 1845 | if (connectedServerRank_.find(receiverSize) != connectedServerRank_.end()) |
---|
[1784] | 1846 | { |
---|
[1869] | 1847 | // delete corresponding map in case of recompute, probably because a grid could has been modifiedd |
---|
| 1848 | // by a transformation |
---|
| 1849 | connectedServerRank_.erase(receiverSize); |
---|
| 1850 | connectedDataSize_.erase(receiverSize); |
---|
| 1851 | globalIndexOnServer_.erase(receiverSize); |
---|
| 1852 | nbSenders_.erase(receiverSize); |
---|
| 1853 | } |
---|
[586] | 1854 | |
---|
[1869] | 1855 | if (client->isServerLeader()) |
---|
| 1856 | { |
---|
| 1857 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1858 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1009] | 1859 | { |
---|
[1869] | 1860 | int rank = *itRank; |
---|
| 1861 | int nb = 1; |
---|
| 1862 | connectedServerRank_[receiverSize].push_back(rank); |
---|
| 1863 | connectedDataSize_[receiverSize][rank] = nb; |
---|
| 1864 | nbSenders_[receiverSize][rank] = nb; |
---|
[1009] | 1865 | } |
---|
[1869] | 1866 | } |
---|
| 1867 | else |
---|
| 1868 | { |
---|
| 1869 | const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 1870 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1202] | 1871 | { |
---|
[1869] | 1872 | int rank = *itRank; |
---|
| 1873 | int nb = 1; |
---|
| 1874 | connectedServerRank_[receiverSize].push_back(rank); |
---|
| 1875 | connectedDataSize_[receiverSize][rank] = nb; |
---|
| 1876 | nbSenders_[receiverSize][rank] = nb; |
---|
[1263] | 1877 | } |
---|
[1202] | 1878 | } |
---|
[586] | 1879 | } |
---|
[1870] | 1880 | |
---|
[1869] | 1881 | computeConnectedClientsScalarGrid_done_.insert(client) ; |
---|
[586] | 1882 | } |
---|
[1622] | 1883 | CATCH_DUMP_ATTR |
---|
[586] | 1884 | |
---|
[1875] | 1885 | void CGrid::sendIndexScalarGrid(CContextClient* client, const string& gridId) |
---|
[1622] | 1886 | TRY |
---|
[586] | 1887 | { |
---|
[1875] | 1888 | if (sendIndexScalarGrid_done_.count(client)!=0) return ; |
---|
| 1889 | else sendIndexScalarGrid_done_.insert(client) ; |
---|
| 1890 | |
---|
[650] | 1891 | CContext* context = CContext::getCurrent(); |
---|
[1875] | 1892 | |
---|
| 1893 | string serverGridId = gridId.empty() ? serverGridId=this->getId() : serverGridId=gridId ; |
---|
[1236] | 1894 | |
---|
[1875] | 1895 | int receiverSize = client->serverSize; |
---|
[509] | 1896 | |
---|
[1875] | 1897 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 1898 | list<CMessage> listMsg; |
---|
| 1899 | list<CArray<size_t,1> > listOutIndex; |
---|
[650] | 1900 | |
---|
[1875] | 1901 | if (client->isServerLeader()) |
---|
| 1902 | { |
---|
| 1903 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1904 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[551] | 1905 | { |
---|
[1875] | 1906 | int rank = *itRank; |
---|
| 1907 | int nb = 1; |
---|
| 1908 | storeIndex_toSrv_[client].insert(std::make_pair(rank, CArray<int,1>(nb))); |
---|
| 1909 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
[650] | 1910 | |
---|
[1875] | 1911 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv_[client][rank]; |
---|
| 1912 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
[650] | 1913 | |
---|
[1875] | 1914 | for (int k = 0; k < nb; ++k) |
---|
| 1915 | { |
---|
| 1916 | outGlobalIndexOnServer(k) = 0; |
---|
| 1917 | outLocalIndexToServer(k) = 0; |
---|
| 1918 | } |
---|
[586] | 1919 | |
---|
[1875] | 1920 | if (context->getServiceType()==CServicesManager::CLIENT) // -> what about for coupling probably unusefull to be check |
---|
| 1921 | storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
[1236] | 1922 | |
---|
[1875] | 1923 | listMsg.push_back(CMessage()); |
---|
| 1924 | listMsg.back() << serverGridId << isCompressible_ << listOutIndex.back(); |
---|
[586] | 1925 | |
---|
[1875] | 1926 | event.push(rank, 1, listMsg.back()); |
---|
[650] | 1927 | } |
---|
[1875] | 1928 | client->sendEvent(event); |
---|
| 1929 | } |
---|
| 1930 | else |
---|
| 1931 | { |
---|
| 1932 | const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 1933 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1021] | 1934 | { |
---|
[1875] | 1935 | int rank = *itRank; |
---|
| 1936 | int nb = 1; |
---|
| 1937 | CArray<int, 1> outLocalIndexToServer(nb); |
---|
| 1938 | for (int k = 0; k < nb; ++k) |
---|
[1021] | 1939 | { |
---|
[1875] | 1940 | outLocalIndexToServer(k) = 0; |
---|
| 1941 | } |
---|
[1236] | 1942 | |
---|
[1875] | 1943 | if (context->getServiceType()==CServicesManager::CLIENT) |
---|
| 1944 | storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
[1021] | 1945 | } |
---|
[1875] | 1946 | client->sendEvent(event); |
---|
[584] | 1947 | } |
---|
[586] | 1948 | } |
---|
[1622] | 1949 | CATCH_DUMP_ATTR |
---|
[551] | 1950 | |
---|
[1875] | 1951 | void CGrid::sendIndex(CContextClient* client, const string& gridId) |
---|
[1622] | 1952 | TRY |
---|
[586] | 1953 | { |
---|
[1875] | 1954 | if (sendIndex_done_.count(client)!=0) return ; |
---|
| 1955 | else sendIndex_done_.insert(client) ; |
---|
[650] | 1956 | CContext* context = CContext::getCurrent(); |
---|
[1875] | 1957 | string serverGridId = gridId.empty() ? this->getId() : gridId ; |
---|
[1294] | 1958 | |
---|
[586] | 1959 | |
---|
| 1960 | |
---|
[1875] | 1961 | int receiverSize = client->serverSize; |
---|
| 1962 | |
---|
| 1963 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 1964 | int rank; |
---|
| 1965 | list<CMessage> listMsg; |
---|
| 1966 | list<CArray<size_t,1> > listOutIndex; |
---|
| 1967 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = getClientDistribution()->getGlobalLocalDataSendToServer(); |
---|
| 1968 | CDistributionClient::GlobalLocalDataMap::const_iterator itbIndex = globalLocalIndexSendToServer.begin(), itIndex, |
---|
| 1969 | iteIndex = globalLocalIndexSendToServer.end(); |
---|
| 1970 | itIndex = itbIndex; |
---|
| 1971 | |
---|
| 1972 | if (!doGridHaveDataDistributed(client)) |
---|
| 1973 | { |
---|
| 1974 | if (client->isServerLeader()) |
---|
[585] | 1975 | { |
---|
[1875] | 1976 | int indexSize = globalLocalIndexSendToServer.size(); |
---|
| 1977 | CArray<size_t,1> outGlobalIndexOnServer(indexSize); |
---|
| 1978 | CArray<int,1> outLocalIndexToServer(indexSize); |
---|
| 1979 | for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) |
---|
[831] | 1980 | { |
---|
[1875] | 1981 | outGlobalIndexOnServer(idx) = itIndex->first; |
---|
| 1982 | outLocalIndexToServer(idx) = itIndex->second; |
---|
| 1983 | } |
---|
[650] | 1984 | |
---|
[1875] | 1985 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1986 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1987 | { |
---|
| 1988 | storeIndex_toSrv_[client].insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1989 | if (context->getServiceType()==CServicesManager::CLIENT) // -> what about for coupling probably unusefull to be check |
---|
| 1990 | storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1991 | |
---|
| 1992 | listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
[585] | 1993 | |
---|
[1875] | 1994 | listMsg.push_back(CMessage()); |
---|
| 1995 | listMsg.back() << serverGridId << isCompressible_ << listOutIndex.back(); |
---|
[585] | 1996 | |
---|
[1875] | 1997 | event.push(*itRank, 1, listMsg.back()); |
---|
[585] | 1998 | } |
---|
[1875] | 1999 | client->sendEvent(event); |
---|
[585] | 2000 | } |
---|
| 2001 | else |
---|
[1009] | 2002 | { |
---|
[1875] | 2003 | int indexSize = globalLocalIndexSendToServer.size(); |
---|
| 2004 | CArray<int,1> outLocalIndexToServer(indexSize); |
---|
| 2005 | for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) |
---|
| 2006 | { |
---|
| 2007 | outLocalIndexToServer(idx) = itIndex->second; |
---|
| 2008 | } |
---|
[1129] | 2009 | |
---|
[1875] | 2010 | const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 2011 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 2012 | { |
---|
| 2013 | storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 2014 | } |
---|
| 2015 | client->sendEvent(event); |
---|
| 2016 | } |
---|
| 2017 | } |
---|
| 2018 | else |
---|
| 2019 | { |
---|
| 2020 | CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; |
---|
| 2021 | itGlobalMap = globalIndexOnServer_[receiverSize].begin(); |
---|
| 2022 | iteGlobalMap = globalIndexOnServer_[receiverSize].end(); |
---|
| 2023 | |
---|
| 2024 | std::map<int,std::vector<int> >localIndexTmp; |
---|
| 2025 | std::map<int,std::vector<size_t> > globalIndexTmp; |
---|
| 2026 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 2027 | { |
---|
| 2028 | int serverRank = itGlobalMap->first; |
---|
| 2029 | int indexSize = itGlobalMap->second.size(); |
---|
| 2030 | const std::vector<size_t>& indexVec = itGlobalMap->second; |
---|
| 2031 | for (int idx = 0; idx < indexSize; ++idx) |
---|
[586] | 2032 | { |
---|
[1875] | 2033 | itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); |
---|
| 2034 | if (iteIndex != itIndex) |
---|
[586] | 2035 | { |
---|
[1875] | 2036 | globalIndexTmp[serverRank].push_back(itIndex->first); |
---|
| 2037 | localIndexTmp[serverRank].push_back(itIndex->second); |
---|
[586] | 2038 | } |
---|
| 2039 | } |
---|
[1875] | 2040 | } |
---|
[586] | 2041 | |
---|
[1875] | 2042 | for (int ns = 0; ns < connectedServerRank_[receiverSize].size(); ++ns) |
---|
| 2043 | { |
---|
| 2044 | rank = connectedServerRank_[receiverSize][ns]; |
---|
| 2045 | int nb = 0; |
---|
| 2046 | if (globalIndexTmp.end() != globalIndexTmp.find(rank)) |
---|
| 2047 | nb = globalIndexTmp[rank].size(); |
---|
[509] | 2048 | |
---|
[1875] | 2049 | storeIndex_toSrv_[client].insert(make_pair(rank, CArray<int,1>(nb))); |
---|
| 2050 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
[650] | 2051 | |
---|
[1875] | 2052 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv_[client][rank]; |
---|
| 2053 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
[650] | 2054 | |
---|
[1875] | 2055 | for (int k = 0; k < nb; ++k) |
---|
| 2056 | { |
---|
| 2057 | outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); |
---|
| 2058 | outLocalIndexToServer(k) = localIndexTmp[rank].at(k); |
---|
| 2059 | } |
---|
[1009] | 2060 | |
---|
[1875] | 2061 | storeIndex_fromSrv_.insert(make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 2062 | listMsg.push_back(CMessage()); |
---|
| 2063 | listMsg.back() << serverGridId << isCompressible_ << listOutIndex.back(); |
---|
[1009] | 2064 | |
---|
[1875] | 2065 | event.push(rank, nbSenders_[receiverSize][rank], listMsg.back()); |
---|
[567] | 2066 | } |
---|
[1875] | 2067 | client->sendEvent(event); |
---|
[300] | 2068 | } |
---|
| 2069 | } |
---|
[1622] | 2070 | CATCH_DUMP_ATTR |
---|
[509] | 2071 | |
---|
[300] | 2072 | void CGrid::recvIndex(CEventServer& event) |
---|
[1622] | 2073 | TRY |
---|
[300] | 2074 | { |
---|
[598] | 2075 | string gridId; |
---|
| 2076 | vector<int> ranks; |
---|
| 2077 | vector<CBufferIn*> buffers; |
---|
| 2078 | |
---|
| 2079 | list<CEventServer::SSubEvent>::iterator it; |
---|
[650] | 2080 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 2081 | { |
---|
[598] | 2082 | ranks.push_back(it->rank); |
---|
| 2083 | CBufferIn* buffer = it->buffer; |
---|
| 2084 | *buffer >> gridId; |
---|
| 2085 | buffers.push_back(buffer); |
---|
[300] | 2086 | } |
---|
[1853] | 2087 | get(gridId)->recvIndex(ranks, buffers, event.getContextServer()); |
---|
[300] | 2088 | } |
---|
[1622] | 2089 | CATCH |
---|
[509] | 2090 | |
---|
[1853] | 2091 | void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers, CContextServer* server) |
---|
[1622] | 2092 | TRY |
---|
[967] | 2093 | { |
---|
[1871] | 2094 | CContextClient* client = server->getAssociatedClient(); |
---|
| 2095 | connectedServerRankRead_ = ranks; |
---|
| 2096 | for (int n = 0; n < ranks.size(); n++) |
---|
| 2097 | { |
---|
| 2098 | int rank = ranks[n]; |
---|
| 2099 | CBufferIn& buffer = *buffers[n]; |
---|
| 2100 | buffer >> isCompressible_; // probably to be removed later |
---|
| 2101 | CArray<size_t,1> outIndex; |
---|
| 2102 | buffer >> outIndex; |
---|
| 2103 | outGlobalIndexFromClient_.insert(std::make_pair(rank, outIndex)); |
---|
| 2104 | connectedDataSizeRead_[rank] = outIndex.numElements(); |
---|
| 2105 | } |
---|
[1881] | 2106 | // ym : displaced to avoid collective call at message reception |
---|
| 2107 | /* |
---|
[1871] | 2108 | nbReadSenders_[client] = CClientServerMappingDistributed::computeConnectedClients(client->serverSize, client->clientSize, |
---|
[1881] | 2109 | client->intraComm, ranks); |
---|
| 2110 | */ |
---|
[1871] | 2111 | } |
---|
| 2112 | CATCH_DUMP_ATTR |
---|
| 2113 | |
---|
[1881] | 2114 | |
---|
| 2115 | /*! |
---|
| 2116 | * Compute the number of connected client for a given contextClient and insert it in the nbReadSenders map. |
---|
| 2117 | * /param[in] client : the given contextClient |
---|
| 2118 | */ |
---|
| 2119 | void CGrid::computeNbReadSenders(CContextClient* client) |
---|
| 2120 | TRY |
---|
| 2121 | |
---|
| 2122 | { |
---|
| 2123 | nbReadSenders_[client] = CClientServerMappingDistributed::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRankRead_); |
---|
| 2124 | } |
---|
| 2125 | CATCH_DUMP_ATTR |
---|
| 2126 | |
---|
[1871] | 2127 | void CGrid::computeServerDistribution(void) |
---|
| 2128 | TRY |
---|
| 2129 | { |
---|
| 2130 | if (computeServerDistribution_done_) return ; |
---|
| 2131 | else computeServerDistribution_done_=true ; |
---|
| 2132 | |
---|
[967] | 2133 | CContext* context = CContext::getCurrent(); |
---|
[1871] | 2134 | |
---|
| 2135 | int idx = 0, numElement = axis_domain_order.numElements(); |
---|
| 2136 | int ssize = numElement; |
---|
| 2137 | std::vector<int> indexMap(numElement); |
---|
| 2138 | for (int i = 0; i < numElement; ++i) |
---|
| 2139 | { |
---|
| 2140 | indexMap[i] = idx; |
---|
| 2141 | if (2 == axis_domain_order(i)) |
---|
| 2142 | { |
---|
| 2143 | ++ssize; |
---|
| 2144 | idx += 2; |
---|
| 2145 | } |
---|
| 2146 | else |
---|
| 2147 | ++idx; |
---|
| 2148 | } |
---|
| 2149 | |
---|
| 2150 | for (int n = 0; n < connectedServerRankRead_.size(); n++) |
---|
| 2151 | { |
---|
| 2152 | int rank = connectedServerRankRead_[n]; |
---|
| 2153 | size_t dataSize = 0; |
---|
| 2154 | |
---|
| 2155 | if (0 == serverDistribution_) |
---|
| 2156 | { |
---|
| 2157 | int axisId = 0, domainId = 0, scalarId = 0, globalSize = 1; |
---|
| 2158 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 2159 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 2160 | std::vector<int> nBegin(ssize), nSize(ssize), nGlob(ssize), nBeginGlobal(ssize), nGlobElement(numElement); |
---|
| 2161 | std::vector<CArray<int,1> > globalIndex(numElement); |
---|
| 2162 | for (int i = 0; i < numElement; ++i) |
---|
| 2163 | { |
---|
| 2164 | nGlobElement[i] = globalSize; |
---|
| 2165 | if (2 == axis_domain_order(i)) //domain |
---|
| 2166 | { |
---|
| 2167 | nBegin[indexMap[i]] = domainList[domainId]->ibegin; |
---|
| 2168 | nSize[indexMap[i]] = domainList[domainId]->ni; |
---|
| 2169 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2170 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
| 2171 | |
---|
| 2172 | nBegin[indexMap[i] + 1] = domainList[domainId]->jbegin; |
---|
| 2173 | nSize[indexMap[i] + 1] = domainList[domainId]->nj; |
---|
| 2174 | nBeginGlobal[indexMap[i] + 1] = 0; |
---|
| 2175 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
| 2176 | |
---|
| 2177 | { |
---|
| 2178 | int count = 0; |
---|
| 2179 | globalIndex[i].resize(nSize[indexMap[i]]*nSize[indexMap[i]+1]); |
---|
| 2180 | for (int jdx = 0; jdx < nSize[indexMap[i]+1]; ++jdx) |
---|
| 2181 | for (int idx = 0; idx < nSize[indexMap[i]]; ++idx) |
---|
| 2182 | { |
---|
| 2183 | globalIndex[i](count) = (nBegin[indexMap[i]] + idx) + (nBegin[indexMap[i]+1] + jdx) * nGlob[indexMap[i]]; |
---|
| 2184 | ++count; |
---|
| 2185 | } |
---|
| 2186 | } |
---|
| 2187 | |
---|
| 2188 | ++domainId; |
---|
| 2189 | } |
---|
| 2190 | else if (1 == axis_domain_order(i)) // axis |
---|
| 2191 | { |
---|
| 2192 | nBegin[indexMap[i]] = axisList[axisId]->begin; |
---|
| 2193 | nSize[indexMap[i]] = axisList[axisId]->n; |
---|
| 2194 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2195 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
| 2196 | globalIndex[i].resize(nSize[indexMap[i]]); |
---|
| 2197 | for (int idx = 0; idx < nSize[indexMap[i]]; ++idx) |
---|
| 2198 | globalIndex[i](idx) = nBegin[indexMap[i]] + idx; |
---|
| 2199 | |
---|
| 2200 | ++axisId; |
---|
| 2201 | } |
---|
| 2202 | else // scalar |
---|
| 2203 | { |
---|
| 2204 | nBegin[indexMap[i]] = 0; |
---|
| 2205 | nSize[indexMap[i]] = 1; |
---|
| 2206 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2207 | nGlob[indexMap[i]] = 1; |
---|
| 2208 | globalIndex[i].resize(1); |
---|
| 2209 | globalIndex[i](0) = 0; |
---|
| 2210 | ++scalarId; |
---|
| 2211 | } |
---|
| 2212 | } |
---|
| 2213 | dataSize = 1; |
---|
| 2214 | |
---|
| 2215 | for (int i = 0; i < nSize.size(); ++i) |
---|
| 2216 | dataSize *= nSize[i]; |
---|
| 2217 | serverDistribution_ = new CDistributionServer(context->intraCommRank_, |
---|
| 2218 | globalIndex, axis_domain_order, |
---|
| 2219 | nBegin, nSize, nBeginGlobal, nGlob); |
---|
| 2220 | } |
---|
| 2221 | } |
---|
| 2222 | } |
---|
| 2223 | CATCH_DUMP_ATTR |
---|
| 2224 | |
---|
| 2225 | |
---|
| 2226 | |
---|
| 2227 | |
---|
| 2228 | |
---|
| 2229 | |
---|
| 2230 | /* old interface => transform into compute receivedIndex |
---|
| 2231 | void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers, CContextServer* server) |
---|
| 2232 | TRY |
---|
| 2233 | { |
---|
| 2234 | CContext* context = CContext::getCurrent(); |
---|
[1330] | 2235 | connectedServerRankRead_ = ranks; |
---|
[1099] | 2236 | |
---|
[1794] | 2237 | nbReadSenders_.clear(); |
---|
[1853] | 2238 | CContextClient* client = server->getAssociatedClient(); |
---|
[1784] | 2239 | |
---|
| 2240 | int idx = 0, numElement = axis_domain_order.numElements(); |
---|
| 2241 | int ssize = numElement; |
---|
| 2242 | std::vector<int> indexMap(numElement); |
---|
| 2243 | for (int i = 0; i < numElement; ++i) |
---|
[967] | 2244 | { |
---|
[1784] | 2245 | indexMap[i] = idx; |
---|
| 2246 | if (2 == axis_domain_order(i)) |
---|
[1129] | 2247 | { |
---|
[1784] | 2248 | ++ssize; |
---|
| 2249 | idx += 2; |
---|
[1129] | 2250 | } |
---|
[1784] | 2251 | else |
---|
| 2252 | ++idx; |
---|
| 2253 | } |
---|
[1129] | 2254 | |
---|
[1784] | 2255 | for (int n = 0; n < ranks.size(); n++) |
---|
| 2256 | { |
---|
| 2257 | int rank = ranks[n]; |
---|
| 2258 | CBufferIn& buffer = *buffers[n]; |
---|
[967] | 2259 | |
---|
[1870] | 2260 | buffer >> isCompressible_; |
---|
[1784] | 2261 | size_t dataSize = 0; |
---|
[1027] | 2262 | |
---|
[1784] | 2263 | if (0 == serverDistribution_) |
---|
[1129] | 2264 | { |
---|
| 2265 | int axisId = 0, domainId = 0, scalarId = 0, globalSize = 1; |
---|
| 2266 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 2267 | std::vector<CAxis*> axisList = getAxis(); |
---|
[1784] | 2268 | std::vector<int> nBegin(ssize), nSize(ssize), nGlob(ssize), nBeginGlobal(ssize), nGlobElement(numElement); |
---|
| 2269 | std::vector<CArray<int,1> > globalIndex(numElement); |
---|
[1129] | 2270 | for (int i = 0; i < numElement; ++i) |
---|
[1784] | 2271 | { |
---|
| 2272 | nGlobElement[i] = globalSize; |
---|
[1129] | 2273 | if (2 == axis_domain_order(i)) //domain |
---|
| 2274 | { |
---|
| 2275 | nBegin[indexMap[i]] = domainList[domainId]->ibegin; |
---|
| 2276 | nSize[indexMap[i]] = domainList[domainId]->ni; |
---|
[1784] | 2277 | nBeginGlobal[indexMap[i]] = 0; |
---|
[1129] | 2278 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
| 2279 | |
---|
| 2280 | nBegin[indexMap[i] + 1] = domainList[domainId]->jbegin; |
---|
| 2281 | nSize[indexMap[i] + 1] = domainList[domainId]->nj; |
---|
[1784] | 2282 | nBeginGlobal[indexMap[i] + 1] = 0; |
---|
[1129] | 2283 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
| 2284 | |
---|
[1784] | 2285 | { |
---|
| 2286 | int count = 0; |
---|
| 2287 | globalIndex[i].resize(nSize[indexMap[i]]*nSize[indexMap[i]+1]); |
---|
| 2288 | for (int jdx = 0; jdx < nSize[indexMap[i]+1]; ++jdx) |
---|
| 2289 | for (int idx = 0; idx < nSize[indexMap[i]]; ++idx) |
---|
| 2290 | { |
---|
| 2291 | globalIndex[i](count) = (nBegin[indexMap[i]] + idx) + (nBegin[indexMap[i]+1] + jdx) * nGlob[indexMap[i]]; |
---|
| 2292 | ++count; |
---|
| 2293 | } |
---|
| 2294 | } |
---|
| 2295 | |
---|
[1129] | 2296 | ++domainId; |
---|
| 2297 | } |
---|
| 2298 | else if (1 == axis_domain_order(i)) // axis |
---|
| 2299 | { |
---|
| 2300 | nBegin[indexMap[i]] = axisList[axisId]->begin; |
---|
| 2301 | nSize[indexMap[i]] = axisList[axisId]->n; |
---|
[1784] | 2302 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2303 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
| 2304 | globalIndex[i].resize(nSize[indexMap[i]]); |
---|
| 2305 | for (int idx = 0; idx < nSize[indexMap[i]]; ++idx) |
---|
| 2306 | globalIndex[i](idx) = nBegin[indexMap[i]] + idx; |
---|
| 2307 | |
---|
[1129] | 2308 | ++axisId; |
---|
| 2309 | } |
---|
| 2310 | else // scalar |
---|
[1784] | 2311 | { |
---|
| 2312 | nBegin[indexMap[i]] = 0; |
---|
| 2313 | nSize[indexMap[i]] = 1; |
---|
| 2314 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2315 | nGlob[indexMap[i]] = 1; |
---|
| 2316 | globalIndex[i].resize(1); |
---|
| 2317 | globalIndex[i](0) = 0; |
---|
| 2318 | ++scalarId; |
---|
[1129] | 2319 | } |
---|
| 2320 | } |
---|
[1784] | 2321 | dataSize = 1; |
---|
| 2322 | |
---|
| 2323 | for (int i = 0; i < nSize.size(); ++i) |
---|
| 2324 | dataSize *= nSize[i]; |
---|
[1847] | 2325 | serverDistribution_ = new CDistributionServer(context->intraCommRank_, |
---|
[1784] | 2326 | globalIndex, axis_domain_order, |
---|
| 2327 | nBegin, nSize, nBeginGlobal, nGlob); |
---|
| 2328 | } |
---|
| 2329 | |
---|
| 2330 | CArray<size_t,1> outIndex; |
---|
| 2331 | buffer >> outIndex; |
---|
[1794] | 2332 | outGlobalIndexFromClient_.insert(std::make_pair(rank, outIndex)); |
---|
[1784] | 2333 | connectedDataSizeRead_[rank] = outIndex.numElements(); |
---|
| 2334 | |
---|
| 2335 | if (doGridHaveDataDistributed(client)) |
---|
| 2336 | {} |
---|
| 2337 | else |
---|
| 2338 | { |
---|
| 2339 | // THE PROBLEM HERE IS THAT DATA CAN BE NONDISTRIBUTED ON CLIENT AND DISTRIBUTED ON SERVER |
---|
| 2340 | // BELOW IS THE TEMPORARY FIX only for a single type of element (domain, asix, scalar) |
---|
| 2341 | dataSize = serverDistribution_->getGridSize(); |
---|
| 2342 | } |
---|
| 2343 | writtenDataSize_ += dataSize; |
---|
| 2344 | } |
---|
| 2345 | |
---|
| 2346 | |
---|
| 2347 | // Compute mask of the current grid |
---|
| 2348 | { |
---|
| 2349 | int axisId = 0, domainId = 0, scalarId = 0, globalSize = 1; |
---|
| 2350 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 2351 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 2352 | int dimSize = 2 * domainList.size() + axisList.size(); |
---|
| 2353 | std::vector<int> nBegin(dimSize), nSize(dimSize), nGlob(dimSize), nBeginGlobal(dimSize); |
---|
| 2354 | for (int i = 0; i < numElement; ++i) |
---|
| 2355 | { |
---|
| 2356 | if (2 == axis_domain_order(i)) //domain |
---|
[1250] | 2357 | { |
---|
[1784] | 2358 | nBegin[indexMap[i]] = domainList[domainId]->ibegin; |
---|
| 2359 | nSize[indexMap[i]] = domainList[domainId]->ni; |
---|
| 2360 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2361 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
| 2362 | |
---|
| 2363 | nBegin[indexMap[i] + 1] = domainList[domainId]->jbegin; |
---|
| 2364 | nSize[indexMap[i] + 1] = domainList[domainId]->nj; |
---|
| 2365 | nBeginGlobal[indexMap[i] + 1] = 0; |
---|
| 2366 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
| 2367 | ++domainId; |
---|
[1250] | 2368 | } |
---|
[1784] | 2369 | else if (1 == axis_domain_order(i)) // axis |
---|
| 2370 | { |
---|
| 2371 | nBegin[indexMap[i]] = axisList[axisId]->begin; |
---|
| 2372 | nSize[indexMap[i]] = axisList[axisId]->n; |
---|
| 2373 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2374 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
| 2375 | ++axisId; |
---|
| 2376 | } |
---|
| 2377 | else // scalar |
---|
| 2378 | { |
---|
| 2379 | } |
---|
[1129] | 2380 | } |
---|
[1784] | 2381 | |
---|
| 2382 | if (nSize.empty()) // Scalar grid |
---|
| 2383 | { |
---|
| 2384 | nBegin.push_back(0); |
---|
| 2385 | nSize.push_back(1); |
---|
| 2386 | nBeginGlobal.push_back(0); |
---|
| 2387 | nGlob.push_back(1); |
---|
| 2388 | } |
---|
| 2389 | } |
---|
[1129] | 2390 | |
---|
[1784] | 2391 | if (isScalarGrid()) return; |
---|
[1027] | 2392 | |
---|
[1853] | 2393 | nbReadSenders_[client] = CClientServerMappingDistributed::computeConnectedClients(client->serverSize, client->clientSize, |
---|
| 2394 | client->intraComm, ranks); |
---|
[1784] | 2395 | |
---|
[967] | 2396 | } |
---|
[1622] | 2397 | CATCH_DUMP_ATTR |
---|
[1871] | 2398 | */ |
---|
[967] | 2399 | |
---|
[1871] | 2400 | |
---|
[1158] | 2401 | /* |
---|
| 2402 | Compute on the fly the global dimension of a grid with its elements |
---|
| 2403 | \param[in/out] globalDim global dimension of grid |
---|
| 2404 | \param[in] domains list of its domains |
---|
| 2405 | \param[in] axiss list of its axis |
---|
| 2406 | \param[in] scalars list of its scalars |
---|
| 2407 | \param[in] axisDomainOrder the order of element in a grid (e.g: scalar then axis) |
---|
| 2408 | \return The dimension of which we do distribution (often for server) |
---|
| 2409 | */ |
---|
| 2410 | int CGrid::computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 2411 | const std::vector<CDomain*> domains, |
---|
| 2412 | const std::vector<CAxis*> axis, |
---|
| 2413 | const std::vector<CScalar*> scalars, |
---|
| 2414 | const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 2415 | TRY |
---|
| 2416 | { |
---|
[1311] | 2417 | // globalDim.resize(domains.size()*2+axis.size()+scalars.size()); |
---|
| 2418 | globalDim.resize(domains.size()*2+axis.size()); |
---|
[1158] | 2419 | int positionDimensionDistributed = 1; |
---|
[887] | 2420 | int idx = 0, idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[567] | 2421 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 2422 | { |
---|
[887] | 2423 | if (2 == axisDomainOrder(i)) |
---|
[567] | 2424 | { |
---|
[657] | 2425 | if (!(domains[idxDomain]->type.isEmpty()) && (domains[idxDomain]->type==CDomain::type_attr::unstructured)) |
---|
| 2426 | { |
---|
[1158] | 2427 | positionDimensionDistributed = idx; |
---|
[657] | 2428 | } |
---|
| 2429 | else |
---|
| 2430 | { |
---|
[1158] | 2431 | positionDimensionDistributed = idx +1; |
---|
[657] | 2432 | } |
---|
| 2433 | |
---|
[1158] | 2434 | globalDim[idx] = domains[idxDomain]->ni_glo.getValue(); |
---|
| 2435 | globalDim[idx+1] = domains[idxDomain]->nj_glo.getValue(); |
---|
[657] | 2436 | |
---|
[567] | 2437 | ++idxDomain; |
---|
| 2438 | idx += 2; |
---|
| 2439 | } |
---|
[887] | 2440 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 2441 | { |
---|
[1158] | 2442 | globalDim[idx] = axis[idxAxis]->n_glo.getValue(); |
---|
[567] | 2443 | ++idxAxis; |
---|
| 2444 | ++idx; |
---|
| 2445 | } |
---|
[887] | 2446 | else |
---|
| 2447 | { |
---|
[1311] | 2448 | // globalDim[idx] = 1; |
---|
[887] | 2449 | ++idxScalar; |
---|
[1311] | 2450 | // ++idx; |
---|
[887] | 2451 | } |
---|
[567] | 2452 | } |
---|
[1158] | 2453 | |
---|
| 2454 | return positionDimensionDistributed; |
---|
[567] | 2455 | } |
---|
[1622] | 2456 | CATCH_DUMP_ATTR |
---|
[567] | 2457 | |
---|
[1158] | 2458 | // Retrieve the global dimension of grid |
---|
[567] | 2459 | std::vector<int> CGrid::getGlobalDimension() |
---|
[1622] | 2460 | TRY |
---|
[567] | 2461 | { |
---|
[1158] | 2462 | std::vector<int> globalDim; |
---|
| 2463 | computeGridGlobalDimension(globalDim, getDomains(), getAxis(), getScalars(), axis_domain_order); |
---|
| 2464 | |
---|
| 2465 | return globalDim; |
---|
[567] | 2466 | } |
---|
[1622] | 2467 | CATCH_DUMP_ATTR |
---|
[567] | 2468 | |
---|
[1158] | 2469 | // Retrieve dimension on which we do distribution (Very often, it should be 2nd dimension) |
---|
| 2470 | int CGrid::getDistributedDimension() |
---|
[1622] | 2471 | TRY |
---|
[1158] | 2472 | { |
---|
| 2473 | std::vector<int> globalDim; |
---|
| 2474 | return computeGridGlobalDimension(globalDim, getDomains(), getAxis(), getScalars(), axis_domain_order); |
---|
| 2475 | } |
---|
[1622] | 2476 | CATCH_DUMP_ATTR |
---|
[1158] | 2477 | |
---|
[600] | 2478 | bool CGrid::isScalarGrid() const |
---|
[1622] | 2479 | TRY |
---|
[600] | 2480 | { |
---|
| 2481 | return (axisList_.empty() && domList_.empty()); |
---|
| 2482 | } |
---|
[1622] | 2483 | CATCH |
---|
[600] | 2484 | |
---|
[567] | 2485 | /*! |
---|
| 2486 | Verify whether one server need to write data |
---|
| 2487 | There are some cases on which one server has nodata to write. For example, when we |
---|
[650] | 2488 | just only want to zoom on a domain. |
---|
[567] | 2489 | */ |
---|
| 2490 | bool CGrid::doGridHaveDataToWrite() |
---|
[1622] | 2491 | TRY |
---|
[567] | 2492 | { |
---|
[1930] | 2493 | return (0 != getGridLocalElements()->getView(CElementView::FULL)->getSize()); |
---|
[567] | 2494 | } |
---|
[1622] | 2495 | CATCH_DUMP_ATTR |
---|
[567] | 2496 | |
---|
| 2497 | /*! |
---|
| 2498 | Return size of data which is written on each server |
---|
| 2499 | Whatever dimension of a grid, data which are written on server must be presented as |
---|
[650] | 2500 | an one dimension array. |
---|
| 2501 | \return size of data written on server |
---|
[567] | 2502 | */ |
---|
[1871] | 2503 | size_t CGrid::getWrittenDataSize() |
---|
[1622] | 2504 | TRY |
---|
[567] | 2505 | { |
---|
[1930] | 2506 | return getGridLocalElements()->getView(CElementView::FULL)->getSize() ; |
---|
[567] | 2507 | } |
---|
[1622] | 2508 | CATCH |
---|
[567] | 2509 | |
---|
[676] | 2510 | /*! |
---|
| 2511 | Returns the number of indexes written by each server. |
---|
| 2512 | \return the number of indexes written by each server |
---|
| 2513 | */ |
---|
| 2514 | int CGrid::getNumberWrittenIndexes() const |
---|
[1622] | 2515 | TRY |
---|
[676] | 2516 | { |
---|
| 2517 | return numberWrittenIndexes_; |
---|
| 2518 | } |
---|
[1622] | 2519 | CATCH |
---|
[676] | 2520 | |
---|
| 2521 | /*! |
---|
| 2522 | Returns the total number of indexes written by the servers. |
---|
| 2523 | \return the total number of indexes written by the servers |
---|
| 2524 | */ |
---|
| 2525 | int CGrid::getTotalNumberWrittenIndexes() const |
---|
[1622] | 2526 | TRY |
---|
[676] | 2527 | { |
---|
| 2528 | return totalNumberWrittenIndexes_; |
---|
| 2529 | } |
---|
[1622] | 2530 | CATCH |
---|
[676] | 2531 | |
---|
| 2532 | /*! |
---|
| 2533 | Returns the offset of indexes written by each server. |
---|
| 2534 | \return the offset of indexes written by each server |
---|
| 2535 | */ |
---|
| 2536 | int CGrid::getOffsetWrittenIndexes() const |
---|
[1622] | 2537 | TRY |
---|
[676] | 2538 | { |
---|
| 2539 | return offsetWrittenIndexes_; |
---|
| 2540 | } |
---|
[1622] | 2541 | CATCH |
---|
[676] | 2542 | |
---|
[1871] | 2543 | |
---|
[1870] | 2544 | CDistributionClient* CGrid::getClientDistribution() |
---|
[1622] | 2545 | TRY |
---|
[620] | 2546 | { |
---|
[1869] | 2547 | if (!computeClientDistribution_done_) computeClientDistribution() ; |
---|
[620] | 2548 | return clientDistribution_; |
---|
| 2549 | } |
---|
[1622] | 2550 | CATCH_DUMP_ATTR |
---|
[620] | 2551 | |
---|
[1235] | 2552 | bool CGrid::doGridHaveDataDistributed(CContextClient* client) |
---|
[1622] | 2553 | TRY |
---|
[567] | 2554 | { |
---|
[1794] | 2555 | // This function is now useless because it will return false only if server and client size are equal to 1 |
---|
| 2556 | // to be seriously check in future |
---|
| 2557 | |
---|
[600] | 2558 | if (isScalarGrid()) return false; |
---|
[1235] | 2559 | else if (0 != client) |
---|
| 2560 | { |
---|
[1870] | 2561 | return (isDataDistributed() || (1 != client->clientSize) || (1 != client->serverSize)); |
---|
[1235] | 2562 | } |
---|
[586] | 2563 | else |
---|
[1870] | 2564 | return isDataDistributed(); |
---|
[567] | 2565 | } |
---|
[1622] | 2566 | CATCH_DUMP_ATTR |
---|
[567] | 2567 | |
---|
[540] | 2568 | /*! |
---|
| 2569 | \brief Dispatch event received from client |
---|
| 2570 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 2571 | its event type. A new event type should be added in the switch list to make sure |
---|
| 2572 | it processed on server side. |
---|
| 2573 | \param [in] event: Received message |
---|
| 2574 | */ |
---|
[300] | 2575 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
[1622] | 2576 | TRY |
---|
[300] | 2577 | { |
---|
[509] | 2578 | |
---|
[650] | 2579 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 2580 | else |
---|
| 2581 | { |
---|
| 2582 | switch(event.type) |
---|
| 2583 | { |
---|
| 2584 | case EVENT_ID_INDEX : |
---|
[650] | 2585 | recvIndex(event); |
---|
| 2586 | return true; |
---|
| 2587 | break; |
---|
[509] | 2588 | |
---|
[540] | 2589 | case EVENT_ID_ADD_DOMAIN : |
---|
[650] | 2590 | recvAddDomain(event); |
---|
| 2591 | return true; |
---|
| 2592 | break; |
---|
[540] | 2593 | |
---|
| 2594 | case EVENT_ID_ADD_AXIS : |
---|
[650] | 2595 | recvAddAxis(event); |
---|
| 2596 | return true; |
---|
| 2597 | break; |
---|
[887] | 2598 | |
---|
| 2599 | case EVENT_ID_ADD_SCALAR : |
---|
| 2600 | recvAddScalar(event); |
---|
| 2601 | return true; |
---|
| 2602 | break; |
---|
[1943] | 2603 | |
---|
| 2604 | case EVENT_ID_SEND_MASK : |
---|
| 2605 | recvMask(event); |
---|
| 2606 | return true; |
---|
| 2607 | break; |
---|
[300] | 2608 | default : |
---|
[1943] | 2609 | ERROR("bool CGrid::dispatchEvent(CEventServer& event)", |
---|
[650] | 2610 | << "Unknown Event"); |
---|
| 2611 | return false; |
---|
[300] | 2612 | } |
---|
| 2613 | } |
---|
| 2614 | } |
---|
[1622] | 2615 | CATCH |
---|
[300] | 2616 | |
---|
[1930] | 2617 | |
---|
[219] | 2618 | |
---|
[1870] | 2619 | void CGrid::sendGridToFileServer(CContextClient* client) |
---|
| 2620 | { |
---|
| 2621 | if (sendGridToFileServer_done_.count(client)!=0) return ; |
---|
| 2622 | else sendGridToFileServer_done_.insert(client) ; |
---|
| 2623 | |
---|
| 2624 | StdString gridDefRoot("grid_definition"); |
---|
| 2625 | CGridGroup* gridPtr = CGridGroup::get(gridDefRoot); |
---|
| 2626 | gridPtr->sendCreateChild(this->getId(),client); |
---|
| 2627 | this->sendAllAttributesToServer(client); |
---|
[1930] | 2628 | //if (isScalarGrid()) sendIndexScalarGrid(client); |
---|
| 2629 | //else sendIndex(client); |
---|
| 2630 | //this->sendAllDomains(client); |
---|
| 2631 | //this->sendAllAxis(client); |
---|
| 2632 | //this->sendAllScalars(client); |
---|
| 2633 | |
---|
| 2634 | distributeGridToFileServer(client) ; |
---|
[1870] | 2635 | } |
---|
| 2636 | |
---|
[1930] | 2637 | |
---|
| 2638 | void CGrid::distributeGridToFileServer(CContextClient* client) |
---|
| 2639 | { |
---|
| 2640 | CContext* context = CContext::getCurrent(); |
---|
| 2641 | // simple Distribution for now |
---|
| 2642 | // distribute over the fisrt element except if it is a scalar |
---|
| 2643 | auto& elements = getElements() ; |
---|
| 2644 | int posDistributed = 0 ; |
---|
| 2645 | for(auto& element : elements) |
---|
| 2646 | { |
---|
| 2647 | if (element.type==TYPE_DOMAIN) break ; |
---|
| 2648 | else if (element.type==TYPE_AXIS) break ; |
---|
| 2649 | else if (element.type==TYPE_SCALAR) posDistributed++ ; |
---|
| 2650 | } |
---|
| 2651 | |
---|
| 2652 | vector<CLocalView*> localViews ; |
---|
| 2653 | vector<CDistributedView*> remoteViews ; |
---|
| 2654 | |
---|
| 2655 | for(int i=0 ; i<elements.size() ; i++) |
---|
| 2656 | { |
---|
| 2657 | if (elements[i].type==TYPE_DOMAIN) |
---|
| 2658 | { |
---|
| 2659 | CDomain* domain = (CDomain*) elements[i].ptr ; |
---|
| 2660 | domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; |
---|
| 2661 | remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; |
---|
| 2662 | localViews.push_back(domain->getLocalView(CElementView::FULL)) ; |
---|
| 2663 | } |
---|
| 2664 | else if (elements[i].type==TYPE_AXIS) |
---|
| 2665 | { |
---|
| 2666 | CAxis* axis = (CAxis*) elements[i].ptr ; |
---|
| 2667 | axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; |
---|
| 2668 | remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; |
---|
| 2669 | localViews.push_back(axis->getLocalView(CElementView::FULL)) ; |
---|
| 2670 | } |
---|
| 2671 | else if (elements[i].type==TYPE_SCALAR) |
---|
| 2672 | { |
---|
| 2673 | CScalar* scalar = (CScalar*) elements[i].ptr ; |
---|
| 2674 | scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; |
---|
| 2675 | remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; |
---|
| 2676 | localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; |
---|
| 2677 | } |
---|
| 2678 | } |
---|
[1938] | 2679 | CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm(), client->getRemoteSize()) ; |
---|
[1930] | 2680 | gridRemoteConnector.computeConnector() ; |
---|
| 2681 | |
---|
[1943] | 2682 | vector<CScattererConnector*> scattererConnectors ; |
---|
[1930] | 2683 | for(int i=0 ; i<elements.size() ; i++) |
---|
| 2684 | { |
---|
| 2685 | if (elements[i].type==TYPE_DOMAIN) |
---|
| 2686 | { |
---|
| 2687 | CDomain* domain = (CDomain*) elements[i].ptr ; |
---|
| 2688 | sendAddDomain(domain->getId(),client) ; |
---|
| 2689 | domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; |
---|
[1943] | 2690 | scattererConnectors.push_back(domain->getClientToServerConnector(client)) ; |
---|
[1930] | 2691 | } |
---|
| 2692 | else if (elements[i].type==TYPE_AXIS) |
---|
| 2693 | { |
---|
| 2694 | CAxis* axis = (CAxis*) elements[i].ptr ; |
---|
| 2695 | sendAddAxis(axis->getId(),client) ; |
---|
| 2696 | axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; |
---|
[1943] | 2697 | scattererConnectors.push_back(axis->getClientToServerConnector(client)) ; |
---|
[1930] | 2698 | } |
---|
| 2699 | else if (elements[i].type==TYPE_SCALAR) |
---|
| 2700 | { |
---|
| 2701 | CScalar* scalar = (CScalar*) elements[i].ptr ; |
---|
| 2702 | sendAddScalar(scalar->getId(),client) ; |
---|
| 2703 | scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; |
---|
[1943] | 2704 | scattererConnectors.push_back(scalar->getClientToServerConnector(client)) ; |
---|
[1930] | 2705 | } |
---|
| 2706 | } |
---|
[1943] | 2707 | |
---|
| 2708 | CGridScattererConnector gridScattererConnector(scattererConnectors) ; |
---|
| 2709 | CGridLocalConnector* workflowToFull = getGridLocalElements()->getConnector(CElementView::WORKFLOW, CElementView::FULL) ; |
---|
| 2710 | CArray<bool,1> maskIn(workflowToFull->getSrcSize()) ; |
---|
| 2711 | CArray<bool,1> maskOut(workflowToFull->getDstSize()) ; |
---|
| 2712 | maskIn = true ; |
---|
| 2713 | workflowToFull->transfer(maskIn,maskOut,false) ; |
---|
| 2714 | |
---|
| 2715 | CEventClient event(getType(), EVENT_ID_SEND_MASK); |
---|
| 2716 | CMessage message ; |
---|
| 2717 | message<<getId() ; |
---|
| 2718 | gridScattererConnector.transfer(maskOut, client, event, message) ; |
---|
| 2719 | |
---|
| 2720 | |
---|
| 2721 | vector<CScattererConnector*> clientToServerConnectors ; |
---|
| 2722 | vector<CGathererConnector*> clientFromServerConnectors ; |
---|
| 2723 | for(auto& element : elements) |
---|
| 2724 | { |
---|
| 2725 | if (element.type==TYPE_DOMAIN) |
---|
| 2726 | { |
---|
| 2727 | clientToServerConnectors.push_back(element.domain->getClientToServerConnector(client)) ; |
---|
| 2728 | clientFromServerConnectors.push_back(element.domain->getClientFromServerConnector(client)) ; |
---|
| 2729 | } |
---|
| 2730 | else if (element.type==TYPE_AXIS) |
---|
| 2731 | { |
---|
| 2732 | clientToServerConnectors.push_back(element.axis->getClientToServerConnector(client)) ; |
---|
| 2733 | clientFromServerConnectors.push_back(element.axis->getClientFromServerConnector(client)) ; |
---|
| 2734 | |
---|
| 2735 | } |
---|
| 2736 | else if (element.type==TYPE_SCALAR) |
---|
| 2737 | { |
---|
| 2738 | clientToServerConnectors.push_back(element.scalar->getClientToServerConnector(client)) ; |
---|
| 2739 | clientFromServerConnectors.push_back(element.scalar->getClientFromServerConnector(client)) ; |
---|
| 2740 | } |
---|
| 2741 | } |
---|
[1930] | 2742 | |
---|
| 2743 | // compute the grid clientToServerConnector to send flux from client to servers |
---|
| 2744 | clientToServerConnector_[client] = new CGridScattererConnector(clientToServerConnectors) ; |
---|
[1934] | 2745 | clientFromServerConnector_[client] = new CGridGathererConnector(clientFromServerConnectors) ; |
---|
[1930] | 2746 | |
---|
[1934] | 2747 | |
---|
[1930] | 2748 | } |
---|
| 2749 | |
---|
[1943] | 2750 | void CGrid::recvMask(CEventServer& event) |
---|
| 2751 | { |
---|
| 2752 | string gridId; |
---|
| 2753 | for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> gridId ; |
---|
| 2754 | get(gridId)->receiveMask(event); |
---|
| 2755 | } |
---|
| 2756 | |
---|
| 2757 | void CGrid::receiveMask(CEventServer& event) |
---|
| 2758 | { |
---|
| 2759 | vector<CGathererConnector*> gathererConnectors ; |
---|
| 2760 | vector<CLocalView*> fullViews ; |
---|
[1930] | 2761 | |
---|
[1943] | 2762 | for(auto& element : getElements()) |
---|
| 2763 | { |
---|
| 2764 | if (element.type==TYPE_DOMAIN) |
---|
| 2765 | { |
---|
| 2766 | gathererConnectors.push_back(element.domain->getGathererConnector()); |
---|
| 2767 | fullViews.push_back(element.domain->getLocalElement()->getView(CElementView::FULL)); |
---|
| 2768 | |
---|
| 2769 | } |
---|
| 2770 | else if (element.type==TYPE_AXIS) |
---|
| 2771 | { |
---|
| 2772 | gathererConnectors.push_back(element.axis->getGathererConnector()); |
---|
| 2773 | fullViews.push_back(element.axis->getLocalElement()->getView(CElementView::FULL)); |
---|
| 2774 | } |
---|
| 2775 | else if (element.type==TYPE_SCALAR) |
---|
| 2776 | { |
---|
| 2777 | gathererConnectors.push_back(element.scalar->getGathererConnector()); |
---|
| 2778 | fullViews.push_back(element.scalar->getLocalElement()->getView(CElementView::FULL)); |
---|
| 2779 | } |
---|
| 2780 | } |
---|
| 2781 | CGridGathererConnector gridGathererConnector(gathererConnectors) ; |
---|
| 2782 | CGridMaskConnector gridMaskConnector(fullViews) ; |
---|
| 2783 | |
---|
| 2784 | CArray<bool,1> maskOut ; |
---|
| 2785 | gridGathererConnector.transfer(event,maskOut,false) ; |
---|
| 2786 | gridMaskConnector.computeConnector(maskOut) ; |
---|
| 2787 | |
---|
| 2788 | CContextClient* client = event.getContextServer()->getAssociatedClient() ; |
---|
| 2789 | int i=0 ; |
---|
| 2790 | for(auto& element : getElements()) |
---|
| 2791 | { |
---|
| 2792 | if (element.type==TYPE_DOMAIN) element.domain->setServerMask(gridMaskConnector.getElementMask(i),client); |
---|
| 2793 | else if (element.type==TYPE_AXIS) element.axis->setServerMask(gridMaskConnector.getElementMask(i),client); |
---|
| 2794 | else if (element.type==TYPE_SCALAR) element.scalar->setServerMask(gridMaskConnector.getElementMask(i),client); |
---|
| 2795 | i++ ; |
---|
| 2796 | } |
---|
| 2797 | } |
---|
| 2798 | |
---|
| 2799 | |
---|
[1875] | 2800 | void CGrid::sendGridToCouplerOut(CContextClient* client, const string& fieldId) |
---|
| 2801 | { |
---|
| 2802 | if (sendGridToCouplerOut_done_.count(client)!=0) return ; |
---|
| 2803 | else sendGridToCouplerOut_done_.insert(client) ; |
---|
[1930] | 2804 | |
---|
| 2805 | CContext* context = CContext::getCurrent(); |
---|
| 2806 | // simple Distribution for now |
---|
| 2807 | // distribute over the fisrt element except if it is a scalar |
---|
| 2808 | auto& elements = getElements() ; |
---|
| 2809 | int posDistributed = 0 ; |
---|
| 2810 | for(auto& element : elements) |
---|
| 2811 | { |
---|
| 2812 | if (element.type==TYPE_DOMAIN) break ; |
---|
| 2813 | else if (element.type==TYPE_AXIS) break ; |
---|
| 2814 | else if (element.type==TYPE_SCALAR) posDistributed++ ; |
---|
| 2815 | } |
---|
[1875] | 2816 | |
---|
[1930] | 2817 | vector<CLocalView*> localViews ; |
---|
| 2818 | vector<CDistributedView*> remoteViews ; |
---|
[1875] | 2819 | |
---|
[1930] | 2820 | for(int i=0 ; i<elements.size() ; i++) |
---|
| 2821 | { |
---|
| 2822 | if (elements[i].type==TYPE_DOMAIN) |
---|
| 2823 | { |
---|
| 2824 | CDomain* domain = (CDomain*) elements[i].ptr ; |
---|
| 2825 | domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; |
---|
| 2826 | remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; |
---|
| 2827 | localViews.push_back(domain->getLocalView(CElementView::FULL)) ; |
---|
| 2828 | } |
---|
| 2829 | else if (elements[i].type==TYPE_AXIS) |
---|
| 2830 | { |
---|
| 2831 | CAxis* axis = (CAxis*) elements[i].ptr ; |
---|
| 2832 | axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; |
---|
| 2833 | remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; |
---|
| 2834 | localViews.push_back(axis->getLocalView(CElementView::FULL)) ; |
---|
| 2835 | } |
---|
| 2836 | else if (elements[i].type==TYPE_SCALAR) |
---|
| 2837 | { |
---|
| 2838 | CScalar* scalar = (CScalar*) elements[i].ptr ; |
---|
| 2839 | scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; |
---|
| 2840 | remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; |
---|
| 2841 | localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; |
---|
| 2842 | } |
---|
| 2843 | } |
---|
[1938] | 2844 | CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm(), client->getRemoteSize()) ; |
---|
[1930] | 2845 | gridRemoteConnector.computeConnector() ; |
---|
| 2846 | |
---|
| 2847 | vector<CScattererConnector*> clientToClientConnectors ; |
---|
| 2848 | for(int i=0 ; i<elements.size() ; i++) |
---|
| 2849 | { |
---|
| 2850 | if (elements[i].type==TYPE_DOMAIN) |
---|
| 2851 | { |
---|
| 2852 | CDomain* domain = (CDomain*) elements[i].ptr ; |
---|
| 2853 | sendAddDomain(domain->getId(),client) ; |
---|
| 2854 | domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; |
---|
| 2855 | clientToClientConnectors.push_back(domain->getClientToServerConnector(client)) ; |
---|
| 2856 | } |
---|
| 2857 | else if (elements[i].type==TYPE_AXIS) |
---|
| 2858 | { |
---|
| 2859 | CAxis* axis = (CAxis*) elements[i].ptr ; |
---|
| 2860 | sendAddAxis(axis->getId(),client) ; |
---|
| 2861 | axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; |
---|
| 2862 | clientToClientConnectors.push_back(axis->getClientToServerConnector(client)) ; |
---|
| 2863 | } |
---|
| 2864 | else if (elements[i].type==TYPE_SCALAR) |
---|
| 2865 | { |
---|
| 2866 | CScalar* scalar = (CScalar*) elements[i].ptr ; |
---|
| 2867 | sendAddScalar(scalar->getId(),client) ; |
---|
| 2868 | scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; |
---|
| 2869 | clientToClientConnectors.push_back(scalar->getClientToServerConnector(client)) ; |
---|
| 2870 | } |
---|
| 2871 | } |
---|
| 2872 | |
---|
| 2873 | // compute the grid clientToServerConnector to send flux from client to servers |
---|
| 2874 | clientToClientConnector_[client] = new CGridScattererConnector(clientToClientConnectors) ; |
---|
[1875] | 2875 | } |
---|
| 2876 | |
---|
| 2877 | void CGrid::makeAliasForCoupling(const string& fieldId) |
---|
| 2878 | { |
---|
| 2879 | string gridId="_grid_of_"+fieldId ; |
---|
| 2880 | createAlias(gridId) ; |
---|
| 2881 | |
---|
| 2882 | const auto& domVect = getDomains() ; |
---|
| 2883 | for (int pos=0; pos<domVect.size();pos++) domVect[pos]->makeAliasForCoupling(fieldId, pos); |
---|
| 2884 | |
---|
| 2885 | const auto& axisVect=getAxis() ; |
---|
| 2886 | for (int pos=0; pos<axisVect.size();pos++) axisVect[pos]->makeAliasForCoupling(fieldId, pos); |
---|
| 2887 | |
---|
| 2888 | const auto& scalVect=getScalars() ; |
---|
| 2889 | for (int pos=0; pos<scalVect.size();pos++) scalVect[pos]->makeAliasForCoupling(fieldId, pos); |
---|
| 2890 | } |
---|
| 2891 | |
---|
[540] | 2892 | /*! |
---|
| 2893 | \brief Send a message to create a domain on server side |
---|
| 2894 | \param[in] id String identity of domain that will be created on server |
---|
| 2895 | */ |
---|
[1784] | 2896 | void CGrid::sendAddDomain(const string& id, CContextClient* contextClient) |
---|
[1622] | 2897 | TRY |
---|
| 2898 | { |
---|
[1784] | 2899 | sendAddItem(id, (int)EVENT_ID_ADD_DOMAIN, contextClient); |
---|
[540] | 2900 | } |
---|
[1622] | 2901 | CATCH_DUMP_ATTR |
---|
[540] | 2902 | |
---|
| 2903 | /*! |
---|
| 2904 | \brief Send a message to create an axis on server side |
---|
| 2905 | \param[in] id String identity of axis that will be created on server |
---|
| 2906 | */ |
---|
[1784] | 2907 | void CGrid::sendAddAxis(const string& id, CContextClient* contextClient) |
---|
[1622] | 2908 | TRY |
---|
[540] | 2909 | { |
---|
[1784] | 2910 | sendAddItem(id, (int)EVENT_ID_ADD_AXIS, contextClient); |
---|
[540] | 2911 | } |
---|
[1622] | 2912 | CATCH_DUMP_ATTR |
---|
[540] | 2913 | |
---|
| 2914 | /*! |
---|
[887] | 2915 | \brief Send a message to create a scalar on server side |
---|
| 2916 | \param[in] id String identity of scalar that will be created on server |
---|
| 2917 | */ |
---|
[1784] | 2918 | void CGrid::sendAddScalar(const string& id, CContextClient* contextClient) |
---|
[1622] | 2919 | TRY |
---|
[887] | 2920 | { |
---|
[1784] | 2921 | sendAddItem(id, (int)EVENT_ID_ADD_SCALAR, contextClient); |
---|
[887] | 2922 | } |
---|
[1622] | 2923 | CATCH_DUMP_ATTR |
---|
[887] | 2924 | |
---|
| 2925 | /*! |
---|
[540] | 2926 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 2927 | \param[in] event Received event |
---|
| 2928 | */ |
---|
| 2929 | void CGrid::recvAddDomain(CEventServer& event) |
---|
[1622] | 2930 | TRY |
---|
[540] | 2931 | { |
---|
| 2932 | |
---|
[650] | 2933 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 2934 | string id; |
---|
[650] | 2935 | *buffer >> id; |
---|
| 2936 | get(id)->recvAddDomain(*buffer); |
---|
[540] | 2937 | } |
---|
[1622] | 2938 | CATCH |
---|
[540] | 2939 | |
---|
| 2940 | /*! |
---|
| 2941 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 2942 | \param[in] buffer Buffer containing message |
---|
| 2943 | */ |
---|
| 2944 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
[1622] | 2945 | TRY |
---|
[540] | 2946 | { |
---|
[650] | 2947 | string id; |
---|
| 2948 | buffer >> id; |
---|
| 2949 | addDomain(id); |
---|
[540] | 2950 | } |
---|
[1622] | 2951 | CATCH_DUMP_ATTR |
---|
[540] | 2952 | |
---|
| 2953 | /*! |
---|
| 2954 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 2955 | \param[in] event Received event |
---|
| 2956 | */ |
---|
| 2957 | void CGrid::recvAddAxis(CEventServer& event) |
---|
[1622] | 2958 | TRY |
---|
[540] | 2959 | { |
---|
| 2960 | |
---|
[650] | 2961 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 2962 | string id; |
---|
[650] | 2963 | *buffer >> id; |
---|
| 2964 | get(id)->recvAddAxis(*buffer); |
---|
[540] | 2965 | } |
---|
[1622] | 2966 | CATCH |
---|
[540] | 2967 | |
---|
| 2968 | /*! |
---|
| 2969 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 2970 | \param[in] buffer Buffer containing message |
---|
| 2971 | */ |
---|
| 2972 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
[1622] | 2973 | TRY |
---|
[540] | 2974 | { |
---|
[650] | 2975 | string id; |
---|
| 2976 | buffer >> id; |
---|
| 2977 | addAxis(id); |
---|
[540] | 2978 | } |
---|
[1622] | 2979 | CATCH_DUMP_ATTR |
---|
[540] | 2980 | |
---|
[887] | 2981 | /*! |
---|
| 2982 | \brief Receive a message annoucing the creation of an scalar on server side |
---|
| 2983 | \param[in] event Received event |
---|
| 2984 | */ |
---|
| 2985 | void CGrid::recvAddScalar(CEventServer& event) |
---|
[1622] | 2986 | TRY |
---|
[887] | 2987 | { |
---|
| 2988 | |
---|
| 2989 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 2990 | string id; |
---|
| 2991 | *buffer >> id; |
---|
| 2992 | get(id)->recvAddScalar(*buffer); |
---|
| 2993 | } |
---|
[1622] | 2994 | CATCH |
---|
[887] | 2995 | |
---|
| 2996 | /*! |
---|
| 2997 | \brief Receive a message annoucing the creation of an scalar on server side |
---|
| 2998 | \param[in] buffer Buffer containing message |
---|
| 2999 | */ |
---|
| 3000 | void CGrid::recvAddScalar(CBufferIn& buffer) |
---|
[1622] | 3001 | TRY |
---|
[887] | 3002 | { |
---|
| 3003 | string id; |
---|
| 3004 | buffer >> id; |
---|
| 3005 | addScalar(id); |
---|
| 3006 | } |
---|
[1622] | 3007 | CATCH_DUMP_ATTR |
---|
[887] | 3008 | |
---|
[551] | 3009 | /*! |
---|
[1869] | 3010 | \brief Check if all elements of the grid are complete |
---|
| 3011 | Before make any grid processing, we must be sure that all grid information elements have |
---|
| 3012 | been sent, for exemple when reading a grid in a file or when grid elements are sent by an |
---|
| 3013 | other context (coupling) |
---|
| 3014 | */ |
---|
[1875] | 3015 | bool CGrid::isCompleted(void) |
---|
[1869] | 3016 | { |
---|
| 3017 | setDomainList(); |
---|
[1875] | 3018 | for (auto domainId : domList_) if (!CDomain::get(domainId)->isCompleted()) return false ; |
---|
[1869] | 3019 | setAxisList() ; |
---|
[1875] | 3020 | for (auto axisId : axisList_) if (!CAxis::get(axisId)->isCompleted()) return false ; |
---|
[1869] | 3021 | setScalarList() ; |
---|
[1875] | 3022 | for (auto scalarId : scalarList_) if (!CScalar::get(scalarId)->isCompleted()) return false ; |
---|
[1869] | 3023 | return true ; |
---|
| 3024 | } |
---|
| 3025 | |
---|
| 3026 | /*! |
---|
[1875] | 3027 | \brief impose that all elements of the grid are complete |
---|
| 3028 | Before make any grid processing, we must be sure that all grid information elements have |
---|
| 3029 | been sent, for exemple when reading a grid in a file or when grid elements are sent by an |
---|
| 3030 | other context (coupling) |
---|
| 3031 | */ |
---|
| 3032 | void CGrid::setCompleted(void) |
---|
| 3033 | { |
---|
| 3034 | setDomainList(); |
---|
| 3035 | for (auto domainId : domList_) CDomain::get(domainId)->setCompleted() ; |
---|
| 3036 | setAxisList() ; |
---|
| 3037 | for (auto axisId : axisList_) CAxis::get(axisId)->setCompleted() ; |
---|
| 3038 | setScalarList() ; |
---|
| 3039 | for (auto scalarId : scalarList_) CScalar::get(scalarId)->setCompleted() ; |
---|
| 3040 | } |
---|
| 3041 | |
---|
| 3042 | /*! |
---|
| 3043 | \brief impose that all elements of the grid are incomplete |
---|
| 3044 | Before make any grid processing, we must be sure that all grid information elements have |
---|
| 3045 | been sent, for exemple when reading a grid in a file or when grid elements are sent by an |
---|
| 3046 | other context (coupling) |
---|
| 3047 | */ |
---|
| 3048 | void CGrid::unsetCompleted(void) |
---|
| 3049 | { |
---|
| 3050 | setDomainList(); |
---|
| 3051 | for (auto domainId : domList_) CDomain::get(domainId)->unsetCompleted() ; |
---|
| 3052 | setAxisList() ; |
---|
| 3053 | for (auto axisId : axisList_) CAxis::get(axisId)->unsetCompleted() ; |
---|
| 3054 | setScalarList() ; |
---|
| 3055 | for (auto scalarId : scalarList_) CScalar::get(scalarId)->unsetCompleted() ; |
---|
| 3056 | } |
---|
| 3057 | |
---|
| 3058 | /*! |
---|
[551] | 3059 | \brief Solve domain and axis references |
---|
| 3060 | As field, domain and axis can refer to other domains or axis. In order to inherit correctly |
---|
| 3061 | all attributes from their parents, they should be processed with this function |
---|
| 3062 | \param[in] apply inherit all attributes of parents (true) |
---|
| 3063 | */ |
---|
[1869] | 3064 | void CGrid::solveElementsRefInheritance(bool apply) |
---|
[1622] | 3065 | TRY |
---|
[540] | 3066 | { |
---|
| 3067 | setDomainList(); |
---|
[1869] | 3068 | for (auto domainId : domList_) |
---|
[540] | 3069 | { |
---|
[1869] | 3070 | CDomain* pDom = CDomain::get(domainId); |
---|
| 3071 | pDom->solveRefInheritance(apply); |
---|
| 3072 | pDom->solveInheritanceTransformation(); |
---|
[540] | 3073 | } |
---|
| 3074 | |
---|
| 3075 | setAxisList(); |
---|
[1869] | 3076 | for (auto axisId : axisList_) |
---|
[540] | 3077 | { |
---|
[1869] | 3078 | CAxis* pAxis = CAxis::get(axisId); |
---|
| 3079 | pAxis->solveRefInheritance(apply); |
---|
| 3080 | pAxis->solveInheritanceTransformation(); |
---|
[540] | 3081 | } |
---|
[887] | 3082 | |
---|
| 3083 | setScalarList(); |
---|
[1869] | 3084 | for (auto scalarId : scalarList_) |
---|
[887] | 3085 | { |
---|
[1869] | 3086 | CScalar* pScalar = CScalar::get(scalarId); |
---|
| 3087 | pScalar->solveRefInheritance(apply); |
---|
| 3088 | pScalar->solveInheritanceTransformation(); |
---|
[887] | 3089 | } |
---|
[540] | 3090 | } |
---|
[1622] | 3091 | CATCH_DUMP_ATTR |
---|
[540] | 3092 | |
---|
[1869] | 3093 | /*! |
---|
| 3094 | \brief check attributes of all elements of the grid |
---|
| 3095 | */ |
---|
| 3096 | void CGrid::checkElementsAttributes(void) |
---|
| 3097 | TRY |
---|
| 3098 | { |
---|
| 3099 | setDomainList(); |
---|
| 3100 | for (auto domainId : domList_) CDomain::get(domainId)->checkAttributes(); |
---|
| 3101 | |
---|
| 3102 | setAxisList(); |
---|
| 3103 | for (auto axisId : axisList_) CAxis::get(axisId)->checkAttributes(); |
---|
| 3104 | |
---|
| 3105 | setScalarList(); |
---|
| 3106 | for (auto scalarId : scalarList_) CScalar::get(scalarId)->checkAttributes(); |
---|
| 3107 | } |
---|
| 3108 | CATCH_DUMP_ATTR |
---|
| 3109 | |
---|
[619] | 3110 | bool CGrid::isTransformed() |
---|
[1622] | 3111 | TRY |
---|
[619] | 3112 | { |
---|
| 3113 | return isTransformed_; |
---|
| 3114 | } |
---|
[1622] | 3115 | CATCH_DUMP_ATTR |
---|
[619] | 3116 | |
---|
| 3117 | void CGrid::setTransformed() |
---|
[1622] | 3118 | TRY |
---|
[619] | 3119 | { |
---|
| 3120 | isTransformed_ = true; |
---|
| 3121 | } |
---|
[1622] | 3122 | CATCH_DUMP_ATTR |
---|
[619] | 3123 | |
---|
[620] | 3124 | CGridTransformation* CGrid::getTransformations() |
---|
[1622] | 3125 | TRY |
---|
[619] | 3126 | { |
---|
[620] | 3127 | return transformations_; |
---|
[619] | 3128 | } |
---|
[1622] | 3129 | CATCH_DUMP_ATTR |
---|
[619] | 3130 | |
---|
[823] | 3131 | void CGrid::addTransGridSource(CGrid* gridSrc) |
---|
[1622] | 3132 | TRY |
---|
[823] | 3133 | { |
---|
| 3134 | if (gridSrc_.end() == gridSrc_.find(gridSrc)) |
---|
| 3135 | gridSrc_.insert(make_pair(gridSrc,make_pair(false,""))); |
---|
| 3136 | } |
---|
[1622] | 3137 | CATCH_DUMP_ATTR |
---|
[823] | 3138 | |
---|
| 3139 | std::map<CGrid*,std::pair<bool,StdString> >& CGrid::getTransGridSource() |
---|
[1622] | 3140 | TRY |
---|
[823] | 3141 | { |
---|
| 3142 | return gridSrc_; |
---|
| 3143 | } |
---|
[1622] | 3144 | CATCH_DUMP_ATTR |
---|
[823] | 3145 | |
---|
[687] | 3146 | /*! |
---|
| 3147 | Complete all the necessary (and lacking) attributes of a grid |
---|
| 3148 | This function is similar to gridTransformation but works only (till now) on generate_rectilinear_domain transformation |
---|
| 3149 | */ |
---|
| 3150 | void CGrid::completeGrid(CGrid* transformGridSrc) |
---|
[1622] | 3151 | TRY |
---|
[687] | 3152 | { |
---|
[1869] | 3153 | if (nullptr != transformGridSrc) |
---|
[687] | 3154 | { |
---|
[775] | 3155 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
| 3156 | { |
---|
| 3157 | ERROR("CGrid::completeGrid(CGrid* transformGridSrc)", |
---|
[940] | 3158 | << "Two grids have different number of elements. " << std::endl |
---|
| 3159 | << "Number of element of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 3160 | << "Number of element of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[775] | 3161 | } |
---|
[687] | 3162 | } |
---|
| 3163 | |
---|
[890] | 3164 | if (isGenerated()) return; |
---|
| 3165 | setGenerated(); |
---|
| 3166 | |
---|
[687] | 3167 | CGridGenerate gridGenerate(this, transformGridSrc); |
---|
| 3168 | gridGenerate.completeGrid(); |
---|
| 3169 | } |
---|
[1622] | 3170 | CATCH_DUMP_ATTR |
---|
[687] | 3171 | |
---|
[890] | 3172 | bool CGrid::isGenerated() |
---|
[1622] | 3173 | TRY |
---|
[890] | 3174 | { |
---|
| 3175 | return isGenerated_; |
---|
| 3176 | } |
---|
[1622] | 3177 | CATCH |
---|
[890] | 3178 | |
---|
| 3179 | void CGrid::setGenerated() |
---|
[1622] | 3180 | TRY |
---|
[890] | 3181 | { |
---|
| 3182 | isGenerated_ = true; |
---|
| 3183 | } |
---|
[1622] | 3184 | CATCH_DUMP_ATTR |
---|
[890] | 3185 | |
---|
[632] | 3186 | void CGrid::transformGrid(CGrid* transformGridSrc) |
---|
[1622] | 3187 | TRY |
---|
[619] | 3188 | { |
---|
[746] | 3189 | if (!transformGridSrc) |
---|
| 3190 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 3191 | << "Impossible to transform grid '" << getId() << "', the source grid is null."); |
---|
| 3192 | |
---|
[632] | 3193 | if (isTransformed()) return; |
---|
| 3194 | setTransformed(); |
---|
| 3195 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
[619] | 3196 | { |
---|
[632] | 3197 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[940] | 3198 | << "Two grids have different number of elements. " << std::endl |
---|
| 3199 | << "Number of element of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 3200 | << "Number of element of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[619] | 3201 | } |
---|
| 3202 | else |
---|
| 3203 | { |
---|
| 3204 | } |
---|
| 3205 | |
---|
[632] | 3206 | transformations_ = new CGridTransformation(this, transformGridSrc); |
---|
[622] | 3207 | transformations_->computeAll(); |
---|
[824] | 3208 | if (0 < transformations_->getNbAlgo()) hasTransform_ = true; |
---|
[623] | 3209 | |
---|
| 3210 | // Ok, now need to compute index of grid source |
---|
[632] | 3211 | transformGridSrc->checkMaskIndex(false); |
---|
[619] | 3212 | } |
---|
[1622] | 3213 | CATCH_DUMP_ATTR |
---|
[619] | 3214 | |
---|
[1869] | 3215 | |
---|
| 3216 | |
---|
| 3217 | |
---|
| 3218 | void CGrid::prepareTransformGrid(CGrid* transformGridSrc) |
---|
| 3219 | TRY |
---|
| 3220 | { |
---|
| 3221 | if (prepareTransformGrid_done_) return ; |
---|
| 3222 | |
---|
| 3223 | if (!transformGridSrc) |
---|
| 3224 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 3225 | << "Impossible to transform grid '" << getId() << "', the source grid is null."); |
---|
| 3226 | |
---|
| 3227 | if (isTransformed()) return; |
---|
| 3228 | setTransformed(); |
---|
| 3229 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
| 3230 | { |
---|
| 3231 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 3232 | << "Two grids have different number of elements. " << std::endl |
---|
| 3233 | << "Number of element of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 3234 | << "Number of element of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
| 3235 | } |
---|
| 3236 | else |
---|
| 3237 | { |
---|
| 3238 | } |
---|
| 3239 | |
---|
| 3240 | transformations_ = new CGridTransformation(this, transformGridSrc); |
---|
| 3241 | if (0 < transformations_->getNbAlgo()) hasTransform_ = true; |
---|
| 3242 | |
---|
| 3243 | prepareTransformGrid_done_ = true; |
---|
| 3244 | } |
---|
| 3245 | CATCH_DUMP_ATTR |
---|
| 3246 | |
---|
| 3247 | |
---|
| 3248 | void CGrid::makeTransformGrid(void) |
---|
| 3249 | TRY |
---|
| 3250 | { |
---|
| 3251 | if (makeTransformGrid_done_) return ; |
---|
| 3252 | transformations_->computeAll(); |
---|
| 3253 | |
---|
| 3254 | makeTransformGrid_done_ = true ; |
---|
| 3255 | } |
---|
| 3256 | CATCH_DUMP_ATTR |
---|
| 3257 | |
---|
| 3258 | |
---|
| 3259 | vector<std::string> CGrid::getAuxInputTransformGrid(void) |
---|
| 3260 | TRY |
---|
| 3261 | { |
---|
| 3262 | if (transformations_ != nullptr) return transformations_->getAuxInputs() ; |
---|
| 3263 | } |
---|
| 3264 | CATCH_DUMP_ATTR |
---|
| 3265 | |
---|
| 3266 | |
---|
| 3267 | |
---|
| 3268 | |
---|
| 3269 | |
---|
| 3270 | |
---|
| 3271 | |
---|
[824] | 3272 | bool CGrid::hasTransform() |
---|
[1622] | 3273 | TRY |
---|
[824] | 3274 | { |
---|
[914] | 3275 | if (hasTransform_) return hasTransform_; |
---|
| 3276 | |
---|
| 3277 | std::vector<CDomain*> domList = getDomains(); |
---|
| 3278 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 3279 | std::vector<CScalar*> scalarList = getScalars(); |
---|
| 3280 | |
---|
| 3281 | for (int idx = 0; idx < domList.size(); ++idx) hasTransform_ |= domList[idx]->hasTransformation(); |
---|
| 3282 | for (int idx = 0; idx < axisList.size(); ++idx) hasTransform_ |= axisList[idx]->hasTransformation(); |
---|
| 3283 | for (int idx = 0; idx < scalarList.size(); ++idx) hasTransform_ |= scalarList[idx]->hasTransformation(); |
---|
| 3284 | |
---|
[824] | 3285 | return hasTransform_; |
---|
| 3286 | } |
---|
[1622] | 3287 | CATCH_DUMP_ATTR |
---|
[824] | 3288 | |
---|
[540] | 3289 | |
---|
| 3290 | |
---|
[551] | 3291 | /*! |
---|
[887] | 3292 | Send all attributes of domains from client to server |
---|
| 3293 | */ |
---|
[1784] | 3294 | void CGrid::sendAllDomains(CContextClient* contextClient) |
---|
[1622] | 3295 | TRY |
---|
[540] | 3296 | { |
---|
| 3297 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
[1870] | 3298 | for (auto domain : domList) |
---|
[540] | 3299 | { |
---|
[1870] | 3300 | sendAddDomain(domain->getId(),contextClient); |
---|
| 3301 | domain->sendDomainToFileServer(contextClient); |
---|
[540] | 3302 | } |
---|
| 3303 | } |
---|
[1622] | 3304 | CATCH_DUMP_ATTR |
---|
[540] | 3305 | |
---|
[887] | 3306 | /*! |
---|
| 3307 | Send all attributes of axis from client to server |
---|
| 3308 | */ |
---|
[1784] | 3309 | void CGrid::sendAllAxis(CContextClient* contextClient) |
---|
[1622] | 3310 | TRY |
---|
[540] | 3311 | { |
---|
| 3312 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
[1870] | 3313 | for (int i=0; i<aList.size() ; ++i) |
---|
[540] | 3314 | { |
---|
[1784] | 3315 | sendAddAxis(aList[i]->getId(),contextClient); |
---|
[1870] | 3316 | aList[i]->sendAxisToFileServer(contextClient, getGlobalDimension(), getAxisPositionInGrid()[i]); |
---|
[540] | 3317 | } |
---|
| 3318 | } |
---|
[1622] | 3319 | CATCH_DUMP_ATTR |
---|
[540] | 3320 | |
---|
[887] | 3321 | /*! |
---|
| 3322 | Send all attributes of scalars from client to server |
---|
| 3323 | */ |
---|
[1784] | 3324 | void CGrid::sendAllScalars(CContextClient* contextClient) |
---|
[1622] | 3325 | TRY |
---|
[887] | 3326 | { |
---|
| 3327 | std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
[1870] | 3328 | for (auto scalar : sList) |
---|
[887] | 3329 | { |
---|
[1870] | 3330 | sendAddScalar(scalar->getId(),contextClient); |
---|
| 3331 | scalar->sendScalarToFileServer(contextClient); |
---|
[887] | 3332 | } |
---|
| 3333 | } |
---|
[1622] | 3334 | CATCH_DUMP_ATTR |
---|
[887] | 3335 | |
---|
[1294] | 3336 | void CGrid::setContextClient(CContextClient* contextClient) |
---|
[1622] | 3337 | TRY |
---|
[1294] | 3338 | { |
---|
[1353] | 3339 | if (clientsSet.find(contextClient)==clientsSet.end()) |
---|
| 3340 | { |
---|
| 3341 | clients.push_back(contextClient) ; |
---|
| 3342 | clientsSet.insert(contextClient); |
---|
| 3343 | } |
---|
[1875] | 3344 | for (auto domain : getDomains()) domain->setContextClient(contextClient); |
---|
| 3345 | for (auto axis : getAxis()) axis->setContextClient(contextClient); |
---|
| 3346 | for (auto scalar : getScalars()) scalar->setContextClient(contextClient); |
---|
| 3347 | |
---|
[1294] | 3348 | } |
---|
[1622] | 3349 | CATCH_DUMP_ATTR |
---|
[1294] | 3350 | |
---|
[1930] | 3351 | |
---|
[1918] | 3352 | void CGrid::computeGridLocalElements() |
---|
| 3353 | { |
---|
| 3354 | std::vector<CDomain*> domainList = this->getDomains(); |
---|
| 3355 | std::vector<CAxis*> axisList = this->getAxis(); |
---|
[1940] | 3356 | std::vector<CScalar*> scalarList = this->getScalars(); |
---|
[1918] | 3357 | auto domain=domainList.begin() ; |
---|
| 3358 | auto axis=axisList.begin() ; |
---|
[1940] | 3359 | auto scalar=scalarList.begin() ; |
---|
[1918] | 3360 | vector<CLocalElement*> elements; |
---|
| 3361 | for(auto order : order_) |
---|
| 3362 | { |
---|
| 3363 | if (order==2) |
---|
| 3364 | { |
---|
| 3365 | elements.push_back((*domain)->getLocalElement()); |
---|
| 3366 | domain++ ; |
---|
| 3367 | } |
---|
| 3368 | else if (order==1) |
---|
| 3369 | { |
---|
| 3370 | elements.push_back((*axis)->getLocalElement()); |
---|
| 3371 | axis++ ; |
---|
| 3372 | } |
---|
| 3373 | else if (order==0) |
---|
| 3374 | { |
---|
[1940] | 3375 | elements.push_back((*scalar)->getLocalElement()); |
---|
| 3376 | scalar++ ; |
---|
[1918] | 3377 | } |
---|
| 3378 | } |
---|
| 3379 | if (hasMask()) |
---|
| 3380 | { |
---|
| 3381 | vector<bool> mask(getMask().getVector()) ; |
---|
| 3382 | gridLocalElements_ = new CGridLocalElements(elements, mask) ; |
---|
| 3383 | } |
---|
| 3384 | else gridLocalElements_ = new CGridLocalElements(elements) ; |
---|
| 3385 | } |
---|
| 3386 | |
---|
| 3387 | void CGrid::computeModelToWorkflowConnector(void) |
---|
| 3388 | { |
---|
| 3389 | modelToWorkflowConnector_ = getGridLocalElements()->getConnector(CElementView::MODEL,CElementView::WORKFLOW) ; |
---|
| 3390 | } |
---|
[1930] | 3391 | |
---|
| 3392 | void CGrid::computeWorkflowToFullConnector(void) |
---|
| 3393 | { |
---|
| 3394 | workflowToFullConnector_ = getGridLocalElements()->getConnector(CElementView::WORKFLOW,CElementView::FULL) ; |
---|
| 3395 | } |
---|
| 3396 | |
---|
| 3397 | void CGrid::computeWorkflowToModelConnector(void) |
---|
| 3398 | { |
---|
| 3399 | workflowToModelConnector_ = getGridLocalElements()->getConnector(CElementView::WORKFLOW,CElementView::MODEL) ; |
---|
| 3400 | } |
---|
| 3401 | |
---|
| 3402 | void CGrid::computeFullToWorkflowConnector(void) |
---|
| 3403 | { |
---|
| 3404 | fullToWorkflowConnector_ = getGridLocalElements()->getConnector(CElementView::FULL,CElementView::WORKFLOW) ; |
---|
| 3405 | } |
---|
| 3406 | |
---|
| 3407 | void CGrid::computeServerFromClientConnector(void) |
---|
| 3408 | { |
---|
| 3409 | vector<CGathererConnector*> connectors ; |
---|
| 3410 | for(auto& element : getElements()) |
---|
| 3411 | { |
---|
| 3412 | if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerFromClientConnector()) ; |
---|
| 3413 | else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerFromClientConnector()) ; |
---|
| 3414 | else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerFromClientConnector()) ; |
---|
| 3415 | } |
---|
| 3416 | serverFromClientConnector_ = new CGridGathererConnector(connectors) ; |
---|
| 3417 | } |
---|
| 3418 | |
---|
[1934] | 3419 | void CGrid::computeServerToClientConnector(void) |
---|
| 3420 | { |
---|
| 3421 | vector<CScattererConnector*> connectors ; |
---|
| 3422 | for(auto& element : getElements()) |
---|
| 3423 | { |
---|
| 3424 | if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerToClientConnector()) ; |
---|
| 3425 | else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerToClientConnector()) ; |
---|
| 3426 | else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerToClientConnector()) ; |
---|
| 3427 | } |
---|
| 3428 | serverToClientConnector_ = new CGridScattererConnector(connectors) ; |
---|
| 3429 | } |
---|
| 3430 | |
---|
[1930] | 3431 | void CGrid::computeClientFromClientConnector(void) |
---|
| 3432 | { |
---|
| 3433 | vector<CGathererConnector*> connectors ; |
---|
| 3434 | for(auto& element : getElements()) |
---|
| 3435 | { |
---|
| 3436 | if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerFromClientConnector()) ; |
---|
| 3437 | else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerFromClientConnector()) ; |
---|
| 3438 | else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerFromClientConnector()) ; |
---|
| 3439 | } |
---|
| 3440 | clientFromClientConnector_ = new CGridGathererConnector(connectors) ; |
---|
| 3441 | } |
---|
[1934] | 3442 | |
---|
| 3443 | |
---|
[335] | 3444 | } // namespace xios |
---|