Changeset 509 for XIOS/trunk/src/node/domain.cpp
- Timestamp:
- 11/13/14 15:09:14 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/domain.cpp
r501 r509 16 16 17 17 namespace xios { 18 18 19 19 /// ////////////////////// Définitions ////////////////////// /// 20 20 21 21 CDomain::CDomain(void) 22 22 : CObjectTemplate<CDomain>(), CDomainAttributes() 23 , isChecked(false), relFiles()23 , isChecked(false), relFiles(), isClientChecked(false) 24 24 { /* Ne rien faire de plus */ } 25 25 26 26 CDomain::CDomain(const StdString & id) 27 27 : CObjectTemplate<CDomain>(id), CDomainAttributes() 28 , isChecked(false), relFiles() 28 , isChecked(false), relFiles(), isClientChecked(false) 29 29 { /* Ne rien faire de plus */ } 30 30 31 31 CDomain::~CDomain(void) 32 { 32 { 33 33 } 34 34 … … 37 37 const std::set<StdString> & CDomain::getRelFiles(void) const 38 38 { 39 return (this->relFiles); 40 } 41 42 //---------------------------------------------------------------- 43 39 return (this->relFiles); 40 } 41 42 //---------------------------------------------------------------- 43 44 44 bool CDomain::hasZoom(void) const 45 45 { 46 return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && 46 return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && 47 47 (this->zoom_nj.getValue() != this->nj_glo.getValue())); 48 48 } 49 50 //---------------------------------------------------------------- 51 49 50 //---------------------------------------------------------------- 51 52 52 bool CDomain::isEmpty(void) const 53 53 { 54 return ((this->zoom_ni_srv == 0) || 54 return ((this->zoom_ni_srv == 0) || 55 55 (this->zoom_nj_srv == 0)); 56 56 } … … 86 86 << "[ Id = " << this->getId() << " ] " 87 87 << "The global domain is badly defined," 88 << " check the \'ni_glo\' value !") 88 << " check the \'ni_glo\' value !") 89 89 } 90 90 nj_glo=ni_glo ; … … 111 111 ibegin=1 ; 112 112 iend=1 ; 113 113 114 114 } 115 115 else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || … … 119 119 << "[ Id = " << this->getId() << " ] " 120 120 << "The global domain is badly defined," 121 << " check the \'ni_glo\' et \'nj_glo\' values !") 121 << " check the \'ni_glo\' et \'nj_glo\' values !") 122 122 } 123 123 checkLocalIDomain() ; 124 124 checkLocalJDomain() ; 125 125 126 126 if (i_index.isEmpty()) 127 127 { 128 128 i_index.resize(ni,nj) ; 129 129 for(int j=0;j<nj;j++) 130 for(int i=0;i<ni;i++) i_index(i,j)=i ; 130 for(int i=0;i<ni;i++) i_index(i,j)=i ; 131 131 } 132 132 133 133 if (j_index.isEmpty()) 134 134 { 135 135 j_index.resize(ni,nj) ; 136 136 for(int j=0;j<nj;j++) 137 for(int i=0;i<ni;i++) j_index(i,j)=j ; 137 for(int i=0;i<ni;i++) j_index(i,j)=j ; 138 138 } 139 139 140 140 } 141 141 … … 211 211 << "Domain is wrong defined," 212 212 << " Check the values : nj, nj_glo, jbegin, jend") ; 213 213 214 214 ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 215 215 jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; … … 221 221 { 222 222 using namespace std; 223 223 224 224 int ibegin_mask = 0, 225 225 jbegin_mask = 0, 226 226 iend_mask = iend.getValue() - ibegin.getValue(), 227 227 jend_mask = jend.getValue() - jbegin.getValue(); 228 228 229 229 if (!zoom_ibegin.isEmpty()) 230 230 { 231 231 int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1; 232 232 int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1; 233 233 234 234 ibegin_mask = max (ibegin.getValue(), zoom_ibegin.getValue()); 235 235 jbegin_mask = max (jbegin.getValue(), zoom_jbegin.getValue()); 236 236 iend_mask = min (iend.getValue(), zoom_iend); 237 237 jend_mask = min (jend.getValue(), zoom_jend); 238 238 239 239 ibegin_mask -= ibegin.getValue(); 240 240 jbegin_mask -= jbegin.getValue(); … … 242 242 jend_mask -= jbegin.getValue(); 243 243 } 244 244 245 245 246 246 if (!mask.isEmpty()) … … 251 251 <<"the mask has not the same size than the local domain"<<endl 252 252 <<"Local size is "<<ni<<"x"<<nj<<endl 253 <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)); 253 <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)); 254 254 for (int i = 0; i < ni; i++) 255 255 { … … 283 283 284 284 void CDomain::checkDomainData(void) 285 { 285 { 286 286 if (!data_dim.isEmpty() && 287 287 !(data_dim.getValue() == 1 || data_dim.getValue() == 2)) … … 378 378 data_i_index.resize(dni) ; 379 379 data_j_index.resize(dni) ; 380 380 381 381 data_n_index.setValue(dni); 382 382 383 383 for(int count = 0, j = 0; j < data_nj.getValue(); j++) 384 384 { … … 394 394 395 395 //---------------------------------------------------------------- 396 396 397 397 void CDomain::completeLonLatClient(void) 398 398 { … … 402 402 CArray<double,2> bounds_lon_temp(nvertex,ni*nj) ; 403 403 CArray<double,2> bounds_lat_temp(nvertex,ni*nj) ; 404 404 405 405 if (type.isEmpty()) 406 406 { 407 if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) 407 if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) 408 408 { 409 409 type.setValue(type_attr::curvilinear) ; 410 410 isCurvilinear=true ; 411 411 } 412 else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) 412 else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) 413 413 { 414 414 type.setValue(type_attr::regular) ; … … 429 429 { 430 430 for(j=0;j<nj;j++) 431 for(i=0;i<ni;i++) 431 for(i=0;i<ni;i++) 432 432 { 433 433 k=j*ni+i ; … … 436 436 if (hasBounds) 437 437 { 438 for(int n=0;n<nvertex;n++) 438 for(int n=0;n<nvertex;n++) 439 439 { 440 440 bounds_lon_temp(n,k)=bounds_lon(n,i) ; … … 444 444 } 445 445 } 446 446 447 447 StdSize dm = zoom_ni_client * zoom_nj_client; 448 448 449 449 lonvalue.resize(dm); 450 450 latvalue.resize(dm); 451 451 452 452 for (int i = 0; i < zoom_ni_client; i++) 453 453 { 454 454 for (int j = 0; j < zoom_nj_client; j++) 455 455 { 456 lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 456 lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 457 457 latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni ); 458 458 if (hasBounds) 459 459 { 460 for(int n=0;n<nvertex;n++) 460 for(int n=0;n<nvertex;n++) 461 461 { 462 bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 462 bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 463 463 bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni ); 464 464 } … … 467 467 } 468 468 } 469 469 470 470 471 471 //---------------------------------------------------------------- … … 487 487 int zoom_iend = zoom_ibegin + zoom_ni - 1; 488 488 int zoom_jend = zoom_jbegin + zoom_nj - 1; 489 489 490 490 if (zoom_ibegin < 1 || zoom_jbegin < 1 || zoom_iend > ni_glo || zoom_jend > nj_glo) 491 491 ERROR("CDomain::checkZoom(void)", … … 496 496 else 497 497 { 498 zoom_ni = ni_glo; 498 zoom_ni = ni_glo; 499 499 zoom_nj = nj_glo; 500 500 zoom_ibegin = 1; 501 501 zoom_jbegin = 1; 502 502 } 503 503 504 504 // compute client zoom indices 505 505 … … 510 510 if (zoom_ni_client<0) zoom_ni_client=0 ; 511 511 512 512 513 513 int zoom_jend=zoom_jbegin+zoom_nj-1 ; 514 514 zoom_jbegin_client = jbegin_client > zoom_jbegin ? jbegin_client : zoom_jbegin ; … … 518 518 519 519 } 520 520 521 521 void CDomain::checkBounds(void) 522 522 { … … 524 524 { 525 525 hasBounds=true ; 526 526 527 527 } 528 else 528 else 529 529 { 530 530 hasBounds=false; … … 532 532 } 533 533 } 534 535 //---------------------------------------------------------------- 536 537 void CDomain::checkAttributes(void) 538 { 539 if (this->isChecked) return; 540 CContext* context=CContext::getCurrent() ; 534 535 //---------------------------------------------------------------- 536 // Divide function checkAttributes into 2 seperate ones 537 // This function only checks all attributes of current domain 538 void CDomain::checkAttributesOnClient() 539 { 540 if (this->isClientChecked) return; 541 CContext* context=CContext::getCurrent(); 541 542 542 543 this->checkDomain(); 543 544 this->checkZoom(); 544 545 this->checkBounds(); 545 546 546 547 if (context->hasClient) 547 548 { // CÃŽté client uniquement … … 550 551 this->checkCompression(); 551 552 this->completeLonLatClient(); 553 this->computeConnectedServer() ; 552 554 } 553 555 else … … 556 558 // ne sert plus // this->completeLonLatServer(); 557 559 } 558 560 561 this->isClientChecked = true; 562 } 563 564 // Send all checked attributes to server 565 void CDomain::sendCheckedAttributes() 566 { 567 if (!this->isClientChecked) checkAttributesOnClient(); 568 CContext* context=CContext::getCurrent() ; 569 570 if (this->isChecked) return; 571 if (context->hasClient) 572 { 573 sendServerAttribut() ; 574 sendLonLat() ; 575 } 576 577 this->isChecked = true; 578 } 579 580 void CDomain::checkAttributes(void) 581 { 582 if (this->isChecked) return; 583 CContext* context=CContext::getCurrent() ; 584 585 this->checkDomain(); 586 this->checkZoom(); 587 this->checkBounds(); 588 589 if (context->hasClient) 590 { // CÃŽté client uniquement 591 this->checkMask(); 592 this->checkDomainData(); 593 this->checkCompression(); 594 this->completeLonLatClient(); 595 } 596 else 597 { // CÃŽté serveur uniquement 598 // if (!this->isEmpty()) 599 // ne sert plus // this->completeLonLatServer(); 600 } 601 559 602 if (context->hasClient) 560 603 { … … 563 606 sendLonLat() ; 564 607 } 565 608 566 609 this->isChecked = true; 567 610 } 568 611 569 612 void CDomain::sendServerAttribut(void) 570 613 { … … 572 615 int ibegin_srv=1 ; 573 616 int iend_srv=ni_glo.getValue() ; 574 617 575 618 int nj_srv ; 576 619 int jbegin_srv ; 577 620 int jend_srv ; 578 621 579 622 CContext* context=CContext::getCurrent() ; 580 623 CContextClient* client=context->client ; 581 624 int nbServer=client->serverSize ; 582 625 int serverRank=client->getServerLeader() ; 583 626 584 627 jend_srv=0 ; 585 628 for(int i=0;i<=serverRank;i++) … … 590 633 jend_srv=jbegin_srv+nj_srv-1 ; 591 634 } 592 593 CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 635 636 CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 594 637 if (client->isServerLeader()) 595 638 { … … 606 649 { 607 650 int i,j,i_ind,j_ind ; 608 651 609 652 ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 610 653 jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 611 654 612 655 CContext* context = CContext::getCurrent() ; 613 656 CContextClient* client=context->client ; … … 617 660 int zoom_iend=zoom_ibegin+zoom_ni-1 ; 618 661 int zoom_jend=zoom_jbegin+zoom_nj-1 ; 619 662 620 663 int blockSize=nj_glo/nbServer ; 621 664 int ns=nj_glo%nbServer ; 622 665 int pos=ns*(blockSize+1) ; 623 666 int serverNum ; 624 667 625 668 mapConnectedServer.resize(ni,nj) ; 626 669 vector<int> nbData(nbServer,0) ; 627 670 vector<int> indServer(nbServer,-1) ; 628 671 vector<bool> IsConnected(nbServer,false) ; 629 672 630 673 for(j=0;j<nj;j++) 631 674 for(i=0;i<ni;i++) … … 633 676 i_ind=ibegin+i_index(i,j)-1 ; 634 677 j_ind=jbegin+j_index(i,j)-1 ; 635 678 636 679 if (j_ind<pos) serverNum=j_ind/(blockSize+1) ; 637 680 else serverNum=ns+(j_ind-pos)/blockSize ; 638 681 IsConnected[serverNum]=true ; 639 682 640 683 if (i_ind >= zoom_ibegin-1 && i_ind <= zoom_iend-1 && j_ind >= zoom_jbegin-1 && j_ind <= zoom_jend-1) 641 684 { … … 647 690 648 691 649 for(serverNum=0 ; serverNum<nbServer ; serverNum++) 692 for(serverNum=0 ; serverNum<nbServer ; serverNum++) 650 693 if (IsConnected[serverNum]) 651 694 { … … 655 698 nbDataSrv.push_back(nbData[serverNum]) ; 656 699 } 657 700 658 701 i_indSrv.resize(connectedServer.size()) ; 659 702 j_indSrv.resize(connectedServer.size()) ; 660 703 661 704 for(j=0;j<nj;j++) 662 for(i=0;i<ni;i++) 705 for(i=0;i<ni;i++) 663 706 { 664 707 if (mapConnectedServer(i,j)>=0) … … 670 713 } 671 714 } 672 715 673 716 int nbConnectedServer=connectedServer.size() ; 674 717 … … 677 720 int* sendBuff=new int[nbConnectedServer] ; 678 721 valarray<int> nbClient(0,client->serverSize) ; 679 722 680 723 for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 681 724 682 725 // get connected server for everybody 683 726 MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,client->intraComm) ; 684 727 685 728 displ[0]=0 ; 686 729 for(int n=1;n<client->clientSize;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 687 730 int recvSize=displ[client->clientSize-1]+recvCount[client->clientSize-1] ; 688 731 int* recvBuff=new int[recvSize] ; 689 690 732 733 691 734 MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,client->intraComm) ; 692 735 for(int n=0;n<recvSize;n++) nbClient[recvBuff[n]]++ ; 693 736 694 737 for(int n=0;n<nbConnectedServer;n++) nbSenders.push_back(nbClient[connectedServer[n]]) ; 695 738 696 739 delete [] recvCount ; 697 740 delete [] displ ; … … 708 751 // send lon lat for each connected server 709 752 CEventClient event(getType(),EVENT_ID_LON_LAT) ; 710 711 list<shared_ptr<CMessage> > list_msg ; 753 754 list<shared_ptr<CMessage> > list_msg ; 712 755 list< CArray<int,1>* > list_indi,list_indj ; 713 756 list< CArray<double,1>* >list_lon,list_lat ; … … 723 766 CArray<double,2> boundslon(nvertex,nbData) ; 724 767 CArray<double,2> boundslat(nvertex,nbData) ; 725 726 for(n=0;n<nbData;n++) 768 769 for(n=0;n<nbData;n++) 727 770 { 728 771 i=i_indSrv[ns][n] ; 729 772 j=j_indSrv[ns][n] ; 730 773 ind=(i-(zoom_ibegin_client-1))+(j-(zoom_jbegin_client-1))*zoom_ni_client ; 731 774 732 775 lon(n)=lonvalue(ind) ; 733 776 lat(n)=latvalue(ind) ; … … 743 786 indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1 ; 744 787 } 745 788 746 789 list_indi.push_back(new CArray<int,1>(indi.copy())) ; 747 790 list_indj.push_back(new CArray<int,1>(indj.copy())) ; … … 761 804 762 805 client->sendEvent(event) ; 763 764 806 807 765 808 for(list<CArray<int,1>* >::iterator it=list_indi.begin();it!=list_indi.end();it++) delete *it; 766 809 for(list<CArray<int,1>* >::iterator it=list_indj.begin();it!=list_indj.end();it++) delete *it; … … 768 811 for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++) delete *it; 769 812 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++) delete *it; 770 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++) delete *it; 771 813 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++) delete *it; 814 772 815 } 773 774 816 817 775 818 bool CDomain::dispatchEvent(CEventServer& event) 776 819 { 777 820 778 821 if (SuperClass::dispatchEvent(event)) return true ; 779 822 else … … 796 839 } 797 840 } 798 841 799 842 void CDomain::recvServerAttribut(CEventServer& event) 800 843 { … … 804 847 get(domainId)->recvServerAttribut(*buffer) ; 805 848 } 806 849 807 850 void CDomain::recvServerAttribut(CBufferIn& buffer) 808 851 { … … 811 854 812 855 buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv; 813 814 856 857 815 858 zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 816 859 zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 817 860 zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 818 861 819 862 zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 820 863 zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 821 864 zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 822 865 823 if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 866 if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 824 867 { 825 868 zoom_ibegin_srv=1 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; … … 830 873 latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 831 874 latvalue_srv = 0. ; 832 if (hasBounds) 875 if (hasBounds) 833 876 { 834 877 bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; … … 838 881 } 839 882 } 840 883 841 884 void CDomain::recvLonLat(CEventServer& event) 842 885 { … … 850 893 } 851 894 } 852 895 853 896 void CDomain::recvLonLat(CBufferIn& buffer) 854 897 { … … 859 902 CArray<double,2> boundslon ; 860 903 CArray<double,2> boundslat ; 861 904 862 905 int type_int ; 863 906 buffer>>type_int>>isCurvilinear>>indi>>indj>>lon>>lat ; … … 872 915 lonvalue_srv(ind_srv)=lon(ind) ; 873 916 latvalue_srv(ind_srv)=lat(ind) ; 874 if (hasBounds) 875 { 876 for(int nv=0;nv<nvertex;nv++) 917 if (hasBounds) 918 { 919 for(int nv=0;nv<nvertex;nv++) 877 920 { 878 921 bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ; … … 883 926 } 884 927 //---------------------------------------------------------------- 885 886 887 928 929 930 888 931 ///--------------------------------------------------------------- 889 932
Note: See TracChangeset
for help on using the changeset viewer.