Changeset 509 for XIOS/trunk/src/node/grid.cpp
- Timestamp:
- 11/13/14 15:09:14 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/grid.cpp
r501 r509 19 19 CGrid::CGrid(void) 20 20 : CObjectTemplate<CGrid>(), CGridAttributes() 21 , withAxis(false), isChecked(false), axis(), domain()22 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) 21 , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 22 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 23 23 { /* Ne rien faire de plus */ } 24 24 25 25 CGrid::CGrid(const StdString & id) 26 26 : CObjectTemplate<CGrid>(id), CGridAttributes() 27 , withAxis(false), isChecked(false), axis(), domain()28 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) 27 , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 28 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 29 29 { /* Ne rien faire de plus */ } 30 30 31 31 CGrid::~CGrid(void) 32 { 32 { 33 33 // this->axis.reset() ; 34 34 // this->domain.reset() ; 35 35 deque< CArray<int, 1>* >::iterator it ; 36 36 37 37 for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++) delete *it ; 38 38 for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; … … 55 55 56 56 const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const 57 { 57 { 58 58 return (this->storeIndex ); 59 59 } … … 62 62 63 63 const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void) const 64 { 65 return (this->out_i_index ); 64 { 65 return (this->out_i_index ); 66 66 } 67 67 … … 69 69 70 70 const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void) const 71 { 72 return (this->out_j_index ); 71 { 72 return (this->out_j_index ); 73 73 } 74 74 … … 76 76 77 77 const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void) const 78 { 79 return (this->out_l_index ); 78 { 79 return (this->out_l_index ); 80 80 } 81 81 … … 83 83 84 84 const CAxis* CGrid::getRelAxis (void) const 85 { 86 return (this->axis ); 85 { 86 return (this->axis ); 87 87 } 88 88 … … 90 90 91 91 const CDomain* CGrid::getRelDomain(void) const 92 { 93 return (this->domain ); 94 } 95 96 //--------------------------------------------------------------- 97 98 bool CGrid::hasAxis(void) const 99 { 100 return (this->withAxis); 92 { 93 return (this->domain ); 94 } 95 96 //--------------------------------------------------------------- 97 98 bool CGrid::hasAxis(void) const 99 { 100 return (this->withAxis); 101 101 } 102 102 … … 122 122 */ 123 123 //--------------------------------------------------------------- 124 124 125 125 /* 126 126 StdSize CGrid::getLocalSize(void) const … … 147 147 //--------------------------------------------------------------- 148 148 149 /* 149 /* 150 150 StdSize CGrid::getGlobalSize(void) const 151 151 { … … 166 166 } 167 167 168 //--------------------------------------------------------------- 169 170 void CGrid::solveReference(void) 171 { 172 if (this->isChecked) return; 173 CContext* context = CContext::getCurrent() ; 174 CContextClient* client=context->client ; 175 176 this->solveDomainRef() ; 177 this->solveAxisRef() ; 178 179 if (context->hasClient) 180 { 181 checkMask() ; 182 this->computeIndex() ; 183 184 this->storeIndex.push_front(new CArray<int,1>() ); 185 this->out_i_index.push_front(new CArray<int,1>()); 186 this->out_j_index.push_front(new CArray<int,1>()); 187 this->out_l_index.push_front(new CArray<int,1>()); 188 } 168 std::map<int, StdSize> CGrid::getConnectedServerDataSize() 169 { 170 std::map<int, StdSize> ret; 171 std::map<int, int>::const_iterator it = domConnectedServerSide_.begin(), 172 itE = domConnectedServerSide_.end(); 173 StdSize retVal = StdSize(0.0); 174 for (; it != itE; ++it) 175 { 176 retVal = it->second; 177 if (this->withAxis) retVal *= this->axis->size.getValue(); 178 retVal *= sizeof(double); 179 ret.insert(make_pair(it->first, retVal)); 180 } 181 return ret; 182 } 183 184 185 //--------------------------------------------------------------- 186 187 // void CGrid::solveReference(void) 188 // { 189 // if (this->isChecked) return; 190 // CContext* context = CContext::getCurrent() ; 191 // CContextClient* client=context->client ; 192 // 193 // this->solveDomainRef() ; 194 // this->solveAxisRef() ; 195 // 196 // if (context->hasClient) 197 // { 198 // checkMask() ; 199 // this->computeIndex() ; 200 // 201 // this->storeIndex.push_front(new CArray<int,1>() ); 202 // this->out_i_index.push_front(new CArray<int,1>()); 203 // this->out_j_index.push_front(new CArray<int,1>()); 204 // this->out_l_index.push_front(new CArray<int,1>()); 205 // } 206 //// this->computeIndexServer(); 207 // this->isChecked = true; 208 // } 209 210 void CGrid::solveDomainAxisRef(bool areAttributesChecked) 211 { 212 if (this->isDomainAxisChecked) return; 213 214 this->solveDomainRef(areAttributesChecked); 215 this->solveAxisRef(areAttributesChecked); 216 217 this->isDomainAxisChecked = areAttributesChecked; 218 } 219 220 void CGrid::checkMaskIndex(bool doSendingIndex) 221 { 222 CContext* context = CContext::getCurrent() ; 223 CContextClient* client=context->client ; 224 225 if (context->hasClient) 226 if (this->isChecked && doSendingIndex) sendIndex(); 227 228 if (this->isChecked) return; 229 230 if (context->hasClient) 231 { 232 checkMask() ; 233 this->computeIndex() ; 234 235 this->storeIndex.push_front(new CArray<int,1>() ); 236 this->out_i_index.push_front(new CArray<int,1>()); 237 this->out_j_index.push_front(new CArray<int,1>()); 238 this->out_l_index.push_front(new CArray<int,1>()); 239 } 189 240 // this->computeIndexServer(); 190 241 this->isChecked = true; 191 242 } 192 243 … … 206 257 (mask.extent(2) != nlu)) 207 258 ERROR("CGrid::checkAttributes(void)", 208 <<"The mask has not the same size than the local grid"<<endl 259 <<"The mask has not the same size than the local grid"<<endl 209 260 <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl 210 261 <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); 211 262 } 212 else 263 else 213 264 { 214 265 mask.resize(niu,nju,nlu) ; 215 266 mask=true ; 216 267 } 217 268 218 269 CArray<bool,2>& domainMask = domain->mask ; 219 270 for (int l=0; l < nlu ; l++) 220 271 for (int j=0; j < nju ; j++) 221 272 for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ; 222 223 224 } 225 226 //--------------------------------------------------------------- 227 228 void CGrid::solveDomainRef(void) 273 274 275 } 276 277 //--------------------------------------------------------------- 278 279 // void CGrid::solveDomainRef(void) 280 // { 281 // if (!domain_ref.isEmpty()) 282 // { 283 // if (CDomain::has(domain_ref.getValue())) 284 // { 285 // this->domain = CDomain::get(domain_ref.getValue()) ; 286 // domain->checkAttributes() ; 287 // } 288 // else ERROR("CGrid::solveDomainRef(void)", 289 // << "Wrong domain reference") ; 290 // } 291 // else ERROR("CGrid::solveDomainRef(void)", 292 // << "Domain reference is not defined") ; 293 // } 294 // 295 // //--------------------------------------------------------------- 296 // 297 // void CGrid::solveAxisRef(void) 298 // { 299 // if (!axis_ref.isEmpty()) 300 // { 301 // this->withAxis = true ; 302 // if (CAxis::get(axis_ref.getValue())) 303 // { 304 // this->axis = CAxis::get(axis_ref.getValue()) ; 305 // axis->checkAttributes() ; 306 // } 307 // else ERROR("CGrid::solveAxisRef(void)", 308 // << "Wrong axis reference") ; 309 // } 310 // else withAxis = false ; 311 // } 312 313 314 void CGrid::solveDomainRef(bool sendAtt) 229 315 { 230 316 if (!domain_ref.isEmpty()) … … 233 319 { 234 320 this->domain = CDomain::get(domain_ref.getValue()) ; 235 domain->checkAttributes() ; 321 if (sendAtt) domain->sendCheckedAttributes(); 322 else domain->checkAttributesOnClient() ; 236 323 } 237 324 else ERROR("CGrid::solveDomainRef(void)", … … 244 331 //--------------------------------------------------------------- 245 332 246 void CGrid::solveAxisRef( void)333 void CGrid::solveAxisRef(bool checkAtt) 247 334 { 248 335 if (!axis_ref.isEmpty()) … … 263 350 264 351 void CGrid::computeIndex(void) 265 { 266 352 { 353 267 354 const int ni = domain->ni.getValue() , 268 355 nj = domain->nj.getValue() , … … 280 367 CArray<int,1> data_i_index = domain->data_i_index ; 281 368 CArray<int,1> data_j_index = domain->data_j_index ; 282 369 283 370 284 371 int indexCount = 0; … … 302 389 } 303 390 } 304 391 305 392 storeIndex[0] = new CArray<int,1>(indexCount) ; 306 393 out_i_index[0] = new CArray<int,1>(indexCount) ; 307 394 out_j_index[0] = new CArray<int,1>(indexCount) ; 308 395 out_l_index[0] = new CArray<int,1>(indexCount) ; 309 396 310 397 storeIndex_client.resize(indexCount) ; 311 398 out_i_client.resize(indexCount) ; 312 399 out_j_client.resize(indexCount) ; 313 400 out_l_client.resize(indexCount) ; 314 315 401 402 316 403 for(int count = 0, indexCount = 0, l = 0; l < size; l++) 317 404 { … … 334 421 (*out_i_index[0])(indexCount) = i ; 335 422 (*out_j_index[0])(indexCount) = j ; 336 423 337 424 storeIndex_client(indexCount) = count ; 338 425 out_i_client(indexCount)=i+domain->ibegin_client-1 ; … … 343 430 } 344 431 } 345 sendIndex() ; 432 computeDomConServer(); 433 // sendIndex() ; 346 434 347 435 … … 370 458 //---------------------------------------------------------------- 371 459 372 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 3>& field) 460 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 3>& field) 373 461 { 374 462 CArray<int,1>& out_i=*out_i_fromClient[rank] ; 375 463 CArray<int,1>& out_j=*out_j_fromClient[rank] ; 376 464 CArray<int,1>& out_l=*out_l_fromClient[rank] ; 377 465 378 466 for(StdSize n = 0; n < stored.numElements(); n++) 379 467 field(out_i(n), out_j(n), out_l(n)) = stored(n) ; 380 468 } 381 469 382 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 2>& field) 470 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 2>& field) 383 471 { 384 472 CArray<int,1>& out_i=*out_i_fromClient[rank] ; 385 473 CArray<int,1>& out_j=*out_j_fromClient[rank] ; 386 474 387 475 for(StdSize n = 0; n < stored.numElements(); n++) 388 476 field(out_i(n), out_j(n)) = stored(n) ; } … … 393 481 { 394 482 CArray<int,1>& out_i=*out_i_fromClient[rank] ; 395 483 396 484 for(StdSize n = 0; n < stored.numElements(); n++) 397 485 field(out_i(n)) = stored(n) ; … … 399 487 400 488 //---------------------------------------------------------------- 401 489 402 490 403 491 void CGrid::storeField_arr … … 409 497 for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; 410 498 } 411 412 //--------------------------------------------------------------- 499 500 //--------------------------------------------------------------- 501 502 // void CGrid::sendIndex(void) 503 // { 504 // CContext* context = CContext::getCurrent() ; 505 // CContextClient* client=context->client ; 506 // 507 // CEventClient event(getType(),EVENT_ID_INDEX) ; 508 // int rank ; 509 // list<shared_ptr<CMessage> > list_msg ; 510 // list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 511 // 512 // for(int ns=0;ns<domain->connectedServer.size();ns++) 513 // { 514 // rank=domain->connectedServer[ns] ; 515 // 516 // int i,j ; 517 // int nb=0 ; 518 // for(int k=0;k<storeIndex_client.numElements();k++) 519 // { 520 // i=out_i_client(k)- domain->ibegin +1; 521 // j=out_j_client(k)- domain->jbegin +1; 522 // if (domain->mapConnectedServer(i,j)==ns) nb++ ; 523 // } 524 // 525 // CArray<int,1> storeIndex(nb) ; 526 // CArray<int,1> out_i(nb) ; 527 // CArray<int,1> out_j(nb) ; 528 // CArray<int,1> out_l(nb) ; 529 // 530 // 531 // nb=0 ; 532 // for(int k=0;k<storeIndex_client.numElements();k++) 533 // { 534 // i=out_i_client(k)- domain->ibegin +1 ; 535 // j=out_j_client(k)- domain->jbegin +1 ; 536 // if (domain->mapConnectedServer(i,j)==ns) 537 // { 538 // storeIndex(nb)=k ; 539 // out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 540 // out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 541 // out_l(nb)=out_l_client(k) ; 542 // nb++ ; 543 // } 544 // } 545 // 546 // storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 547 // nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 548 // list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 549 // list_out_i.push_back(new CArray<int,1>(out_i)) ; 550 // list_out_j.push_back(new CArray<int,1>(out_j)) ; 551 // list_out_l.push_back(new CArray<int,1>(out_l)) ; 552 // 553 // *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; 554 // event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; 555 // } 556 // client->sendEvent(event) ; 557 // 558 // for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; 559 // for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 560 // for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 561 // 562 // } 563 564 void CGrid::computeDomConServer() 565 { 566 if (!isDomConServerComputed_) 567 { 568 for(int ns=0;ns<domain->connectedServer.size(); ++ns) 569 { 570 int rank=domain->connectedServer[ns] ; 571 572 int i,j ; 573 int nb=0 ; 574 for(int k=0;k<storeIndex_client.numElements();++k) 575 { 576 i=out_i_client(k)- domain->ibegin +1; 577 j=out_j_client(k)- domain->jbegin +1; 578 if (domain->mapConnectedServer(i,j)==ns) ++nb ; 579 } 580 581 domConnectedServerSide_.insert(std::make_pair(rank, nb)); 582 } 583 isDomConServerComputed_ = true; 584 } 585 } 586 587 588 std::map<int, int> CGrid::getDomConServerSide() 589 { 590 return domConnectedServerSide_; 591 } 413 592 414 593 void CGrid::sendIndex(void) … … 416 595 CContext* context = CContext::getCurrent() ; 417 596 CContextClient* client=context->client ; 418 597 419 598 CEventClient event(getType(),EVENT_ID_INDEX) ; 420 599 int rank ; 421 600 list<shared_ptr<CMessage> > list_msg ; 422 601 list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 423 602 603 if (!isDomConServerComputed_) computeDomConServer(); 604 424 605 for(int ns=0;ns<domain->connectedServer.size();ns++) 425 606 { 426 607 rank=domain->connectedServer[ns] ; 427 428 int i,j ; 429 int nb=0 ; 430 for(int k=0;k<storeIndex_client.numElements();k++) 431 { 432 i=out_i_client(k)- domain->ibegin +1; 433 j=out_j_client(k)- domain->jbegin +1; 434 if (domain->mapConnectedServer(i,j)==ns) nb++ ; 435 } 436 608 609 int nb = domConnectedServerSide_.find(rank)->second; 437 610 CArray<int,1> storeIndex(nb) ; 438 611 CArray<int,1> out_i(nb) ; 439 612 CArray<int,1> out_j(nb) ; 440 613 CArray<int,1> out_l(nb) ; 441 442 614 615 int i, j; 443 616 nb=0 ; 444 617 for(int k=0;k<storeIndex_client.numElements();k++) … … 450 623 storeIndex(nb)=k ; 451 624 out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 452 out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 625 out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 453 626 out_l(nb)=out_l_client(k) ; 454 627 nb++ ; 455 628 } 456 629 } 457 630 458 631 storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 459 632 nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; … … 471 644 for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 472 645 for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 473 646 474 647 } 475 648 476 649 void CGrid::recvIndex(CEventServer& event) 477 650 { … … 486 659 } 487 660 } 488 661 489 662 void CGrid::recvIndex(int rank, CBufferIn& buffer) 490 663 { … … 492 665 CArray<int,1> out_j ; 493 666 CArray<int,1> out_l ; 494 667 495 668 buffer>>out_i>>out_j>>out_l ; 496 669 497 670 out_i -= domain->zoom_ibegin_srv-1 ; 498 671 out_j -= domain->zoom_jbegin_srv-1 ; 499 672 500 673 out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; 501 674 out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; … … 505 678 bool CGrid::dispatchEvent(CEventServer& event) 506 679 { 507 680 508 681 if (SuperClass::dispatchEvent(event)) return true ; 509 682 else … … 515 688 return true ; 516 689 break ; 517 690 518 691 default : 519 692 ERROR("bool CDomain::dispatchEvent(CEventServer& event)", … … 532 705 << "Data from clients are missing!") ; 533 706 storedServer.resize(storeIndex[0]->numElements()); 534 707 535 708 for (StdSize i = 0, n = 0; i < storedClient.size(); i++) 536 709 for (StdSize j = 0; j < storedClient[i]->numElements(); j++) … … 543 716 int nb=index.numElements() ; 544 717 fieldOut.resize(nb) ; 545 718 546 719 for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; 547 720 }
Note: See TracChangeset
for help on using the changeset viewer.