[219] | 1 | #include "axis.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
| 6 | #include "message.hpp" |
---|
| 7 | #include "type.hpp" |
---|
[567] | 8 | #include "context.hpp" |
---|
| 9 | #include "context_client.hpp" |
---|
[676] | 10 | #include "context_server.hpp" |
---|
[591] | 11 | #include "xios_spl.hpp" |
---|
[633] | 12 | #include "server_distribution_description.hpp" |
---|
| 13 | #include "client_server_mapping_distributed.hpp" |
---|
[676] | 14 | #include "distribution_client.hpp" |
---|
[219] | 15 | |
---|
[335] | 16 | namespace xios { |
---|
[540] | 17 | |
---|
[1421] | 18 | /// ////////////////////// Definitions ////////////////////// /// |
---|
[219] | 19 | |
---|
| 20 | CAxis::CAxis(void) |
---|
| 21 | : CObjectTemplate<CAxis>() |
---|
[771] | 22 | , CAxisAttributes(), isChecked(false), relFiles(), areClientAttributesChecked_(false) |
---|
[927] | 23 | , isClientAfterTransformationChecked(false) |
---|
[1235] | 24 | , hasBounds(false), isCompressible_(false) |
---|
[1249] | 25 | , numberWrittenIndexes_(), totalNumberWrittenIndexes_(), offsetWrittenIndexes_() |
---|
[1202] | 26 | , transformationMap_(), hasValue(false), hasLabel(false) |
---|
[1129] | 27 | , computedWrittenIndex_(false) |
---|
[1345] | 28 | , clients() |
---|
[621] | 29 | { |
---|
| 30 | } |
---|
[219] | 31 | |
---|
| 32 | CAxis::CAxis(const StdString & id) |
---|
| 33 | : CObjectTemplate<CAxis>(id) |
---|
[771] | 34 | , CAxisAttributes(), isChecked(false), relFiles(), areClientAttributesChecked_(false) |
---|
[927] | 35 | , isClientAfterTransformationChecked(false) |
---|
[1235] | 36 | , hasBounds(false), isCompressible_(false) |
---|
[1249] | 37 | , numberWrittenIndexes_(), totalNumberWrittenIndexes_(), offsetWrittenIndexes_() |
---|
[1202] | 38 | , transformationMap_(), hasValue(false), hasLabel(false) |
---|
[1129] | 39 | , computedWrittenIndex_(false) |
---|
[1345] | 40 | , clients() |
---|
[621] | 41 | { |
---|
| 42 | } |
---|
[219] | 43 | |
---|
| 44 | CAxis::~CAxis(void) |
---|
| 45 | { /* Ne rien faire de plus */ } |
---|
| 46 | |
---|
[836] | 47 | std::map<StdString, ETranformationType> CAxis::transformationMapList_ = std::map<StdString, ETranformationType>(); |
---|
| 48 | bool CAxis::dummyTransformationMapList_ = CAxis::initializeTransformationMap(CAxis::transformationMapList_); |
---|
| 49 | bool CAxis::initializeTransformationMap(std::map<StdString, ETranformationType>& m) |
---|
[1622] | 50 | TRY |
---|
[836] | 51 | { |
---|
| 52 | m["zoom_axis"] = TRANS_ZOOM_AXIS; |
---|
| 53 | m["interpolate_axis"] = TRANS_INTERPOLATE_AXIS; |
---|
[1558] | 54 | m["extract_axis"] = TRANS_EXTRACT_AXIS; |
---|
[836] | 55 | m["inverse_axis"] = TRANS_INVERSE_AXIS; |
---|
[895] | 56 | m["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_AXIS; |
---|
[1301] | 57 | m["reduce_axis"] = TRANS_REDUCE_AXIS_TO_AXIS; |
---|
[895] | 58 | m["extract_domain"] = TRANS_EXTRACT_DOMAIN_TO_AXIS; |
---|
[1275] | 59 | m["temporal_splitting"] = TRANS_TEMPORAL_SPLITTING; |
---|
[1314] | 60 | m["duplicate_scalar"] = TRANS_DUPLICATE_SCALAR_TO_AXIS; |
---|
| 61 | |
---|
[836] | 62 | } |
---|
[1622] | 63 | CATCH |
---|
[836] | 64 | |
---|
[219] | 65 | ///--------------------------------------------------------------- |
---|
[1158] | 66 | |
---|
| 67 | const std::set<StdString> & CAxis::getRelFiles(void) const |
---|
[1622] | 68 | TRY |
---|
[1158] | 69 | { |
---|
| 70 | return (this->relFiles); |
---|
| 71 | } |
---|
[1622] | 72 | CATCH |
---|
[1158] | 73 | |
---|
[219] | 74 | bool CAxis::IsWritten(const StdString & filename) const |
---|
[1622] | 75 | TRY |
---|
[219] | 76 | { |
---|
| 77 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
| 78 | } |
---|
[1622] | 79 | CATCH |
---|
[219] | 80 | |
---|
[676] | 81 | bool CAxis::isWrittenCompressed(const StdString& filename) const |
---|
[1622] | 82 | TRY |
---|
[676] | 83 | { |
---|
| 84 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 85 | } |
---|
[1622] | 86 | CATCH |
---|
[676] | 87 | |
---|
[594] | 88 | bool CAxis::isDistributed(void) const |
---|
[1622] | 89 | TRY |
---|
[594] | 90 | { |
---|
[1158] | 91 | bool distributed = (!this->begin.isEmpty() && !this->n.isEmpty() && (this->begin + this->n < this->n_glo)) || |
---|
| 92 | (!this->n.isEmpty() && (this->n != this->n_glo)); |
---|
[1622] | 93 | // A condition to make sure that if there is only one client, axis |
---|
[1158] | 94 | // should be considered to be distributed. This should be a temporary solution |
---|
[1787] | 95 | distributed |= (1 == CContext::getCurrent()->intraCommSize_); |
---|
[1158] | 96 | return distributed; |
---|
[594] | 97 | } |
---|
[1622] | 98 | CATCH |
---|
[594] | 99 | |
---|
[676] | 100 | /*! |
---|
| 101 | * Test whether the data defined on the axis can be outputted in a compressed way. |
---|
[742] | 102 | * |
---|
[676] | 103 | * \return true if and only if a mask was defined for this axis |
---|
| 104 | */ |
---|
| 105 | bool CAxis::isCompressible(void) const |
---|
[1622] | 106 | TRY |
---|
[676] | 107 | { |
---|
| 108 | return isCompressible_; |
---|
| 109 | } |
---|
[1622] | 110 | CATCH |
---|
[676] | 111 | |
---|
[219] | 112 | void CAxis::addRelFile(const StdString & filename) |
---|
[1622] | 113 | TRY |
---|
[219] | 114 | { |
---|
| 115 | this->relFiles.insert(filename); |
---|
| 116 | } |
---|
[1622] | 117 | CATCH_DUMP_ATTR |
---|
[219] | 118 | |
---|
[676] | 119 | void CAxis::addRelFileCompressed(const StdString& filename) |
---|
[1622] | 120 | TRY |
---|
[676] | 121 | { |
---|
| 122 | this->relFilesCompressed.insert(filename); |
---|
| 123 | } |
---|
[1622] | 124 | CATCH_DUMP_ATTR |
---|
[676] | 125 | |
---|
[219] | 126 | //---------------------------------------------------------------- |
---|
| 127 | |
---|
[676] | 128 | /*! |
---|
| 129 | Returns the number of indexes written by each server. |
---|
| 130 | \return the number of indexes written by each server |
---|
| 131 | */ |
---|
[1639] | 132 | int CAxis::getNumberWrittenIndexes(MPI_Comm writtenCom) |
---|
[1622] | 133 | TRY |
---|
[676] | 134 | { |
---|
[1249] | 135 | int writtenSize; |
---|
[1639] | 136 | MPI_Comm_size(writtenCom, &writtenSize); |
---|
[1249] | 137 | return numberWrittenIndexes_[writtenSize]; |
---|
[676] | 138 | } |
---|
[1622] | 139 | CATCH_DUMP_ATTR |
---|
[676] | 140 | |
---|
| 141 | /*! |
---|
| 142 | Returns the total number of indexes written by the servers. |
---|
| 143 | \return the total number of indexes written by the servers |
---|
| 144 | */ |
---|
[1639] | 145 | int CAxis::getTotalNumberWrittenIndexes(MPI_Comm writtenCom) |
---|
[1622] | 146 | TRY |
---|
[676] | 147 | { |
---|
[1249] | 148 | int writtenSize; |
---|
[1639] | 149 | MPI_Comm_size(writtenCom, &writtenSize); |
---|
[1249] | 150 | return totalNumberWrittenIndexes_[writtenSize]; |
---|
[676] | 151 | } |
---|
[1622] | 152 | CATCH_DUMP_ATTR |
---|
[676] | 153 | |
---|
| 154 | /*! |
---|
| 155 | Returns the offset of indexes written by each server. |
---|
| 156 | \return the offset of indexes written by each server |
---|
| 157 | */ |
---|
[1639] | 158 | int CAxis::getOffsetWrittenIndexes(MPI_Comm writtenCom) |
---|
[1622] | 159 | TRY |
---|
[676] | 160 | { |
---|
[1249] | 161 | int writtenSize; |
---|
[1639] | 162 | MPI_Comm_size(writtenCom, &writtenSize); |
---|
[1249] | 163 | return offsetWrittenIndexes_[writtenSize]; |
---|
[676] | 164 | } |
---|
[1622] | 165 | CATCH_DUMP_ATTR |
---|
[676] | 166 | |
---|
[1639] | 167 | CArray<int, 1>& CAxis::getCompressedIndexToWriteOnServer(MPI_Comm writtenCom) |
---|
[1622] | 168 | TRY |
---|
[1249] | 169 | { |
---|
| 170 | int writtenSize; |
---|
[1639] | 171 | MPI_Comm_size(writtenCom, &writtenSize); |
---|
[1249] | 172 | return compressedIndexToWriteOnServer[writtenSize]; |
---|
| 173 | } |
---|
[1622] | 174 | CATCH_DUMP_ATTR |
---|
| 175 | |
---|
[676] | 176 | //---------------------------------------------------------------- |
---|
| 177 | |
---|
[731] | 178 | /*! |
---|
| 179 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 180 | * |
---|
| 181 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 182 | */ |
---|
[1371] | 183 | std::map<int, StdSize> CAxis::getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 184 | CServerDistributionDescription::ServerDistributionType distType) |
---|
[1622] | 185 | TRY |
---|
[731] | 186 | { |
---|
| 187 | |
---|
[1330] | 188 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(client); |
---|
[731] | 189 | |
---|
[1371] | 190 | // bool isNonDistributed = (n_glo == n); |
---|
| 191 | bool isDistributed = (orderPositionInGrid == CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), distType)) |
---|
| 192 | || (index.numElements() != n_glo); |
---|
[731] | 193 | |
---|
| 194 | if (client->isServerLeader()) |
---|
| 195 | { |
---|
| 196 | // size estimation for sendServerAttribut |
---|
| 197 | size_t size = 6 * sizeof(size_t); |
---|
| 198 | // size estimation for sendNonDistributedValue |
---|
[1371] | 199 | if (!isDistributed) |
---|
| 200 | { |
---|
| 201 | // size = std::max(size, CArray<double,1>::size(n_glo) + (isCompressible_ ? CArray<int,1>::size(n_glo) : 0)); |
---|
| 202 | size += CArray<int,1>::size(n_glo); |
---|
| 203 | size += CArray<int,1>::size(n_glo); |
---|
| 204 | size += CArray<bool,1>::size(n_glo); |
---|
| 205 | size += CArray<double,1>::size(n_glo); |
---|
| 206 | if (hasBounds) |
---|
| 207 | size += CArray<double,2>::size(2*n_glo); |
---|
| 208 | if (hasLabel) |
---|
| 209 | size += CArray<StdString,1>::size(n_glo); |
---|
| 210 | } |
---|
[731] | 211 | size += CEventClient::headerSize + getId().size() + sizeof(size_t); |
---|
| 212 | |
---|
| 213 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 214 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 215 | { |
---|
| 216 | if (size > attributesSizes[*itRank]) |
---|
| 217 | attributesSizes[*itRank] = size; |
---|
| 218 | } |
---|
[1371] | 219 | const std::list<int>& ranksNonLeaders = client->getRanksServerNotLeader(); |
---|
| 220 | for (std::list<int>::const_iterator itRank = ranksNonLeaders.begin(), itRankEnd = ranksNonLeaders.end(); itRank != itRankEnd; ++itRank) |
---|
| 221 | { |
---|
| 222 | if (size > attributesSizes[*itRank]) |
---|
| 223 | attributesSizes[*itRank] = size; |
---|
| 224 | } |
---|
| 225 | |
---|
[731] | 226 | } |
---|
| 227 | |
---|
[1371] | 228 | if (isDistributed) |
---|
[731] | 229 | { |
---|
| 230 | // size estimation for sendDistributedValue |
---|
[1542] | 231 | std::unordered_map<int, vector<size_t> >::const_iterator it, ite = indSrv_[client->serverSize].end(); |
---|
[1337] | 232 | for (it = indSrv_[client->serverSize].begin(); it != ite; ++it) |
---|
[731] | 233 | { |
---|
[1371] | 234 | size_t size = 6 * sizeof(size_t); |
---|
| 235 | size += CArray<int,1>::size(it->second.size()); |
---|
| 236 | size += CArray<int,1>::size(it->second.size()); |
---|
| 237 | size += CArray<bool,1>::size(it->second.size()); |
---|
| 238 | size += CArray<double,1>::size(it->second.size()); |
---|
[1235] | 239 | if (hasBounds) |
---|
[1371] | 240 | size += CArray<double,2>::size(2 * it->second.size()); |
---|
[1158] | 241 | if (hasLabel) |
---|
[1371] | 242 | size += CArray<StdString,1>::size(it->second.size()); |
---|
[731] | 243 | |
---|
[1371] | 244 | size += CEventClient::headerSize + getId().size() + sizeof(size_t); |
---|
[731] | 245 | if (size > attributesSizes[it->first]) |
---|
| 246 | attributesSizes[it->first] = size; |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | return attributesSizes; |
---|
| 250 | } |
---|
[1622] | 251 | CATCH_DUMP_ATTR |
---|
[731] | 252 | |
---|
| 253 | //---------------------------------------------------------------- |
---|
| 254 | |
---|
[219] | 255 | StdString CAxis::GetName(void) { return (StdString("axis")); } |
---|
| 256 | StdString CAxis::GetDefName(void){ return (CAxis::GetName()); } |
---|
| 257 | ENodeType CAxis::GetType(void) { return (eAxis); } |
---|
| 258 | |
---|
| 259 | //---------------------------------------------------------------- |
---|
| 260 | |
---|
[622] | 261 | CAxis* CAxis::createAxis() |
---|
[1622] | 262 | TRY |
---|
[622] | 263 | { |
---|
| 264 | CAxis* axis = CAxisGroup::get("axis_definition")->createChild(); |
---|
| 265 | return axis; |
---|
| 266 | } |
---|
[1622] | 267 | CATCH |
---|
[622] | 268 | |
---|
[1144] | 269 | /*! |
---|
| 270 | Check common attributes of an axis. |
---|
| 271 | This check should be done in the very beginning of work flow |
---|
| 272 | */ |
---|
[219] | 273 | void CAxis::checkAttributes(void) |
---|
[1622] | 274 | TRY |
---|
[219] | 275 | { |
---|
[1869] | 276 | if (checkAttributes_done_) return ; |
---|
| 277 | |
---|
[1637] | 278 | CContext* context=CContext::getCurrent(); |
---|
| 279 | |
---|
| 280 | if (this->n_glo.isEmpty()) |
---|
[679] | 281 | ERROR("CAxis::checkAttributes(void)", |
---|
| 282 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 283 | << "The axis is wrongly defined, attribute 'n_glo' must be specified"); |
---|
[666] | 284 | StdSize size = this->n_glo.getValue(); |
---|
[540] | 285 | |
---|
[970] | 286 | if (!this->index.isEmpty()) |
---|
[551] | 287 | { |
---|
[970] | 288 | if (n.isEmpty()) n = index.numElements(); |
---|
| 289 | |
---|
| 290 | // It's not so correct but if begin is not the first value of index |
---|
| 291 | // then data on the local axis has user-defined distribution. In this case, begin has no meaning. |
---|
| 292 | if (begin.isEmpty()) begin = index(0); |
---|
[551] | 293 | } |
---|
[970] | 294 | else |
---|
| 295 | { |
---|
| 296 | if (!this->begin.isEmpty()) |
---|
| 297 | { |
---|
| 298 | if (begin < 0 || begin > size - 1) |
---|
| 299 | ERROR("CAxis::checkAttributes(void)", |
---|
| 300 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 301 | << "The axis is wrongly defined, attribute 'begin' (" << begin.getValue() << ") must be non-negative and smaller than size-1 (" << size - 1 << ")."); |
---|
| 302 | } |
---|
| 303 | else this->begin.setValue(0); |
---|
[551] | 304 | |
---|
[970] | 305 | if (!this->n.isEmpty()) |
---|
| 306 | { |
---|
| 307 | if (n < 0 || n > size) |
---|
| 308 | ERROR("CAxis::checkAttributes(void)", |
---|
| 309 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 310 | << "The axis is wrongly defined, attribute 'n' (" << n.getValue() << ") must be non-negative and smaller than size (" << size << ")."); |
---|
| 311 | } |
---|
| 312 | else this->n.setValue(size); |
---|
| 313 | |
---|
| 314 | { |
---|
| 315 | index.resize(n); |
---|
| 316 | for (int i = 0; i < n; ++i) index(i) = i+begin; |
---|
| 317 | } |
---|
[551] | 318 | } |
---|
[624] | 319 | |
---|
[816] | 320 | if (!this->value.isEmpty()) |
---|
| 321 | { |
---|
[1869] | 322 | StdSize true_size = value.numElements(); |
---|
| 323 | if (this->n.getValue() != true_size) |
---|
| 324 | ERROR("CAxis::checkAttributes(void)", |
---|
| 325 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 326 | << "The axis is wrongly defined, attribute 'value' has a different size (" << true_size |
---|
| 327 | << ") than the one defined by the \'size\' attribute (" << n.getValue() << ")."); |
---|
[816] | 328 | this->hasValue = true; |
---|
| 329 | } |
---|
[219] | 330 | |
---|
[1158] | 331 | this->checkBounds(); |
---|
[1869] | 332 | this->checkMask(); |
---|
| 333 | this->checkData(); |
---|
| 334 | this->checkLabel(); |
---|
| 335 | |
---|
| 336 | checkAttributes_done_ = true ; |
---|
[219] | 337 | } |
---|
[1622] | 338 | CATCH_DUMP_ATTR |
---|
[219] | 339 | |
---|
[1144] | 340 | /*! |
---|
[1637] | 341 | Check the validity of data, fill in values if any, and apply mask. |
---|
[1144] | 342 | */ |
---|
[551] | 343 | void CAxis::checkData() |
---|
[1622] | 344 | TRY |
---|
[551] | 345 | { |
---|
| 346 | if (data_begin.isEmpty()) data_begin.setValue(0); |
---|
[679] | 347 | |
---|
| 348 | if (data_n.isEmpty()) |
---|
[551] | 349 | { |
---|
[679] | 350 | data_n.setValue(n); |
---|
| 351 | } |
---|
| 352 | else if (data_n.getValue() < 0) |
---|
| 353 | { |
---|
[551] | 354 | ERROR("CAxis::checkData(void)", |
---|
[679] | 355 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 356 | << "The data size should be strictly positive ('data_n' = " << data_n.getValue() << ")."); |
---|
[551] | 357 | } |
---|
| 358 | |
---|
| 359 | if (data_index.isEmpty()) |
---|
| 360 | { |
---|
[679] | 361 | data_index.resize(data_n); |
---|
[1637] | 362 | for (int i = 0; i < data_n; ++i) |
---|
| 363 | { |
---|
| 364 | if ((i+data_begin) >= 0 && (i+data_begin<n)) |
---|
| 365 | { |
---|
| 366 | if (mask(i+data_begin)) |
---|
| 367 | data_index(i) = i+data_begin; |
---|
| 368 | else |
---|
| 369 | data_index(i) = -1; |
---|
| 370 | } |
---|
| 371 | else |
---|
| 372 | data_index(i) = -1; |
---|
| 373 | } |
---|
[551] | 374 | } |
---|
[1637] | 375 | else |
---|
| 376 | { |
---|
| 377 | if (data_index.numElements() != data_n) |
---|
| 378 | { |
---|
| 379 | ERROR("CAxis::checkData(void)", |
---|
| 380 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 381 | << "The size of data_index = "<< data_index.numElements() << "is not equal to the data size data_n = " << data_n.getValue() << ")."); |
---|
| 382 | } |
---|
| 383 | for (int i = 0; i < data_n; ++i) |
---|
| 384 | { |
---|
[1872] | 385 | if (data_index(i) >= 0 && data_index(i)<n) |
---|
| 386 | if (!mask(data_index(i))) data_index(i) = -1; |
---|
[1637] | 387 | } |
---|
| 388 | } |
---|
| 389 | |
---|
[551] | 390 | } |
---|
[1622] | 391 | CATCH_DUMP_ATTR |
---|
[551] | 392 | |
---|
[1215] | 393 | size_t CAxis::getGlobalWrittenSize(void) |
---|
| 394 | { |
---|
[1559] | 395 | return n_glo ; |
---|
[1215] | 396 | } |
---|
| 397 | |
---|
[1144] | 398 | /*! |
---|
| 399 | Check validity of mask info and fill in values if any. |
---|
| 400 | */ |
---|
[551] | 401 | void CAxis::checkMask() |
---|
[1622] | 402 | TRY |
---|
[551] | 403 | { |
---|
| 404 | if (!mask.isEmpty()) |
---|
| 405 | { |
---|
[1637] | 406 | if (mask.extent(0) != n) |
---|
| 407 | { |
---|
| 408 | ERROR("CAxis::checkMask(void)", |
---|
| 409 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 410 | << "The mask does not have the same size as the local domain." << std::endl |
---|
| 411 | << "Local size is " << n.getValue() << "." << std::endl |
---|
| 412 | << "Mask size is " << mask.extent(0) << "."); |
---|
| 413 | } |
---|
[551] | 414 | } |
---|
[1637] | 415 | else |
---|
| 416 | { |
---|
| 417 | mask.resize(n); |
---|
| 418 | mask = true; |
---|
[551] | 419 | } |
---|
| 420 | } |
---|
[1622] | 421 | CATCH_DUMP_ATTR |
---|
[551] | 422 | |
---|
[1144] | 423 | /*! |
---|
| 424 | Check validity of bounds info and fill in values if any. |
---|
| 425 | */ |
---|
| 426 | void CAxis::checkBounds() |
---|
[1622] | 427 | TRY |
---|
[1144] | 428 | { |
---|
| 429 | if (!bounds.isEmpty()) |
---|
| 430 | { |
---|
| 431 | if (bounds.extent(0) != 2 || bounds.extent(1) != n) |
---|
| 432 | ERROR("CAxis::checkAttributes(void)", |
---|
| 433 | << "The bounds array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension 2 x axis size." << std::endl |
---|
| 434 | << "Axis size is " << n.getValue() << "." << std::endl |
---|
| 435 | << "Bounds size is "<< bounds.extent(0) << " x " << bounds.extent(1) << "."); |
---|
[1235] | 436 | hasBounds = true; |
---|
[1144] | 437 | } |
---|
[1235] | 438 | else hasBounds = false; |
---|
[1144] | 439 | } |
---|
[1622] | 440 | CATCH_DUMP_ATTR |
---|
[633] | 441 | |
---|
[1158] | 442 | void CAxis::checkLabel() |
---|
[1622] | 443 | TRY |
---|
[1158] | 444 | { |
---|
| 445 | if (!label.isEmpty()) |
---|
| 446 | { |
---|
| 447 | if (label.extent(0) != n) |
---|
| 448 | ERROR("CAxis::checkLabel(void)", |
---|
| 449 | << "The label array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension of axis size." << std::endl |
---|
| 450 | << "Axis size is " << n.getValue() << "." << std::endl |
---|
| 451 | << "label size is "<< label.extent(0)<< " ."); |
---|
| 452 | hasLabel = true; |
---|
| 453 | } |
---|
| 454 | else hasLabel = false; |
---|
| 455 | } |
---|
[1622] | 456 | CATCH_DUMP_ATTR |
---|
[1202] | 457 | |
---|
[1235] | 458 | /*! |
---|
| 459 | Check whether we can do compressed output |
---|
| 460 | */ |
---|
[1158] | 461 | void CAxis::checkEligibilityForCompressedOutput() |
---|
[1622] | 462 | TRY |
---|
[1158] | 463 | { |
---|
| 464 | // We don't check if the mask is valid here, just if a mask has been defined at this point. |
---|
| 465 | isCompressible_ = !mask.isEmpty(); |
---|
| 466 | } |
---|
[1622] | 467 | CATCH_DUMP_ATTR |
---|
[633] | 468 | |
---|
[1235] | 469 | /*! |
---|
| 470 | Dispatch event from the lower communication layer then process event according to its type |
---|
| 471 | */ |
---|
| 472 | bool CAxis::dispatchEvent(CEventServer& event) |
---|
[1622] | 473 | TRY |
---|
[1235] | 474 | { |
---|
| 475 | if (SuperClass::dispatchEvent(event)) return true; |
---|
| 476 | else |
---|
| 477 | { |
---|
| 478 | switch(event.type) |
---|
| 479 | { |
---|
| 480 | case EVENT_ID_DISTRIBUTION_ATTRIBUTE : |
---|
| 481 | recvDistributionAttribute(event); |
---|
[633] | 482 | return true; |
---|
| 483 | break; |
---|
[1235] | 484 | case EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES: |
---|
| 485 | recvNonDistributedAttributes(event); |
---|
| 486 | return true; |
---|
| 487 | break; |
---|
| 488 | case EVENT_ID_DISTRIBUTED_ATTRIBUTES: |
---|
| 489 | recvDistributedAttributes(event); |
---|
| 490 | return true; |
---|
| 491 | break; |
---|
| 492 | default : |
---|
| 493 | ERROR("bool CAxis::dispatchEvent(CEventServer& event)", |
---|
| 494 | << "Unknown Event"); |
---|
| 495 | return false; |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | } |
---|
[1622] | 499 | CATCH |
---|
[567] | 500 | |
---|
[1144] | 501 | /*! |
---|
| 502 | Check attributes on client side (This name is still adequate???) |
---|
| 503 | */ |
---|
[742] | 504 | void CAxis::checkAttributesOnClient() |
---|
[1622] | 505 | TRY |
---|
[567] | 506 | { |
---|
| 507 | if (this->areClientAttributesChecked_) return; |
---|
[595] | 508 | |
---|
[1421] | 509 | CContext* context=CContext::getCurrent(); |
---|
[1853] | 510 | if (context->getServiceType()==CServicesManager::CLIENT) this->checkAttributes(); |
---|
[567] | 511 | |
---|
| 512 | this->areClientAttributesChecked_ = true; |
---|
| 513 | } |
---|
[1622] | 514 | CATCH_DUMP_ATTR |
---|
[567] | 515 | |
---|
[1144] | 516 | /* |
---|
[1235] | 517 | The (spatial) transformation sometimes can change attributes of an axis (e.g zoom can change mask or generate can change whole attributes) |
---|
| 518 | Therefore, we should recheck them. |
---|
[1144] | 519 | */ |
---|
[1869] | 520 | // ym : obsolete to be removed |
---|
[927] | 521 | void CAxis::checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 522 | CServerDistributionDescription::ServerDistributionType distType) |
---|
[1622] | 523 | TRY |
---|
[927] | 524 | { |
---|
| 525 | CContext* context=CContext::getCurrent() ; |
---|
| 526 | |
---|
| 527 | if (this->isClientAfterTransformationChecked) return; |
---|
[1853] | 528 | if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) |
---|
[1235] | 529 | { |
---|
[1869] | 530 | /* suppressed because of interface changed |
---|
[1258] | 531 | if (orderPositionInGrid == CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), distType)) |
---|
| 532 | computeConnectedClients(globalDim, orderPositionInGrid, distType); |
---|
| 533 | else if (index.numElements() != n_glo) computeConnectedClients(globalDim, orderPositionInGrid, CServerDistributionDescription::ROOT_DISTRIBUTION); |
---|
[1869] | 534 | */ |
---|
[927] | 535 | } |
---|
| 536 | |
---|
| 537 | this->isClientAfterTransformationChecked = true; |
---|
| 538 | } |
---|
[1622] | 539 | CATCH_DUMP_ATTR |
---|
[927] | 540 | |
---|
[1235] | 541 | /* |
---|
| 542 | Send all checked attributes to server? (We dont have notion of server any more so client==server) |
---|
| 543 | \param [in] globalDim global dimension of grid containing this axis |
---|
| 544 | \param [in] orderPositionInGrid the relative order of this axis in the grid (e.g grid composed of domain+axis -> orderPositionInGrid is 2) |
---|
| 545 | \param [in] distType distribution type of the server. For now, we only have band distribution. |
---|
| 546 | |
---|
| 547 | */ |
---|
[1870] | 548 | //ym obsolete : to be removed |
---|
[567] | 549 | void CAxis::sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 550 | CServerDistributionDescription::ServerDistributionType distType) |
---|
[1622] | 551 | TRY |
---|
[567] | 552 | { |
---|
[742] | 553 | if (!this->areClientAttributesChecked_) checkAttributesOnClient(); |
---|
[927] | 554 | if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation(globalDim, orderPositionInGrid, distType); |
---|
[595] | 555 | CContext* context = CContext::getCurrent(); |
---|
[567] | 556 | |
---|
| 557 | if (this->isChecked) return; |
---|
[1870] | 558 | if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) /*sendAttributes(globalDim, orderPositionInGrid, distType)*/; |
---|
[567] | 559 | |
---|
| 560 | this->isChecked = true; |
---|
| 561 | } |
---|
[1622] | 562 | CATCH_DUMP_ATTR |
---|
[567] | 563 | |
---|
[1870] | 564 | |
---|
| 565 | void CAxis::sendAxisToFileServer(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) |
---|
| 566 | { |
---|
| 567 | if (sendAxisToFileServer_done_.count(client)!=0) return ; |
---|
| 568 | else sendAxisToFileServer_done_.insert(client) ; |
---|
| 569 | |
---|
| 570 | StdString axisDefRoot("axis_definition"); |
---|
| 571 | CAxisGroup* axisPtr = CAxisGroup::get(axisDefRoot); |
---|
| 572 | axisPtr->sendCreateChild(this->getId(),client); |
---|
| 573 | this->sendAllAttributesToServer(client) ; |
---|
| 574 | this->sendAttributes(client, globalDim, orderPositionInGrid, CServerDistributionDescription::BAND_DISTRIBUTION) ; |
---|
| 575 | } |
---|
| 576 | |
---|
[1875] | 577 | void CAxis::sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) |
---|
| 578 | { |
---|
| 579 | if (sendAxisToFileServer_done_.count(client)!=0) return ; |
---|
| 580 | else sendAxisToFileServer_done_.insert(client) ; |
---|
| 581 | |
---|
| 582 | string axisId="_axis["+std::to_string(posInGrid)+"]_of_"+fieldId ; |
---|
| 583 | |
---|
| 584 | if (!axis_ref.isEmpty()) |
---|
| 585 | { |
---|
| 586 | auto axis_ref_tmp=axis_ref.getValue() ; |
---|
| 587 | axis_ref.reset() ; // remove the reference, find an other way to do that more cleanly |
---|
| 588 | this->sendAllAttributesToServer(client, axisId) ; |
---|
| 589 | axis_ref = axis_ref_tmp ; |
---|
| 590 | } |
---|
| 591 | else this->sendAllAttributesToServer(client, axisId) ; |
---|
| 592 | |
---|
| 593 | this->sendAttributes(client, globalDim, orderPositionInGrid, CServerDistributionDescription::BAND_DISTRIBUTION, axisId) ; |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | void CAxis::makeAliasForCoupling(const string& fieldId, int posInGrid) |
---|
| 597 | { |
---|
| 598 | const string axisId = "_axis["+std::to_string(posInGrid)+"]_of_"+fieldId ; |
---|
| 599 | this->createAlias(axisId) ; |
---|
| 600 | } |
---|
| 601 | |
---|
[1144] | 602 | /*! |
---|
| 603 | Send attributes from one client to other clients |
---|
| 604 | \param[in] globalDim global dimension of grid which contains this axis |
---|
| 605 | \param[in] order |
---|
| 606 | */ |
---|
[1870] | 607 | void CAxis::sendAttributes(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
[1875] | 608 | CServerDistributionDescription::ServerDistributionType distType, const string& axisId) |
---|
[1622] | 609 | TRY |
---|
[633] | 610 | { |
---|
[1875] | 611 | sendDistributionAttribute(client, globalDim, orderPositionInGrid, distType, axisId); |
---|
[1235] | 612 | |
---|
| 613 | // if (index.numElements() == n_glo.getValue()) |
---|
| 614 | if ((orderPositionInGrid == CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), distType)) |
---|
| 615 | || (index.numElements() != n_glo)) |
---|
[1099] | 616 | { |
---|
[1875] | 617 | sendDistributedAttributes(client, axisId); |
---|
[1099] | 618 | } |
---|
[1235] | 619 | else |
---|
| 620 | { |
---|
[1875] | 621 | sendNonDistributedAttributes(client, axisId); |
---|
[1235] | 622 | } |
---|
[633] | 623 | } |
---|
[1622] | 624 | CATCH_DUMP_ATTR |
---|
[633] | 625 | |
---|
[1235] | 626 | /* |
---|
| 627 | Compute the connection between group of clients (or clients/servers). |
---|
| 628 | (E.g: Suppose we have 2 group of clients in two model: A (client role) connect to B (server role), |
---|
| 629 | this function calculate number of clients B connect to one client of A) |
---|
| 630 | \param [in] globalDim global dimension of grid containing this axis |
---|
| 631 | \param [in] orderPositionInGrid the relative order of this axis in the grid (e.g grid composed of domain+axis -> orderPositionInGrid is 2) |
---|
| 632 | \param [in] distType distribution type of the server. For now, we only have band distribution. |
---|
| 633 | */ |
---|
[1869] | 634 | void CAxis::computeConnectedClients(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) |
---|
[1622] | 635 | TRY |
---|
[633] | 636 | { |
---|
[1869] | 637 | if (computeConnectedClients_done_.count(client)!=0) return ; |
---|
| 638 | else computeConnectedClients_done_.insert(client) ; |
---|
| 639 | |
---|
[633] | 640 | CContext* context = CContext::getCurrent(); |
---|
[1869] | 641 | CServerDistributionDescription::ServerDistributionType distType ; |
---|
| 642 | int defaultDistributedPos = CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), CServerDistributionDescription::BAND_DISTRIBUTION) ; |
---|
| 643 | |
---|
| 644 | if (orderPositionInGrid == defaultDistributedPos) distType = CServerDistributionDescription::BAND_DISTRIBUTION ; |
---|
| 645 | else if (index.numElements() != n_glo) distType = CServerDistributionDescription::ROOT_DISTRIBUTION ; |
---|
| 646 | else return ; |
---|
[1099] | 647 | |
---|
[1869] | 648 | int nbServer = client->serverSize; |
---|
| 649 | int range, clientSize = client->clientSize; |
---|
| 650 | int rank = client->clientRank; |
---|
[1236] | 651 | |
---|
[1869] | 652 | if (listNbServer_.count(nbServer) == 0) |
---|
[667] | 653 | { |
---|
[1869] | 654 | listNbServer_.insert(nbServer) ; |
---|
[667] | 655 | |
---|
[1869] | 656 | if (connectedServerRank_.find(nbServer) != connectedServerRank_.end()) |
---|
[1346] | 657 | { |
---|
[1869] | 658 | nbSenders.erase(nbServer); |
---|
| 659 | connectedServerRank_.erase(nbServer); |
---|
| 660 | } |
---|
[1784] | 661 | |
---|
[1869] | 662 | size_t ni = this->n.getValue(); |
---|
| 663 | size_t ibegin = this->begin.getValue(); |
---|
| 664 | size_t nbIndex = index.numElements(); |
---|
[1099] | 665 | |
---|
[1869] | 666 | // First of all, we should compute the mapping of the global index and local index of the current client |
---|
| 667 | if (globalLocalIndexMap_.empty()) |
---|
| 668 | { |
---|
| 669 | for (size_t idx = 0; idx < nbIndex; ++idx) |
---|
[1235] | 670 | { |
---|
[1869] | 671 | globalLocalIndexMap_[index(idx)] = idx; |
---|
[1235] | 672 | } |
---|
[1869] | 673 | } |
---|
[1235] | 674 | |
---|
[1869] | 675 | // Calculate the compressed index if any |
---|
| 676 | // std::set<int> writtenInd; |
---|
| 677 | // if (isCompressible_) |
---|
| 678 | // { |
---|
| 679 | // for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 680 | // { |
---|
| 681 | // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); |
---|
| 682 | // |
---|
| 683 | // if (ind >= 0 && ind < ni && mask(ind)) |
---|
| 684 | // { |
---|
| 685 | // ind += ibegin; |
---|
| 686 | // writtenInd.insert(ind); |
---|
| 687 | // } |
---|
| 688 | // } |
---|
| 689 | // } |
---|
[1099] | 690 | |
---|
[1869] | 691 | // Compute the global index of the current client (process) hold |
---|
| 692 | std::vector<int> nGlobAxis(1); |
---|
| 693 | nGlobAxis[0] = n_glo.getValue(); |
---|
[1235] | 694 | |
---|
[1869] | 695 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 696 | for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; |
---|
| 697 | indexBegin = 0; |
---|
| 698 | if (globalSizeIndex <= clientSize) |
---|
| 699 | { |
---|
| 700 | indexBegin = rank%globalSizeIndex; |
---|
| 701 | indexEnd = indexBegin; |
---|
| 702 | } |
---|
| 703 | else |
---|
| 704 | { |
---|
| 705 | for (int i = 0; i < clientSize; ++i) |
---|
[906] | 706 | { |
---|
[1869] | 707 | range = globalSizeIndex / clientSize; |
---|
| 708 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 709 | if (i == client->clientRank) break; |
---|
| 710 | indexBegin += range; |
---|
[906] | 711 | } |
---|
[1869] | 712 | indexEnd = indexBegin + range - 1; |
---|
| 713 | } |
---|
[815] | 714 | |
---|
[1869] | 715 | CArray<size_t,1> globalIndex(index.numElements()); |
---|
| 716 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 717 | globalIndex(idx) = index(idx); |
---|
[1235] | 718 | |
---|
[1869] | 719 | // Describe the distribution of server side |
---|
[1258] | 720 | |
---|
[1869] | 721 | CServerDistributionDescription serverDescription(nGlobAxis, nbServer, distType); |
---|
| 722 | |
---|
| 723 | std::vector<int> serverZeroIndex; |
---|
| 724 | serverZeroIndex = serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t&,size_t&>(indexBegin, indexEnd), 0); |
---|
[1235] | 725 | |
---|
[1869] | 726 | std::list<int> serverZeroIndexLeader; |
---|
| 727 | std::list<int> serverZeroIndexNotLeader; |
---|
| 728 | CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); |
---|
| 729 | for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 730 | *it = serverZeroIndex[*it]; |
---|
[1235] | 731 | |
---|
[1869] | 732 | // Find out the connection between client and server side |
---|
| 733 | CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); |
---|
| 734 | clientServerMap->computeServerIndexMapping(globalIndex, nbServer); |
---|
| 735 | CClientServerMapping::GlobalIndexMap& globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); |
---|
[1235] | 736 | |
---|
[1869] | 737 | indSrv_[nbServer].swap(globalIndexAxisOnServer); |
---|
[1235] | 738 | |
---|
[1869] | 739 | if (distType==CServerDistributionDescription::ROOT_DISTRIBUTION) |
---|
| 740 | { |
---|
| 741 | for(int i=1; i<nbServer; ++i) indSrv_[nbServer].insert(pair<int, vector<size_t> >(i,indSrv_[nbServer][0]) ) ; |
---|
| 742 | serverZeroIndexLeader.clear() ; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | CClientServerMapping::GlobalIndexMap::const_iterator it = indSrv_[nbServer].begin(), |
---|
| 746 | ite = indSrv_[nbServer].end(); |
---|
[1025] | 747 | |
---|
[1869] | 748 | for (it = indSrv_[nbServer].begin(); it != ite; ++it) connectedServerRank_[nbServer].push_back(it->first); |
---|
[1258] | 749 | |
---|
[1869] | 750 | for (std::list<int>::const_iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 751 | connectedServerRank_[nbServer].push_back(*it); |
---|
[1235] | 752 | |
---|
[1869] | 753 | // Even if a client has no index, it must connect to at least one server and |
---|
| 754 | // send an "empty" data to this server |
---|
| 755 | if (connectedServerRank_[nbServer].empty()) |
---|
| 756 | connectedServerRank_[nbServer].push_back(client->clientRank % client->serverSize); |
---|
[1235] | 757 | |
---|
[1869] | 758 | nbSenders[nbServer] = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[nbServer]); |
---|
[1235] | 759 | |
---|
[1869] | 760 | delete clientServerMap; |
---|
[633] | 761 | } |
---|
| 762 | } |
---|
[1622] | 763 | CATCH_DUMP_ATTR |
---|
[633] | 764 | |
---|
[1235] | 765 | /* |
---|
| 766 | Compute the index of data to write into file |
---|
| 767 | (Different from the previous version, this version of XIOS allows data be written into file (classical role), |
---|
| 768 | or transfered to another clients) |
---|
| 769 | */ |
---|
| 770 | void CAxis::computeWrittenIndex() |
---|
[1622] | 771 | TRY |
---|
[1235] | 772 | { |
---|
| 773 | if (computedWrittenIndex_) return; |
---|
| 774 | computedWrittenIndex_ = true; |
---|
[633] | 775 | |
---|
[1235] | 776 | CContext* context=CContext::getCurrent(); |
---|
[1129] | 777 | |
---|
[1235] | 778 | // We describe the distribution of client (server) on which data are written |
---|
| 779 | std::vector<int> nBegin(1), nSize(1), nBeginGlobal(1), nGlob(1); |
---|
[1561] | 780 | nBegin[0] = begin; |
---|
[1559] | 781 | nSize[0] = n; |
---|
[1235] | 782 | nBeginGlobal[0] = 0; |
---|
| 783 | nGlob[0] = n_glo; |
---|
[1853] | 784 | CDistributionServer srvDist(context->intraCommSize_, nBegin, nSize, nBeginGlobal, nGlob); |
---|
[1235] | 785 | const CArray<size_t,1>& writtenGlobalIndex = srvDist.getGlobalIndex(); |
---|
[1129] | 786 | |
---|
[1235] | 787 | // Because all written data are local on a client, |
---|
| 788 | // we need to compute the local index on the server from its corresponding global index |
---|
| 789 | size_t nbWritten = 0, indGlo; |
---|
[1542] | 790 | std::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), |
---|
[1235] | 791 | ite = globalLocalIndexMap_.end(), it; |
---|
| 792 | CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), |
---|
| 793 | itSrve = writtenGlobalIndex.end(), itSrv; |
---|
[1143] | 794 | |
---|
[1559] | 795 | localIndexToWriteOnServer.resize(writtenGlobalIndex.numElements()); |
---|
| 796 | nbWritten = 0; |
---|
| 797 | for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) |
---|
[1235] | 798 | { |
---|
[1559] | 799 | indGlo = *itSrv; |
---|
| 800 | if (ite != globalLocalIndexMap_.find(indGlo)) |
---|
[1129] | 801 | { |
---|
[1559] | 802 | localIndexToWriteOnServer(nbWritten) = globalLocalIndexMap_[indGlo]; |
---|
[1235] | 803 | } |
---|
[1637] | 804 | else |
---|
| 805 | { |
---|
| 806 | localIndexToWriteOnServer(nbWritten) = -1; |
---|
| 807 | } |
---|
| 808 | ++nbWritten; |
---|
[1235] | 809 | } |
---|
[1637] | 810 | |
---|
[1249] | 811 | } |
---|
[1622] | 812 | CATCH_DUMP_ATTR |
---|
[1249] | 813 | |
---|
[1639] | 814 | void CAxis::computeWrittenCompressedIndex(MPI_Comm writtenComm) |
---|
[1622] | 815 | TRY |
---|
[1249] | 816 | { |
---|
| 817 | int writtenCommSize; |
---|
[1639] | 818 | MPI_Comm_size(writtenComm, &writtenCommSize); |
---|
[1249] | 819 | if (compressedIndexToWriteOnServer.find(writtenCommSize) != compressedIndexToWriteOnServer.end()) |
---|
| 820 | return; |
---|
| 821 | |
---|
[1235] | 822 | if (isCompressible()) |
---|
| 823 | { |
---|
[1249] | 824 | size_t nbWritten = 0, indGlo; |
---|
| 825 | CContext* context=CContext::getCurrent(); |
---|
[1853] | 826 | |
---|
[1249] | 827 | // We describe the distribution of client (server) on which data are written |
---|
| 828 | std::vector<int> nBegin(1), nSize(1), nBeginGlobal(1), nGlob(1); |
---|
[1559] | 829 | nBegin[0] = 0; |
---|
| 830 | nSize[0] = n; |
---|
[1249] | 831 | nBeginGlobal[0] = 0; |
---|
| 832 | nGlob[0] = n_glo; |
---|
[1853] | 833 | CDistributionServer srvDist(context->intraCommSize_, nBegin, nSize, nBeginGlobal, nGlob); |
---|
[1249] | 834 | const CArray<size_t,1>& writtenGlobalIndex = srvDist.getGlobalIndex(); |
---|
[1542] | 835 | std::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), |
---|
[1249] | 836 | ite = globalLocalIndexMap_.end(), it; |
---|
| 837 | |
---|
| 838 | CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), |
---|
| 839 | itSrve = writtenGlobalIndex.end(), itSrv; |
---|
[1542] | 840 | std::unordered_map<size_t,size_t> localGlobalIndexMap; |
---|
[1235] | 841 | for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) |
---|
[1143] | 842 | { |
---|
[1235] | 843 | indGlo = *itSrv; |
---|
| 844 | if (ite != globalLocalIndexMap_.find(indGlo)) |
---|
[1143] | 845 | { |
---|
[1235] | 846 | localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; |
---|
| 847 | ++nbWritten; |
---|
| 848 | } |
---|
| 849 | } |
---|
[1637] | 850 | // |
---|
| 851 | // nbWritten = 0; |
---|
| 852 | // for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 853 | // { |
---|
| 854 | // if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_index(idx))) |
---|
| 855 | // { |
---|
| 856 | // ++nbWritten; |
---|
| 857 | // } |
---|
| 858 | // } |
---|
| 859 | // |
---|
| 860 | // compressedIndexToWriteOnServer[writtenCommSize].resize(nbWritten); |
---|
| 861 | // nbWritten = 0; |
---|
| 862 | // for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 863 | // { |
---|
| 864 | // if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_index(idx))) |
---|
| 865 | // { |
---|
| 866 | // compressedIndexToWriteOnServer[writtenCommSize](nbWritten) = localGlobalIndexMap[data_index(idx)]; |
---|
| 867 | // ++nbWritten; |
---|
| 868 | // } |
---|
| 869 | // } |
---|
[1143] | 870 | |
---|
[1235] | 871 | nbWritten = 0; |
---|
| 872 | for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 873 | { |
---|
| 874 | if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_index(idx))) |
---|
[1143] | 875 | { |
---|
[1235] | 876 | ++nbWritten; |
---|
[1143] | 877 | } |
---|
[1235] | 878 | } |
---|
[1143] | 879 | |
---|
[1249] | 880 | compressedIndexToWriteOnServer[writtenCommSize].resize(nbWritten); |
---|
[1235] | 881 | nbWritten = 0; |
---|
| 882 | for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 883 | { |
---|
| 884 | if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_index(idx))) |
---|
[1143] | 885 | { |
---|
[1249] | 886 | compressedIndexToWriteOnServer[writtenCommSize](nbWritten) = localGlobalIndexMap[data_index(idx)]; |
---|
[1235] | 887 | ++nbWritten; |
---|
[1143] | 888 | } |
---|
[1235] | 889 | } |
---|
[1143] | 890 | |
---|
[1249] | 891 | numberWrittenIndexes_[writtenCommSize] = nbWritten; |
---|
[1761] | 892 | |
---|
| 893 | bool distributed_glo, distributed=isDistributed() ; |
---|
| 894 | MPI_Allreduce(&distributed,&distributed_glo, 1, MPI_INT, MPI_LOR, writtenComm) ; |
---|
| 895 | if (distributed_glo) |
---|
[1235] | 896 | { |
---|
| 897 | |
---|
[1639] | 898 | MPI_Allreduce(&numberWrittenIndexes_[writtenCommSize], &totalNumberWrittenIndexes_[writtenCommSize], 1, MPI_INT, MPI_SUM, writtenComm); |
---|
| 899 | MPI_Scan(&numberWrittenIndexes_[writtenCommSize], &offsetWrittenIndexes_[writtenCommSize], 1, MPI_INT, MPI_SUM, writtenComm); |
---|
[1249] | 900 | offsetWrittenIndexes_[writtenCommSize] -= numberWrittenIndexes_[writtenCommSize]; |
---|
[1143] | 901 | } |
---|
[1235] | 902 | else |
---|
[1249] | 903 | totalNumberWrittenIndexes_[writtenCommSize] = numberWrittenIndexes_[writtenCommSize]; |
---|
[1235] | 904 | } |
---|
| 905 | } |
---|
[1622] | 906 | CATCH_DUMP_ATTR |
---|
[1143] | 907 | |
---|
[1235] | 908 | /*! |
---|
| 909 | Send distribution information from a group of client (client role) to another group of client (server role) |
---|
| 910 | The distribution of a group of client (server role) is imposed by the group of client (client role) |
---|
| 911 | \param [in] globalDim global dimension of grid containing this axis |
---|
| 912 | \param [in] orderPositionInGrid the relative order of this axis in the grid (e.g grid composed of domain+axis -> orderPositionInGrid is 2) |
---|
| 913 | \param [in] distType distribution type of the server. For now, we only have band distribution. |
---|
| 914 | */ |
---|
[1870] | 915 | void CAxis::sendDistributionAttribute(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
[1875] | 916 | CServerDistributionDescription::ServerDistributionType distType, const string& axisId) |
---|
[1622] | 917 | TRY |
---|
[1099] | 918 | { |
---|
[1875] | 919 | string serverAxisId = axisId.empty() ? this->getId() : axisId ; |
---|
[1870] | 920 | int nbServer = client->serverSize; |
---|
[1099] | 921 | |
---|
[1870] | 922 | CServerDistributionDescription serverDescription(globalDim, nbServer); |
---|
| 923 | serverDescription.computeServerDistribution(); |
---|
[1099] | 924 | |
---|
[1870] | 925 | std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); |
---|
| 926 | std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); |
---|
[1099] | 927 | |
---|
[1870] | 928 | CEventClient event(getType(),EVENT_ID_DISTRIBUTION_ATTRIBUTE); |
---|
| 929 | if (client->isServerLeader()) |
---|
| 930 | { |
---|
| 931 | std::list<CMessage> msgs; |
---|
| 932 | |
---|
| 933 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 934 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1099] | 935 | { |
---|
[1870] | 936 | // Use const int to ensure CMessage holds a copy of the value instead of just a reference |
---|
| 937 | const int begin = serverIndexBegin[*itRank][orderPositionInGrid]; |
---|
| 938 | const int ni = serverDimensionSizes[*itRank][orderPositionInGrid]; |
---|
[1099] | 939 | |
---|
[1870] | 940 | msgs.push_back(CMessage()); |
---|
| 941 | CMessage& msg = msgs.back(); |
---|
[1875] | 942 | msg << serverAxisId; |
---|
[1870] | 943 | msg << ni << begin; |
---|
| 944 | msg << isCompressible_; |
---|
[1099] | 945 | |
---|
[1870] | 946 | event.push(*itRank,1,msg); |
---|
[1099] | 947 | } |
---|
[1870] | 948 | client->sendEvent(event); |
---|
[1099] | 949 | } |
---|
[1870] | 950 | else client->sendEvent(event); |
---|
[1099] | 951 | } |
---|
[1622] | 952 | CATCH_DUMP_ATTR |
---|
[1099] | 953 | |
---|
[1235] | 954 | /* |
---|
| 955 | Receive distribution attribute from another client |
---|
| 956 | \param [in] event event containing data of these attributes |
---|
| 957 | */ |
---|
| 958 | void CAxis::recvDistributionAttribute(CEventServer& event) |
---|
[1622] | 959 | TRY |
---|
[1235] | 960 | { |
---|
| 961 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 962 | string axisId; |
---|
| 963 | *buffer >> axisId; |
---|
| 964 | get(axisId)->recvDistributionAttribute(*buffer); |
---|
| 965 | } |
---|
[1622] | 966 | CATCH |
---|
[1235] | 967 | |
---|
| 968 | /* |
---|
| 969 | Receive distribution attribute from another client |
---|
| 970 | \param [in] buffer buffer containing data of these attributes |
---|
| 971 | */ |
---|
| 972 | void CAxis::recvDistributionAttribute(CBufferIn& buffer) |
---|
[1622] | 973 | TRY |
---|
[1235] | 974 | { |
---|
[1566] | 975 | int ni_srv, begin_srv; |
---|
| 976 | buffer >> ni_srv >> begin_srv; |
---|
[1235] | 977 | buffer >> isCompressible_; |
---|
| 978 | |
---|
| 979 | // Set up new local size of axis on the receiving clients |
---|
| 980 | n.setValue(ni_srv); |
---|
| 981 | begin.setValue(begin_srv); |
---|
| 982 | } |
---|
[1622] | 983 | CATCH_DUMP_ATTR |
---|
[1235] | 984 | |
---|
| 985 | /* |
---|
| 986 | Send attributes of axis from a group of client to other group of clients/servers |
---|
| 987 | on supposing that these attributes are not distributed among the sending group |
---|
| 988 | In the future, if new attributes are added, they should also be processed in this function |
---|
| 989 | */ |
---|
[1875] | 990 | void CAxis::sendNonDistributedAttributes(CContextClient* client, const string& axisId) |
---|
[1622] | 991 | TRY |
---|
[1025] | 992 | { |
---|
[1875] | 993 | string serverAxisId = axisId.empty() ? this->getId() : axisId ; |
---|
| 994 | |
---|
[1870] | 995 | CEventClient event(getType(), EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES); |
---|
| 996 | size_t nbIndex = index.numElements(); |
---|
| 997 | size_t nbDataIndex = 0; |
---|
[1099] | 998 | |
---|
[1870] | 999 | for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 1000 | { |
---|
| 1001 | int ind = data_index(idx); |
---|
| 1002 | if (ind >= 0 && ind < nbIndex) ++nbDataIndex; |
---|
| 1003 | } |
---|
[633] | 1004 | |
---|
[1870] | 1005 | CArray<int,1> dataIndex(nbDataIndex); |
---|
| 1006 | nbDataIndex = 0; |
---|
| 1007 | for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 1008 | { |
---|
| 1009 | int ind = data_index(idx); |
---|
| 1010 | if (ind >= 0 && ind < nbIndex) |
---|
[676] | 1011 | { |
---|
[1870] | 1012 | dataIndex(nbDataIndex) = ind; |
---|
| 1013 | ++nbDataIndex; |
---|
[1027] | 1014 | } |
---|
[1870] | 1015 | } |
---|
[676] | 1016 | |
---|
[1870] | 1017 | if (client->isServerLeader()) |
---|
| 1018 | { |
---|
| 1019 | std::list<CMessage> msgs; |
---|
[633] | 1020 | |
---|
[1870] | 1021 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1022 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[633] | 1023 | { |
---|
[1870] | 1024 | msgs.push_back(CMessage()); |
---|
| 1025 | CMessage& msg = msgs.back(); |
---|
[1875] | 1026 | msg << serverAxisId; |
---|
[1870] | 1027 | msg << index.getValue() << dataIndex << mask.getValue(); |
---|
| 1028 | msg << hasValue; |
---|
| 1029 | if (hasValue) msg << value.getValue(); |
---|
| 1030 | msg << hasBounds; |
---|
| 1031 | if (hasBounds) msg << bounds.getValue(); |
---|
| 1032 | msg << hasLabel; |
---|
| 1033 | if (hasLabel) msg << label.getValue(); |
---|
[1025] | 1034 | |
---|
[1870] | 1035 | event.push(*itRank, 1, msg); |
---|
[633] | 1036 | } |
---|
[1870] | 1037 | client->sendEvent(event); |
---|
[633] | 1038 | } |
---|
[1870] | 1039 | else client->sendEvent(event); |
---|
[633] | 1040 | } |
---|
[1622] | 1041 | CATCH_DUMP_ATTR |
---|
[633] | 1042 | |
---|
[1235] | 1043 | /* |
---|
| 1044 | Receive the non-distributed attributes from another group of clients |
---|
| 1045 | \param [in] event event containing data of these attributes |
---|
| 1046 | */ |
---|
[1025] | 1047 | void CAxis::recvNonDistributedAttributes(CEventServer& event) |
---|
[1622] | 1048 | TRY |
---|
[633] | 1049 | { |
---|
[1025] | 1050 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 1051 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 1052 | { |
---|
| 1053 | CBufferIn* buffer = it->buffer; |
---|
| 1054 | string axisId; |
---|
| 1055 | *buffer >> axisId; |
---|
| 1056 | get(axisId)->recvNonDistributedAttributes(it->rank, *buffer); |
---|
| 1057 | } |
---|
| 1058 | } |
---|
[1622] | 1059 | CATCH |
---|
[1025] | 1060 | |
---|
[1235] | 1061 | /* |
---|
| 1062 | Receive the non-distributed attributes from another group of clients |
---|
| 1063 | \param [in] rank rank of the sender |
---|
| 1064 | \param [in] buffer buffer containing data sent from the sender |
---|
| 1065 | */ |
---|
[1025] | 1066 | void CAxis::recvNonDistributedAttributes(int rank, CBufferIn& buffer) |
---|
[1622] | 1067 | TRY |
---|
[1025] | 1068 | { |
---|
[1559] | 1069 | CArray<int,1> tmp_index, tmp_data_index; |
---|
[1025] | 1070 | CArray<bool,1> tmp_mask; |
---|
| 1071 | CArray<double,1> tmp_val; |
---|
| 1072 | CArray<double,2> tmp_bnds; |
---|
[1235] | 1073 | CArray<string,1> tmp_label; |
---|
[1025] | 1074 | |
---|
| 1075 | buffer >> tmp_index; |
---|
| 1076 | index.reference(tmp_index); |
---|
| 1077 | buffer >> tmp_data_index; |
---|
| 1078 | data_index.reference(tmp_data_index); |
---|
| 1079 | buffer >> tmp_mask; |
---|
| 1080 | mask.reference(tmp_mask); |
---|
[1129] | 1081 | |
---|
[1025] | 1082 | buffer >> hasValue; |
---|
| 1083 | if (hasValue) |
---|
| 1084 | { |
---|
| 1085 | buffer >> tmp_val; |
---|
| 1086 | value.reference(tmp_val); |
---|
| 1087 | } |
---|
| 1088 | |
---|
[1235] | 1089 | buffer >> hasBounds; |
---|
| 1090 | if (hasBounds) |
---|
[1025] | 1091 | { |
---|
| 1092 | buffer >> tmp_bnds; |
---|
| 1093 | bounds.reference(tmp_bnds); |
---|
| 1094 | } |
---|
| 1095 | |
---|
[1235] | 1096 | buffer >> hasLabel; |
---|
| 1097 | if (hasLabel) |
---|
| 1098 | { |
---|
| 1099 | buffer >> tmp_label; |
---|
| 1100 | label.reference(tmp_label); |
---|
| 1101 | } |
---|
| 1102 | |
---|
| 1103 | // Some value should be reset here |
---|
[1129] | 1104 | data_begin.setValue(0); |
---|
[1871] | 1105 | data_n.setValue(data_index.numElements()); |
---|
[1129] | 1106 | globalLocalIndexMap_.rehash(std::ceil(index.numElements()/globalLocalIndexMap_.max_load_factor())); |
---|
[1416] | 1107 | // for (int idx = 0; idx < index.numElements(); ++idx) globalLocalIndexMap_[idx] = index(idx); |
---|
| 1108 | for (int idx = 0; idx < index.numElements(); ++idx) globalLocalIndexMap_[index(idx)] = idx; |
---|
[1025] | 1109 | } |
---|
[1622] | 1110 | CATCH_DUMP_ATTR |
---|
[1025] | 1111 | |
---|
[1235] | 1112 | /* |
---|
[1637] | 1113 | Send axis attributes from a group of clients to another group of clients/servers |
---|
| 1114 | supposing that these attributes are distributed among the clients of the sending group |
---|
| 1115 | In future, if new attributes are added, they should also be processed in this function |
---|
[1235] | 1116 | */ |
---|
[1875] | 1117 | void CAxis::sendDistributedAttributes(CContextClient* client, const string& axisId) |
---|
[1622] | 1118 | TRY |
---|
[1025] | 1119 | { |
---|
[1875] | 1120 | string serverAxisId = axisId.empty() ? this->getId() : axisId ; |
---|
| 1121 | |
---|
[1637] | 1122 | int ind, idx; |
---|
[1870] | 1123 | int nbServer = client->serverSize; |
---|
[1345] | 1124 | |
---|
[1870] | 1125 | CEventClient eventData(getType(), EVENT_ID_DISTRIBUTED_ATTRIBUTES); |
---|
| 1126 | |
---|
| 1127 | list<CMessage> listData; |
---|
| 1128 | list<CArray<int,1> > list_indi, list_dataInd; |
---|
| 1129 | list<CArray<double,1> > list_val; |
---|
| 1130 | list<CArray<double,2> > list_bounds; |
---|
| 1131 | list<CArray<string,1> > list_label; |
---|
| 1132 | |
---|
| 1133 | // Cut off the ghost points |
---|
| 1134 | int nbIndex = index.numElements(); |
---|
| 1135 | CArray<int,1> dataIndex(nbIndex); |
---|
| 1136 | dataIndex = -1; |
---|
| 1137 | for (idx = 0; idx < data_index.numElements(); ++idx) |
---|
[1025] | 1138 | { |
---|
[1870] | 1139 | if (0 <= data_index(idx) && data_index(idx) < nbIndex) |
---|
| 1140 | dataIndex(data_index(idx)) = 1; |
---|
| 1141 | } |
---|
[1025] | 1142 | |
---|
[1870] | 1143 | std::unordered_map<int, std::vector<size_t> >::const_iterator it, iteMap; |
---|
| 1144 | iteMap = indSrv_[nbServer].end(); |
---|
| 1145 | for (int k = 0; k < connectedServerRank_[nbServer].size(); ++k) |
---|
| 1146 | { |
---|
| 1147 | int nbData = 0, nbDataCount = 0; |
---|
| 1148 | int rank = connectedServerRank_[nbServer][k]; |
---|
| 1149 | it = indSrv_[nbServer].find(rank); |
---|
| 1150 | if (iteMap != it) |
---|
| 1151 | nbData = it->second.size(); |
---|
[633] | 1152 | |
---|
[1870] | 1153 | list_indi.push_back(CArray<int,1>(nbData)); |
---|
| 1154 | list_dataInd.push_back(CArray<int,1>(nbData)); |
---|
[633] | 1155 | |
---|
[1870] | 1156 | if (hasValue) |
---|
| 1157 | list_val.push_back(CArray<double,1>(nbData)); |
---|
[633] | 1158 | |
---|
[1870] | 1159 | if (hasBounds) |
---|
| 1160 | list_bounds.push_back(CArray<double,2>(2,nbData)); |
---|
| 1161 | |
---|
| 1162 | if (hasLabel) |
---|
| 1163 | list_label.push_back(CArray<string,1>(nbData)); |
---|
| 1164 | |
---|
| 1165 | CArray<int,1>& indi = list_indi.back(); |
---|
| 1166 | CArray<int,1>& dataIndi = list_dataInd.back(); |
---|
| 1167 | dataIndi = -1; |
---|
| 1168 | |
---|
| 1169 | for (int n = 0; n < nbData; ++n) |
---|
[633] | 1170 | { |
---|
[1870] | 1171 | idx = static_cast<int>(it->second[n]); |
---|
| 1172 | indi(n) = idx; |
---|
[633] | 1173 | |
---|
[1870] | 1174 | ind = globalLocalIndexMap_[idx]; |
---|
| 1175 | dataIndi(n) = dataIndex(ind); |
---|
[1025] | 1176 | |
---|
| 1177 | if (hasValue) |
---|
[1870] | 1178 | { |
---|
| 1179 | CArray<double,1>& val = list_val.back(); |
---|
| 1180 | val(n) = value(ind); |
---|
| 1181 | } |
---|
[1027] | 1182 | |
---|
[1870] | 1183 | if (hasBounds) |
---|
| 1184 | { |
---|
| 1185 | CArray<double,2>& boundsVal = list_bounds.back(); |
---|
| 1186 | boundsVal(0, n) = bounds(0,ind); |
---|
| 1187 | boundsVal(1, n) = bounds(1,ind); |
---|
| 1188 | } |
---|
[1025] | 1189 | |
---|
[1235] | 1190 | if (hasLabel) |
---|
[633] | 1191 | { |
---|
[1870] | 1192 | CArray<string,1>& labelVal = list_label.back(); |
---|
| 1193 | labelVal(n) = label(ind); |
---|
[633] | 1194 | } |
---|
[1870] | 1195 | } |
---|
[1027] | 1196 | |
---|
[1870] | 1197 | listData.push_back(CMessage()); |
---|
[1875] | 1198 | listData.back() << serverAxisId |
---|
[1870] | 1199 | << list_indi.back() << list_dataInd.back(); |
---|
[1099] | 1200 | |
---|
[1870] | 1201 | listData.back() << hasValue; |
---|
| 1202 | if (hasValue) |
---|
| 1203 | listData.back() << list_val.back(); |
---|
[1099] | 1204 | |
---|
[1870] | 1205 | listData.back() << hasBounds; |
---|
| 1206 | if (hasBounds) |
---|
| 1207 | listData.back() << list_bounds.back(); |
---|
[1027] | 1208 | |
---|
[1870] | 1209 | listData.back() << hasLabel; |
---|
| 1210 | if (hasLabel) |
---|
| 1211 | listData.back() << list_label.back(); |
---|
[1235] | 1212 | |
---|
[1870] | 1213 | eventData.push(rank, nbSenders[nbServer][rank], listData.back()); |
---|
| 1214 | } |
---|
[633] | 1215 | |
---|
[1870] | 1216 | client->sendEvent(eventData); |
---|
[633] | 1217 | } |
---|
[1622] | 1218 | CATCH_DUMP_ATTR |
---|
[633] | 1219 | |
---|
[1235] | 1220 | /* |
---|
| 1221 | Receive the distributed attributes from another group of clients |
---|
| 1222 | \param [in] event event containing data of these attributes |
---|
| 1223 | */ |
---|
[1025] | 1224 | void CAxis::recvDistributedAttributes(CEventServer& event) |
---|
[1622] | 1225 | TRY |
---|
[633] | 1226 | { |
---|
[1025] | 1227 | string axisId; |
---|
| 1228 | vector<int> ranks; |
---|
| 1229 | vector<CBufferIn*> buffers; |
---|
[676] | 1230 | |
---|
[633] | 1231 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 1232 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 1233 | { |
---|
[1025] | 1234 | ranks.push_back(it->rank); |
---|
[633] | 1235 | CBufferIn* buffer = it->buffer; |
---|
[676] | 1236 | *buffer >> axisId; |
---|
[1025] | 1237 | buffers.push_back(buffer); |
---|
[633] | 1238 | } |
---|
[1025] | 1239 | get(axisId)->recvDistributedAttributes(ranks, buffers); |
---|
[633] | 1240 | } |
---|
[1622] | 1241 | CATCH |
---|
[633] | 1242 | |
---|
[1235] | 1243 | /* |
---|
| 1244 | Receive the non-distributed attributes from another group of clients |
---|
| 1245 | \param [in] ranks rank of the sender |
---|
| 1246 | \param [in] buffers buffer containing data sent from the sender |
---|
| 1247 | */ |
---|
[1025] | 1248 | void CAxis::recvDistributedAttributes(vector<int>& ranks, vector<CBufferIn*> buffers) |
---|
[1622] | 1249 | TRY |
---|
[633] | 1250 | { |
---|
[1235] | 1251 | int nbReceived = ranks.size(), idx, ind, gloInd, locInd; |
---|
[1559] | 1252 | vector<CArray<int,1> > vec_indi(nbReceived), vec_dataInd(nbReceived); |
---|
[1025] | 1253 | vector<CArray<double,1> > vec_val(nbReceived); |
---|
| 1254 | vector<CArray<double,2> > vec_bounds(nbReceived); |
---|
[1235] | 1255 | vector<CArray<string,1> > vec_label(nbReceived); |
---|
[1025] | 1256 | |
---|
[1235] | 1257 | for (idx = 0; idx < nbReceived; ++idx) |
---|
[1025] | 1258 | { |
---|
| 1259 | CBufferIn& buffer = *buffers[idx]; |
---|
| 1260 | buffer >> vec_indi[idx]; |
---|
[1099] | 1261 | buffer >> vec_dataInd[idx]; |
---|
[676] | 1262 | |
---|
[1025] | 1263 | buffer >> hasValue; |
---|
| 1264 | if (hasValue) |
---|
| 1265 | buffer >> vec_val[idx]; |
---|
[1099] | 1266 | |
---|
[1235] | 1267 | buffer >> hasBounds; |
---|
| 1268 | if (hasBounds) |
---|
[1025] | 1269 | buffer >> vec_bounds[idx]; |
---|
[1235] | 1270 | |
---|
| 1271 | buffer >> hasLabel; |
---|
| 1272 | if (hasLabel) |
---|
| 1273 | buffer >> vec_label[idx]; |
---|
[676] | 1274 | } |
---|
[633] | 1275 | |
---|
[1235] | 1276 | // Estimate size of index array |
---|
| 1277 | int nbIndexGlob = 0; |
---|
| 1278 | for (idx = 0; idx < nbReceived; ++idx) |
---|
[633] | 1279 | { |
---|
[1235] | 1280 | nbIndexGlob += vec_indi[idx].numElements(); |
---|
[633] | 1281 | } |
---|
[1129] | 1282 | |
---|
[1235] | 1283 | // Recompute global index |
---|
| 1284 | // Take account of the overlapped index |
---|
| 1285 | index.resize(nbIndexGlob); |
---|
[1129] | 1286 | globalLocalIndexMap_.rehash(std::ceil(index.numElements()/globalLocalIndexMap_.max_load_factor())); |
---|
[1235] | 1287 | nbIndexGlob = 0; |
---|
[1566] | 1288 | int nbIndLoc = 0; |
---|
[1235] | 1289 | for (idx = 0; idx < nbReceived; ++idx) |
---|
| 1290 | { |
---|
| 1291 | CArray<int,1>& tmp = vec_indi[idx]; |
---|
| 1292 | for (ind = 0; ind < tmp.numElements(); ++ind) |
---|
| 1293 | { |
---|
| 1294 | gloInd = tmp(ind); |
---|
[1566] | 1295 | nbIndLoc = (gloInd % n_glo)-begin; |
---|
[1235] | 1296 | if (0 == globalLocalIndexMap_.count(gloInd)) |
---|
| 1297 | { |
---|
[1637] | 1298 | index(nbIndexGlob) = gloInd % n_glo; |
---|
| 1299 | globalLocalIndexMap_[gloInd] = nbIndexGlob; |
---|
[1235] | 1300 | ++nbIndexGlob; |
---|
| 1301 | } |
---|
| 1302 | } |
---|
| 1303 | } |
---|
| 1304 | |
---|
| 1305 | // Resize index to its real size |
---|
[1301] | 1306 | if (nbIndexGlob==0) index.resize(nbIndexGlob) ; |
---|
| 1307 | else index.resizeAndPreserve(nbIndexGlob); |
---|
[1235] | 1308 | |
---|
| 1309 | int nbData = nbIndexGlob; |
---|
| 1310 | CArray<int,1> nonCompressedData(nbData); |
---|
| 1311 | nonCompressedData = -1; |
---|
[1637] | 1312 | // Mask is incorporated into data_index and is not sent/received anymore |
---|
[1872] | 1313 | mask.reset(); |
---|
[1025] | 1314 | if (hasValue) |
---|
| 1315 | value.resize(nbData); |
---|
[1235] | 1316 | if (hasBounds) |
---|
[1025] | 1317 | bounds.resize(2,nbData); |
---|
[1235] | 1318 | if (hasLabel) |
---|
| 1319 | label.resize(nbData); |
---|
[633] | 1320 | |
---|
[1025] | 1321 | nbData = 0; |
---|
[1235] | 1322 | for (idx = 0; idx < nbReceived; ++idx) |
---|
[633] | 1323 | { |
---|
[1025] | 1324 | CArray<int,1>& indi = vec_indi[idx]; |
---|
| 1325 | CArray<int,1>& dataIndi = vec_dataInd[idx]; |
---|
| 1326 | int nb = indi.numElements(); |
---|
| 1327 | for (int n = 0; n < nb; ++n) |
---|
[1235] | 1328 | { |
---|
| 1329 | locInd = globalLocalIndexMap_[size_t(indi(n))]; |
---|
| 1330 | |
---|
| 1331 | nonCompressedData(locInd) = (-1 == nonCompressedData(locInd)) ? dataIndi(n) : nonCompressedData(locInd); |
---|
| 1332 | |
---|
[1025] | 1333 | if (hasValue) |
---|
[1235] | 1334 | value(locInd) = vec_val[idx](n); |
---|
| 1335 | |
---|
| 1336 | if (hasBounds) |
---|
[1025] | 1337 | { |
---|
[1235] | 1338 | bounds(0,locInd) = vec_bounds[idx](0,n); |
---|
| 1339 | bounds(1,locInd) = vec_bounds[idx](1,n); |
---|
[1025] | 1340 | } |
---|
[1235] | 1341 | |
---|
| 1342 | if (hasLabel) |
---|
| 1343 | label(locInd) = vec_label[idx](n); |
---|
[633] | 1344 | } |
---|
| 1345 | } |
---|
[1235] | 1346 | |
---|
[1637] | 1347 | int nbCompressedData = 0; |
---|
[1235] | 1348 | for (idx = 0; idx < nonCompressedData.numElements(); ++idx) |
---|
[1025] | 1349 | { |
---|
[1235] | 1350 | if (0 <= nonCompressedData(idx)) |
---|
[1637] | 1351 | ++nbCompressedData; |
---|
[1025] | 1352 | } |
---|
[676] | 1353 | |
---|
[1025] | 1354 | data_index.resize(nbCompressedData); |
---|
| 1355 | nbCompressedData = 0; |
---|
[1235] | 1356 | for (idx = 0; idx < nonCompressedData.numElements(); ++idx) |
---|
[633] | 1357 | { |
---|
[1235] | 1358 | if (0 <= nonCompressedData(idx)) |
---|
[1025] | 1359 | { |
---|
[1235] | 1360 | data_index(nbCompressedData) = idx % n; |
---|
[1637] | 1361 | ++nbCompressedData; |
---|
[1025] | 1362 | } |
---|
[633] | 1363 | } |
---|
[1235] | 1364 | |
---|
[1129] | 1365 | data_begin.setValue(0); |
---|
[1637] | 1366 | data_n.setValue(data_index.numElements()); |
---|
[633] | 1367 | } |
---|
[1622] | 1368 | CATCH_DUMP_ATTR |
---|
[633] | 1369 | |
---|
[1158] | 1370 | /*! |
---|
| 1371 | Compare two axis objects. |
---|
| 1372 | They are equal if only if they have identical attributes as well as their values. |
---|
| 1373 | Moreover, they must have the same transformations. |
---|
| 1374 | \param [in] axis Compared axis |
---|
| 1375 | \return result of the comparison |
---|
| 1376 | */ |
---|
| 1377 | bool CAxis::isEqual(CAxis* obj) |
---|
[1622] | 1378 | TRY |
---|
[1158] | 1379 | { |
---|
| 1380 | vector<StdString> excludedAttr; |
---|
| 1381 | excludedAttr.push_back("axis_ref"); |
---|
[987] | 1382 | |
---|
[1158] | 1383 | bool objEqual = SuperClass::isEqual(obj, excludedAttr); |
---|
| 1384 | if (!objEqual) return objEqual; |
---|
| 1385 | |
---|
| 1386 | TransMapTypes thisTrans = this->getAllTransformations(); |
---|
| 1387 | TransMapTypes objTrans = obj->getAllTransformations(); |
---|
| 1388 | |
---|
| 1389 | TransMapTypes::const_iterator it, itb, ite; |
---|
| 1390 | std::vector<ETranformationType> thisTransType, objTransType; |
---|
| 1391 | for (it = thisTrans.begin(); it != thisTrans.end(); ++it) |
---|
| 1392 | thisTransType.push_back(it->first); |
---|
| 1393 | for (it = objTrans.begin(); it != objTrans.end(); ++it) |
---|
| 1394 | objTransType.push_back(it->first); |
---|
| 1395 | |
---|
| 1396 | if (thisTransType.size() != objTransType.size()) return false; |
---|
| 1397 | for (int idx = 0; idx < thisTransType.size(); ++idx) |
---|
| 1398 | objEqual &= (thisTransType[idx] == objTransType[idx]); |
---|
| 1399 | |
---|
| 1400 | return objEqual; |
---|
| 1401 | } |
---|
[1622] | 1402 | CATCH_DUMP_ATTR |
---|
[1158] | 1403 | |
---|
[1235] | 1404 | /* |
---|
| 1405 | Add transformation into axis. This function only servers for Fortran interface |
---|
| 1406 | \param [in] transType transformation type |
---|
| 1407 | \param [in] id identifier of the transformation object |
---|
| 1408 | */ |
---|
[836] | 1409 | CTransformation<CAxis>* CAxis::addTransformation(ETranformationType transType, const StdString& id) |
---|
[1622] | 1410 | TRY |
---|
[836] | 1411 | { |
---|
| 1412 | transformationMap_.push_back(std::make_pair(transType, CTransformation<CAxis>::createTransformation(transType,id))); |
---|
| 1413 | return transformationMap_.back().second; |
---|
| 1414 | } |
---|
[1622] | 1415 | CATCH_DUMP_ATTR |
---|
[836] | 1416 | |
---|
[1235] | 1417 | /* |
---|
| 1418 | Check whether an axis has (spatial) transformation |
---|
| 1419 | */ |
---|
[619] | 1420 | bool CAxis::hasTransformation() |
---|
[1622] | 1421 | TRY |
---|
[619] | 1422 | { |
---|
[621] | 1423 | return (!transformationMap_.empty()); |
---|
[619] | 1424 | } |
---|
[1622] | 1425 | CATCH_DUMP_ATTR |
---|
[619] | 1426 | |
---|
[1235] | 1427 | /* |
---|
| 1428 | Set transformation |
---|
| 1429 | \param [in] axisTrans transformation to set |
---|
| 1430 | */ |
---|
[621] | 1431 | void CAxis::setTransformations(const TransMapTypes& axisTrans) |
---|
[1622] | 1432 | TRY |
---|
[619] | 1433 | { |
---|
[621] | 1434 | transformationMap_ = axisTrans; |
---|
[619] | 1435 | } |
---|
[1622] | 1436 | CATCH_DUMP_ATTR |
---|
[619] | 1437 | |
---|
[1235] | 1438 | /* |
---|
| 1439 | Return all transformation held by the axis |
---|
| 1440 | \return transformation the axis has |
---|
| 1441 | */ |
---|
[621] | 1442 | CAxis::TransMapTypes CAxis::getAllTransformations(void) |
---|
[1622] | 1443 | TRY |
---|
[620] | 1444 | { |
---|
[621] | 1445 | return transformationMap_; |
---|
| 1446 | } |
---|
[1622] | 1447 | CATCH_DUMP_ATTR |
---|
[620] | 1448 | |
---|
[1235] | 1449 | /* |
---|
| 1450 | Duplicate transformation of another axis |
---|
| 1451 | \param [in] src axis whose transformations are copied |
---|
| 1452 | */ |
---|
[823] | 1453 | void CAxis::duplicateTransformation(CAxis* src) |
---|
[1622] | 1454 | TRY |
---|
[823] | 1455 | { |
---|
| 1456 | if (src->hasTransformation()) |
---|
| 1457 | { |
---|
| 1458 | this->setTransformations(src->getAllTransformations()); |
---|
| 1459 | } |
---|
| 1460 | } |
---|
[1622] | 1461 | CATCH_DUMP_ATTR |
---|
[823] | 1462 | |
---|
[747] | 1463 | /*! |
---|
| 1464 | * Go through the hierarchy to find the axis from which the transformations must be inherited |
---|
| 1465 | */ |
---|
[619] | 1466 | void CAxis::solveInheritanceTransformation() |
---|
[1622] | 1467 | TRY |
---|
[619] | 1468 | { |
---|
[747] | 1469 | if (hasTransformation() || !hasDirectAxisReference()) |
---|
| 1470 | return; |
---|
[619] | 1471 | |
---|
[747] | 1472 | CAxis* axis = this; |
---|
[619] | 1473 | std::vector<CAxis*> refAxis; |
---|
[747] | 1474 | while (!axis->hasTransformation() && axis->hasDirectAxisReference()) |
---|
[619] | 1475 | { |
---|
[747] | 1476 | refAxis.push_back(axis); |
---|
| 1477 | axis = axis->getDirectAxisReference(); |
---|
[619] | 1478 | } |
---|
| 1479 | |
---|
[747] | 1480 | if (axis->hasTransformation()) |
---|
| 1481 | for (size_t i = 0; i < refAxis.size(); ++i) |
---|
| 1482 | refAxis[i]->setTransformations(axis->getAllTransformations()); |
---|
[619] | 1483 | } |
---|
[1622] | 1484 | CATCH_DUMP_ATTR |
---|
[619] | 1485 | |
---|
[1345] | 1486 | void CAxis::setContextClient(CContextClient* contextClient) |
---|
[1622] | 1487 | TRY |
---|
[1345] | 1488 | { |
---|
[1353] | 1489 | if (clientsSet.find(contextClient)==clientsSet.end()) |
---|
| 1490 | { |
---|
| 1491 | clients.push_back(contextClient) ; |
---|
| 1492 | clientsSet.insert(contextClient); |
---|
| 1493 | } |
---|
[1622] | 1494 | } |
---|
| 1495 | CATCH_DUMP_ATTR |
---|
[1345] | 1496 | |
---|
[619] | 1497 | void CAxis::parse(xml::CXMLNode & node) |
---|
[1622] | 1498 | TRY |
---|
[619] | 1499 | { |
---|
| 1500 | SuperClass::parse(node); |
---|
| 1501 | |
---|
| 1502 | if (node.goToChildElement()) |
---|
| 1503 | { |
---|
[836] | 1504 | StdString nodeElementName; |
---|
[619] | 1505 | do |
---|
| 1506 | { |
---|
[784] | 1507 | StdString nodeId(""); |
---|
| 1508 | if (node.getAttributes().end() != node.getAttributes().find("id")) |
---|
| 1509 | { nodeId = node.getAttributes()["id"]; } |
---|
| 1510 | |
---|
[836] | 1511 | nodeElementName = node.getElementName(); |
---|
| 1512 | std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it; |
---|
| 1513 | it = transformationMapList_.find(nodeElementName); |
---|
| 1514 | if (ite != it) |
---|
| 1515 | { |
---|
| 1516 | transformationMap_.push_back(std::make_pair(it->second, CTransformation<CAxis>::createTransformation(it->second, |
---|
| 1517 | nodeId, |
---|
| 1518 | &node))); |
---|
[786] | 1519 | } |
---|
[968] | 1520 | else |
---|
| 1521 | { |
---|
| 1522 | ERROR("void CAxis::parse(xml::CXMLNode & node)", |
---|
| 1523 | << "The transformation " << nodeElementName << " has not been supported yet."); |
---|
| 1524 | } |
---|
[619] | 1525 | } while (node.goToNextElement()) ; |
---|
| 1526 | node.goToParentElement(); |
---|
| 1527 | } |
---|
| 1528 | } |
---|
[1622] | 1529 | CATCH_DUMP_ATTR |
---|
[619] | 1530 | |
---|
[620] | 1531 | DEFINE_REF_FUNC(Axis,axis) |
---|
[619] | 1532 | |
---|
[219] | 1533 | ///--------------------------------------------------------------- |
---|
| 1534 | |
---|
[335] | 1535 | } // namespace xios |
---|