[219] | 1 | #include "domain.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[219] | 6 | |
---|
[591] | 7 | #include "xios_spl.hpp" |
---|
[300] | 8 | #include "event_client.hpp" |
---|
| 9 | #include "event_server.hpp" |
---|
| 10 | #include "buffer_in.hpp" |
---|
[352] | 11 | #include "message.hpp" |
---|
| 12 | #include "type.hpp" |
---|
| 13 | #include "context.hpp" |
---|
| 14 | #include "context_client.hpp" |
---|
[676] | 15 | #include "context_server.hpp" |
---|
[369] | 16 | #include "array_new.hpp" |
---|
[676] | 17 | #include "distribution_client.hpp" |
---|
[553] | 18 | #include "server_distribution_description.hpp" |
---|
[569] | 19 | #include "client_server_mapping_distributed.hpp" |
---|
[274] | 20 | |
---|
[676] | 21 | #include <algorithm> |
---|
| 22 | |
---|
[335] | 23 | namespace xios { |
---|
[509] | 24 | |
---|
[1328] | 25 | /// ////////////////////// Définitions ////////////////////// /// |
---|
[219] | 26 | |
---|
| 27 | CDomain::CDomain(void) |
---|
| 28 | : CObjectTemplate<CDomain>(), CDomainAttributes() |
---|
[1460] | 29 | , isChecked(false), relFiles(), isClientChecked(false), nbSenders(), indSrv_(), connectedServerRank_() |
---|
| 30 | , hasBounds(false), hasArea(false), isCompressible_(false), isUnstructed_(false) |
---|
[665] | 31 | , isClientAfterTransformationChecked(false), hasLonLat(false) |
---|
[1642] | 32 | , isRedistributed_(false), hasPole(false) |
---|
[1460] | 33 | , lonvalue(), latvalue(), bounds_lonvalue(), bounds_latvalue() |
---|
| 34 | , globalLocalIndexMap_(), computedWrittenIndex_(false) |
---|
[1642] | 35 | , clients(), hasLatInReadFile_(false), hasBoundsLatInReadFile_(false) |
---|
| 36 | , hasLonInReadFile_(false), hasBoundsLonInReadFile_(false) |
---|
[878] | 37 | { |
---|
[924] | 38 | } |
---|
[219] | 39 | |
---|
| 40 | CDomain::CDomain(const StdString & id) |
---|
| 41 | : CObjectTemplate<CDomain>(id), CDomainAttributes() |
---|
[1460] | 42 | , isChecked(false), relFiles(), isClientChecked(false), nbSenders(), indSrv_(), connectedServerRank_() |
---|
| 43 | , hasBounds(false), hasArea(false), isCompressible_(false), isUnstructed_(false) |
---|
[665] | 44 | , isClientAfterTransformationChecked(false), hasLonLat(false) |
---|
[1642] | 45 | , isRedistributed_(false), hasPole(false) |
---|
[1460] | 46 | , lonvalue(), latvalue(), bounds_lonvalue(), bounds_latvalue() |
---|
| 47 | , globalLocalIndexMap_(), computedWrittenIndex_(false) |
---|
[1642] | 48 | , clients(), hasLatInReadFile_(false), hasBoundsLatInReadFile_(false) |
---|
| 49 | , hasLonInReadFile_(false), hasBoundsLonInReadFile_(false) |
---|
[878] | 50 | { |
---|
[1460] | 51 | } |
---|
[219] | 52 | |
---|
| 53 | CDomain::~CDomain(void) |
---|
[509] | 54 | { |
---|
[219] | 55 | } |
---|
| 56 | |
---|
| 57 | ///--------------------------------------------------------------- |
---|
| 58 | |
---|
[924] | 59 | void CDomain::assignMesh(const StdString meshName, const int nvertex) |
---|
[1642] | 60 | TRY |
---|
[881] | 61 | { |
---|
[924] | 62 | mesh = CMesh::getMesh(meshName, nvertex); |
---|
[881] | 63 | } |
---|
[1642] | 64 | CATCH_DUMP_ATTR |
---|
[881] | 65 | |
---|
[622] | 66 | CDomain* CDomain::createDomain() |
---|
[1642] | 67 | TRY |
---|
[622] | 68 | { |
---|
| 69 | CDomain* domain = CDomainGroup::get("domain_definition")->createChild(); |
---|
| 70 | return domain; |
---|
| 71 | } |
---|
[1642] | 72 | CATCH |
---|
[622] | 73 | |
---|
[1642] | 74 | std::map<StdString, ETranformationType> CDomain::transformationMapList_ = std::map<StdString, ETranformationType>(); |
---|
| 75 | bool CDomain::_dummyTransformationMapList = CDomain::initializeTransformationMap(CDomain::transformationMapList_); |
---|
[836] | 76 | |
---|
| 77 | bool CDomain::initializeTransformationMap(std::map<StdString, ETranformationType>& m) |
---|
[1642] | 78 | TRY |
---|
[836] | 79 | { |
---|
| 80 | m["zoom_domain"] = TRANS_ZOOM_DOMAIN; |
---|
| 81 | m["interpolate_domain"] = TRANS_INTERPOLATE_DOMAIN; |
---|
| 82 | m["generate_rectilinear_domain"] = TRANS_GENERATE_RECTILINEAR_DOMAIN; |
---|
[934] | 83 | m["compute_connectivity_domain"] = TRANS_COMPUTE_CONNECTIVITY_DOMAIN; |
---|
[935] | 84 | m["expand_domain"] = TRANS_EXPAND_DOMAIN; |
---|
[1460] | 85 | m["reorder_domain"] = TRANS_REORDER_DOMAIN; |
---|
[1642] | 86 | m["extract_domain"] = TRANS_EXTRACT_DOMAIN; |
---|
[836] | 87 | } |
---|
[1642] | 88 | CATCH |
---|
[836] | 89 | |
---|
[219] | 90 | const std::set<StdString> & CDomain::getRelFiles(void) const |
---|
[1642] | 91 | TRY |
---|
[219] | 92 | { |
---|
[509] | 93 | return (this->relFiles); |
---|
[219] | 94 | } |
---|
[1642] | 95 | CATCH |
---|
[219] | 96 | |
---|
[676] | 97 | /*! |
---|
| 98 | Returns the number of indexes written by each server. |
---|
| 99 | \return the number of indexes written by each server |
---|
| 100 | */ |
---|
[1460] | 101 | int CDomain::getNumberWrittenIndexes(ep_lib::MPI_Comm writtenCom) |
---|
[1642] | 102 | TRY |
---|
[676] | 103 | { |
---|
[1460] | 104 | int writtenSize; |
---|
| 105 | ep_lib::MPI_Comm_size(writtenCom, &writtenSize); |
---|
| 106 | return numberWrittenIndexes_[writtenSize]; |
---|
[676] | 107 | } |
---|
[1642] | 108 | CATCH_DUMP_ATTR |
---|
[676] | 109 | |
---|
| 110 | /*! |
---|
| 111 | Returns the total number of indexes written by the servers. |
---|
| 112 | \return the total number of indexes written by the servers |
---|
| 113 | */ |
---|
[1460] | 114 | int CDomain::getTotalNumberWrittenIndexes(ep_lib::MPI_Comm writtenCom) |
---|
[1642] | 115 | TRY |
---|
[676] | 116 | { |
---|
[1460] | 117 | int writtenSize; |
---|
| 118 | ep_lib::MPI_Comm_size(writtenCom, &writtenSize); |
---|
| 119 | return totalNumberWrittenIndexes_[writtenSize]; |
---|
[676] | 120 | } |
---|
[1642] | 121 | CATCH_DUMP_ATTR |
---|
[676] | 122 | |
---|
| 123 | /*! |
---|
| 124 | Returns the offset of indexes written by each server. |
---|
| 125 | \return the offset of indexes written by each server |
---|
| 126 | */ |
---|
[1460] | 127 | int CDomain::getOffsetWrittenIndexes(ep_lib::MPI_Comm writtenCom) |
---|
[1642] | 128 | TRY |
---|
[676] | 129 | { |
---|
[1460] | 130 | int writtenSize; |
---|
| 131 | ep_lib::MPI_Comm_size(writtenCom, &writtenSize); |
---|
| 132 | return offsetWrittenIndexes_[writtenSize]; |
---|
[676] | 133 | } |
---|
[1642] | 134 | CATCH_DUMP_ATTR |
---|
[676] | 135 | |
---|
[1460] | 136 | CArray<int, 1>& CDomain::getCompressedIndexToWriteOnServer(ep_lib::MPI_Comm writtenCom) |
---|
[1642] | 137 | TRY |
---|
[1460] | 138 | { |
---|
| 139 | int writtenSize; |
---|
| 140 | ep_lib::MPI_Comm_size(writtenCom, &writtenSize); |
---|
| 141 | return compressedIndexToWriteOnServer[writtenSize]; |
---|
| 142 | } |
---|
[1642] | 143 | CATCH_DUMP_ATTR |
---|
[1460] | 144 | |
---|
[676] | 145 | //---------------------------------------------------------------- |
---|
| 146 | |
---|
[731] | 147 | /*! |
---|
| 148 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 149 | * |
---|
| 150 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 151 | */ |
---|
[1460] | 152 | std::map<int, StdSize> CDomain::getAttributesBufferSize(CContextClient* client, bool bufferForWriting /*= false*/) |
---|
[1642] | 153 | TRY |
---|
[731] | 154 | { |
---|
| 155 | |
---|
[1460] | 156 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(client); |
---|
[731] | 157 | |
---|
| 158 | if (client->isServerLeader()) |
---|
| 159 | { |
---|
[1460] | 160 | // size estimation for sendDistributionAttribut |
---|
[731] | 161 | size_t size = 11 * sizeof(size_t); |
---|
| 162 | |
---|
| 163 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 164 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 165 | { |
---|
| 166 | if (size > attributesSizes[*itRank]) |
---|
| 167 | attributesSizes[*itRank] = size; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
[1545] | 171 | std::unordered_map<int, vector<size_t> >::const_iterator itIndexEnd = indSrv_[client->serverSize].end(); |
---|
[1460] | 172 | // std::map<int, std::vector<int> >::const_iterator itWrittenIndexEnd = indWrittenSrv_.end(); |
---|
| 173 | for (size_t k = 0; k < connectedServerRank_[client->serverSize].size(); ++k) |
---|
[731] | 174 | { |
---|
[1460] | 175 | int rank = connectedServerRank_[client->serverSize][k]; |
---|
[1545] | 176 | std::unordered_map<int, std::vector<size_t> >::const_iterator it = indSrv_[client->serverSize].find(rank); |
---|
[764] | 177 | size_t idxCount = (it != itIndexEnd) ? it->second.size() : 0; |
---|
| 178 | |
---|
[731] | 179 | // size estimation for sendIndex (and sendArea which is always smaller or equal) |
---|
[764] | 180 | size_t sizeIndexEvent = 2 * sizeof(size_t) + 2 * CArray<int,1>::size(idxCount); |
---|
[731] | 181 | |
---|
| 182 | // size estimation for sendLonLat |
---|
[764] | 183 | size_t sizeLonLatEvent = CArray<double,1>::size(idxCount); |
---|
[731] | 184 | if (hasBounds) |
---|
[764] | 185 | sizeLonLatEvent += CArray<double,2>::size(nvertex * idxCount); |
---|
[731] | 186 | |
---|
| 187 | size_t size = CEventClient::headerSize + getId().size() + sizeof(size_t) + std::max(sizeIndexEvent, sizeLonLatEvent); |
---|
[764] | 188 | if (size > attributesSizes[rank]) |
---|
| 189 | attributesSizes[rank] = size; |
---|
[731] | 190 | } |
---|
| 191 | |
---|
| 192 | return attributesSizes; |
---|
| 193 | } |
---|
[1642] | 194 | CATCH_DUMP_ATTR |
---|
[731] | 195 | |
---|
| 196 | //---------------------------------------------------------------- |
---|
| 197 | |
---|
[219] | 198 | bool CDomain::isEmpty(void) const |
---|
[1642] | 199 | TRY |
---|
[219] | 200 | { |
---|
[1642] | 201 | return ((this->i_index.isEmpty()) || (0 == this->i_index.numElements())); |
---|
[219] | 202 | } |
---|
[1642] | 203 | CATCH |
---|
[219] | 204 | |
---|
| 205 | //---------------------------------------------------------------- |
---|
[676] | 206 | |
---|
[219] | 207 | bool CDomain::IsWritten(const StdString & filename) const |
---|
[1642] | 208 | TRY |
---|
[219] | 209 | { |
---|
| 210 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
| 211 | } |
---|
[1642] | 212 | CATCH |
---|
[219] | 213 | |
---|
[676] | 214 | bool CDomain::isWrittenCompressed(const StdString& filename) const |
---|
[1642] | 215 | TRY |
---|
[676] | 216 | { |
---|
| 217 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 218 | } |
---|
[1642] | 219 | CATCH |
---|
[676] | 220 | |
---|
[219] | 221 | //---------------------------------------------------------------- |
---|
[676] | 222 | |
---|
[594] | 223 | bool CDomain::isDistributed(void) const |
---|
[1642] | 224 | TRY |
---|
[594] | 225 | { |
---|
[1460] | 226 | bool distributed = !((!ni.isEmpty() && (ni == ni_glo) && !nj.isEmpty() && (nj == nj_glo)) || |
---|
| 227 | (!i_index.isEmpty() && i_index.numElements() == ni_glo*nj_glo)); |
---|
| 228 | distributed |= (1 == CContext::getCurrent()->client->clientSize); |
---|
| 229 | |
---|
| 230 | return distributed; |
---|
[594] | 231 | } |
---|
[1642] | 232 | CATCH |
---|
[594] | 233 | |
---|
| 234 | //---------------------------------------------------------------- |
---|
[676] | 235 | |
---|
| 236 | /*! |
---|
| 237 | * Test whether the data defined on the domain can be outputted in a compressed way. |
---|
[679] | 238 | * |
---|
[676] | 239 | * \return true if and only if a mask was defined for this domain |
---|
| 240 | */ |
---|
| 241 | bool CDomain::isCompressible(void) const |
---|
[1642] | 242 | TRY |
---|
[676] | 243 | { |
---|
| 244 | return isCompressible_; |
---|
| 245 | } |
---|
[1642] | 246 | CATCH |
---|
[676] | 247 | |
---|
[219] | 248 | void CDomain::addRelFile(const StdString & filename) |
---|
[1642] | 249 | TRY |
---|
[219] | 250 | { |
---|
| 251 | this->relFiles.insert(filename); |
---|
| 252 | } |
---|
[1642] | 253 | CATCH_DUMP_ATTR |
---|
[895] | 254 | |
---|
[676] | 255 | void CDomain::addRelFileCompressed(const StdString& filename) |
---|
[1642] | 256 | TRY |
---|
[676] | 257 | { |
---|
| 258 | this->relFilesCompressed.insert(filename); |
---|
| 259 | } |
---|
[1642] | 260 | CATCH_DUMP_ATTR |
---|
[219] | 261 | |
---|
| 262 | StdString CDomain::GetName(void) { return (StdString("domain")); } |
---|
| 263 | StdString CDomain::GetDefName(void){ return (CDomain::GetName()); } |
---|
| 264 | ENodeType CDomain::GetType(void) { return (eDomain); } |
---|
| 265 | |
---|
| 266 | //---------------------------------------------------------------- |
---|
| 267 | |
---|
[687] | 268 | /*! |
---|
[1064] | 269 | Verify if all distribution information of a domain are available |
---|
| 270 | This checking verifies the definition of distribution attributes (ni, nj, ibegin, jbegin) |
---|
| 271 | */ |
---|
| 272 | bool CDomain::distributionAttributesHaveValue() const |
---|
[1642] | 273 | TRY |
---|
[1064] | 274 | { |
---|
| 275 | bool hasValues = true; |
---|
| 276 | |
---|
| 277 | if (ni.isEmpty() && ibegin.isEmpty() && i_index.isEmpty()) |
---|
| 278 | { |
---|
| 279 | hasValues = false; |
---|
| 280 | return hasValues; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | return hasValues; |
---|
| 284 | } |
---|
[1642] | 285 | CATCH |
---|
[1064] | 286 | |
---|
| 287 | /*! |
---|
[1460] | 288 | Redistribute RECTILINEAR or CURVILINEAR domain with a number of local domains. |
---|
[687] | 289 | All attributes ni,nj,ibegin,jbegin (if defined) will be rewritten |
---|
| 290 | The optional attributes lonvalue, latvalue will be added. Because this function only serves (for now) |
---|
| 291 | for interpolation from unstructured domain to rectilinear one, range of latvalue is 0-360 and lonvalue is -90 - +90 |
---|
| 292 | \param [in] nbLocalDomain number of local domain on the domain destination |
---|
| 293 | */ |
---|
| 294 | void CDomain::redistribute(int nbLocalDomain) |
---|
[1642] | 295 | TRY |
---|
[687] | 296 | { |
---|
[715] | 297 | if (this->isRedistributed_) return; |
---|
[727] | 298 | |
---|
[783] | 299 | this->isRedistributed_ = true; |
---|
| 300 | CContext* context = CContext::getCurrent(); |
---|
[1460] | 301 | // For now the assumption is that secondary server pools consist of the same number of procs. |
---|
| 302 | // CHANGE the line below if the assumption changes. |
---|
| 303 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[0] : context->client; |
---|
[783] | 304 | int rankClient = client->clientRank; |
---|
| 305 | int rankOnDomain = rankClient%nbLocalDomain; |
---|
[687] | 306 | |
---|
[783] | 307 | if (ni_glo.isEmpty() || ni_glo <= 0 ) |
---|
| 308 | { |
---|
| 309 | ERROR("CDomain::redistribute(int nbLocalDomain)", |
---|
| 310 | << "[ Id = " << this->getId() << " ] " |
---|
| 311 | << "The global domain is badly defined," |
---|
| 312 | << " check the \'ni_glo\' value !") |
---|
| 313 | } |
---|
[687] | 314 | |
---|
[783] | 315 | if (nj_glo.isEmpty() || nj_glo <= 0 ) |
---|
| 316 | { |
---|
| 317 | ERROR("CDomain::redistribute(int nbLocalDomain)", |
---|
| 318 | << "[ Id = " << this->getId() << " ] " |
---|
| 319 | << "The global domain is badly defined," |
---|
| 320 | << " check the \'nj_glo\' value !") |
---|
| 321 | } |
---|
[687] | 322 | |
---|
[783] | 323 | if ((type_attr::rectilinear == type) || (type_attr::curvilinear == type)) |
---|
| 324 | { |
---|
[687] | 325 | int globalDomainSize = ni_glo * nj_glo; |
---|
| 326 | if (globalDomainSize <= nbLocalDomain) |
---|
| 327 | { |
---|
| 328 | for (int idx = 0; idx < nbLocalDomain; ++idx) |
---|
| 329 | { |
---|
| 330 | if (rankOnDomain < globalDomainSize) |
---|
| 331 | { |
---|
| 332 | int iIdx = rankOnDomain % ni_glo; |
---|
| 333 | int jIdx = rankOnDomain / ni_glo; |
---|
| 334 | ibegin.setValue(iIdx); jbegin.setValue(jIdx); |
---|
| 335 | ni.setValue(1); nj.setValue(1); |
---|
| 336 | } |
---|
| 337 | else |
---|
| 338 | { |
---|
| 339 | ibegin.setValue(0); jbegin.setValue(0); |
---|
| 340 | ni.setValue(0); nj.setValue(0); |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | } |
---|
| 344 | else |
---|
| 345 | { |
---|
[688] | 346 | float njGlo = nj_glo.getValue(); |
---|
| 347 | float niGlo = ni_glo.getValue(); |
---|
| 348 | int nbProcOnX, nbProcOnY, range; |
---|
| 349 | |
---|
[687] | 350 | // Compute (approximately) number of segment on x and y axis |
---|
[688] | 351 | float yOverXRatio = njGlo/niGlo; |
---|
| 352 | |
---|
[687] | 353 | nbProcOnX = std::ceil(std::sqrt(nbLocalDomain/yOverXRatio)); |
---|
| 354 | nbProcOnY = std::ceil(((float)nbLocalDomain)/nbProcOnX); |
---|
| 355 | |
---|
| 356 | // Simple distribution: Sweep from top to bottom, left to right |
---|
| 357 | // Calculate local begin on x |
---|
| 358 | std::vector<int> ibeginVec(nbProcOnX,0), jbeginVec(nbProcOnY,0); |
---|
| 359 | std::vector<int> niVec(nbProcOnX), njVec(nbProcOnY); |
---|
| 360 | for (int i = 1; i < nbProcOnX; ++i) |
---|
| 361 | { |
---|
| 362 | range = ni_glo / nbProcOnX; |
---|
| 363 | if (i < (ni_glo%nbProcOnX)) ++range; |
---|
| 364 | niVec[i-1] = range; |
---|
| 365 | ibeginVec[i] = ibeginVec[i-1] + niVec[i-1]; |
---|
| 366 | } |
---|
| 367 | niVec[nbProcOnX-1] = ni_glo - ibeginVec[nbProcOnX-1]; |
---|
| 368 | |
---|
| 369 | // Calculate local begin on y |
---|
| 370 | for (int j = 1; j < nbProcOnY; ++j) |
---|
| 371 | { |
---|
| 372 | range = nj_glo / nbProcOnY; |
---|
| 373 | if (j < (nj_glo%nbProcOnY)) ++range; |
---|
| 374 | njVec[j-1] = range; |
---|
| 375 | jbeginVec[j] = jbeginVec[j-1] + njVec[j-1]; |
---|
| 376 | } |
---|
| 377 | njVec[nbProcOnY-1] = nj_glo - jbeginVec[nbProcOnY-1]; |
---|
| 378 | |
---|
| 379 | // Now assign value to ni, ibegin, nj, jbegin |
---|
| 380 | int iIdx = rankOnDomain % nbProcOnX; |
---|
| 381 | int jIdx = rankOnDomain / nbProcOnX; |
---|
| 382 | |
---|
| 383 | if (rankOnDomain != (nbLocalDomain-1)) |
---|
| 384 | { |
---|
| 385 | ibegin.setValue(ibeginVec[iIdx]); |
---|
| 386 | jbegin.setValue(jbeginVec[jIdx]); |
---|
| 387 | nj.setValue(njVec[jIdx]); |
---|
| 388 | ni.setValue(niVec[iIdx]); |
---|
| 389 | } |
---|
| 390 | else // just merge all the remaining rectangle into the last one |
---|
| 391 | { |
---|
| 392 | ibegin.setValue(ibeginVec[iIdx]); |
---|
| 393 | jbegin.setValue(jbeginVec[jIdx]); |
---|
| 394 | nj.setValue(njVec[jIdx]); |
---|
| 395 | ni.setValue(ni_glo - ibeginVec[iIdx]); |
---|
| 396 | } |
---|
[1064] | 397 | } |
---|
[687] | 398 | } |
---|
[783] | 399 | else // unstructured domain |
---|
| 400 | { |
---|
[785] | 401 | if (this->i_index.isEmpty()) |
---|
| 402 | { |
---|
| 403 | int globalDomainSize = ni_glo * nj_glo; |
---|
| 404 | if (globalDomainSize <= nbLocalDomain) |
---|
[783] | 405 | { |
---|
[785] | 406 | for (int idx = 0; idx < nbLocalDomain; ++idx) |
---|
[783] | 407 | { |
---|
[785] | 408 | if (rankOnDomain < globalDomainSize) |
---|
| 409 | { |
---|
| 410 | int iIdx = rankOnDomain % ni_glo; |
---|
| 411 | int jIdx = rankOnDomain / ni_glo; |
---|
| 412 | ibegin.setValue(iIdx); jbegin.setValue(jIdx); |
---|
| 413 | ni.setValue(1); nj.setValue(1); |
---|
| 414 | } |
---|
| 415 | else |
---|
| 416 | { |
---|
| 417 | ibegin.setValue(0); jbegin.setValue(0); |
---|
| 418 | ni.setValue(0); nj.setValue(0); |
---|
| 419 | } |
---|
[783] | 420 | } |
---|
[785] | 421 | } |
---|
| 422 | else |
---|
| 423 | { |
---|
| 424 | float njGlo = nj_glo.getValue(); |
---|
| 425 | float niGlo = ni_glo.getValue(); |
---|
| 426 | std::vector<int> ibeginVec(nbLocalDomain,0); |
---|
| 427 | std::vector<int> niVec(nbLocalDomain); |
---|
| 428 | for (int i = 1; i < nbLocalDomain; ++i) |
---|
[783] | 429 | { |
---|
[785] | 430 | int range = ni_glo / nbLocalDomain; |
---|
| 431 | if (i < (ni_glo%nbLocalDomain)) ++range; |
---|
| 432 | niVec[i-1] = range; |
---|
| 433 | ibeginVec[i] = ibeginVec[i-1] + niVec[i-1]; |
---|
[783] | 434 | } |
---|
[785] | 435 | niVec[nbLocalDomain-1] = ni_glo - ibeginVec[nbLocalDomain-1]; |
---|
| 436 | |
---|
| 437 | int iIdx = rankOnDomain % nbLocalDomain; |
---|
| 438 | ibegin.setValue(ibeginVec[iIdx]); |
---|
| 439 | jbegin.setValue(0); |
---|
| 440 | ni.setValue(niVec[iIdx]); |
---|
| 441 | nj.setValue(1); |
---|
[783] | 442 | } |
---|
[1064] | 443 | |
---|
| 444 | i_index.resize(ni); |
---|
| 445 | for(int idx = 0; idx < ni; ++idx) i_index(idx)=ibegin+idx; |
---|
[783] | 446 | } |
---|
| 447 | else |
---|
| 448 | { |
---|
[785] | 449 | ibegin.setValue(this->i_index(0)); |
---|
[783] | 450 | jbegin.setValue(0); |
---|
[785] | 451 | ni.setValue(this->i_index.numElements()); |
---|
[783] | 452 | nj.setValue(1); |
---|
| 453 | } |
---|
| 454 | } |
---|
[785] | 455 | |
---|
| 456 | checkDomain(); |
---|
[687] | 457 | } |
---|
[1642] | 458 | CATCH_DUMP_ATTR |
---|
[687] | 459 | |
---|
| 460 | /*! |
---|
[1064] | 461 | Fill in longitude and latitude whose values are read from file |
---|
| 462 | */ |
---|
| 463 | void CDomain::fillInLonLat() |
---|
[1642] | 464 | TRY |
---|
[1064] | 465 | { |
---|
| 466 | switch (type) |
---|
| 467 | { |
---|
| 468 | case type_attr::rectilinear: |
---|
| 469 | fillInRectilinearLonLat(); |
---|
| 470 | break; |
---|
| 471 | case type_attr::curvilinear: |
---|
| 472 | fillInCurvilinearLonLat(); |
---|
| 473 | break; |
---|
| 474 | case type_attr::unstructured: |
---|
| 475 | fillInUnstructuredLonLat(); |
---|
| 476 | break; |
---|
| 477 | |
---|
| 478 | default: |
---|
| 479 | break; |
---|
| 480 | } |
---|
[1328] | 481 | completeLonLatClient() ; |
---|
[1064] | 482 | } |
---|
[1642] | 483 | CATCH_DUMP_ATTR |
---|
[1064] | 484 | |
---|
| 485 | /*! |
---|
[687] | 486 | Fill in the values for lonvalue_1d and latvalue_1d of rectilinear domain |
---|
| 487 | Range of longitude value from 0 - 360 |
---|
| 488 | Range of latitude value from -90 - +90 |
---|
| 489 | */ |
---|
| 490 | void CDomain::fillInRectilinearLonLat() |
---|
[1642] | 491 | TRY |
---|
[687] | 492 | { |
---|
[1642] | 493 | if (!lonvalue_rectilinear_read_from_file.isEmpty() && lonvalue_2d.isEmpty() && lonvalue_1d.isEmpty()) |
---|
[775] | 494 | { |
---|
| 495 | lonvalue_1d.resize(ni); |
---|
| 496 | for (int idx = 0; idx < ni; ++idx) |
---|
| 497 | lonvalue_1d(idx) = lonvalue_rectilinear_read_from_file(idx+ibegin); |
---|
| 498 | lon_start.setValue(lonvalue_rectilinear_read_from_file(0)); |
---|
| 499 | lon_end.setValue(lonvalue_rectilinear_read_from_file(ni_glo-1)); |
---|
| 500 | } |
---|
[1642] | 501 | else if (!hasLonInReadFile_) |
---|
[775] | 502 | { |
---|
| 503 | if (!lonvalue_2d.isEmpty()) lonvalue_2d.free(); |
---|
| 504 | lonvalue_1d.resize(ni); |
---|
| 505 | double lonRange = lon_end - lon_start; |
---|
| 506 | double lonStep = (1 == ni_glo.getValue()) ? lonRange : lonRange/double(ni_glo.getValue()-1); |
---|
[688] | 507 | |
---|
[775] | 508 | // Assign lon value |
---|
| 509 | for (int i = 0; i < ni; ++i) |
---|
| 510 | { |
---|
| 511 | if (0 == (ibegin + i)) |
---|
| 512 | { |
---|
| 513 | lonvalue_1d(i) = lon_start; |
---|
| 514 | } |
---|
| 515 | else if (ni_glo == (ibegin + i + 1)) |
---|
| 516 | { |
---|
| 517 | lonvalue_1d(i) = lon_end; |
---|
| 518 | } |
---|
| 519 | else |
---|
| 520 | { |
---|
| 521 | lonvalue_1d(i) = (ibegin + i) * lonStep + lon_start; |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | } |
---|
[687] | 525 | |
---|
[727] | 526 | |
---|
[1642] | 527 | if (!latvalue_rectilinear_read_from_file.isEmpty() && latvalue_2d.isEmpty() && latvalue_1d.isEmpty()) |
---|
[687] | 528 | { |
---|
[775] | 529 | latvalue_1d.resize(nj); |
---|
| 530 | for (int idx = 0; idx < nj; ++idx) |
---|
| 531 | latvalue_1d(idx) = latvalue_rectilinear_read_from_file(idx+jbegin); |
---|
| 532 | lat_start.setValue(latvalue_rectilinear_read_from_file(0)); |
---|
| 533 | lat_end.setValue(latvalue_rectilinear_read_from_file(nj_glo-1)); |
---|
[687] | 534 | } |
---|
[1642] | 535 | else if (!hasLatInReadFile_) |
---|
[775] | 536 | { |
---|
| 537 | if (!latvalue_2d.isEmpty()) latvalue_1d.free(); |
---|
| 538 | latvalue_1d.resize(nj); |
---|
[687] | 539 | |
---|
[775] | 540 | double latRange = lat_end - lat_start; |
---|
| 541 | double latStep = (1 == nj_glo.getValue()) ? latRange : latRange/double(nj_glo.getValue()-1); |
---|
| 542 | |
---|
| 543 | for (int j = 0; j < nj; ++j) |
---|
[727] | 544 | { |
---|
[775] | 545 | if (0 == (jbegin + j)) |
---|
| 546 | { |
---|
| 547 | latvalue_1d(j) = lat_start; |
---|
| 548 | } |
---|
| 549 | else if (nj_glo == (jbegin + j + 1)) |
---|
| 550 | { |
---|
| 551 | latvalue_1d(j) = lat_end; |
---|
| 552 | } |
---|
| 553 | else |
---|
| 554 | { |
---|
| 555 | latvalue_1d(j) = (jbegin + j) * latStep + lat_start; |
---|
| 556 | } |
---|
[727] | 557 | } |
---|
[687] | 558 | } |
---|
| 559 | } |
---|
[1642] | 560 | CATCH_DUMP_ATTR |
---|
[687] | 561 | |
---|
[1064] | 562 | /* |
---|
[1642] | 563 | Fill in 2D longitude and latitude of curvilinear domain read from a file. |
---|
| 564 | If there are already longitude and latitude defined by model. We just ignore read value. |
---|
[1064] | 565 | */ |
---|
| 566 | void CDomain::fillInCurvilinearLonLat() |
---|
[1642] | 567 | TRY |
---|
[1064] | 568 | { |
---|
[1642] | 569 | if (!lonvalue_curvilinear_read_from_file.isEmpty() && lonvalue_2d.isEmpty() && lonvalue_1d.isEmpty()) |
---|
[1064] | 570 | { |
---|
| 571 | lonvalue_2d.resize(ni,nj); |
---|
| 572 | for (int jdx = 0; jdx < nj; ++jdx) |
---|
| 573 | for (int idx = 0; idx < ni; ++idx) |
---|
[1460] | 574 | lonvalue_2d(idx,jdx) = lonvalue_curvilinear_read_from_file(idx, jdx); |
---|
[809] | 575 | |
---|
[1064] | 576 | lonvalue_curvilinear_read_from_file.free(); |
---|
| 577 | } |
---|
[809] | 578 | |
---|
[1642] | 579 | if (!latvalue_curvilinear_read_from_file.isEmpty() && latvalue_2d.isEmpty() && latvalue_1d.isEmpty()) |
---|
[1064] | 580 | { |
---|
| 581 | latvalue_2d.resize(ni,nj); |
---|
| 582 | for (int jdx = 0; jdx < nj; ++jdx) |
---|
| 583 | for (int idx = 0; idx < ni; ++idx) |
---|
[1460] | 584 | latvalue_2d(idx,jdx) = latvalue_curvilinear_read_from_file(idx, jdx); |
---|
[1064] | 585 | |
---|
| 586 | latvalue_curvilinear_read_from_file.free(); |
---|
| 587 | } |
---|
| 588 | |
---|
[1642] | 589 | if (!bounds_lonvalue_curvilinear_read_from_file.isEmpty() && bounds_lon_2d.isEmpty() && bounds_lon_1d.isEmpty()) |
---|
[1064] | 590 | { |
---|
| 591 | bounds_lon_2d.resize(nvertex,ni,nj); |
---|
| 592 | for (int jdx = 0; jdx < nj; ++jdx) |
---|
| 593 | for (int idx = 0; idx < ni; ++idx) |
---|
| 594 | for (int ndx = 0; ndx < nvertex; ++ndx) |
---|
[1460] | 595 | bounds_lon_2d(ndx,idx,jdx) = bounds_lonvalue_curvilinear_read_from_file(ndx,idx, jdx); |
---|
[1064] | 596 | |
---|
| 597 | bounds_lonvalue_curvilinear_read_from_file.free(); |
---|
| 598 | } |
---|
| 599 | |
---|
[1642] | 600 | if (!bounds_latvalue_curvilinear_read_from_file.isEmpty() && bounds_lat_2d.isEmpty() && bounds_lat_1d.isEmpty()) |
---|
[1064] | 601 | { |
---|
| 602 | bounds_lat_2d.resize(nvertex,ni,nj); |
---|
| 603 | for (int jdx = 0; jdx < nj; ++jdx) |
---|
| 604 | for (int idx = 0; idx < ni; ++idx) |
---|
| 605 | for (int ndx = 0; ndx < nvertex; ++ndx) |
---|
[1460] | 606 | bounds_lat_2d(ndx,idx,jdx) = bounds_latvalue_curvilinear_read_from_file(ndx,idx, jdx); |
---|
[1064] | 607 | |
---|
| 608 | bounds_latvalue_curvilinear_read_from_file.free(); |
---|
| 609 | } |
---|
| 610 | } |
---|
[1642] | 611 | CATCH_DUMP_ATTR |
---|
[1064] | 612 | |
---|
| 613 | /* |
---|
| 614 | Fill in longitude and latitude of unstructured domain read from a file |
---|
| 615 | If there are already longitude and latitude defined by model. We just igonore reading value. |
---|
| 616 | */ |
---|
| 617 | void CDomain::fillInUnstructuredLonLat() |
---|
[1642] | 618 | TRY |
---|
[1064] | 619 | { |
---|
| 620 | if (i_index.isEmpty()) |
---|
| 621 | { |
---|
| 622 | i_index.resize(ni); |
---|
| 623 | for(int idx = 0; idx < ni; ++idx) i_index(idx)=ibegin+idx; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | if (!lonvalue_unstructured_read_from_file.isEmpty() && lonvalue_1d.isEmpty()) |
---|
| 627 | { |
---|
| 628 | lonvalue_1d.resize(ni); |
---|
| 629 | for (int idx = 0; idx < ni; ++idx) |
---|
[1460] | 630 | lonvalue_1d(idx) = lonvalue_unstructured_read_from_file(idx); |
---|
[1064] | 631 | |
---|
| 632 | // We dont need these values anymore, so just delete them |
---|
| 633 | lonvalue_unstructured_read_from_file.free(); |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | if (!latvalue_unstructured_read_from_file.isEmpty() && latvalue_1d.isEmpty()) |
---|
| 637 | { |
---|
| 638 | latvalue_1d.resize(ni); |
---|
| 639 | for (int idx = 0; idx < ni; ++idx) |
---|
[1460] | 640 | latvalue_1d(idx) = latvalue_unstructured_read_from_file(idx); |
---|
[1064] | 641 | |
---|
| 642 | // We dont need these values anymore, so just delete them |
---|
| 643 | latvalue_unstructured_read_from_file.free(); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | if (!bounds_lonvalue_unstructured_read_from_file.isEmpty() && bounds_lon_1d.isEmpty()) |
---|
| 647 | { |
---|
| 648 | int nbVertex = nvertex; |
---|
| 649 | bounds_lon_1d.resize(nbVertex,ni); |
---|
| 650 | for (int idx = 0; idx < ni; ++idx) |
---|
| 651 | for (int jdx = 0; jdx < nbVertex; ++jdx) |
---|
[1460] | 652 | bounds_lon_1d(jdx,idx) = bounds_lonvalue_unstructured_read_from_file(jdx, idx); |
---|
[1064] | 653 | |
---|
| 654 | // We dont need these values anymore, so just delete them |
---|
[1460] | 655 | bounds_lonvalue_unstructured_read_from_file.free(); |
---|
[1064] | 656 | } |
---|
| 657 | |
---|
| 658 | if (!bounds_latvalue_unstructured_read_from_file.isEmpty() && bounds_lat_1d.isEmpty()) |
---|
| 659 | { |
---|
| 660 | int nbVertex = nvertex; |
---|
| 661 | bounds_lat_1d.resize(nbVertex,ni); |
---|
| 662 | for (int idx = 0; idx < ni; ++idx) |
---|
| 663 | for (int jdx = 0; jdx < nbVertex; ++jdx) |
---|
[1460] | 664 | bounds_lat_1d(jdx,idx) = bounds_latvalue_unstructured_read_from_file(jdx, idx); |
---|
[1064] | 665 | |
---|
| 666 | // We dont need these values anymore, so just delete them |
---|
[1460] | 667 | bounds_latvalue_unstructured_read_from_file.free(); |
---|
[1064] | 668 | } |
---|
| 669 | } |
---|
[1642] | 670 | CATCH_DUMP_ATTR |
---|
[1064] | 671 | |
---|
| 672 | /* |
---|
| 673 | Get global longitude and latitude of rectilinear domain. |
---|
| 674 | */ |
---|
[809] | 675 | void CDomain::AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat, CArray<double,1>& lon_g, CArray<double,1>& lat_g) |
---|
[1642] | 676 | TRY |
---|
[688] | 677 | { |
---|
[1460] | 678 | CContext* context = CContext::getCurrent(); |
---|
| 679 | // For now the assumption is that secondary server pools consist of the same number of procs. |
---|
| 680 | // CHANGE the line below if the assumption changes. |
---|
| 681 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[0] : context->client; |
---|
| 682 | lon_g.resize(ni_glo) ; |
---|
| 683 | lat_g.resize(nj_glo) ; |
---|
[815] | 684 | |
---|
| 685 | |
---|
[1460] | 686 | int* ibegin_g = new int[client->clientSize] ; |
---|
| 687 | int* jbegin_g = new int[client->clientSize] ; |
---|
| 688 | int* ni_g = new int[client->clientSize] ; |
---|
| 689 | int* nj_g = new int[client->clientSize] ; |
---|
| 690 | int v ; |
---|
| 691 | v=ibegin ; |
---|
[1642] | 692 | ep_lib::MPI_Allgather(&v,1,EP_INT,ibegin_g,1,EP_INT,client->intraComm) ; |
---|
[1460] | 693 | v=jbegin ; |
---|
[1642] | 694 | ep_lib::MPI_Allgather(&v,1,EP_INT,jbegin_g,1,EP_INT,client->intraComm) ; |
---|
[1460] | 695 | v=ni ; |
---|
[1642] | 696 | ep_lib::MPI_Allgather(&v,1,EP_INT,ni_g,1,EP_INT,client->intraComm) ; |
---|
[1460] | 697 | v=nj ; |
---|
[1642] | 698 | ep_lib::MPI_Allgather(&v,1,EP_INT,nj_g,1,EP_INT,client->intraComm) ; |
---|
[815] | 699 | |
---|
[1642] | 700 | ep_lib::MPI_Allgatherv(lon.dataFirst(),ni,EP_DOUBLE,lon_g.dataFirst(),ni_g, ibegin_g,EP_DOUBLE,client->intraComm) ; |
---|
| 701 | ep_lib::MPI_Allgatherv(lat.dataFirst(),nj,EP_DOUBLE,lat_g.dataFirst(),nj_g, jbegin_g,EP_DOUBLE,client->intraComm) ; |
---|
[815] | 702 | |
---|
[809] | 703 | delete[] ibegin_g ; |
---|
| 704 | delete[] jbegin_g ; |
---|
| 705 | delete[] ni_g ; |
---|
| 706 | delete[] nj_g ; |
---|
| 707 | } |
---|
[1642] | 708 | CATCH_DUMP_ATTR |
---|
[809] | 709 | |
---|
| 710 | void CDomain::fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat, |
---|
| 711 | CArray<double,2>& boundsLon, CArray<double,2>& boundsLat) |
---|
[1642] | 712 | TRY |
---|
| 713 | { |
---|
[688] | 714 | int i,j,k; |
---|
[815] | 715 | |
---|
[688] | 716 | const int nvertexValue = 4; |
---|
[775] | 717 | boundsLon.resize(nvertexValue,ni*nj); |
---|
[688] | 718 | |
---|
[899] | 719 | if (ni_glo>1) |
---|
| 720 | { |
---|
| 721 | double lonStepStart = lon(1)-lon(0); |
---|
| 722 | bounds_lon_start=lon(0) - lonStepStart/2; |
---|
| 723 | double lonStepEnd = lon(ni_glo-1)-lon(ni_glo-2); |
---|
| 724 | bounds_lon_end=lon(ni_glo-1) + lonStepEnd/2; |
---|
| 725 | double errorBoundsLon = std::abs(360-std::abs(bounds_lon_end-bounds_lon_start)); |
---|
[810] | 726 | |
---|
[899] | 727 | // if errorBoundsLon is reasonably small (0.1 x cell size) consider it as closed in longitude |
---|
| 728 | if (errorBoundsLon < std::abs(lonStepStart)*1e-1 || errorBoundsLon < std::abs(lonStepEnd)*1e-1 ) |
---|
| 729 | { |
---|
| 730 | bounds_lon_start= (lon(0) + lon(ni_glo-1)-360)/2 ; |
---|
| 731 | bounds_lon_end= (lon(0) +360 + lon(ni_glo-1))/2 ; |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | else |
---|
[810] | 735 | { |
---|
[899] | 736 | if (bounds_lon_start.isEmpty()) bounds_lon_start=-180. ; |
---|
| 737 | if (bounds_lon_end.isEmpty()) bounds_lon_end=180.-1e-8 ; |
---|
[810] | 738 | } |
---|
[906] | 739 | |
---|
[809] | 740 | for(j=0;j<nj;++j) |
---|
| 741 | for(i=0;i<ni;++i) |
---|
| 742 | { |
---|
| 743 | k=j*ni+i; |
---|
| 744 | boundsLon(0,k) = boundsLon(1,k) = (0 == (ibegin + i)) ? bounds_lon_start |
---|
| 745 | : (lon(ibegin + i)+lon(ibegin + i-1))/2; |
---|
| 746 | boundsLon(2,k) = boundsLon(3,k) = ((ibegin + i + 1) == ni_glo) ? bounds_lon_end |
---|
| 747 | : (lon(ibegin + i + 1)+lon(ibegin + i))/2; |
---|
| 748 | } |
---|
[727] | 749 | |
---|
[815] | 750 | |
---|
[809] | 751 | boundsLat.resize(nvertexValue,nj*ni); |
---|
[810] | 752 | bool isNorthPole=false ; |
---|
| 753 | bool isSouthPole=false ; |
---|
[809] | 754 | if (std::abs(90 - std::abs(lat(0))) < NumTraits<double>::epsilon()) isNorthPole = true; |
---|
| 755 | if (std::abs(90 - std::abs(lat(nj_glo-1))) < NumTraits<double>::epsilon()) isSouthPole = true; |
---|
[808] | 756 | |
---|
[810] | 757 | // lat boundaries beyond pole the assimilate it to pole |
---|
| 758 | // lat boundarie is relativelly close to pole (0.1 x cell size) assimilate it to pole |
---|
[899] | 759 | if (nj_glo>1) |
---|
[810] | 760 | { |
---|
[899] | 761 | double latStepStart = lat(1)-lat(0); |
---|
| 762 | if (isNorthPole) bounds_lat_start=lat(0); |
---|
| 763 | else |
---|
[810] | 764 | { |
---|
[899] | 765 | bounds_lat_start=lat(0)-latStepStart/2; |
---|
| 766 | if (bounds_lat_start >= 90 ) bounds_lat_start=90 ; |
---|
| 767 | else if (bounds_lat_start <= -90 ) bounds_lat_start=-90 ; |
---|
| 768 | else if (bounds_lat_start <= 90 && bounds_lat_start >= lat(0)) |
---|
| 769 | { |
---|
| 770 | if ( std::abs(90-bounds_lat_start) <= 0.1*std::abs(latStepStart)) bounds_lat_start=90 ; |
---|
| 771 | } |
---|
| 772 | else if (bounds_lat_start >= -90 && bounds_lat_start <= lat(0)) |
---|
| 773 | { |
---|
| 774 | if ( std::abs(-90 - bounds_lat_start) <= 0.1*std::abs(latStepStart)) bounds_lat_start=-90 ; |
---|
| 775 | } |
---|
[810] | 776 | } |
---|
[899] | 777 | |
---|
| 778 | double latStepEnd = lat(nj_glo-1)-lat(nj_glo-2); |
---|
| 779 | if (isSouthPole) bounds_lat_end=lat(nj_glo-1); |
---|
| 780 | else |
---|
[810] | 781 | { |
---|
[899] | 782 | bounds_lat_end=lat(nj_glo-1)+latStepEnd/2; |
---|
| 783 | |
---|
| 784 | if (bounds_lat_end >= 90 ) bounds_lat_end=90 ; |
---|
| 785 | else if (bounds_lat_end <= -90 ) bounds_lat_end=-90 ; |
---|
| 786 | else if (bounds_lat_end <= 90 && bounds_lat_end >= lat(nj_glo-1)) |
---|
| 787 | { |
---|
| 788 | if ( std::abs(90-bounds_lat_end) <= 0.1*std::abs(latStepEnd)) bounds_lat_end=90 ; |
---|
| 789 | } |
---|
| 790 | else if (bounds_lat_end >= -90 && bounds_lat_end <= lat(nj_glo-1)) |
---|
| 791 | { |
---|
| 792 | if ( std::abs(-90 - bounds_lat_end) <= 0.1*std::abs(latStepEnd)) bounds_lat_end=-90 ; |
---|
| 793 | } |
---|
[810] | 794 | } |
---|
| 795 | } |
---|
| 796 | else |
---|
| 797 | { |
---|
[1062] | 798 | if (bounds_lat_start.isEmpty()) bounds_lat_start=-90. ; |
---|
[899] | 799 | if (bounds_lat_end.isEmpty()) bounds_lat_end=90 ; |
---|
[815] | 800 | } |
---|
| 801 | |
---|
[809] | 802 | for(j=0;j<nj;++j) |
---|
| 803 | for(i=0;i<ni;++i) |
---|
| 804 | { |
---|
| 805 | k=j*ni+i; |
---|
| 806 | boundsLat(1,k) = boundsLat(2,k) = (0 == (jbegin + j)) ? bounds_lat_start |
---|
| 807 | : (lat(jbegin + j)+lat(jbegin + j-1))/2; |
---|
| 808 | boundsLat(0,k) = boundsLat(3,k) = ((jbegin + j +1) == nj_glo) ? bounds_lat_end |
---|
| 809 | : (lat(jbegin + j + 1)+lat(jbegin + j))/2; |
---|
| 810 | } |
---|
[688] | 811 | } |
---|
[1642] | 812 | CATCH_DUMP_ATTR |
---|
[688] | 813 | |
---|
[1460] | 814 | /* |
---|
| 815 | General check of the domain to verify its mandatory attributes |
---|
| 816 | */ |
---|
[467] | 817 | void CDomain::checkDomain(void) |
---|
[1642] | 818 | TRY |
---|
[219] | 819 | { |
---|
[664] | 820 | if (type.isEmpty()) |
---|
| 821 | { |
---|
| 822 | ERROR("CDomain::checkDomain(void)", |
---|
[679] | 823 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 824 | << "The domain type is mandatory, " |
---|
| 825 | << "please define the 'type' attribute.") |
---|
[664] | 826 | } |
---|
[969] | 827 | |
---|
[953] | 828 | if (type == type_attr::gaussian) |
---|
| 829 | { |
---|
[1460] | 830 | hasPole=true ; |
---|
| 831 | type.setValue(type_attr::unstructured) ; |
---|
| 832 | } |
---|
| 833 | else if (type == type_attr::rectilinear) hasPole=true ; |
---|
| 834 | |
---|
[679] | 835 | if (type == type_attr::unstructured) |
---|
[664] | 836 | { |
---|
[679] | 837 | if (ni_glo.isEmpty()) |
---|
[664] | 838 | { |
---|
[679] | 839 | ERROR("CDomain::checkDomain(void)", |
---|
| 840 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 841 | << "The global domain is badly defined, " |
---|
| 842 | << "the mandatory 'ni_glo' attribute is missing.") |
---|
[664] | 843 | } |
---|
[679] | 844 | else if (ni_glo <= 0) |
---|
| 845 | { |
---|
| 846 | ERROR("CDomain::checkDomain(void)", |
---|
| 847 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 848 | << "The global domain is badly defined, " |
---|
| 849 | << "'ni_glo' attribute should be strictly positive so 'ni_glo = " << ni_glo.getValue() << "' is invalid.") |
---|
| 850 | } |
---|
[664] | 851 | isUnstructed_ = true; |
---|
| 852 | nj_glo = 1; |
---|
| 853 | nj = 1; |
---|
| 854 | jbegin = 0; |
---|
[942] | 855 | if (!i_index.isEmpty()) ni = i_index.numElements(); |
---|
[664] | 856 | j_index.resize(ni); |
---|
| 857 | for(int i=0;i<ni;++i) j_index(i)=0; |
---|
[611] | 858 | |
---|
[664] | 859 | if (!area.isEmpty()) |
---|
| 860 | area.transposeSelf(1, 0); |
---|
| 861 | } |
---|
[679] | 862 | |
---|
| 863 | if (ni_glo.isEmpty()) |
---|
[664] | 864 | { |
---|
[679] | 865 | ERROR("CDomain::checkDomain(void)", |
---|
| 866 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 867 | << "The global domain is badly defined, " |
---|
| 868 | << "the mandatory 'ni_glo' attribute is missing.") |
---|
[664] | 869 | } |
---|
[679] | 870 | else if (ni_glo <= 0) |
---|
| 871 | { |
---|
| 872 | ERROR("CDomain::checkDomain(void)", |
---|
| 873 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 874 | << "The global domain is badly defined, " |
---|
| 875 | << "'ni_glo' attribute should be strictly positive so 'ni_glo = " << ni_glo.getValue() << "' is invalid.") |
---|
| 876 | } |
---|
[509] | 877 | |
---|
[679] | 878 | if (nj_glo.isEmpty()) |
---|
| 879 | { |
---|
| 880 | ERROR("CDomain::checkDomain(void)", |
---|
| 881 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 882 | << "The global domain is badly defined, " |
---|
| 883 | << "the mandatory 'nj_glo' attribute is missing.") |
---|
| 884 | } |
---|
| 885 | else if (nj_glo <= 0) |
---|
| 886 | { |
---|
| 887 | ERROR("CDomain::checkDomain(void)", |
---|
| 888 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 889 | << "The global domain is badly defined, " |
---|
| 890 | << "'nj_glo' attribute should be strictly positive so 'nj_glo = " << nj_glo.getValue() << "' is invalid.") |
---|
| 891 | } |
---|
| 892 | |
---|
[664] | 893 | checkLocalIDomain(); |
---|
| 894 | checkLocalJDomain(); |
---|
[509] | 895 | |
---|
[664] | 896 | if (i_index.isEmpty()) |
---|
| 897 | { |
---|
| 898 | i_index.resize(ni*nj); |
---|
| 899 | for (int j = 0; j < nj; ++j) |
---|
| 900 | for (int i = 0; i < ni; ++i) i_index(i+j*ni) = i+ibegin; |
---|
| 901 | } |
---|
[594] | 902 | |
---|
[664] | 903 | if (j_index.isEmpty()) |
---|
| 904 | { |
---|
| 905 | j_index.resize(ni*nj); |
---|
| 906 | for (int j = 0; j < nj; ++j) |
---|
| 907 | for (int i = 0; i < ni; ++i) j_index(i+j*ni) = j+jbegin; |
---|
| 908 | } |
---|
[821] | 909 | } |
---|
[1642] | 910 | CATCH_DUMP_ATTR |
---|
[663] | 911 | |
---|
[1460] | 912 | size_t CDomain::getGlobalWrittenSize(void) |
---|
| 913 | { |
---|
[1642] | 914 | return ni_glo*nj_glo ; |
---|
[1460] | 915 | } |
---|
[219] | 916 | //---------------------------------------------------------------- |
---|
| 917 | |
---|
[969] | 918 | // Check validity of local domain on using the combination of 3 parameters: ibegin, ni and i_index |
---|
[219] | 919 | void CDomain::checkLocalIDomain(void) |
---|
[1642] | 920 | TRY |
---|
[219] | 921 | { |
---|
[969] | 922 | // If ibegin and ni are provided then we use them to check the validity of local domain |
---|
| 923 | if (i_index.isEmpty() && !ibegin.isEmpty() && !ni.isEmpty()) |
---|
[219] | 924 | { |
---|
[969] | 925 | if ((ni.getValue() < 0 || ibegin.getValue() < 0) || ((ibegin.getValue() + ni.getValue()) > ni_glo.getValue())) |
---|
| 926 | { |
---|
| 927 | ERROR("CDomain::checkLocalIDomain(void)", |
---|
| 928 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 929 | << "The local domain is wrongly defined," |
---|
| 930 | << " check the attributes 'ni_glo' (" << ni_glo.getValue() << "), 'ni' (" << ni.getValue() << ") and 'ibegin' (" << ibegin.getValue() << ")"); |
---|
| 931 | } |
---|
| 932 | } |
---|
| 933 | |
---|
| 934 | // i_index has higher priority than ibegin and ni |
---|
| 935 | if (!i_index.isEmpty()) |
---|
| 936 | { |
---|
[975] | 937 | int minIIndex = (0 < i_index.numElements()) ? i_index(0) : 0; |
---|
[969] | 938 | if (ni.isEmpty()) |
---|
| 939 | { |
---|
| 940 | // No information about ni |
---|
| 941 | int minIndex = ni_glo - 1; |
---|
| 942 | int maxIndex = 0; |
---|
| 943 | for (int idx = 0; idx < i_index.numElements(); ++idx) |
---|
| 944 | { |
---|
| 945 | if (i_index(idx) < minIndex) minIndex = i_index(idx); |
---|
| 946 | if (i_index(idx) > maxIndex) maxIndex = i_index(idx); |
---|
| 947 | } |
---|
| 948 | ni = maxIndex - minIndex + 1; |
---|
| 949 | minIIndex = minIIndex; |
---|
| 950 | } |
---|
| 951 | |
---|
| 952 | // It's not so correct but if ibegin is not the first value of i_index |
---|
| 953 | // then data on local domain has user-defined distribution. In this case, ibegin, ni have no meaning. |
---|
| 954 | if (ibegin.isEmpty()) ibegin = minIIndex; |
---|
| 955 | } |
---|
| 956 | else if (ibegin.isEmpty() && ni.isEmpty()) |
---|
| 957 | { |
---|
[594] | 958 | ibegin = 0; |
---|
| 959 | ni = ni_glo; |
---|
| 960 | } |
---|
[971] | 961 | else if ((!ibegin.isEmpty() && ni.isEmpty()) || (ibegin.isEmpty() && !ni.isEmpty())) |
---|
[219] | 962 | { |
---|
[969] | 963 | ERROR("CDomain::checkLocalIDomain(void)", |
---|
| 964 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
[971] | 965 | << "The local domain is wrongly defined," << endl |
---|
| 966 | << "i_index is empty and either 'ni' or 'ibegin' is not defined. " |
---|
| 967 | << "If 'ni' and 'ibegin' are used to define a domain, both of them must not be empty."); |
---|
[219] | 968 | } |
---|
[969] | 969 | |
---|
[219] | 970 | |
---|
[969] | 971 | if ((ni.getValue() < 0 || ibegin.getValue() < 0)) |
---|
[594] | 972 | { |
---|
| 973 | ERROR("CDomain::checkLocalIDomain(void)", |
---|
[679] | 974 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
[594] | 975 | << "The local domain is wrongly defined," |
---|
[679] | 976 | << " check the attributes 'ni_glo' (" << ni_glo.getValue() << "), 'ni' (" << ni.getValue() << ") and 'ibegin' (" << ibegin.getValue() << ")"); |
---|
[594] | 977 | } |
---|
[219] | 978 | } |
---|
[1642] | 979 | CATCH_DUMP_ATTR |
---|
[219] | 980 | |
---|
[969] | 981 | // Check validity of local domain on using the combination of 3 parameters: jbegin, nj and j_index |
---|
[219] | 982 | void CDomain::checkLocalJDomain(void) |
---|
[1642] | 983 | TRY |
---|
[219] | 984 | { |
---|
[969] | 985 | // If jbegin and nj are provided then we use them to check the validity of local domain |
---|
| 986 | if (j_index.isEmpty() && !jbegin.isEmpty() && !nj.isEmpty()) |
---|
[657] | 987 | { |
---|
[969] | 988 | if ((nj.getValue() < 0 || jbegin.getValue() < 0) || (jbegin.getValue() + nj.getValue()) > nj_glo.getValue()) |
---|
| 989 | { |
---|
| 990 | ERROR("CDomain::checkLocalJDomain(void)", |
---|
| 991 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 992 | << "The local domain is wrongly defined," |
---|
| 993 | << " check the attributes 'nj_glo' (" << nj_glo.getValue() << "), 'nj' (" << nj.getValue() << ") and 'jbegin' (" << jbegin.getValue() << ")"); |
---|
| 994 | } |
---|
[657] | 995 | } |
---|
[969] | 996 | |
---|
| 997 | if (!j_index.isEmpty()) |
---|
[657] | 998 | { |
---|
[975] | 999 | int minJIndex = (0 < j_index.numElements()) ? j_index(0) : 0; |
---|
[969] | 1000 | if (nj.isEmpty()) |
---|
| 1001 | { |
---|
| 1002 | // No information about nj |
---|
| 1003 | int minIndex = nj_glo - 1; |
---|
| 1004 | int maxIndex = 0; |
---|
| 1005 | for (int idx = 0; idx < j_index.numElements(); ++idx) |
---|
| 1006 | { |
---|
| 1007 | if (j_index(idx) < minIndex) minIndex = j_index(idx); |
---|
| 1008 | if (j_index(idx) > maxIndex) maxIndex = j_index(idx); |
---|
| 1009 | } |
---|
| 1010 | nj = maxIndex - minIndex + 1; |
---|
| 1011 | minJIndex = minIndex; |
---|
| 1012 | } |
---|
| 1013 | // It's the same as checkLocalIDomain. It's not so correct but if jbegin is not the first value of j_index |
---|
| 1014 | // then data on local domain has user-defined distribution. In this case, jbegin has no meaning. |
---|
| 1015 | if (jbegin.isEmpty()) jbegin = minJIndex; |
---|
[657] | 1016 | } |
---|
[969] | 1017 | else if (jbegin.isEmpty() && nj.isEmpty()) |
---|
| 1018 | { |
---|
| 1019 | jbegin = 0; |
---|
| 1020 | nj = nj_glo; |
---|
| 1021 | } |
---|
[219] | 1022 | |
---|
[969] | 1023 | |
---|
| 1024 | if ((nj.getValue() < 0 || jbegin.getValue() < 0)) |
---|
| 1025 | { |
---|
| 1026 | ERROR("CDomain::checkLocalJDomain(void)", |
---|
[679] | 1027 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
[594] | 1028 | << "The local domain is wrongly defined," |
---|
[679] | 1029 | << " check the attributes 'nj_glo' (" << nj_glo.getValue() << "), 'nj' (" << nj.getValue() << ") and 'jbegin' (" << jbegin.getValue() << ")"); |
---|
[969] | 1030 | } |
---|
[219] | 1031 | } |
---|
[1642] | 1032 | CATCH_DUMP_ATTR |
---|
[219] | 1033 | |
---|
| 1034 | //---------------------------------------------------------------- |
---|
[679] | 1035 | |
---|
[219] | 1036 | void CDomain::checkMask(void) |
---|
[1642] | 1037 | TRY |
---|
[219] | 1038 | { |
---|
[664] | 1039 | if (!mask_1d.isEmpty() && !mask_2d.isEmpty()) |
---|
[657] | 1040 | ERROR("CDomain::checkMask(void)", |
---|
[679] | 1041 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1042 | << "Both mask_1d and mask_2d are defined but only one can be used at the same time." << std::endl |
---|
| 1043 | << "Please define only one mask: 'mask_1d' or 'mask_2d'."); |
---|
[657] | 1044 | |
---|
[664] | 1045 | if (!mask_1d.isEmpty() && mask_2d.isEmpty()) |
---|
[219] | 1046 | { |
---|
[664] | 1047 | if (mask_1d.numElements() != i_index.numElements()) |
---|
[657] | 1048 | ERROR("CDomain::checkMask(void)", |
---|
[679] | 1049 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1050 | << "'mask_1d' does not have the same size as the local domain." << std::endl |
---|
| 1051 | << "Local size is " << i_index.numElements() << "." << std::endl |
---|
| 1052 | << "Mask size is " << mask_1d.numElements() << "."); |
---|
[657] | 1053 | } |
---|
[509] | 1054 | |
---|
[664] | 1055 | if (mask_1d.isEmpty() && !mask_2d.isEmpty()) |
---|
[657] | 1056 | { |
---|
[679] | 1057 | if (mask_2d.extent(0) != ni || mask_2d.extent(1) != nj) |
---|
| 1058 | ERROR("CDomain::checkMask(void)", |
---|
| 1059 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1060 | << "The mask does not have the same size as the local domain." << std::endl |
---|
| 1061 | << "Local size is " << ni.getValue() << " x " << nj.getValue() << "." << std::endl |
---|
| 1062 | << "Mask size is " << mask_2d.extent(0) << " x " << mask_2d.extent(1) << "."); |
---|
[657] | 1063 | } |
---|
[509] | 1064 | |
---|
[664] | 1065 | if (!mask_2d.isEmpty()) |
---|
[657] | 1066 | { |
---|
[1460] | 1067 | domainMask.resize(mask_2d.extent(0) * mask_2d.extent(1)); |
---|
[657] | 1068 | for (int j = 0; j < nj; ++j) |
---|
[1460] | 1069 | for (int i = 0; i < ni; ++i) domainMask(i+j*ni) = mask_2d(i,j); |
---|
| 1070 | // mask_2d.reset(); |
---|
[657] | 1071 | } |
---|
[675] | 1072 | else if (mask_1d.isEmpty()) |
---|
[657] | 1073 | { |
---|
[1460] | 1074 | domainMask.resize(i_index.numElements()); |
---|
| 1075 | for (int i = 0; i < i_index.numElements(); ++i) domainMask(i) = true; |
---|
[657] | 1076 | } |
---|
[1460] | 1077 | else |
---|
| 1078 | { |
---|
| 1079 | domainMask.resize(mask_1d.numElements()); |
---|
| 1080 | domainMask=mask_1d ; |
---|
| 1081 | } |
---|
[219] | 1082 | } |
---|
[1642] | 1083 | CATCH_DUMP_ATTR |
---|
[219] | 1084 | |
---|
[676] | 1085 | //---------------------------------------------------------------- |
---|
[219] | 1086 | |
---|
| 1087 | void CDomain::checkDomainData(void) |
---|
[1642] | 1088 | TRY |
---|
[509] | 1089 | { |
---|
[679] | 1090 | if (data_dim.isEmpty()) |
---|
[219] | 1091 | { |
---|
[679] | 1092 | data_dim.setValue(1); |
---|
[219] | 1093 | } |
---|
[679] | 1094 | else if (!(data_dim.getValue() == 1 || data_dim.getValue() == 2)) |
---|
[219] | 1095 | { |
---|
[679] | 1096 | ERROR("CDomain::checkDomainData(void)", |
---|
| 1097 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1098 | << "The data dimension is invalid, 'data_dim' must be 1 or 2 not << " << data_dim.getValue() << "."); |
---|
[219] | 1099 | } |
---|
| 1100 | |
---|
| 1101 | if (data_ibegin.isEmpty()) |
---|
[679] | 1102 | data_ibegin.setValue(0); |
---|
[660] | 1103 | if (data_jbegin.isEmpty()) |
---|
[679] | 1104 | data_jbegin.setValue(0); |
---|
[219] | 1105 | |
---|
[679] | 1106 | if (data_ni.isEmpty()) |
---|
[219] | 1107 | { |
---|
[679] | 1108 | data_ni.setValue((data_dim == 1) ? (ni.getValue() * nj.getValue()) : ni.getValue()); |
---|
[219] | 1109 | } |
---|
[679] | 1110 | else if (data_ni.getValue() < 0) |
---|
[219] | 1111 | { |
---|
[679] | 1112 | ERROR("CDomain::checkDomainData(void)", |
---|
| 1113 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1114 | << "The data size cannot be negative ('data_ni' = " << data_ni.getValue() << ")."); |
---|
[219] | 1115 | } |
---|
| 1116 | |
---|
[679] | 1117 | if (data_nj.isEmpty()) |
---|
[219] | 1118 | { |
---|
[679] | 1119 | data_nj.setValue((data_dim.getValue() == 1) ? (ni.getValue() * nj.getValue()) : nj.getValue()); |
---|
[219] | 1120 | } |
---|
[679] | 1121 | else if (data_nj.getValue() < 0) |
---|
| 1122 | { |
---|
| 1123 | ERROR("CDomain::checkDomainData(void)", |
---|
| 1124 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1125 | << "The data size cannot be negative ('data_nj' = " << data_nj.getValue() << ")."); |
---|
| 1126 | } |
---|
[219] | 1127 | } |
---|
[1642] | 1128 | CATCH_DUMP_ATTR |
---|
[219] | 1129 | |
---|
| 1130 | //---------------------------------------------------------------- |
---|
[679] | 1131 | |
---|
[219] | 1132 | void CDomain::checkCompression(void) |
---|
[1642] | 1133 | TRY |
---|
[219] | 1134 | { |
---|
[1642] | 1135 | int i,j,ind; |
---|
[219] | 1136 | if (!data_i_index.isEmpty()) |
---|
| 1137 | { |
---|
[664] | 1138 | if (!data_j_index.isEmpty() && |
---|
[678] | 1139 | data_j_index.numElements() != data_i_index.numElements()) |
---|
[664] | 1140 | { |
---|
[679] | 1141 | ERROR("CDomain::checkCompression(void)", |
---|
| 1142 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1143 | << "'data_i_index' and 'data_j_index' arrays must have the same size." << std::endl |
---|
| 1144 | << "'data_i_index' size = " << data_i_index.numElements() << std::endl |
---|
| 1145 | << "'data_j_index' size = " << data_j_index.numElements()); |
---|
[664] | 1146 | } |
---|
| 1147 | |
---|
[679] | 1148 | if (2 == data_dim) |
---|
| 1149 | { |
---|
[664] | 1150 | if (data_j_index.isEmpty()) |
---|
[660] | 1151 | { |
---|
[679] | 1152 | ERROR("CDomain::checkCompression(void)", |
---|
| 1153 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1154 | << "'data_j_index' must be defined when 'data_i_index' is set and 'data_dim' is 2."); |
---|
[660] | 1155 | } |
---|
[1642] | 1156 | for (int k=0; k<data_i_index.numElements(); ++k) |
---|
| 1157 | { |
---|
| 1158 | i = data_i_index(k)+data_ibegin ; |
---|
| 1159 | j = data_j_index(k)+data_jbegin ; |
---|
| 1160 | if (i>=0 && i<ni && j>=0 && j<nj) |
---|
| 1161 | { |
---|
| 1162 | ind=j*ni+i ; |
---|
| 1163 | if (!domainMask(ind)) |
---|
| 1164 | { |
---|
| 1165 | data_i_index(k) = -1; |
---|
| 1166 | data_j_index(k) = -1; |
---|
| 1167 | } |
---|
| 1168 | } |
---|
| 1169 | else |
---|
| 1170 | { |
---|
| 1171 | data_i_index(k) = -1; |
---|
| 1172 | data_j_index(k) = -1; |
---|
| 1173 | } |
---|
| 1174 | } |
---|
[679] | 1175 | } |
---|
| 1176 | else // (1 == data_dim) |
---|
| 1177 | { |
---|
[664] | 1178 | if (data_j_index.isEmpty()) |
---|
| 1179 | { |
---|
[679] | 1180 | data_j_index.resize(data_ni); |
---|
[1642] | 1181 | data_j_index = 0; |
---|
[664] | 1182 | } |
---|
[1642] | 1183 | for (int k=0; k<data_i_index.numElements(); ++k) |
---|
| 1184 | { |
---|
| 1185 | i=data_i_index(k)+data_ibegin ; |
---|
| 1186 | if (i>=0 && i < domainMask.size()) |
---|
| 1187 | { |
---|
| 1188 | if (!domainMask(i)) data_i_index(k) = -1; |
---|
| 1189 | } |
---|
| 1190 | else |
---|
| 1191 | data_i_index(k) = -1; |
---|
| 1192 | |
---|
| 1193 | if (!domainMask(i)) data_i_index(k) = -1; |
---|
| 1194 | } |
---|
[679] | 1195 | } |
---|
[219] | 1196 | } |
---|
| 1197 | else |
---|
| 1198 | { |
---|
[679] | 1199 | if (data_dim == 2 && !data_j_index.isEmpty()) |
---|
| 1200 | ERROR("CDomain::checkCompression(void)", |
---|
| 1201 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1202 | << "'data_i_index' must be defined when 'data_j_index' is set and 'data_dim' is 2."); |
---|
[219] | 1203 | |
---|
[679] | 1204 | if (1 == data_dim) |
---|
| 1205 | { |
---|
| 1206 | data_i_index.resize(data_ni); |
---|
| 1207 | data_j_index.resize(data_ni); |
---|
[1642] | 1208 | data_j_index = 0; |
---|
[666] | 1209 | |
---|
[1642] | 1210 | for (int k = 0; k < data_ni; ++k) |
---|
[679] | 1211 | { |
---|
[1642] | 1212 | i=k+data_ibegin ; |
---|
| 1213 | if (i>=0 && i < domainMask.size()) |
---|
| 1214 | { |
---|
| 1215 | if (domainMask(i)) |
---|
| 1216 | data_i_index(k) = k; |
---|
| 1217 | else |
---|
| 1218 | data_i_index(k) = -1; |
---|
| 1219 | } |
---|
| 1220 | else |
---|
| 1221 | data_i_index(k) = -1; |
---|
[679] | 1222 | } |
---|
| 1223 | } |
---|
| 1224 | else // (data_dim == 2) |
---|
| 1225 | { |
---|
| 1226 | const int dsize = data_ni * data_nj; |
---|
| 1227 | data_i_index.resize(dsize); |
---|
| 1228 | data_j_index.resize(dsize); |
---|
[509] | 1229 | |
---|
[1642] | 1230 | for(int count = 0, kj = 0; kj < data_nj; ++kj) |
---|
[679] | 1231 | { |
---|
[1642] | 1232 | for(int ki = 0; ki < data_ni; ++ki, ++count) |
---|
[219] | 1233 | { |
---|
[1642] | 1234 | i = ki + data_ibegin; |
---|
| 1235 | j = kj + data_jbegin; |
---|
| 1236 | ind=j*ni+i ; |
---|
| 1237 | if (i>=0 && i<ni && j>=0 && j<nj) |
---|
| 1238 | { |
---|
| 1239 | if (domainMask(ind)) |
---|
| 1240 | { |
---|
| 1241 | data_i_index(count) = ki; |
---|
| 1242 | data_j_index(count) = kj; |
---|
| 1243 | } |
---|
| 1244 | else |
---|
| 1245 | { |
---|
| 1246 | data_i_index(count) = -1; |
---|
| 1247 | data_j_index(count) = -1; |
---|
| 1248 | } |
---|
| 1249 | } |
---|
| 1250 | else |
---|
| 1251 | { |
---|
| 1252 | data_i_index(count) = -1; |
---|
| 1253 | data_j_index(count) = -1; |
---|
| 1254 | } |
---|
[219] | 1255 | } |
---|
[679] | 1256 | } |
---|
| 1257 | } |
---|
[219] | 1258 | } |
---|
| 1259 | } |
---|
[1642] | 1260 | CATCH_DUMP_ATTR |
---|
[219] | 1261 | |
---|
[666] | 1262 | //---------------------------------------------------------------- |
---|
[893] | 1263 | void CDomain::computeLocalMask(void) |
---|
[1642] | 1264 | TRY |
---|
[893] | 1265 | { |
---|
[1460] | 1266 | localMask.resize(i_index.numElements()) ; |
---|
[893] | 1267 | localMask=false ; |
---|
[676] | 1268 | |
---|
[893] | 1269 | size_t dn=data_i_index.numElements() ; |
---|
| 1270 | int i,j ; |
---|
| 1271 | size_t k,ind ; |
---|
[906] | 1272 | |
---|
[893] | 1273 | for(k=0;k<dn;k++) |
---|
| 1274 | { |
---|
| 1275 | if (data_dim==2) |
---|
| 1276 | { |
---|
| 1277 | i=data_i_index(k)+data_ibegin ; |
---|
| 1278 | j=data_j_index(k)+data_jbegin ; |
---|
[1460] | 1279 | if (i>=0 && i<ni && j>=0 && j<nj) |
---|
| 1280 | { |
---|
| 1281 | ind=j*ni+i ; |
---|
| 1282 | localMask(ind)=domainMask(ind) ; |
---|
| 1283 | } |
---|
[893] | 1284 | } |
---|
| 1285 | else |
---|
| 1286 | { |
---|
[1460] | 1287 | i=data_i_index(k)+data_ibegin ; |
---|
| 1288 | if (i>=0 && i<i_index.numElements()) |
---|
| 1289 | { |
---|
| 1290 | ind=i ; |
---|
| 1291 | localMask(ind)=domainMask(ind) ; |
---|
| 1292 | } |
---|
[893] | 1293 | } |
---|
| 1294 | } |
---|
| 1295 | } |
---|
[1642] | 1296 | CATCH_DUMP_ATTR |
---|
[893] | 1297 | |
---|
[676] | 1298 | void CDomain::checkEligibilityForCompressedOutput(void) |
---|
[1642] | 1299 | TRY |
---|
[676] | 1300 | { |
---|
| 1301 | // We don't check if the mask or the indexes are valid here, just if they have been defined at this point. |
---|
| 1302 | isCompressible_ = !mask_1d.isEmpty() || !mask_2d.isEmpty() || !data_i_index.isEmpty(); |
---|
| 1303 | } |
---|
[1642] | 1304 | CATCH_DUMP_ATTR |
---|
[676] | 1305 | |
---|
| 1306 | //---------------------------------------------------------------- |
---|
| 1307 | |
---|
[1460] | 1308 | /* |
---|
[1642] | 1309 | Fill in longitude, latitude, bounds, and area into internal values (lonvalue, latvalue, bounds_lonvalue, bounds_latvalue, areavalue) |
---|
| 1310 | which will be used by XIOS. |
---|
[1460] | 1311 | */ |
---|
[666] | 1312 | void CDomain::completeLonLatClient(void) |
---|
[1642] | 1313 | TRY |
---|
[219] | 1314 | { |
---|
[1460] | 1315 | bool lonlatValueExisted = (0 != lonvalue.numElements()) || (0 != latvalue.numElements()); |
---|
| 1316 | checkBounds() ; |
---|
[1642] | 1317 | checkArea() ; |
---|
| 1318 | |
---|
[1460] | 1319 | if (!lonvalue_2d.isEmpty() && !lonlatValueExisted) |
---|
[664] | 1320 | { |
---|
[1460] | 1321 | lonvalue.resize(ni * nj); |
---|
| 1322 | latvalue.resize(ni * nj); |
---|
[761] | 1323 | if (hasBounds) |
---|
| 1324 | { |
---|
[1460] | 1325 | bounds_lonvalue.resize(nvertex, ni * nj); |
---|
| 1326 | bounds_latvalue.resize(nvertex, ni * nj); |
---|
[761] | 1327 | } |
---|
| 1328 | |
---|
| 1329 | for (int j = 0; j < nj; ++j) |
---|
| 1330 | { |
---|
| 1331 | for (int i = 0; i < ni; ++i) |
---|
| 1332 | { |
---|
| 1333 | int k = j * ni + i; |
---|
| 1334 | |
---|
[1460] | 1335 | lonvalue(k) = lonvalue_2d(i,j); |
---|
| 1336 | latvalue(k) = latvalue_2d(i,j); |
---|
[761] | 1337 | |
---|
| 1338 | if (hasBounds) |
---|
| 1339 | { |
---|
| 1340 | for (int n = 0; n < nvertex; ++n) |
---|
| 1341 | { |
---|
[1460] | 1342 | bounds_lonvalue(n,k) = bounds_lon_2d(n,i,j); |
---|
| 1343 | bounds_latvalue(n,k) = bounds_lat_2d(n,i,j); |
---|
[761] | 1344 | } |
---|
| 1345 | } |
---|
| 1346 | } |
---|
| 1347 | } |
---|
[664] | 1348 | } |
---|
[1460] | 1349 | else if (!lonvalue_1d.isEmpty() && !lonlatValueExisted) |
---|
[664] | 1350 | { |
---|
| 1351 | if (type_attr::rectilinear == type) |
---|
| 1352 | { |
---|
[679] | 1353 | if (ni == lonvalue_1d.numElements() && nj == latvalue_1d.numElements()) |
---|
[664] | 1354 | { |
---|
[1460] | 1355 | lonvalue.resize(ni * nj); |
---|
| 1356 | latvalue.resize(ni * nj); |
---|
[761] | 1357 | if (hasBounds) |
---|
| 1358 | { |
---|
[1460] | 1359 | bounds_lonvalue.resize(nvertex, ni * nj); |
---|
| 1360 | bounds_latvalue.resize(nvertex, ni * nj); |
---|
[761] | 1361 | } |
---|
| 1362 | |
---|
| 1363 | for (int j = 0; j < nj; ++j) |
---|
| 1364 | { |
---|
| 1365 | for (int i = 0; i < ni; ++i) |
---|
[664] | 1366 | { |
---|
[761] | 1367 | int k = j * ni + i; |
---|
| 1368 | |
---|
[1460] | 1369 | lonvalue(k) = lonvalue_1d(i); |
---|
| 1370 | latvalue(k) = latvalue_1d(j); |
---|
[761] | 1371 | |
---|
[664] | 1372 | if (hasBounds) |
---|
| 1373 | { |
---|
[679] | 1374 | for (int n = 0; n < nvertex; ++n) |
---|
[666] | 1375 | { |
---|
[1460] | 1376 | bounds_lonvalue(n,k) = bounds_lon_1d(n,i); |
---|
| 1377 | bounds_latvalue(n,k) = bounds_lat_1d(n,j); |
---|
[666] | 1378 | } |
---|
[664] | 1379 | } |
---|
| 1380 | } |
---|
[761] | 1381 | } |
---|
| 1382 | } |
---|
[1460] | 1383 | else if (i_index.numElements() == lonvalue_1d.numElements() && j_index.numElements() == latvalue_1d.numElements() && !lonlatValueExisted) |
---|
[974] | 1384 | { |
---|
[1460] | 1385 | lonvalue.reference(lonvalue_1d); |
---|
| 1386 | latvalue.reference(latvalue_1d); |
---|
[974] | 1387 | if (hasBounds) |
---|
| 1388 | { |
---|
[1460] | 1389 | bounds_lonvalue.reference(bounds_lon_1d); |
---|
| 1390 | bounds_latvalue.reference(bounds_lat_1d); |
---|
[974] | 1391 | } |
---|
| 1392 | } |
---|
[761] | 1393 | else |
---|
| 1394 | ERROR("CDomain::completeLonClient(void)", |
---|
| 1395 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1396 | << "'lonvalue_1d' and 'latvalue_1d' does not have the same size as the local domain." << std::endl |
---|
[974] | 1397 | << "'lonvalue_1d' size is " << lonvalue_1d.numElements() |
---|
| 1398 | << " and 'latvalue_1d' size is " << latvalue_1d.numElements() << std::endl |
---|
| 1399 | << " They should be correspondingly " << ni.getValue() << " and " << nj.getValue() << " or " << std::endl |
---|
| 1400 | << i_index.numElements() << " and " << j_index.numElements() << "."); |
---|
[664] | 1401 | } |
---|
[1460] | 1402 | else if (type == type_attr::curvilinear || type == type_attr::unstructured && !lonlatValueExisted) |
---|
[664] | 1403 | { |
---|
[1460] | 1404 | lonvalue.reference(lonvalue_1d); |
---|
| 1405 | latvalue.reference(latvalue_1d); |
---|
[664] | 1406 | if (hasBounds) |
---|
| 1407 | { |
---|
[1460] | 1408 | bounds_lonvalue.reference(bounds_lon_1d); |
---|
| 1409 | bounds_latvalue.reference(bounds_lat_1d); |
---|
[664] | 1410 | } |
---|
| 1411 | } |
---|
| 1412 | } |
---|
[1642] | 1413 | |
---|
| 1414 | if (!area.isEmpty() && areavalue.isEmpty()) |
---|
| 1415 | { |
---|
| 1416 | areavalue.resize(ni*nj); |
---|
| 1417 | for (int j = 0; j < nj; ++j) |
---|
| 1418 | { |
---|
| 1419 | for (int i = 0; i < ni; ++i) |
---|
| 1420 | { |
---|
| 1421 | int k = j * ni + i; |
---|
| 1422 | areavalue(k) = area(i,j); |
---|
| 1423 | } |
---|
| 1424 | } |
---|
| 1425 | } |
---|
[664] | 1426 | } |
---|
[1642] | 1427 | CATCH_DUMP_ATTR |
---|
[664] | 1428 | |
---|
[1460] | 1429 | /* |
---|
| 1430 | Convert internal longitude latitude value used by XIOS to "lonvalue_*" which can be retrieved with Fortran interface |
---|
| 1431 | */ |
---|
| 1432 | void CDomain::convertLonLatValue(void) |
---|
[1642] | 1433 | TRY |
---|
[1460] | 1434 | { |
---|
| 1435 | bool lonlatValueExisted = (0 != lonvalue.numElements()) || (0 != latvalue.numElements()); |
---|
| 1436 | if (!lonvalue_2d.isEmpty() && lonlatValueExisted) |
---|
| 1437 | { |
---|
| 1438 | lonvalue_2d.resize(ni,nj); |
---|
| 1439 | latvalue_2d.resize(ni,nj); |
---|
| 1440 | if (hasBounds) |
---|
| 1441 | { |
---|
| 1442 | bounds_lon_2d.resize(nvertex, ni, nj); |
---|
| 1443 | bounds_lat_2d.resize(nvertex, ni, nj); |
---|
| 1444 | } |
---|
| 1445 | |
---|
| 1446 | for (int j = 0; j < nj; ++j) |
---|
| 1447 | { |
---|
| 1448 | for (int i = 0; i < ni; ++i) |
---|
| 1449 | { |
---|
| 1450 | int k = j * ni + i; |
---|
| 1451 | |
---|
| 1452 | lonvalue_2d(i,j) = lonvalue(k); |
---|
| 1453 | latvalue_2d(i,j) = latvalue(k); |
---|
| 1454 | |
---|
| 1455 | if (hasBounds) |
---|
| 1456 | { |
---|
| 1457 | for (int n = 0; n < nvertex; ++n) |
---|
| 1458 | { |
---|
| 1459 | bounds_lon_2d(n,i,j) = bounds_lonvalue(n,k); |
---|
| 1460 | bounds_lat_2d(n,i,j) = bounds_latvalue(n,k); |
---|
| 1461 | } |
---|
| 1462 | } |
---|
| 1463 | } |
---|
| 1464 | } |
---|
| 1465 | } |
---|
| 1466 | else if (!lonvalue_1d.isEmpty() && lonlatValueExisted) |
---|
| 1467 | { |
---|
| 1468 | if (type_attr::rectilinear == type) |
---|
| 1469 | { |
---|
| 1470 | if (ni == lonvalue_1d.numElements() && nj == latvalue_1d.numElements()) |
---|
| 1471 | { |
---|
| 1472 | lonvalue.resize(ni * nj); |
---|
| 1473 | latvalue.resize(ni * nj); |
---|
| 1474 | if (hasBounds) |
---|
| 1475 | { |
---|
| 1476 | bounds_lonvalue.resize(nvertex, ni * nj); |
---|
| 1477 | bounds_latvalue.resize(nvertex, ni * nj); |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | for (int j = 0; j < nj; ++j) |
---|
| 1481 | { |
---|
| 1482 | for (int i = 0; i < ni; ++i) |
---|
| 1483 | { |
---|
| 1484 | int k = j * ni + i; |
---|
| 1485 | |
---|
| 1486 | lonvalue(k) = lonvalue_1d(i); |
---|
| 1487 | latvalue(k) = latvalue_1d(j); |
---|
| 1488 | |
---|
| 1489 | if (hasBounds) |
---|
| 1490 | { |
---|
| 1491 | for (int n = 0; n < nvertex; ++n) |
---|
| 1492 | { |
---|
| 1493 | bounds_lonvalue(n,k) = bounds_lon_1d(n,i); |
---|
| 1494 | bounds_latvalue(n,k) = bounds_lat_1d(n,j); |
---|
| 1495 | } |
---|
| 1496 | } |
---|
| 1497 | } |
---|
| 1498 | } |
---|
| 1499 | } |
---|
| 1500 | else if (i_index.numElements() == lonvalue_1d.numElements() && j_index.numElements() == latvalue_1d.numElements() && !lonlatValueExisted) |
---|
| 1501 | { |
---|
| 1502 | lonvalue.reference(lonvalue_1d); |
---|
| 1503 | latvalue.reference(latvalue_1d); |
---|
| 1504 | if (hasBounds) |
---|
| 1505 | { |
---|
| 1506 | bounds_lonvalue.reference(bounds_lon_1d); |
---|
| 1507 | bounds_latvalue.reference(bounds_lat_1d); |
---|
| 1508 | } |
---|
| 1509 | } |
---|
| 1510 | else |
---|
| 1511 | ERROR("CDomain::completeLonClient(void)", |
---|
| 1512 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1513 | << "'lonvalue_1d' and 'latvalue_1d' does not have the same size as the local domain." << std::endl |
---|
| 1514 | << "'lonvalue_1d' size is " << lonvalue_1d.numElements() |
---|
| 1515 | << " and 'latvalue_1d' size is " << latvalue_1d.numElements() << std::endl |
---|
| 1516 | << " They should be correspondingly " << ni.getValue() << " and " << nj.getValue() << " or " << std::endl |
---|
| 1517 | << i_index.numElements() << " and " << j_index.numElements() << "."); |
---|
| 1518 | } |
---|
| 1519 | else if (type == type_attr::curvilinear || type == type_attr::unstructured && !lonlatValueExisted) |
---|
| 1520 | { |
---|
| 1521 | lonvalue.reference(lonvalue_1d); |
---|
| 1522 | latvalue.reference(latvalue_1d); |
---|
| 1523 | if (hasBounds) |
---|
| 1524 | { |
---|
| 1525 | bounds_lonvalue.reference(bounds_lon_1d); |
---|
| 1526 | bounds_latvalue.reference(bounds_lat_1d); |
---|
| 1527 | } |
---|
| 1528 | } |
---|
| 1529 | } |
---|
| 1530 | } |
---|
[1642] | 1531 | CATCH_DUMP_ATTR |
---|
[1460] | 1532 | |
---|
[449] | 1533 | void CDomain::checkBounds(void) |
---|
[1642] | 1534 | TRY |
---|
[449] | 1535 | { |
---|
[1460] | 1536 | bool hasBoundValues = (0 != bounds_lonvalue.numElements()) || (0 != bounds_latvalue.numElements()); |
---|
| 1537 | if (!nvertex.isEmpty() && nvertex > 0 && !hasBoundValues) |
---|
[449] | 1538 | { |
---|
[664] | 1539 | if (!bounds_lon_1d.isEmpty() && !bounds_lon_2d.isEmpty()) |
---|
| 1540 | ERROR("CDomain::checkBounds(void)", |
---|
[679] | 1541 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1542 | << "Only one longitude boundary attribute can be used but both 'bounds_lon_1d' and 'bounds_lon_2d' are defined." << std::endl |
---|
| 1543 | << "Define only one longitude boundary attribute: 'bounds_lon_1d' or 'bounds_lon_2d'."); |
---|
[664] | 1544 | |
---|
| 1545 | if (!bounds_lat_1d.isEmpty() && !bounds_lat_2d.isEmpty()) |
---|
| 1546 | ERROR("CDomain::checkBounds(void)", |
---|
[679] | 1547 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1548 | << "Only one latitude boundary attribute can be used but both 'bounds_lat_1d' and 'bounds_lat_2d' are defined." << std::endl |
---|
| 1549 | << "Define only one latitude boundary attribute: 'bounds_lat_1d' or 'bounds_lat_2d'."); |
---|
[664] | 1550 | |
---|
| 1551 | if ((!bounds_lon_1d.isEmpty() && bounds_lat_1d.isEmpty()) || (bounds_lon_1d.isEmpty() && !bounds_lat_1d.isEmpty())) |
---|
| 1552 | { |
---|
| 1553 | ERROR("CDomain::checkBounds(void)", |
---|
[679] | 1554 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1555 | << "Only 'bounds_lon_1d' or 'bounds_lat_1d' is defined." << std::endl |
---|
| 1556 | << "Please define either both attributes or none."); |
---|
[664] | 1557 | } |
---|
| 1558 | |
---|
| 1559 | if ((!bounds_lon_2d.isEmpty() && bounds_lat_2d.isEmpty()) || (bounds_lon_2d.isEmpty() && !bounds_lat_2d.isEmpty())) |
---|
| 1560 | { |
---|
| 1561 | ERROR("CDomain::checkBounds(void)", |
---|
[679] | 1562 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1563 | << "Only 'bounds_lon_2d' or 'bounds_lat_2d' is defined." << std::endl |
---|
| 1564 | << "Please define either both attributes or none."); |
---|
[664] | 1565 | } |
---|
| 1566 | |
---|
[691] | 1567 | if (!bounds_lon_1d.isEmpty() && nvertex.getValue() != bounds_lon_1d.extent(0)) |
---|
[679] | 1568 | ERROR("CDomain::checkBounds(void)", |
---|
| 1569 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1570 | << "'bounds_lon_1d' dimension is not compatible with 'nvertex'." << std::endl |
---|
[1642] | 1571 | << "'bounds_lon_1d' dimension is " << bounds_lon_1d.extent(0) |
---|
[679] | 1572 | << " but nvertex is " << nvertex.getValue() << "."); |
---|
[664] | 1573 | |
---|
[691] | 1574 | if (!bounds_lon_2d.isEmpty() && nvertex.getValue() != bounds_lon_2d.extent(0)) |
---|
[679] | 1575 | ERROR("CDomain::checkBounds(void)", |
---|
| 1576 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1577 | << "'bounds_lon_2d' dimension is not compatible with 'nvertex'." << std::endl |
---|
[1642] | 1578 | << "'bounds_lon_2d' dimension is " << bounds_lon_2d.extent(0) |
---|
[679] | 1579 | << " but nvertex is " << nvertex.getValue() << "."); |
---|
[664] | 1580 | |
---|
| 1581 | if (!bounds_lon_1d.isEmpty() && lonvalue_1d.isEmpty()) |
---|
[679] | 1582 | ERROR("CDomain::checkBounds(void)", |
---|
| 1583 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1584 | << "Since 'bounds_lon_1d' is defined, 'lonvalue_1d' must be defined too." << std::endl); |
---|
[664] | 1585 | |
---|
| 1586 | if (!bounds_lon_2d.isEmpty() && lonvalue_2d.isEmpty()) |
---|
[679] | 1587 | ERROR("CDomain::checkBounds(void)", |
---|
| 1588 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1589 | << "Since 'bounds_lon_2d' is defined, 'lonvalue_2d' must be defined too." << std::endl); |
---|
[664] | 1590 | |
---|
[691] | 1591 | if (!bounds_lat_1d.isEmpty() && nvertex.getValue() != bounds_lat_1d.extent(0)) |
---|
[679] | 1592 | ERROR("CDomain::checkBounds(void)", |
---|
| 1593 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1594 | << "'bounds_lat_1d' dimension is not compatible with 'nvertex'." << std::endl |
---|
[1642] | 1595 | << "'bounds_lat_1d' dimension is " << bounds_lat_1d.extent(0) |
---|
[679] | 1596 | << " but nvertex is " << nvertex.getValue() << "."); |
---|
[664] | 1597 | |
---|
[691] | 1598 | if (!bounds_lat_2d.isEmpty() && nvertex.getValue() != bounds_lat_2d.extent(0)) |
---|
[679] | 1599 | ERROR("CDomain::checkBounds(void)", |
---|
| 1600 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1601 | << "'bounds_lat_2d' dimension is not compatible with 'nvertex'." << std::endl |
---|
[1642] | 1602 | << "'bounds_lat_2d' dimension is " << bounds_lat_2d.extent(0) |
---|
[679] | 1603 | << " but nvertex is " << nvertex.getValue() << "."); |
---|
[664] | 1604 | |
---|
| 1605 | if (!bounds_lat_1d.isEmpty() && latvalue_1d.isEmpty()) |
---|
[679] | 1606 | ERROR("CDomain::checkBounds(void)", |
---|
| 1607 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1608 | << "Since 'bounds_lat_1d' is defined, 'latvalue_1d' must be defined too." << std::endl); |
---|
[664] | 1609 | |
---|
| 1610 | if (!bounds_lat_2d.isEmpty() && latvalue_2d.isEmpty()) |
---|
[679] | 1611 | ERROR("CDomain::checkBounds(void)", |
---|
| 1612 | << "Since 'bounds_lat_2d' is defined, 'latvalue_2d' must be defined too." << std::endl); |
---|
[1545] | 1613 | |
---|
[1491] | 1614 | // In case of reading UGRID bounds values are not required |
---|
| 1615 | hasBounds = (!bounds_lat_1d.isEmpty() || !bounds_lat_2d.isEmpty() ); |
---|
[449] | 1616 | } |
---|
[1460] | 1617 | else if (hasBoundValues) |
---|
| 1618 | { |
---|
| 1619 | hasBounds = true; |
---|
| 1620 | } |
---|
[509] | 1621 | else |
---|
[449] | 1622 | { |
---|
[679] | 1623 | hasBounds = false; |
---|
[449] | 1624 | } |
---|
| 1625 | } |
---|
[1642] | 1626 | CATCH_DUMP_ATTR |
---|
[509] | 1627 | |
---|
[611] | 1628 | void CDomain::checkArea(void) |
---|
[1642] | 1629 | TRY |
---|
[611] | 1630 | { |
---|
[1460] | 1631 | bool hasAreaValue = (!areavalue.isEmpty() && 0 != areavalue.numElements()); |
---|
[611] | 1632 | hasArea = !area.isEmpty(); |
---|
[1460] | 1633 | if (hasArea && !hasAreaValue) |
---|
[611] | 1634 | { |
---|
| 1635 | if (area.extent(0) != ni || area.extent(1) != nj) |
---|
| 1636 | { |
---|
[679] | 1637 | ERROR("CDomain::checkArea(void)", |
---|
| 1638 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1639 | << "The area does not have the same size as the local domain." << std::endl |
---|
| 1640 | << "Local size is " << ni.getValue() << " x " << nj.getValue() << "." << std::endl |
---|
| 1641 | << "Area size is " << area.extent(0) << " x " << area.extent(1) << "."); |
---|
[611] | 1642 | } |
---|
[1642] | 1643 | // if (areavalue.isEmpty()) |
---|
| 1644 | // { |
---|
| 1645 | // areavalue.resize(ni*nj); |
---|
| 1646 | // for (int j = 0; j < nj; ++j) |
---|
| 1647 | // { |
---|
| 1648 | // for (int i = 0; i < ni; ++i) |
---|
| 1649 | // { |
---|
| 1650 | // int k = j * ni + i; |
---|
| 1651 | // areavalue(k) = area(i,j); |
---|
| 1652 | // } |
---|
| 1653 | // } |
---|
| 1654 | // } |
---|
[611] | 1655 | } |
---|
| 1656 | } |
---|
[1642] | 1657 | CATCH_DUMP_ATTR |
---|
[611] | 1658 | |
---|
[665] | 1659 | void CDomain::checkLonLat() |
---|
[1642] | 1660 | TRY |
---|
[665] | 1661 | { |
---|
[1460] | 1662 | if (!hasLonLat) hasLonLat = (!latvalue_1d.isEmpty() && !lonvalue_1d.isEmpty()) || |
---|
| 1663 | (!latvalue_2d.isEmpty() && !lonvalue_2d.isEmpty()); |
---|
| 1664 | bool hasLonLatValue = (0 != lonvalue.numElements()) || (0 != latvalue.numElements()); |
---|
| 1665 | if (hasLonLat && !hasLonLatValue) |
---|
[666] | 1666 | { |
---|
| 1667 | if (!lonvalue_1d.isEmpty() && !lonvalue_2d.isEmpty()) |
---|
[762] | 1668 | ERROR("CDomain::checkLonLat()", |
---|
[679] | 1669 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1670 | << "Only one longitude attribute can be used but both 'lonvalue_1d' and 'lonvalue_2d' are defined." << std::endl |
---|
| 1671 | << "Define only one longitude attribute: 'lonvalue_1d' or 'lonvalue_2d'."); |
---|
[666] | 1672 | |
---|
| 1673 | if (!lonvalue_1d.isEmpty() && lonvalue_2d.isEmpty()) |
---|
| 1674 | { |
---|
[687] | 1675 | if ((type_attr::rectilinear != type) && (lonvalue_1d.numElements() != i_index.numElements())) |
---|
[762] | 1676 | ERROR("CDomain::checkLonLat()", |
---|
[679] | 1677 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1678 | << "'lonvalue_1d' does not have the same size as the local domain." << std::endl |
---|
| 1679 | << "Local size is " << i_index.numElements() << "." << std::endl |
---|
| 1680 | << "'lonvalue_1d' size is " << lonvalue_1d.numElements() << "."); |
---|
[666] | 1681 | } |
---|
| 1682 | |
---|
| 1683 | if (lonvalue_1d.isEmpty() && !lonvalue_2d.isEmpty()) |
---|
| 1684 | { |
---|
[679] | 1685 | if (lonvalue_2d.extent(0) != ni || lonvalue_2d.extent(1) != nj) |
---|
[762] | 1686 | ERROR("CDomain::checkLonLat()", |
---|
[679] | 1687 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1688 | << "'lonvalue_2d' does not have the same size as the local domain." << std::endl |
---|
| 1689 | << "Local size is " << ni.getValue() << " x " << nj.getValue() << "." << std::endl |
---|
| 1690 | << "'lonvalue_2d' size is " << lonvalue_2d.extent(0) << " x " << lonvalue_2d.extent(1) << "."); |
---|
[666] | 1691 | } |
---|
| 1692 | |
---|
| 1693 | if (!latvalue_1d.isEmpty() && !latvalue_2d.isEmpty()) |
---|
[762] | 1694 | ERROR("CDomain::checkLonLat()", |
---|
[679] | 1695 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1696 | << "Only one latitude attribute can be used but both 'latvalue_1d' and 'latvalue_2d' are defined." << std::endl |
---|
| 1697 | << "Define only one latitude attribute: 'latvalue_1d' or 'latvalue_2d'."); |
---|
[666] | 1698 | |
---|
| 1699 | if (!latvalue_1d.isEmpty() && latvalue_2d.isEmpty()) |
---|
| 1700 | { |
---|
[687] | 1701 | if ((type_attr::rectilinear != type) && (latvalue_1d.numElements() != i_index.numElements())) |
---|
[762] | 1702 | ERROR("CDomain::checkLonLat()", |
---|
[679] | 1703 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1704 | << "'latvalue_1d' does not have the same size as the local domain." << std::endl |
---|
| 1705 | << "Local size is " << i_index.numElements() << "." << std::endl |
---|
| 1706 | << "'latvalue_1d' size is " << latvalue_1d.numElements() << "."); |
---|
[666] | 1707 | } |
---|
| 1708 | |
---|
| 1709 | if (latvalue_1d.isEmpty() && !latvalue_2d.isEmpty()) |
---|
| 1710 | { |
---|
[679] | 1711 | if (latvalue_2d.extent(0) != ni || latvalue_2d.extent(1) != nj) |
---|
[762] | 1712 | ERROR("CDomain::checkLonLat()", |
---|
[679] | 1713 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 1714 | << "'latvalue_2d' does not have the same size as the local domain." << std::endl |
---|
| 1715 | << "Local size is " << ni.getValue() << " x " << nj.getValue() << "." << std::endl |
---|
| 1716 | << "'latvalue_2d' size is " << latvalue_2d.extent(0) << " x " << latvalue_2d.extent(1) << "."); |
---|
[666] | 1717 | } |
---|
| 1718 | } |
---|
[665] | 1719 | } |
---|
[1642] | 1720 | CATCH_DUMP_ATTR |
---|
[665] | 1721 | |
---|
[657] | 1722 | void CDomain::checkAttributesOnClientAfterTransformation() |
---|
[1642] | 1723 | TRY |
---|
[657] | 1724 | { |
---|
| 1725 | CContext* context=CContext::getCurrent() ; |
---|
| 1726 | |
---|
| 1727 | if (this->isClientAfterTransformationChecked) return; |
---|
| 1728 | if (context->hasClient) |
---|
| 1729 | { |
---|
[1460] | 1730 | this->computeConnectedClients(); |
---|
| 1731 | if (hasLonLat) |
---|
| 1732 | if (!context->hasServer) |
---|
| 1733 | this->completeLonLatClient(); |
---|
[657] | 1734 | } |
---|
| 1735 | |
---|
| 1736 | this->isClientAfterTransformationChecked = true; |
---|
| 1737 | } |
---|
[1642] | 1738 | CATCH_DUMP_ATTR |
---|
[657] | 1739 | |
---|
[219] | 1740 | //---------------------------------------------------------------- |
---|
[667] | 1741 | // Divide function checkAttributes into 2 seperate ones |
---|
[509] | 1742 | // This function only checks all attributes of current domain |
---|
| 1743 | void CDomain::checkAttributesOnClient() |
---|
[1642] | 1744 | TRY |
---|
[509] | 1745 | { |
---|
| 1746 | if (this->isClientChecked) return; |
---|
| 1747 | CContext* context=CContext::getCurrent(); |
---|
[219] | 1748 | |
---|
[1460] | 1749 | if (context->hasClient && !context->hasServer) |
---|
| 1750 | { |
---|
| 1751 | this->checkDomain(); |
---|
| 1752 | this->checkBounds(); |
---|
| 1753 | this->checkArea(); |
---|
| 1754 | this->checkLonLat(); |
---|
| 1755 | } |
---|
[509] | 1756 | |
---|
[1460] | 1757 | if (context->hasClient && !context->hasServer) |
---|
| 1758 | { // Ct client uniquement |
---|
[509] | 1759 | this->checkMask(); |
---|
| 1760 | this->checkDomainData(); |
---|
| 1761 | this->checkCompression(); |
---|
[893] | 1762 | this->computeLocalMask() ; |
---|
[509] | 1763 | } |
---|
| 1764 | else |
---|
[1460] | 1765 | { // Ct serveur uniquement |
---|
[509] | 1766 | } |
---|
| 1767 | |
---|
| 1768 | this->isClientChecked = true; |
---|
| 1769 | } |
---|
[1642] | 1770 | CATCH_DUMP_ATTR |
---|
[509] | 1771 | |
---|
| 1772 | // Send all checked attributes to server |
---|
| 1773 | void CDomain::sendCheckedAttributes() |
---|
[1642] | 1774 | TRY |
---|
[509] | 1775 | { |
---|
| 1776 | if (!this->isClientChecked) checkAttributesOnClient(); |
---|
[657] | 1777 | if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation(); |
---|
[509] | 1778 | CContext* context=CContext::getCurrent() ; |
---|
| 1779 | |
---|
| 1780 | if (this->isChecked) return; |
---|
| 1781 | if (context->hasClient) |
---|
| 1782 | { |
---|
[1460] | 1783 | sendAttributes(); |
---|
[509] | 1784 | } |
---|
| 1785 | this->isChecked = true; |
---|
| 1786 | } |
---|
[1642] | 1787 | CATCH_DUMP_ATTR |
---|
[509] | 1788 | |
---|
[219] | 1789 | void CDomain::checkAttributes(void) |
---|
[1642] | 1790 | TRY |
---|
[219] | 1791 | { |
---|
| 1792 | if (this->isChecked) return; |
---|
[347] | 1793 | CContext* context=CContext::getCurrent() ; |
---|
[219] | 1794 | |
---|
[467] | 1795 | this->checkDomain(); |
---|
[665] | 1796 | this->checkLonLat(); |
---|
[449] | 1797 | this->checkBounds(); |
---|
[611] | 1798 | this->checkArea(); |
---|
[509] | 1799 | |
---|
[300] | 1800 | if (context->hasClient) |
---|
[1460] | 1801 | { // Ct client uniquement |
---|
[219] | 1802 | this->checkMask(); |
---|
| 1803 | this->checkDomainData(); |
---|
| 1804 | this->checkCompression(); |
---|
[893] | 1805 | this->computeLocalMask() ; |
---|
[666] | 1806 | |
---|
[219] | 1807 | } |
---|
| 1808 | else |
---|
[1460] | 1809 | { // Ct serveur uniquement |
---|
[219] | 1810 | } |
---|
[509] | 1811 | |
---|
[300] | 1812 | if (context->hasClient) |
---|
| 1813 | { |
---|
[1460] | 1814 | this->computeConnectedClients(); |
---|
[666] | 1815 | this->completeLonLatClient(); |
---|
[300] | 1816 | } |
---|
[509] | 1817 | |
---|
[219] | 1818 | this->isChecked = true; |
---|
| 1819 | } |
---|
[1642] | 1820 | CATCH_DUMP_ATTR |
---|
[509] | 1821 | |
---|
[1460] | 1822 | /*! |
---|
| 1823 | Compute the connection of a client to other clients to determine which clients to send attributes to. |
---|
| 1824 | The sending clients are supposed to already know the distribution of receiving clients (In simple cases, it's band) |
---|
| 1825 | The connection among clients is calculated by using global index. |
---|
| 1826 | A client connects to other clients which holds the same global index as it. |
---|
| 1827 | */ |
---|
| 1828 | void CDomain::computeConnectedClients() |
---|
[1642] | 1829 | TRY |
---|
[300] | 1830 | { |
---|
[1460] | 1831 | CContext* context=CContext::getCurrent() ; |
---|
| 1832 | |
---|
| 1833 | // This line should be changed soon. |
---|
| 1834 | int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1; |
---|
[509] | 1835 | |
---|
[1460] | 1836 | nbSenders.clear(); |
---|
| 1837 | connectedServerRank_.clear(); |
---|
[657] | 1838 | |
---|
[1460] | 1839 | for (int p = 0; p < nbSrvPools; ++p) |
---|
[595] | 1840 | { |
---|
[1460] | 1841 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client; |
---|
| 1842 | int nbServer = client->serverSize; |
---|
| 1843 | int nbClient = client->clientSize; |
---|
| 1844 | int rank = client->clientRank; |
---|
| 1845 | bool doComputeGlobalIndexServer = true; |
---|
[509] | 1846 | |
---|
[1460] | 1847 | if (connectedServerRank_.find(nbServer) == connectedServerRank_.end()) |
---|
[595] | 1848 | { |
---|
[509] | 1849 | |
---|
[1460] | 1850 | if (indSrv_.find(nbServer) == indSrv_.end()) |
---|
| 1851 | { |
---|
[1642] | 1852 | int i,j,i_ind,j_ind, nbIndex=i_index.numElements(); |
---|
| 1853 | int globalIndexCount = i_index.numElements(); |
---|
| 1854 | // Fill in index |
---|
| 1855 | CArray<size_t,1> globalIndexDomain(nbIndex); |
---|
| 1856 | size_t globalIndex; |
---|
[595] | 1857 | |
---|
[1642] | 1858 | for (i = 0; i < nbIndex; ++i) |
---|
| 1859 | { |
---|
| 1860 | i_ind=i_index(i); |
---|
| 1861 | j_ind=j_index(i); |
---|
| 1862 | globalIndex = i_ind + j_ind * ni_glo; |
---|
| 1863 | globalIndexDomain(i) = globalIndex; |
---|
| 1864 | } |
---|
[467] | 1865 | |
---|
[1642] | 1866 | if (globalLocalIndexMap_.empty()) |
---|
| 1867 | { |
---|
| 1868 | for (i = 0; i < nbIndex; ++i) |
---|
| 1869 | globalLocalIndexMap_[globalIndexDomain(i)] = i; |
---|
| 1870 | } |
---|
[1078] | 1871 | |
---|
[1642] | 1872 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 1873 | int range, clientSize = client->clientSize; |
---|
| 1874 | std::vector<int> nGlobDomain(2); |
---|
| 1875 | nGlobDomain[0] = this->ni_glo; |
---|
| 1876 | nGlobDomain[1] = this->nj_glo; |
---|
| 1877 | for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i]; |
---|
| 1878 | indexBegin = 0; |
---|
| 1879 | if (globalSizeIndex <= clientSize) |
---|
| 1880 | { |
---|
| 1881 | indexBegin = rank%globalSizeIndex; |
---|
| 1882 | indexEnd = indexBegin; |
---|
| 1883 | } |
---|
| 1884 | else |
---|
| 1885 | { |
---|
| 1886 | for (int i = 0; i < clientSize; ++i) |
---|
| 1887 | { |
---|
| 1888 | range = globalSizeIndex / clientSize; |
---|
| 1889 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 1890 | if (i == client->clientRank) break; |
---|
| 1891 | indexBegin += range; |
---|
| 1892 | } |
---|
| 1893 | indexEnd = indexBegin + range - 1; |
---|
| 1894 | } |
---|
[657] | 1895 | |
---|
[1642] | 1896 | // Even if servers have no index, they must received something from client |
---|
| 1897 | // We only use several client to send "empty" message to these servers |
---|
| 1898 | CServerDistributionDescription serverDescription(nGlobDomain, nbServer); |
---|
| 1899 | std::vector<int> serverZeroIndex; |
---|
| 1900 | if (isUnstructed_) serverZeroIndex = serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t&,size_t&>(indexBegin, indexEnd), 0); |
---|
| 1901 | else serverZeroIndex = serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t&,size_t&>(indexBegin, indexEnd), 1); |
---|
[449] | 1902 | |
---|
[1642] | 1903 | std::list<int> serverZeroIndexLeader; |
---|
| 1904 | std::list<int> serverZeroIndexNotLeader; |
---|
| 1905 | CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); |
---|
| 1906 | for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 1907 | *it = serverZeroIndex[*it]; |
---|
[509] | 1908 | |
---|
[1642] | 1909 | CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); |
---|
| 1910 | clientServerMap->computeServerIndexMapping(globalIndexDomain, nbServer); |
---|
| 1911 | CClientServerMapping::GlobalIndexMap& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer(); |
---|
[657] | 1912 | |
---|
[1642] | 1913 | CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexDomainOnServer.begin(), |
---|
| 1914 | ite = globalIndexDomainOnServer.end(); |
---|
| 1915 | indSrv_[nbServer].swap(globalIndexDomainOnServer); |
---|
| 1916 | connectedServerRank_[nbServer].clear(); |
---|
| 1917 | for (it = indSrv_[nbServer].begin(); it != ite; ++it) |
---|
| 1918 | connectedServerRank_[nbServer].push_back(it->first); |
---|
[467] | 1919 | |
---|
[1642] | 1920 | for (std::list<int>::const_iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 1921 | connectedServerRank_[nbServer].push_back(*it); |
---|
[1460] | 1922 | |
---|
[1642] | 1923 | // Even if a client has no index, it must connect to at least one server and |
---|
| 1924 | // send an "empty" data to this server |
---|
| 1925 | if (connectedServerRank_[nbServer].empty()) |
---|
| 1926 | connectedServerRank_[nbServer].push_back(client->clientRank % client->serverSize); |
---|
[1460] | 1927 | |
---|
[1642] | 1928 | // Now check if all servers have data to receive. If not, master client will send empty data. |
---|
| 1929 | // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. |
---|
| 1930 | std::vector<int> counts (clientSize); |
---|
| 1931 | std::vector<int> displs (clientSize); |
---|
| 1932 | displs[0] = 0; |
---|
| 1933 | int localCount = connectedServerRank_[nbServer].size() ; |
---|
| 1934 | ep_lib::MPI_Gather(&localCount, 1, EP_INT, &counts[0], 1, EP_INT, 0, client->intraComm) ; |
---|
| 1935 | for (int i = 0; i < clientSize-1; ++i) |
---|
| 1936 | { |
---|
| 1937 | displs[i+1] = displs[i] + counts[i]; |
---|
| 1938 | } |
---|
| 1939 | std::vector<int> allConnectedServers(displs[clientSize-1]+counts[clientSize-1]); |
---|
| 1940 | ep_lib::MPI_Gatherv(&(connectedServerRank_[nbServer])[0], localCount, EP_INT, &allConnectedServers[0], &counts[0], &displs[0], EP_INT, 0, client->intraComm); |
---|
[1460] | 1941 | |
---|
[1642] | 1942 | if ((allConnectedServers.size() != nbServer) && (rank == 0)) |
---|
| 1943 | { |
---|
| 1944 | std::vector<bool> isSrvConnected (nbServer, false); |
---|
| 1945 | for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; |
---|
| 1946 | for (int i = 0; i < nbServer; ++i) |
---|
| 1947 | { |
---|
| 1948 | if (!isSrvConnected[i]) connectedServerRank_[nbServer].push_back(i); |
---|
| 1949 | } |
---|
| 1950 | } |
---|
| 1951 | nbSenders[nbServer] = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[nbServer]); |
---|
| 1952 | delete clientServerMap; |
---|
[676] | 1953 | } |
---|
| 1954 | } |
---|
| 1955 | } |
---|
[1460] | 1956 | } |
---|
[1642] | 1957 | CATCH_DUMP_ATTR |
---|
[676] | 1958 | |
---|
[1460] | 1959 | /*! |
---|
| 1960 | Compute index to write data. We only write data on the zoomed region, therefore, there should |
---|
| 1961 | be a map between the complete grid and the reduced grid where we write data. |
---|
| 1962 | By using global index we can easily create this kind of mapping. |
---|
| 1963 | */ |
---|
| 1964 | void CDomain::computeWrittenIndex() |
---|
[1642] | 1965 | TRY |
---|
[1460] | 1966 | { |
---|
| 1967 | if (computedWrittenIndex_) return; |
---|
| 1968 | computedWrittenIndex_ = true; |
---|
[467] | 1969 | |
---|
[1460] | 1970 | CContext* context=CContext::getCurrent(); |
---|
| 1971 | CContextServer* server = context->server; |
---|
[509] | 1972 | |
---|
[1460] | 1973 | std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2); |
---|
[1642] | 1974 | nBegin[0] = ibegin; nBegin[1] = jbegin; |
---|
| 1975 | nSize[0] = ni; nSize[1] = nj; |
---|
[1460] | 1976 | nBeginGlobal[0] = 0; nBeginGlobal[1] = 0; |
---|
| 1977 | nGlob[0] = ni_glo; nGlob[1] = nj_glo; |
---|
| 1978 | CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); |
---|
| 1979 | const CArray<size_t,1>& writtenGlobalIndex = srvDist.getGlobalIndex(); |
---|
| 1980 | |
---|
| 1981 | size_t nbWritten = 0, indGlo; |
---|
[1545] | 1982 | std::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), |
---|
[1460] | 1983 | ite = globalLocalIndexMap_.end(), it; |
---|
| 1984 | CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), |
---|
| 1985 | itSrve = writtenGlobalIndex.end(), itSrv; |
---|
| 1986 | |
---|
| 1987 | localIndexToWriteOnServer.resize(writtenGlobalIndex.numElements()); |
---|
| 1988 | nbWritten = 0; |
---|
| 1989 | for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) |
---|
[676] | 1990 | { |
---|
[1460] | 1991 | indGlo = *itSrv; |
---|
| 1992 | if (ite != globalLocalIndexMap_.find(indGlo)) |
---|
[676] | 1993 | { |
---|
[1460] | 1994 | localIndexToWriteOnServer(nbWritten) = globalLocalIndexMap_[indGlo]; |
---|
[676] | 1995 | } |
---|
[1460] | 1996 | else |
---|
| 1997 | { |
---|
[1642] | 1998 | localIndexToWriteOnServer(nbWritten) = -1; |
---|
[1460] | 1999 | } |
---|
[1642] | 2000 | ++nbWritten; |
---|
[676] | 2001 | } |
---|
[1460] | 2002 | } |
---|
[1642] | 2003 | CATCH_DUMP_ATTR |
---|
[584] | 2004 | |
---|
[1460] | 2005 | void CDomain::computeWrittenCompressedIndex(ep_lib::MPI_Comm writtenComm) |
---|
[1642] | 2006 | TRY |
---|
[1460] | 2007 | { |
---|
| 2008 | int writtenCommSize; |
---|
| 2009 | ep_lib::MPI_Comm_size(writtenComm, &writtenCommSize); |
---|
| 2010 | if (compressedIndexToWriteOnServer.find(writtenCommSize) != compressedIndexToWriteOnServer.end()) |
---|
| 2011 | return; |
---|
[668] | 2012 | |
---|
[1460] | 2013 | if (isCompressible()) |
---|
[584] | 2014 | { |
---|
[1460] | 2015 | size_t nbWritten = 0, indGlo; |
---|
| 2016 | CContext* context=CContext::getCurrent(); |
---|
| 2017 | CContextServer* server = context->server; |
---|
| 2018 | |
---|
| 2019 | std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2); |
---|
[1642] | 2020 | nBegin[0] = ibegin; nBegin[1] = jbegin; |
---|
| 2021 | nSize[0] = ni; nSize[1] = nj; |
---|
[1460] | 2022 | nBeginGlobal[0] = 0; nBeginGlobal[1] = 0; |
---|
| 2023 | nGlob[0] = ni_glo; nGlob[1] = nj_glo; |
---|
| 2024 | CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); |
---|
| 2025 | const CArray<size_t,1>& writtenGlobalIndex = srvDist.getGlobalIndex(); |
---|
| 2026 | |
---|
[1545] | 2027 | std::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), |
---|
[1460] | 2028 | ite = globalLocalIndexMap_.end(), it; |
---|
| 2029 | CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), |
---|
| 2030 | itSrve = writtenGlobalIndex.end(), itSrv; |
---|
[1545] | 2031 | std::unordered_map<size_t,size_t> localGlobalIndexMap; |
---|
[1460] | 2032 | for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) |
---|
[584] | 2033 | { |
---|
[1460] | 2034 | indGlo = *itSrv; |
---|
| 2035 | if (ite != globalLocalIndexMap_.find(indGlo)) |
---|
[584] | 2036 | { |
---|
[1460] | 2037 | localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; |
---|
| 2038 | ++nbWritten; |
---|
| 2039 | } |
---|
| 2040 | } |
---|
| 2041 | |
---|
| 2042 | nbWritten = 0; |
---|
| 2043 | for (int idx = 0; idx < data_i_index.numElements(); ++idx) |
---|
| 2044 | { |
---|
| 2045 | if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) |
---|
| 2046 | { |
---|
| 2047 | ++nbWritten; |
---|
[584] | 2048 | } |
---|
| 2049 | } |
---|
[1460] | 2050 | |
---|
| 2051 | compressedIndexToWriteOnServer[writtenCommSize].resize(nbWritten); |
---|
| 2052 | nbWritten = 0; |
---|
| 2053 | for (int idx = 0; idx < data_i_index.numElements(); ++idx) |
---|
[676] | 2054 | { |
---|
[1460] | 2055 | if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) |
---|
[676] | 2056 | { |
---|
[1460] | 2057 | compressedIndexToWriteOnServer[writtenCommSize](nbWritten) = localGlobalIndexMap[data_i_index(idx)]; |
---|
| 2058 | ++nbWritten; |
---|
[676] | 2059 | } |
---|
| 2060 | } |
---|
[569] | 2061 | |
---|
[1460] | 2062 | numberWrittenIndexes_[writtenCommSize] = nbWritten; |
---|
| 2063 | if (isDistributed()) |
---|
| 2064 | { |
---|
| 2065 | |
---|
[1642] | 2066 | ep_lib::MPI_Allreduce(&numberWrittenIndexes_[writtenCommSize], &totalNumberWrittenIndexes_[writtenCommSize], 1, EP_INT, EP_SUM, writtenComm); |
---|
| 2067 | ep_lib::MPI_Scan(&numberWrittenIndexes_[writtenCommSize], &offsetWrittenIndexes_[writtenCommSize], 1, EP_INT, EP_SUM, writtenComm); |
---|
[1460] | 2068 | offsetWrittenIndexes_[writtenCommSize] -= numberWrittenIndexes_[writtenCommSize]; |
---|
| 2069 | } |
---|
| 2070 | else |
---|
| 2071 | totalNumberWrittenIndexes_[writtenCommSize] = numberWrittenIndexes_[writtenCommSize]; |
---|
| 2072 | } |
---|
[300] | 2073 | } |
---|
[1642] | 2074 | CATCH_DUMP_ATTR |
---|
[467] | 2075 | |
---|
[1460] | 2076 | /*! |
---|
| 2077 | Send all attributes from client to connected clients |
---|
| 2078 | The attributes will be rebuilt on receiving side |
---|
| 2079 | */ |
---|
| 2080 | void CDomain::sendAttributes() |
---|
[1642] | 2081 | TRY |
---|
[657] | 2082 | { |
---|
[1460] | 2083 | sendDistributionAttributes(); |
---|
| 2084 | sendIndex(); |
---|
| 2085 | sendLonLat(); |
---|
| 2086 | sendArea(); |
---|
| 2087 | sendDataIndex(); |
---|
[657] | 2088 | } |
---|
[1642] | 2089 | CATCH |
---|
[667] | 2090 | /*! |
---|
[1642] | 2091 | Send global index from client to connected client(s) |
---|
[667] | 2092 | */ |
---|
[665] | 2093 | void CDomain::sendIndex() |
---|
[1642] | 2094 | TRY |
---|
[300] | 2095 | { |
---|
[610] | 2096 | int ns, n, i, j, ind, nv, idx; |
---|
[1460] | 2097 | std::list<CContextClient*>::iterator it; |
---|
| 2098 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
| 2099 | { |
---|
| 2100 | CContextClient* client = *it; |
---|
[610] | 2101 | |
---|
[1460] | 2102 | int serverSize = client->serverSize; |
---|
| 2103 | CEventClient eventIndex(getType(), EVENT_ID_INDEX); |
---|
[665] | 2104 | |
---|
[1460] | 2105 | list<CMessage> list_msgsIndex; |
---|
[1642] | 2106 | list<CArray<int,1> > list_indGlob; |
---|
[665] | 2107 | |
---|
[1545] | 2108 | std::unordered_map<int, vector<size_t> >::const_iterator itIndex, iteIndex; |
---|
[1460] | 2109 | iteIndex = indSrv_[serverSize].end(); |
---|
| 2110 | for (int k = 0; k < connectedServerRank_[serverSize].size(); ++k) |
---|
| 2111 | { |
---|
| 2112 | int nbIndGlob = 0; |
---|
| 2113 | int rank = connectedServerRank_[serverSize][k]; |
---|
| 2114 | itIndex = indSrv_[serverSize].find(rank); |
---|
| 2115 | if (iteIndex != itIndex) |
---|
| 2116 | nbIndGlob = itIndex->second.size(); |
---|
| 2117 | |
---|
| 2118 | list_indGlob.push_back(CArray<int,1>(nbIndGlob)); |
---|
| 2119 | |
---|
| 2120 | CArray<int,1>& indGlob = list_indGlob.back(); |
---|
| 2121 | for (n = 0; n < nbIndGlob; ++n) |
---|
| 2122 | { |
---|
| 2123 | indGlob(n) = static_cast<int>(itIndex->second[n]); |
---|
| 2124 | } |
---|
| 2125 | |
---|
| 2126 | list_msgsIndex.push_back(CMessage()); |
---|
| 2127 | list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix |
---|
| 2128 | list_msgsIndex.back() << isCurvilinear; |
---|
| 2129 | list_msgsIndex.back() << list_indGlob.back(); //list_indi.back() << list_indj.back(); |
---|
| 2130 | |
---|
| 2131 | eventIndex.push(rank, nbSenders[serverSize][rank], list_msgsIndex.back()); |
---|
| 2132 | } |
---|
| 2133 | |
---|
| 2134 | client->sendEvent(eventIndex); |
---|
| 2135 | } |
---|
| 2136 | } |
---|
[1642] | 2137 | CATCH_DUMP_ATTR |
---|
[1460] | 2138 | |
---|
| 2139 | /*! |
---|
| 2140 | Send distribution from client to other clients |
---|
| 2141 | Because a client in a level knows correctly the grid distribution of client on the next level |
---|
| 2142 | it calculates this distribution then sends it to the corresponding clients on the next level |
---|
| 2143 | */ |
---|
| 2144 | void CDomain::sendDistributionAttributes(void) |
---|
[1642] | 2145 | TRY |
---|
[1460] | 2146 | { |
---|
| 2147 | std::list<CContextClient*>::iterator it; |
---|
| 2148 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
[665] | 2149 | { |
---|
[1460] | 2150 | CContextClient* client = *it; |
---|
| 2151 | int nbServer = client->serverSize; |
---|
| 2152 | std::vector<int> nGlobDomain(2); |
---|
| 2153 | nGlobDomain[0] = this->ni_glo; |
---|
| 2154 | nGlobDomain[1] = this->nj_glo; |
---|
[665] | 2155 | |
---|
[1460] | 2156 | CServerDistributionDescription serverDescription(nGlobDomain, nbServer); |
---|
| 2157 | if (isUnstructed_) serverDescription.computeServerDistribution(false, 0); |
---|
| 2158 | else serverDescription.computeServerDistribution(false, 1); |
---|
[665] | 2159 | |
---|
[1460] | 2160 | std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); |
---|
| 2161 | std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); |
---|
| 2162 | |
---|
| 2163 | CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT); |
---|
| 2164 | if (client->isServerLeader()) |
---|
[665] | 2165 | { |
---|
[1460] | 2166 | std::list<CMessage> msgs; |
---|
| 2167 | |
---|
| 2168 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 2169 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 2170 | { |
---|
| 2171 | // Use const int to ensure CMessage holds a copy of the value instead of just a reference |
---|
| 2172 | const int ibegin_srv = serverIndexBegin[*itRank][0]; |
---|
| 2173 | const int jbegin_srv = serverIndexBegin[*itRank][1]; |
---|
| 2174 | const int ni_srv = serverDimensionSizes[*itRank][0]; |
---|
| 2175 | const int nj_srv = serverDimensionSizes[*itRank][1]; |
---|
| 2176 | |
---|
| 2177 | msgs.push_back(CMessage()); |
---|
| 2178 | CMessage& msg = msgs.back(); |
---|
| 2179 | msg << this->getId() ; |
---|
| 2180 | msg << isUnstructed_; |
---|
| 2181 | msg << ni_srv << ibegin_srv << nj_srv << jbegin_srv; |
---|
[1642] | 2182 | msg << ni_glo.getValue() << nj_glo.getValue(); |
---|
[1460] | 2183 | msg << isCompressible_; |
---|
| 2184 | |
---|
| 2185 | event.push(*itRank,1,msg); |
---|
| 2186 | } |
---|
| 2187 | client->sendEvent(event); |
---|
[665] | 2188 | } |
---|
[1460] | 2189 | else client->sendEvent(event); |
---|
| 2190 | } |
---|
| 2191 | } |
---|
[1642] | 2192 | CATCH_DUMP_ATTR |
---|
[665] | 2193 | |
---|
[1460] | 2194 | /*! |
---|
| 2195 | Send area from client to connected client(s) |
---|
[667] | 2196 | */ |
---|
[665] | 2197 | void CDomain::sendArea() |
---|
[1642] | 2198 | TRY |
---|
[665] | 2199 | { |
---|
| 2200 | if (!hasArea) return; |
---|
| 2201 | |
---|
| 2202 | int ns, n, i, j, ind, nv, idx; |
---|
[1460] | 2203 | std::list<CContextClient*>::iterator it; |
---|
[665] | 2204 | |
---|
[1460] | 2205 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
| 2206 | { |
---|
| 2207 | CContextClient* client = *it; |
---|
| 2208 | int serverSize = client->serverSize; |
---|
[665] | 2209 | |
---|
[1460] | 2210 | // send area for each connected server |
---|
| 2211 | CEventClient eventArea(getType(), EVENT_ID_AREA); |
---|
[665] | 2212 | |
---|
[1460] | 2213 | list<CMessage> list_msgsArea; |
---|
| 2214 | list<CArray<double,1> > list_area; |
---|
[665] | 2215 | |
---|
[1545] | 2216 | std::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; |
---|
[1460] | 2217 | iteMap = indSrv_[serverSize].end(); |
---|
| 2218 | for (int k = 0; k < connectedServerRank_[serverSize].size(); ++k) |
---|
[665] | 2219 | { |
---|
[1460] | 2220 | int nbData = 0; |
---|
| 2221 | int rank = connectedServerRank_[serverSize][k]; |
---|
| 2222 | it = indSrv_[serverSize].find(rank); |
---|
| 2223 | if (iteMap != it) |
---|
| 2224 | nbData = it->second.size(); |
---|
| 2225 | list_area.push_back(CArray<double,1>(nbData)); |
---|
| 2226 | |
---|
| 2227 | const std::vector<size_t>& temp = it->second; |
---|
| 2228 | for (n = 0; n < nbData; ++n) |
---|
| 2229 | { |
---|
| 2230 | idx = static_cast<int>(it->second[n]); |
---|
| 2231 | list_area.back()(n) = areavalue(globalLocalIndexMap_[idx]); |
---|
| 2232 | } |
---|
| 2233 | |
---|
| 2234 | list_msgsArea.push_back(CMessage()); |
---|
| 2235 | list_msgsArea.back() << this->getId() << hasArea; |
---|
| 2236 | list_msgsArea.back() << list_area.back(); |
---|
| 2237 | eventArea.push(rank, nbSenders[serverSize][rank], list_msgsArea.back()); |
---|
[665] | 2238 | } |
---|
[1460] | 2239 | client->sendEvent(eventArea); |
---|
[665] | 2240 | } |
---|
| 2241 | } |
---|
[1642] | 2242 | CATCH_DUMP_ATTR |
---|
[665] | 2243 | |
---|
[667] | 2244 | /*! |
---|
| 2245 | Send longitude and latitude from client to servers |
---|
[1460] | 2246 | Each client send long and lat information to corresponding connected clients(s). |
---|
[667] | 2247 | Because longitude and latitude are optional, this function only called if latitude and longitude exist |
---|
| 2248 | */ |
---|
[665] | 2249 | void CDomain::sendLonLat() |
---|
[1642] | 2250 | TRY |
---|
[665] | 2251 | { |
---|
| 2252 | if (!hasLonLat) return; |
---|
| 2253 | |
---|
| 2254 | int ns, n, i, j, ind, nv, idx; |
---|
[1460] | 2255 | std::list<CContextClient*>::iterator it; |
---|
| 2256 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
[300] | 2257 | { |
---|
[1460] | 2258 | CContextClient* client = *it; |
---|
| 2259 | int serverSize = client->serverSize; |
---|
[584] | 2260 | |
---|
[1460] | 2261 | // send lon lat for each connected server |
---|
| 2262 | CEventClient eventLon(getType(), EVENT_ID_LON); |
---|
| 2263 | CEventClient eventLat(getType(), EVENT_ID_LAT); |
---|
[509] | 2264 | |
---|
[1460] | 2265 | list<CMessage> list_msgsLon, list_msgsLat; |
---|
| 2266 | list<CArray<double,1> > list_lon, list_lat; |
---|
| 2267 | list<CArray<double,2> > list_boundslon, list_boundslat; |
---|
[610] | 2268 | |
---|
[1545] | 2269 | std::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; |
---|
[1460] | 2270 | iteMap = indSrv_[serverSize].end(); |
---|
| 2271 | for (int k = 0; k < connectedServerRank_[serverSize].size(); ++k) |
---|
[467] | 2272 | { |
---|
[1460] | 2273 | int nbData = 0; |
---|
| 2274 | int rank = connectedServerRank_[serverSize][k]; |
---|
| 2275 | it = indSrv_[serverSize].find(rank); |
---|
| 2276 | if (iteMap != it) |
---|
| 2277 | nbData = it->second.size(); |
---|
[509] | 2278 | |
---|
[1460] | 2279 | list_lon.push_back(CArray<double,1>(nbData)); |
---|
| 2280 | list_lat.push_back(CArray<double,1>(nbData)); |
---|
| 2281 | |
---|
[467] | 2282 | if (hasBounds) |
---|
[300] | 2283 | { |
---|
[1460] | 2284 | list_boundslon.push_back(CArray<double,2>(nvertex, nbData)); |
---|
| 2285 | list_boundslat.push_back(CArray<double,2>(nvertex, nbData)); |
---|
| 2286 | } |
---|
[610] | 2287 | |
---|
[1460] | 2288 | CArray<double,1>& lon = list_lon.back(); |
---|
| 2289 | CArray<double,1>& lat = list_lat.back(); |
---|
| 2290 | const std::vector<size_t>& temp = it->second; |
---|
| 2291 | for (n = 0; n < nbData; ++n) |
---|
| 2292 | { |
---|
| 2293 | idx = static_cast<int>(it->second[n]); |
---|
| 2294 | int localInd = globalLocalIndexMap_[idx]; |
---|
| 2295 | lon(n) = lonvalue(localInd); |
---|
| 2296 | lat(n) = latvalue(localInd); |
---|
| 2297 | |
---|
| 2298 | if (hasBounds) |
---|
[449] | 2299 | { |
---|
[1460] | 2300 | CArray<double,2>& boundslon = list_boundslon.back(); |
---|
| 2301 | CArray<double,2>& boundslat = list_boundslat.back(); |
---|
| 2302 | |
---|
| 2303 | for (nv = 0; nv < nvertex; ++nv) |
---|
| 2304 | { |
---|
| 2305 | boundslon(nv, n) = bounds_lonvalue(nv, localInd); |
---|
| 2306 | boundslat(nv, n) = bounds_latvalue(nv, localInd); |
---|
| 2307 | } |
---|
[449] | 2308 | } |
---|
[300] | 2309 | } |
---|
[509] | 2310 | |
---|
[1460] | 2311 | list_msgsLon.push_back(CMessage()); |
---|
| 2312 | list_msgsLat.push_back(CMessage()); |
---|
[518] | 2313 | |
---|
[1460] | 2314 | list_msgsLon.back() << this->getId() << hasLonLat; |
---|
| 2315 | if (hasLonLat) |
---|
| 2316 | list_msgsLon.back() << list_lon.back(); |
---|
| 2317 | list_msgsLon.back() << hasBounds; |
---|
| 2318 | if (hasBounds) |
---|
| 2319 | { |
---|
| 2320 | list_msgsLon.back() << list_boundslon.back(); |
---|
| 2321 | } |
---|
[610] | 2322 | |
---|
[1460] | 2323 | list_msgsLat.back() << this->getId() << hasLonLat; |
---|
| 2324 | if (hasLonLat) |
---|
| 2325 | list_msgsLat.back() << list_lat.back(); |
---|
| 2326 | list_msgsLat.back() << hasBounds; |
---|
| 2327 | if (hasBounds) |
---|
| 2328 | { |
---|
| 2329 | list_msgsLat.back() << list_boundslat.back(); |
---|
| 2330 | } |
---|
| 2331 | |
---|
| 2332 | eventLon.push(rank, nbSenders[serverSize][rank], list_msgsLon.back()); |
---|
| 2333 | eventLat.push(rank, nbSenders[serverSize][rank], list_msgsLat.back()); |
---|
[518] | 2334 | } |
---|
[1460] | 2335 | client->sendEvent(eventLon); |
---|
| 2336 | client->sendEvent(eventLat); |
---|
[300] | 2337 | } |
---|
| 2338 | } |
---|
[1642] | 2339 | CATCH_DUMP_ATTR |
---|
[509] | 2340 | |
---|
[667] | 2341 | /*! |
---|
[1460] | 2342 | Send data index to corresponding connected clients. |
---|
| 2343 | Data index can be compressed however, we always send decompressed data index |
---|
| 2344 | and they will be compressed on receiving. |
---|
| 2345 | The compressed index are represented with 1 and others are represented with -1 |
---|
[667] | 2346 | */ |
---|
[1460] | 2347 | void CDomain::sendDataIndex() |
---|
[1642] | 2348 | TRY |
---|
[665] | 2349 | { |
---|
[1460] | 2350 | int ns, n, i, j, ind, nv, idx; |
---|
| 2351 | std::list<CContextClient*>::iterator it; |
---|
| 2352 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
| 2353 | { |
---|
| 2354 | CContextClient* client = *it; |
---|
| 2355 | |
---|
| 2356 | int serverSize = client->serverSize; |
---|
| 2357 | |
---|
| 2358 | // send area for each connected server |
---|
| 2359 | CEventClient eventDataIndex(getType(), EVENT_ID_DATA_INDEX); |
---|
| 2360 | |
---|
| 2361 | list<CMessage> list_msgsDataIndex; |
---|
| 2362 | list<CArray<int,1> > list_data_i_index, list_data_j_index; |
---|
| 2363 | |
---|
| 2364 | int nbIndex = i_index.numElements(); |
---|
| 2365 | int niByIndex = max(i_index) - min(i_index) + 1; |
---|
| 2366 | int njByIndex = max(j_index) - min(j_index) + 1; |
---|
| 2367 | int dataIindexBound = (1 == data_dim) ? (niByIndex * njByIndex) : niByIndex; |
---|
| 2368 | int dataJindexBound = (1 == data_dim) ? (niByIndex * njByIndex) : njByIndex; |
---|
| 2369 | |
---|
| 2370 | |
---|
| 2371 | CArray<int,1> dataIIndex(nbIndex), dataJIndex(nbIndex); |
---|
| 2372 | dataIIndex = -1; |
---|
| 2373 | dataJIndex = -1; |
---|
| 2374 | ind = 0; |
---|
| 2375 | |
---|
| 2376 | for (idx = 0; idx < data_i_index.numElements(); ++idx) |
---|
| 2377 | { |
---|
| 2378 | int dataIidx = data_i_index(idx) + data_ibegin; |
---|
| 2379 | int dataJidx = data_j_index(idx) + data_jbegin; |
---|
| 2380 | if ((0 <= dataIidx) && (dataIidx < dataIindexBound) && |
---|
| 2381 | (0 <= dataJidx) && (dataJidx < dataJindexBound)) |
---|
| 2382 | { |
---|
| 2383 | dataIIndex((1 == data_dim) ? dataIidx : dataJidx * ni + dataIidx) = 1; //i_index(dataIidx);//dataIidx; |
---|
| 2384 | dataJIndex((1 == data_dim) ? dataIidx : dataJidx * ni + dataIidx) = 1; //j_index(dataJidx);// |
---|
| 2385 | } |
---|
| 2386 | } |
---|
| 2387 | |
---|
[1545] | 2388 | std::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; |
---|
[1460] | 2389 | iteMap = indSrv_[serverSize].end(); |
---|
| 2390 | for (int k = 0; k < connectedServerRank_[serverSize].size(); ++k) |
---|
| 2391 | { |
---|
| 2392 | int nbData = 0; |
---|
| 2393 | int rank = connectedServerRank_[serverSize][k]; |
---|
| 2394 | it = indSrv_[serverSize].find(rank); |
---|
| 2395 | if (iteMap != it) |
---|
| 2396 | nbData = it->second.size(); |
---|
| 2397 | list_data_i_index.push_back(CArray<int,1>(nbData)); |
---|
| 2398 | list_data_j_index.push_back(CArray<int,1>(nbData)); |
---|
| 2399 | |
---|
| 2400 | const std::vector<size_t>& temp = it->second; |
---|
| 2401 | for (n = 0; n < nbData; ++n) |
---|
| 2402 | { |
---|
| 2403 | idx = static_cast<int>(it->second[n]); |
---|
| 2404 | i = globalLocalIndexMap_[idx]; |
---|
| 2405 | list_data_i_index.back()(n) = dataIIndex(i); |
---|
| 2406 | list_data_j_index.back()(n) = dataJIndex(i); |
---|
| 2407 | } |
---|
| 2408 | |
---|
| 2409 | list_msgsDataIndex.push_back(CMessage()); |
---|
| 2410 | list_msgsDataIndex.back() << this->getId(); |
---|
| 2411 | list_msgsDataIndex.back() << list_data_i_index.back() << list_data_j_index.back(); |
---|
| 2412 | eventDataIndex.push(rank, nbSenders[serverSize][rank], list_msgsDataIndex.back()); |
---|
| 2413 | } |
---|
| 2414 | client->sendEvent(eventDataIndex); |
---|
| 2415 | } |
---|
[665] | 2416 | } |
---|
[1642] | 2417 | CATCH |
---|
[1460] | 2418 | |
---|
[300] | 2419 | bool CDomain::dispatchEvent(CEventServer& event) |
---|
[1642] | 2420 | TRY |
---|
[610] | 2421 | { |
---|
| 2422 | if (SuperClass::dispatchEvent(event)) return true; |
---|
| 2423 | else |
---|
| 2424 | { |
---|
| 2425 | switch(event.type) |
---|
[300] | 2426 | { |
---|
[610] | 2427 | case EVENT_ID_SERVER_ATTRIBUT: |
---|
[1460] | 2428 | recvDistributionAttributes(event); |
---|
[610] | 2429 | return true; |
---|
| 2430 | break; |
---|
| 2431 | case EVENT_ID_INDEX: |
---|
| 2432 | recvIndex(event); |
---|
| 2433 | return true; |
---|
| 2434 | break; |
---|
| 2435 | case EVENT_ID_LON: |
---|
| 2436 | recvLon(event); |
---|
| 2437 | return true; |
---|
| 2438 | break; |
---|
| 2439 | case EVENT_ID_LAT: |
---|
| 2440 | recvLat(event); |
---|
| 2441 | return true; |
---|
| 2442 | break; |
---|
[611] | 2443 | case EVENT_ID_AREA: |
---|
| 2444 | recvArea(event); |
---|
| 2445 | return true; |
---|
[1460] | 2446 | break; |
---|
| 2447 | case EVENT_ID_DATA_INDEX: |
---|
| 2448 | recvDataIndex(event); |
---|
| 2449 | return true; |
---|
[611] | 2450 | break; |
---|
[610] | 2451 | default: |
---|
[762] | 2452 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
[610] | 2453 | << "Unknown Event"); |
---|
| 2454 | return false; |
---|
| 2455 | } |
---|
| 2456 | } |
---|
| 2457 | } |
---|
[1642] | 2458 | CATCH |
---|
[509] | 2459 | |
---|
[667] | 2460 | /*! |
---|
[1460] | 2461 | Receive index event from clients(s) |
---|
| 2462 | \param[in] event event contain info about rank and associated index |
---|
| 2463 | */ |
---|
| 2464 | void CDomain::recvIndex(CEventServer& event) |
---|
[1642] | 2465 | TRY |
---|
[1460] | 2466 | { |
---|
| 2467 | string domainId; |
---|
| 2468 | std::map<int, CBufferIn*> rankBuffers; |
---|
| 2469 | |
---|
| 2470 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 2471 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 2472 | { |
---|
| 2473 | CBufferIn* buffer = it->buffer; |
---|
| 2474 | *buffer >> domainId; |
---|
| 2475 | rankBuffers[it->rank] = buffer; |
---|
| 2476 | } |
---|
| 2477 | get(domainId)->recvIndex(rankBuffers); |
---|
| 2478 | } |
---|
[1642] | 2479 | CATCH |
---|
[1460] | 2480 | |
---|
| 2481 | /*! |
---|
| 2482 | Receive index information from client(s). We use the global index for mapping index between |
---|
| 2483 | sending clients and receiving clients. |
---|
| 2484 | \param[in] rankBuffers rank of sending client and the corresponding receive buffer |
---|
| 2485 | */ |
---|
| 2486 | void CDomain::recvIndex(std::map<int, CBufferIn*>& rankBuffers) |
---|
[1642] | 2487 | TRY |
---|
[1460] | 2488 | { |
---|
| 2489 | int nbReceived = rankBuffers.size(), i, ind, index, type_int, iIndex, jIndex; |
---|
| 2490 | recvClientRanks_.resize(nbReceived); |
---|
| 2491 | |
---|
| 2492 | std::map<int, CBufferIn*>::iterator it = rankBuffers.begin(), ite = rankBuffers.end(); |
---|
| 2493 | ind = 0; |
---|
| 2494 | for (ind = 0; it != ite; ++it, ++ind) |
---|
| 2495 | { |
---|
| 2496 | recvClientRanks_[ind] = it->first; |
---|
| 2497 | CBufferIn& buffer = *(it->second); |
---|
| 2498 | buffer >> type_int >> isCurvilinear >> indGlob_[it->first]; |
---|
| 2499 | type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix |
---|
| 2500 | } |
---|
| 2501 | int nbIndGlob = 0; |
---|
| 2502 | for (i = 0; i < nbReceived; ++i) |
---|
| 2503 | { |
---|
| 2504 | nbIndGlob += indGlob_[recvClientRanks_[i]].numElements(); |
---|
| 2505 | } |
---|
| 2506 | |
---|
| 2507 | globalLocalIndexMap_.rehash(std::ceil(nbIndGlob/globalLocalIndexMap_.max_load_factor())); |
---|
| 2508 | i_index.resize(nbIndGlob); |
---|
| 2509 | j_index.resize(nbIndGlob); |
---|
| 2510 | int nbIndexGlobMax = nbIndGlob, nbIndLoc; |
---|
| 2511 | |
---|
| 2512 | nbIndGlob = 0; |
---|
| 2513 | for (i = 0; i < nbReceived; ++i) |
---|
| 2514 | { |
---|
| 2515 | CArray<int,1>& tmp = indGlob_[recvClientRanks_[i]]; |
---|
| 2516 | for (ind = 0; ind < tmp.numElements(); ++ind) |
---|
| 2517 | { |
---|
| 2518 | index = tmp(ind); |
---|
| 2519 | if (0 == globalLocalIndexMap_.count(index)) |
---|
| 2520 | { |
---|
| 2521 | iIndex = (index%ni_glo)-ibegin; |
---|
| 2522 | iIndex = (iIndex < 0) ? 0 : iIndex; |
---|
| 2523 | jIndex = (index/ni_glo)-jbegin; |
---|
| 2524 | jIndex = (jIndex < 0) ? 0 : jIndex; |
---|
| 2525 | nbIndLoc = iIndex + ni * jIndex; |
---|
[1642] | 2526 | i_index(nbIndGlob) = index % ni_glo; |
---|
| 2527 | j_index(nbIndGlob) = index / ni_glo; |
---|
| 2528 | globalLocalIndexMap_[index] = nbIndGlob; |
---|
| 2529 | ++nbIndGlob; |
---|
[1460] | 2530 | } |
---|
| 2531 | } |
---|
| 2532 | } |
---|
| 2533 | |
---|
| 2534 | if (nbIndGlob==0) |
---|
| 2535 | { |
---|
| 2536 | i_index.resize(nbIndGlob); |
---|
| 2537 | j_index.resize(nbIndGlob); |
---|
| 2538 | } |
---|
| 2539 | else |
---|
| 2540 | { |
---|
| 2541 | i_index.resizeAndPreserve(nbIndGlob); |
---|
| 2542 | j_index.resizeAndPreserve(nbIndGlob); |
---|
| 2543 | } |
---|
[1642] | 2544 | |
---|
| 2545 | domainMask.resize(0); // Mask is not defined anymore on servers |
---|
[1460] | 2546 | } |
---|
[1642] | 2547 | CATCH |
---|
[1460] | 2548 | |
---|
| 2549 | /*! |
---|
[667] | 2550 | Receive attributes event from clients(s) |
---|
| 2551 | \param[in] event event contain info about rank and associated attributes |
---|
| 2552 | */ |
---|
[1460] | 2553 | void CDomain::recvDistributionAttributes(CEventServer& event) |
---|
[1642] | 2554 | TRY |
---|
[300] | 2555 | { |
---|
| 2556 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 2557 | string domainId ; |
---|
| 2558 | *buffer>>domainId ; |
---|
[1460] | 2559 | get(domainId)->recvDistributionAttributes(*buffer); |
---|
[300] | 2560 | } |
---|
[1642] | 2561 | CATCH |
---|
[509] | 2562 | |
---|
[667] | 2563 | /*! |
---|
[1642] | 2564 | Receive attributes from client(s) |
---|
[667] | 2565 | \param[in] rank rank of client source |
---|
| 2566 | \param[in] buffer message containing attributes info |
---|
| 2567 | */ |
---|
[1460] | 2568 | void CDomain::recvDistributionAttributes(CBufferIn& buffer) |
---|
[1642] | 2569 | TRY |
---|
[300] | 2570 | { |
---|
[1460] | 2571 | int ni_tmp, ibegin_tmp, nj_tmp, jbegin_tmp; |
---|
[1642] | 2572 | int ni_glo_tmp, nj_glo_tmp; |
---|
[1460] | 2573 | buffer >> isUnstructed_ >> ni_tmp >> ibegin_tmp >> nj_tmp >> jbegin_tmp |
---|
[1642] | 2574 | >> ni_glo_tmp >> nj_glo_tmp |
---|
[676] | 2575 | >> isCompressible_; |
---|
[1642] | 2576 | |
---|
[1460] | 2577 | ni.setValue(ni_tmp); |
---|
| 2578 | ibegin.setValue(ibegin_tmp); |
---|
| 2579 | nj.setValue(nj_tmp); |
---|
| 2580 | jbegin.setValue(jbegin_tmp); |
---|
[1642] | 2581 | ni_glo.setValue(ni_glo_tmp); |
---|
| 2582 | nj_glo.setValue(nj_glo_tmp); |
---|
[300] | 2583 | |
---|
| 2584 | } |
---|
[1642] | 2585 | CATCH_DUMP_ATTR |
---|
[667] | 2586 | /*! |
---|
| 2587 | Receive longitude event from clients(s) |
---|
| 2588 | \param[in] event event contain info about rank and associated longitude |
---|
| 2589 | */ |
---|
[518] | 2590 | void CDomain::recvLon(CEventServer& event) |
---|
[1642] | 2591 | TRY |
---|
[300] | 2592 | { |
---|
[1460] | 2593 | string domainId; |
---|
| 2594 | std::map<int, CBufferIn*> rankBuffers; |
---|
| 2595 | |
---|
[610] | 2596 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 2597 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[1460] | 2598 | { |
---|
[610] | 2599 | CBufferIn* buffer = it->buffer; |
---|
| 2600 | *buffer >> domainId; |
---|
[1460] | 2601 | rankBuffers[it->rank] = buffer; |
---|
[300] | 2602 | } |
---|
[1460] | 2603 | get(domainId)->recvLon(rankBuffers); |
---|
[300] | 2604 | } |
---|
[1642] | 2605 | CATCH |
---|
[509] | 2606 | |
---|
[667] | 2607 | /*! |
---|
| 2608 | Receive longitude information from client(s) |
---|
[1460] | 2609 | \param[in] rankBuffers rank of sending client and the corresponding receive buffer |
---|
[667] | 2610 | */ |
---|
[1460] | 2611 | void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers) |
---|
[1642] | 2612 | TRY |
---|
[300] | 2613 | { |
---|
[1460] | 2614 | int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex, lInd; |
---|
| 2615 | if (nbReceived != recvClientRanks_.size()) |
---|
| 2616 | ERROR("void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers)", |
---|
| 2617 | << "The number of sending clients is not correct." |
---|
| 2618 | << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); |
---|
[518] | 2619 | |
---|
[1460] | 2620 | vector<CArray<double,1> > recvLonValue(nbReceived); |
---|
| 2621 | vector<CArray<double,2> > recvBoundsLonValue(nbReceived); |
---|
| 2622 | for (i = 0; i < recvClientRanks_.size(); ++i) |
---|
| 2623 | { |
---|
| 2624 | int rank = recvClientRanks_[i]; |
---|
| 2625 | CBufferIn& buffer = *(rankBuffers[rank]); |
---|
| 2626 | buffer >> hasLonLat; |
---|
| 2627 | if (hasLonLat) |
---|
| 2628 | buffer >> recvLonValue[i]; |
---|
| 2629 | buffer >> hasBounds; |
---|
| 2630 | if (hasBounds) |
---|
| 2631 | buffer >> recvBoundsLonValue[i]; |
---|
| 2632 | } |
---|
[924] | 2633 | |
---|
[1460] | 2634 | if (hasLonLat) |
---|
| 2635 | { |
---|
| 2636 | int nbLonInd = 0; |
---|
| 2637 | for (i = 0; i < nbReceived; ++i) |
---|
| 2638 | { |
---|
| 2639 | nbLonInd += recvLonValue[i].numElements(); |
---|
| 2640 | } |
---|
| 2641 | |
---|
| 2642 | if (nbLonInd != globalLocalIndexMap_.size()) |
---|
[1545] | 2643 | info (0) << "If domain " << this->getDomainOutputName() <<" does not have overlapped regions between processes " |
---|
| 2644 | << "something must be wrong with longitude index "<< std::endl; |
---|
[518] | 2645 | |
---|
[1460] | 2646 | nbLonInd = globalLocalIndexMap_.size(); |
---|
| 2647 | lonvalue.resize(nbLonInd); |
---|
[518] | 2648 | if (hasBounds) |
---|
| 2649 | { |
---|
[1460] | 2650 | bounds_lonvalue.resize(nvertex,nbLonInd); |
---|
| 2651 | bounds_lonvalue = 0.; |
---|
[518] | 2652 | } |
---|
[1460] | 2653 | |
---|
| 2654 | nbLonInd = 0; |
---|
| 2655 | for (i = 0; i < nbReceived; ++i) |
---|
| 2656 | { |
---|
| 2657 | CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; |
---|
| 2658 | CArray<double,1>& tmp = recvLonValue[i]; |
---|
| 2659 | for (ind = 0; ind < tmp.numElements(); ++ind) |
---|
| 2660 | { |
---|
| 2661 | lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; |
---|
| 2662 | lonvalue(lInd) = tmp(ind); |
---|
| 2663 | if (hasBounds) |
---|
| 2664 | { |
---|
| 2665 | for (int nv = 0; nv < nvertex; ++nv) |
---|
| 2666 | bounds_lonvalue(nv, lInd) = recvBoundsLonValue[i](nv, ind); |
---|
| 2667 | } |
---|
| 2668 | } |
---|
| 2669 | } |
---|
[518] | 2670 | } |
---|
| 2671 | } |
---|
[1642] | 2672 | CATCH_DUMP_ATTR |
---|
[518] | 2673 | |
---|
[667] | 2674 | /*! |
---|
| 2675 | Receive latitude event from clients(s) |
---|
| 2676 | \param[in] event event contain info about rank and associated latitude |
---|
| 2677 | */ |
---|
[518] | 2678 | void CDomain::recvLat(CEventServer& event) |
---|
[1642] | 2679 | TRY |
---|
[518] | 2680 | { |
---|
[1460] | 2681 | string domainId; |
---|
| 2682 | std::map<int, CBufferIn*> rankBuffers; |
---|
| 2683 | |
---|
[610] | 2684 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 2685 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[1460] | 2686 | { |
---|
[610] | 2687 | CBufferIn* buffer = it->buffer; |
---|
| 2688 | *buffer >> domainId; |
---|
[1460] | 2689 | rankBuffers[it->rank] = buffer; |
---|
[518] | 2690 | } |
---|
[1460] | 2691 | get(domainId)->recvLat(rankBuffers); |
---|
[518] | 2692 | } |
---|
[1642] | 2693 | CATCH |
---|
[518] | 2694 | |
---|
[667] | 2695 | /*! |
---|
| 2696 | Receive latitude information from client(s) |
---|
[1460] | 2697 | \param[in] rankBuffers rank of sending client and the corresponding receive buffer |
---|
[667] | 2698 | */ |
---|
[1460] | 2699 | void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers) |
---|
[1642] | 2700 | TRY |
---|
[518] | 2701 | { |
---|
[1460] | 2702 | int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex, lInd; |
---|
| 2703 | if (nbReceived != recvClientRanks_.size()) |
---|
| 2704 | ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", |
---|
| 2705 | << "The number of sending clients is not correct." |
---|
| 2706 | << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); |
---|
[509] | 2707 | |
---|
[1460] | 2708 | vector<CArray<double,1> > recvLatValue(nbReceived); |
---|
| 2709 | vector<CArray<double,2> > recvBoundsLatValue(nbReceived); |
---|
| 2710 | for (i = 0; i < recvClientRanks_.size(); ++i) |
---|
| 2711 | { |
---|
| 2712 | int rank = recvClientRanks_[i]; |
---|
| 2713 | CBufferIn& buffer = *(rankBuffers[rank]); |
---|
| 2714 | buffer >> hasLonLat; |
---|
| 2715 | if (hasLonLat) |
---|
| 2716 | buffer >> recvLatValue[i]; |
---|
| 2717 | buffer >> hasBounds; |
---|
| 2718 | if (hasBounds) |
---|
| 2719 | buffer >> recvBoundsLatValue[i]; |
---|
| 2720 | } |
---|
[610] | 2721 | |
---|
[1460] | 2722 | if (hasLonLat) |
---|
[300] | 2723 | { |
---|
[1460] | 2724 | int nbLatInd = 0; |
---|
| 2725 | for (i = 0; i < nbReceived; ++i) |
---|
| 2726 | { |
---|
| 2727 | nbLatInd += recvLatValue[i].numElements(); |
---|
| 2728 | } |
---|
| 2729 | |
---|
| 2730 | if (nbLatInd != globalLocalIndexMap_.size()) |
---|
[1545] | 2731 | info (0) << "If domain " << this->getDomainOutputName() <<" does not have overlapped regions between processes " |
---|
| 2732 | << "something must be wrong with latitude index "<< std::endl; |
---|
[1460] | 2733 | |
---|
| 2734 | nbLatInd = globalLocalIndexMap_.size(); |
---|
| 2735 | latvalue.resize(nbLatInd); |
---|
[509] | 2736 | if (hasBounds) |
---|
[449] | 2737 | { |
---|
[1460] | 2738 | bounds_latvalue.resize(nvertex,nbLatInd); |
---|
| 2739 | bounds_latvalue = 0. ; |
---|
[449] | 2740 | } |
---|
[1460] | 2741 | |
---|
| 2742 | nbLatInd = 0; |
---|
| 2743 | for (i = 0; i < nbReceived; ++i) |
---|
| 2744 | { |
---|
| 2745 | CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; |
---|
| 2746 | CArray<double,1>& tmp = recvLatValue[i]; |
---|
| 2747 | for (ind = 0; ind < tmp.numElements(); ++ind) |
---|
| 2748 | { |
---|
| 2749 | lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; |
---|
| 2750 | latvalue(lInd) = tmp(ind); |
---|
| 2751 | if (hasBounds) |
---|
| 2752 | { |
---|
| 2753 | CArray<double,2>& boundslat = recvBoundsLatValue[i]; |
---|
| 2754 | for (int nv = 0; nv < nvertex; ++nv) |
---|
| 2755 | bounds_latvalue(nv, lInd) = boundslat(nv, ind); |
---|
| 2756 | } |
---|
| 2757 | ++nbLatInd; |
---|
| 2758 | } |
---|
| 2759 | } |
---|
[300] | 2760 | } |
---|
| 2761 | } |
---|
[1642] | 2762 | CATCH_DUMP_ATTR |
---|
[553] | 2763 | |
---|
[667] | 2764 | /*! |
---|
| 2765 | Receive area event from clients(s) |
---|
| 2766 | \param[in] event event contain info about rank and associated area |
---|
| 2767 | */ |
---|
[611] | 2768 | void CDomain::recvArea(CEventServer& event) |
---|
[1642] | 2769 | TRY |
---|
[611] | 2770 | { |
---|
[1460] | 2771 | string domainId; |
---|
| 2772 | std::map<int, CBufferIn*> rankBuffers; |
---|
| 2773 | |
---|
[611] | 2774 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 2775 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[1460] | 2776 | { |
---|
[611] | 2777 | CBufferIn* buffer = it->buffer; |
---|
| 2778 | *buffer >> domainId; |
---|
[1460] | 2779 | rankBuffers[it->rank] = buffer; |
---|
[611] | 2780 | } |
---|
[1460] | 2781 | get(domainId)->recvArea(rankBuffers); |
---|
[611] | 2782 | } |
---|
[1642] | 2783 | CATCH |
---|
[611] | 2784 | |
---|
[667] | 2785 | /*! |
---|
| 2786 | Receive area information from client(s) |
---|
[1460] | 2787 | \param[in] rankBuffers rank of sending client and the corresponding receive buffer |
---|
[667] | 2788 | */ |
---|
[1460] | 2789 | void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers) |
---|
[1642] | 2790 | TRY |
---|
[611] | 2791 | { |
---|
[1460] | 2792 | int nbReceived = rankBuffers.size(), i, ind, index, lInd; |
---|
| 2793 | if (nbReceived != recvClientRanks_.size()) |
---|
| 2794 | ERROR("void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)", |
---|
| 2795 | << "The number of sending clients is not correct." |
---|
| 2796 | << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); |
---|
[611] | 2797 | |
---|
[1460] | 2798 | vector<CArray<double,1> > recvAreaValue(nbReceived); |
---|
| 2799 | for (i = 0; i < recvClientRanks_.size(); ++i) |
---|
| 2800 | { |
---|
| 2801 | int rank = recvClientRanks_[i]; |
---|
| 2802 | CBufferIn& buffer = *(rankBuffers[rank]); |
---|
| 2803 | buffer >> hasArea; |
---|
| 2804 | if (hasArea) |
---|
| 2805 | buffer >> recvAreaValue[i]; |
---|
| 2806 | } |
---|
[611] | 2807 | |
---|
[1460] | 2808 | if (hasArea) |
---|
[611] | 2809 | { |
---|
[1460] | 2810 | int nbAreaInd = 0; |
---|
| 2811 | for (i = 0; i < nbReceived; ++i) |
---|
| 2812 | { |
---|
| 2813 | nbAreaInd += recvAreaValue[i].numElements(); |
---|
| 2814 | } |
---|
| 2815 | |
---|
| 2816 | if (nbAreaInd != globalLocalIndexMap_.size()) |
---|
[1545] | 2817 | info (0) << "If domain " << this->getDomainOutputName() <<" does not have overlapped regions between processes " |
---|
| 2818 | << "something must be wrong with area index "<< std::endl; |
---|
[1460] | 2819 | |
---|
| 2820 | nbAreaInd = globalLocalIndexMap_.size(); |
---|
| 2821 | areavalue.resize(nbAreaInd); |
---|
| 2822 | nbAreaInd = 0; |
---|
| 2823 | for (i = 0; i < nbReceived; ++i) |
---|
| 2824 | { |
---|
| 2825 | CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; |
---|
| 2826 | CArray<double,1>& tmp = recvAreaValue[i]; |
---|
| 2827 | for (ind = 0; ind < tmp.numElements(); ++ind) |
---|
| 2828 | { |
---|
| 2829 | lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; |
---|
| 2830 | areavalue(lInd) = tmp(ind); |
---|
| 2831 | } |
---|
| 2832 | } |
---|
| 2833 | |
---|
[611] | 2834 | } |
---|
| 2835 | } |
---|
[1642] | 2836 | CATCH_DUMP_ATTR |
---|
[611] | 2837 | |
---|
[1106] | 2838 | /*! |
---|
| 2839 | Compare two domain objects. |
---|
| 2840 | They are equal if only if they have identical attributes as well as their values. |
---|
| 2841 | Moreover, they must have the same transformations. |
---|
| 2842 | \param [in] domain Compared domain |
---|
| 2843 | \return result of the comparison |
---|
| 2844 | */ |
---|
| 2845 | bool CDomain::isEqual(CDomain* obj) |
---|
[1642] | 2846 | TRY |
---|
[1106] | 2847 | { |
---|
[1117] | 2848 | vector<StdString> excludedAttr; |
---|
| 2849 | excludedAttr.push_back("domain_ref"); |
---|
| 2850 | bool objEqual = SuperClass::isEqual(obj, excludedAttr); |
---|
[1106] | 2851 | if (!objEqual) return objEqual; |
---|
| 2852 | |
---|
| 2853 | TransMapTypes thisTrans = this->getAllTransformations(); |
---|
| 2854 | TransMapTypes objTrans = obj->getAllTransformations(); |
---|
| 2855 | |
---|
| 2856 | TransMapTypes::const_iterator it, itb, ite; |
---|
| 2857 | std::vector<ETranformationType> thisTransType, objTransType; |
---|
| 2858 | for (it = thisTrans.begin(); it != thisTrans.end(); ++it) |
---|
| 2859 | thisTransType.push_back(it->first); |
---|
| 2860 | for (it = objTrans.begin(); it != objTrans.end(); ++it) |
---|
| 2861 | objTransType.push_back(it->first); |
---|
| 2862 | |
---|
| 2863 | if (thisTransType.size() != objTransType.size()) return false; |
---|
| 2864 | for (int idx = 0; idx < thisTransType.size(); ++idx) |
---|
| 2865 | objEqual &= (thisTransType[idx] == objTransType[idx]); |
---|
| 2866 | |
---|
| 2867 | return objEqual; |
---|
| 2868 | } |
---|
[1642] | 2869 | CATCH_DUMP_ATTR |
---|
[1106] | 2870 | |
---|
[1460] | 2871 | /*! |
---|
| 2872 | Receive data index event from clients(s) |
---|
| 2873 | \param[in] event event contain info about rank and associated index |
---|
| 2874 | */ |
---|
| 2875 | void CDomain::recvDataIndex(CEventServer& event) |
---|
[1642] | 2876 | TRY |
---|
[1460] | 2877 | { |
---|
| 2878 | string domainId; |
---|
| 2879 | std::map<int, CBufferIn*> rankBuffers; |
---|
| 2880 | |
---|
| 2881 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 2882 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 2883 | { |
---|
| 2884 | CBufferIn* buffer = it->buffer; |
---|
| 2885 | *buffer >> domainId; |
---|
| 2886 | rankBuffers[it->rank] = buffer; |
---|
| 2887 | } |
---|
| 2888 | get(domainId)->recvDataIndex(rankBuffers); |
---|
| 2889 | } |
---|
[1642] | 2890 | CATCH |
---|
[1460] | 2891 | |
---|
| 2892 | /*! |
---|
| 2893 | Receive data index information from client(s) |
---|
| 2894 | A client receives data index from different clients to rebuild its own data index. |
---|
| 2895 | Because we use global index + mask info to calculate the sending data to client(s), |
---|
| 2896 | this data index must be updated with mask info (maybe it will change in the future) |
---|
| 2897 | Because the data index is local, to rebuild data index of received client, we should use global index along with. |
---|
| 2898 | |
---|
| 2899 | \param[in] rankBuffers rank of sending client and the corresponding receive buffer |
---|
| 2900 | */ |
---|
| 2901 | void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers) |
---|
[1642] | 2902 | TRY |
---|
[1460] | 2903 | { |
---|
| 2904 | int nbReceived = rankBuffers.size(), i, ind, index, indexI, indexJ, type_int, lInd; |
---|
| 2905 | if (nbReceived != recvClientRanks_.size()) |
---|
| 2906 | ERROR("void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers)", |
---|
| 2907 | << "The number of sending clients is not correct." |
---|
| 2908 | << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); |
---|
| 2909 | |
---|
| 2910 | vector<CArray<int,1> > recvDataIIndex(nbReceived),recvDataJIndex(nbReceived); |
---|
| 2911 | for (i = 0; i < recvClientRanks_.size(); ++i) |
---|
| 2912 | { |
---|
| 2913 | int rank = recvClientRanks_[i]; |
---|
| 2914 | CBufferIn& buffer = *(rankBuffers[rank]); |
---|
| 2915 | buffer >> recvDataIIndex[i]; |
---|
| 2916 | buffer >> recvDataJIndex[i]; |
---|
| 2917 | } |
---|
| 2918 | |
---|
| 2919 | int nbIndex = i_index.numElements(); |
---|
| 2920 | CArray<int,1> dataIIndex(nbIndex), dataJIndex(nbIndex); |
---|
| 2921 | dataIIndex = -1; dataJIndex = -1; |
---|
| 2922 | |
---|
| 2923 | nbIndex = 0; |
---|
| 2924 | for (i = 0; i < nbReceived; ++i) |
---|
| 2925 | { |
---|
| 2926 | CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; |
---|
| 2927 | CArray<int,1>& tmpI = recvDataIIndex[i]; |
---|
| 2928 | CArray<int,1>& tmpJ = recvDataJIndex[i]; |
---|
| 2929 | if ((tmpI.numElements() != tmpInd.numElements()) || (tmpJ.numElements() != tmpInd.numElements())) |
---|
| 2930 | ERROR("void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers)", |
---|
| 2931 | << "The number of global received index is not coherent with the number of received data index." |
---|
| 2932 | << "Expected number of global index: " << tmpI.numElements() << " but received " << tmpInd.numElements()); |
---|
| 2933 | |
---|
| 2934 | for (ind = 0; ind < tmpI.numElements(); ++ind) |
---|
| 2935 | { |
---|
| 2936 | lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; |
---|
| 2937 | dataIIndex(lInd) = (-1 == dataIIndex(lInd)) ? tmpI(ind) : dataIIndex(lInd); // Only fill in dataIndex if there is no data |
---|
| 2938 | dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd); |
---|
| 2939 | } |
---|
| 2940 | } |
---|
| 2941 | |
---|
| 2942 | int nbCompressedData = 0; |
---|
| 2943 | for (ind = 0; ind < dataIIndex.numElements(); ++ind) |
---|
| 2944 | { |
---|
| 2945 | indexI = dataIIndex(ind); indexJ = dataJIndex(ind); |
---|
| 2946 | if ((0 <= indexI) && (0 <= indexJ)) |
---|
| 2947 | ++nbCompressedData; |
---|
| 2948 | } |
---|
| 2949 | |
---|
| 2950 | data_i_index.resize(nbCompressedData); |
---|
| 2951 | data_j_index.resize(nbCompressedData); |
---|
| 2952 | |
---|
| 2953 | nbCompressedData = 0; |
---|
| 2954 | for (ind = 0; ind < dataIIndex.numElements(); ++ind) |
---|
| 2955 | { |
---|
| 2956 | indexI = dataIIndex(ind); indexJ = dataJIndex(ind); |
---|
| 2957 | if ((0 <= indexI) && (0 <= indexJ)) |
---|
| 2958 | { |
---|
| 2959 | data_i_index(nbCompressedData) = (1 == data_dim) ? ind : ind % ni; |
---|
| 2960 | data_j_index(nbCompressedData) = (1 == data_dim) ? 0 : ind / ni; |
---|
| 2961 | ++nbCompressedData; |
---|
| 2962 | } |
---|
| 2963 | } |
---|
| 2964 | |
---|
| 2965 | // Reset data_ibegin, data_jbegin |
---|
| 2966 | data_ibegin.setValue(0); |
---|
| 2967 | data_jbegin.setValue(0); |
---|
| 2968 | } |
---|
[1642] | 2969 | CATCH_DUMP_ATTR |
---|
[1460] | 2970 | |
---|
[836] | 2971 | CTransformation<CDomain>* CDomain::addTransformation(ETranformationType transType, const StdString& id) |
---|
[1642] | 2972 | TRY |
---|
[836] | 2973 | { |
---|
| 2974 | transformationMap_.push_back(std::make_pair(transType, CTransformation<CDomain>::createTransformation(transType,id))); |
---|
| 2975 | return transformationMap_.back().second; |
---|
| 2976 | } |
---|
[1642] | 2977 | CATCH_DUMP_ATTR |
---|
[836] | 2978 | |
---|
[667] | 2979 | /*! |
---|
| 2980 | Check whether a domain has transformation |
---|
| 2981 | \return true if domain has transformation |
---|
| 2982 | */ |
---|
[631] | 2983 | bool CDomain::hasTransformation() |
---|
[1642] | 2984 | TRY |
---|
[631] | 2985 | { |
---|
| 2986 | return (!transformationMap_.empty()); |
---|
| 2987 | } |
---|
[1642] | 2988 | CATCH_DUMP_ATTR |
---|
[631] | 2989 | |
---|
[667] | 2990 | /*! |
---|
| 2991 | Set transformation for current domain. It's the method to move transformation in hierarchy |
---|
| 2992 | \param [in] domTrans transformation on domain |
---|
| 2993 | */ |
---|
[631] | 2994 | void CDomain::setTransformations(const TransMapTypes& domTrans) |
---|
[1642] | 2995 | TRY |
---|
[631] | 2996 | { |
---|
| 2997 | transformationMap_ = domTrans; |
---|
| 2998 | } |
---|
[1642] | 2999 | CATCH_DUMP_ATTR |
---|
[631] | 3000 | |
---|
[667] | 3001 | /*! |
---|
| 3002 | Get all transformation current domain has |
---|
| 3003 | \return all transformation |
---|
| 3004 | */ |
---|
[631] | 3005 | CDomain::TransMapTypes CDomain::getAllTransformations(void) |
---|
[1642] | 3006 | TRY |
---|
[631] | 3007 | { |
---|
| 3008 | return transformationMap_; |
---|
| 3009 | } |
---|
[1642] | 3010 | CATCH_DUMP_ATTR |
---|
[631] | 3011 | |
---|
[823] | 3012 | void CDomain::duplicateTransformation(CDomain* src) |
---|
[1642] | 3013 | TRY |
---|
[823] | 3014 | { |
---|
| 3015 | if (src->hasTransformation()) |
---|
| 3016 | { |
---|
| 3017 | this->setTransformations(src->getAllTransformations()); |
---|
| 3018 | } |
---|
| 3019 | } |
---|
[1642] | 3020 | CATCH_DUMP_ATTR |
---|
[823] | 3021 | |
---|
[667] | 3022 | /*! |
---|
[747] | 3023 | * Go through the hierarchy to find the domain from which the transformations must be inherited |
---|
| 3024 | */ |
---|
[631] | 3025 | void CDomain::solveInheritanceTransformation() |
---|
[1642] | 3026 | TRY |
---|
[631] | 3027 | { |
---|
[747] | 3028 | if (hasTransformation() || !hasDirectDomainReference()) |
---|
| 3029 | return; |
---|
[631] | 3030 | |
---|
[747] | 3031 | CDomain* domain = this; |
---|
| 3032 | std::vector<CDomain*> refDomains; |
---|
| 3033 | while (!domain->hasTransformation() && domain->hasDirectDomainReference()) |
---|
[631] | 3034 | { |
---|
[747] | 3035 | refDomains.push_back(domain); |
---|
| 3036 | domain = domain->getDirectDomainReference(); |
---|
[631] | 3037 | } |
---|
| 3038 | |
---|
[747] | 3039 | if (domain->hasTransformation()) |
---|
| 3040 | for (size_t i = 0; i < refDomains.size(); ++i) |
---|
| 3041 | refDomains[i]->setTransformations(domain->getAllTransformations()); |
---|
[631] | 3042 | } |
---|
[1642] | 3043 | CATCH_DUMP_ATTR |
---|
[631] | 3044 | |
---|
[1460] | 3045 | void CDomain::setContextClient(CContextClient* contextClient) |
---|
[1642] | 3046 | TRY |
---|
[1460] | 3047 | { |
---|
| 3048 | if (clientsSet.find(contextClient)==clientsSet.end()) |
---|
| 3049 | { |
---|
| 3050 | clients.push_back(contextClient) ; |
---|
| 3051 | clientsSet.insert(contextClient); |
---|
| 3052 | } |
---|
| 3053 | } |
---|
[1642] | 3054 | CATCH_DUMP_ATTR |
---|
[1460] | 3055 | |
---|
[667] | 3056 | /*! |
---|
| 3057 | Parse children nodes of a domain in xml file. |
---|
| 3058 | Whenver there is a new transformation, its type and name should be added into this function |
---|
| 3059 | \param node child node to process |
---|
| 3060 | */ |
---|
[631] | 3061 | void CDomain::parse(xml::CXMLNode & node) |
---|
[1642] | 3062 | TRY |
---|
[631] | 3063 | { |
---|
| 3064 | SuperClass::parse(node); |
---|
| 3065 | |
---|
| 3066 | if (node.goToChildElement()) |
---|
| 3067 | { |
---|
[836] | 3068 | StdString nodeElementName; |
---|
[631] | 3069 | do |
---|
| 3070 | { |
---|
[784] | 3071 | StdString nodeId(""); |
---|
| 3072 | if (node.getAttributes().end() != node.getAttributes().find("id")) |
---|
| 3073 | { nodeId = node.getAttributes()["id"]; } |
---|
| 3074 | |
---|
[836] | 3075 | nodeElementName = node.getElementName(); |
---|
[1642] | 3076 | std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it; |
---|
| 3077 | it = transformationMapList_.find(nodeElementName); |
---|
[836] | 3078 | if (ite != it) |
---|
[657] | 3079 | { |
---|
[836] | 3080 | transformationMap_.push_back(std::make_pair(it->second, CTransformation<CDomain>::createTransformation(it->second, |
---|
| 3081 | nodeId, |
---|
| 3082 | &node))); |
---|
[657] | 3083 | } |
---|
[968] | 3084 | else |
---|
| 3085 | { |
---|
| 3086 | ERROR("void CDomain::parse(xml::CXMLNode & node)", |
---|
| 3087 | << "The transformation " << nodeElementName << " has not been supported yet."); |
---|
| 3088 | } |
---|
[631] | 3089 | } while (node.goToNextElement()) ; |
---|
| 3090 | node.goToParentElement(); |
---|
| 3091 | } |
---|
| 3092 | } |
---|
[1642] | 3093 | CATCH_DUMP_ATTR |
---|
[219] | 3094 | //---------------------------------------------------------------- |
---|
[509] | 3095 | |
---|
[540] | 3096 | DEFINE_REF_FUNC(Domain,domain) |
---|
[509] | 3097 | |
---|
[219] | 3098 | ///--------------------------------------------------------------- |
---|
| 3099 | |
---|
[335] | 3100 | } // namespace xios |
---|