Changeset 553 for XIOS/trunk/src/node/domain.cpp
- Timestamp:
- 02/11/15 16:23:12 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/domain.cpp
r551 r553 14 14 #include "context_client.hpp" 15 15 #include "array_new.hpp" 16 #include "server_distribution_description.hpp" 16 17 17 18 namespace xios { … … 21 22 CDomain::CDomain(void) 22 23 : CObjectTemplate<CDomain>(), CDomainAttributes() 23 , isChecked(false), relFiles(), isClientChecked(false) 24 , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_() 24 25 { /* Ne rien faire de plus */ } 25 26 26 27 CDomain::CDomain(const StdString & id) 27 28 : CObjectTemplate<CDomain>(id), CDomainAttributes() 28 , isChecked(false), relFiles(), isClientChecked(false) 29 , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_() 29 30 { /* Ne rien faire de plus */ } 30 31 … … 612 613 void CDomain::sendServerAttribut(void) 613 614 { 615 std::vector<int> nGlobDomain(2); 616 nGlobDomain[0] = ni_glo.getValue(); 617 nGlobDomain[1] = nj_glo.getValue(); 618 CServerDistributionDescription serverDescription(nGlobDomain); 619 614 620 int ni_srv=ni_glo.getValue() ; 615 621 int ibegin_srv=0 ; … … 625 631 int serverRank=client->getServerLeader() ; 626 632 627 // jend_srv=0;628 jend_srv= -1;629 for(int i=0;i<=serverRank;i++)630 {631 jbegin_srv=jend_srv+1;632 nj_srv=nj_glo.getValue()/nbServer;633 if (i<nj_glo.getValue()%nbServer) nj_srv++;634 jend_srv=jbegin_srv+nj_srv-1;635 }633 serverDescription.computeServerDistribution(nbServer); 634 std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); 635 std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); 636 ibegin_srv = (serverIndexBegin[serverRank])[0]; 637 jbegin_srv = serverIndexBegin[serverRank][1]; 638 ni_srv = serverDimensionSizes[serverRank][0]; 639 nj_srv = serverDimensionSizes[serverRank][1]; 640 iend_srv = ibegin_srv+ni_srv-1; 641 jend_srv = jbegin_srv+nj_srv-1; 636 642 637 643 CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; … … 649 655 void CDomain::computeConnectedServer(void) 650 656 { 651 int i,j,i_ind,j_ind ;652 653 657 ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 654 658 jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 655 659 656 CContext* context =CContext::getCurrent() ;660 CContext* context=CContext::getCurrent() ; 657 661 CContextClient* client=context->client ; 658 int nbServer=client->serverSize ; 659 660 // find how much client are connected to a server 662 int nbServer=client->serverSize; 663 bool doComputeGlobalIndexServer = true; 664 665 int i,j,i_ind,j_ind ; 661 666 int zoom_iend=zoom_ibegin+zoom_ni-1 ; 662 667 int zoom_jend=zoom_jbegin+zoom_nj-1 ; 663 668 664 int blockSize=nj_glo/nbServer ; 665 int ns=nj_glo%nbServer ; 666 int pos=ns*(blockSize+1) ; 667 // int pos=ns*(blockSize) ; 668 int serverNum ; 669 670 mapConnectedServer.resize(ni,nj) ; 671 vector<int> nbData(nbServer,0) ; 672 vector<int> indServer(nbServer,-1) ; 673 vector<bool> IsConnected(nbServer,false) ; 674 669 std::vector<int> nGlobDomain(2); 670 nGlobDomain[0] = ni_glo.getValue(); 671 nGlobDomain[1] = nj_glo.getValue(); 672 CServerDistributionDescription serverDescription(nGlobDomain); 673 serverDescription.computeServerDistribution(nbServer, doComputeGlobalIndexServer); 674 675 // Precompute number of index 676 int globalIndexCount = 0; 675 677 for(j=0;j<nj;j++) 676 678 for(i=0;i<ni;i++) … … 679 681 j_ind=jbegin+j_index(i,j) ; 680 682 681 if (j_ind<pos) serverNum=j_ind/(blockSize+1) ;682 else serverNum=ns+(j_ind-pos)/blockSize ;683 IsConnected[serverNum]=true ;684 685 683 if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend) 686 684 { 687 mapConnectedServer(i,j)=serverNum ; 688 nbData[serverNum]++ ; 685 ++globalIndexCount; 689 686 } 690 else mapConnectedServer(i,j)=-1 ; 691 } 692 693 694 for(serverNum=0 ; serverNum<nbServer ; serverNum++) 695 if (IsConnected[serverNum]) 696 { 697 ns=connectedServer.size() ; 698 indServer[serverNum]=ns; 699 connectedServer.push_back(serverNum) ; 700 nbDataSrv.push_back(nbData[serverNum]) ; 701 } 702 703 i_indSrv.resize(connectedServer.size()) ; 704 j_indSrv.resize(connectedServer.size()) ; 705 706 for(j=0;j<nj;j++) 687 } 688 689 // Fill in index 690 CArray<size_t,1> globalIndexDomain(globalIndexCount); 691 size_t globalIndex; 692 globalIndexCount = 0; 693 694 for(j=0;j<nj;j++) 707 695 for(i=0;i<ni;i++) 708 696 { 709 if (mapConnectedServer(i,j)>=0) 697 i_ind=ibegin+i_index(i,j) ; 698 j_ind=jbegin+j_index(i,j) ; 699 700 if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend) 710 701 { 711 ns=indServer[mapConnectedServer(i,j)] ; 712 mapConnectedServer(i,j)= ns ; 713 i_indSrv[ns].push_back(i+ibegin) ; 714 j_indSrv[ns].push_back(j+jbegin) ; 702 globalIndex = i_ind + j_ind * ni_glo; 703 globalIndexDomain(globalIndexCount) = globalIndex; 704 ++globalIndexCount; 715 705 } 716 706 } 717 707 718 int nbConnectedServer=connectedServer.size() ; 719 720 int* recvCount=new int[client->clientSize] ; 721 int* displ=new int[client->clientSize] ; 722 int* sendBuff=new int[nbConnectedServer] ; 723 valarray<int> nbClient(0,client->serverSize) ; 724 725 for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 726 727 // get connected server for everybody 728 MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,client->intraComm) ; 729 730 displ[0]=0 ; 731 for(int n=1;n<client->clientSize;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 732 int recvSize=displ[client->clientSize-1]+recvCount[client->clientSize-1] ; 733 int* recvBuff=new int[recvSize] ; 734 735 736 MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,client->intraComm) ; 737 for(int n=0;n<recvSize;n++) nbClient[recvBuff[n]]++ ; 738 739 for(int n=0;n<nbConnectedServer;n++) nbSenders.push_back(nbClient[connectedServer[n]]) ; 740 741 delete [] recvCount ; 742 delete [] displ ; 743 delete [] sendBuff ; 744 delete [] recvBuff ; 708 CClientServerMapping clientServerMap; 709 clientServerMap.computeServerIndexMapping(globalIndexDomain, serverDescription.getGlobalIndex()); 710 const std::map<int, std::vector<size_t> >& globalIndexDomainOnServer = clientServerMap.getGlobalIndexOnServer(); 711 std::vector<int> connectedServerRank; 712 for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexDomainOnServer.begin(); it != globalIndexDomainOnServer.end(); ++it) { 713 connectedServerRank.push_back(it->first); 714 } 715 nbConnectedClients_ = clientServerMap.computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank); 716 indSrv_ = globalIndexDomainOnServer; 745 717 } 746 747 748 // void CDomain::sendLonLat(void)749 // {750 // int ns,n,i,j,ind,nv ;751 // CContext* context = CContext::getCurrent() ;752 // CContextClient* client=context->client ;753 // // send lon lat for each connected server754 //755 // CEventClient eventLon(getType(),EVENT_ID_LON) ;756 // CEventClient eventLat(getType(),EVENT_ID_LAT) ;757 //758 // list<shared_ptr<CMessage> > list_msgLon ;759 // list<shared_ptr<CMessage> > list_msgLat ;760 // list< CArray<int,1>* > list_indi,list_indj ;761 // list< CArray<double,1>* >list_lon,list_lat ;762 // list< CArray<double,2>* >list_boundslon,list_boundslat ;763 //764 // for(int ns=0;ns<connectedServer.size();ns++)765 // {766 // int nbData = nbDataSrv[ns] ;767 // CArray<int,1> indi(nbData) ;768 // CArray<int,1> indj(nbData) ;769 // CArray<double,1> lon(nbData) ;770 // CArray<double,1> lat(nbData) ;771 // CArray<double,2> boundslon(nvertex,nbData) ;772 // CArray<double,2> boundslat(nvertex,nbData) ;773 //774 // for(n=0;n<nbData;n++)775 // {776 // i=i_indSrv[ns][n] ;777 // j=j_indSrv[ns][n] ;778 // ind=(i-(zoom_ibegin_client-1))+(j-(zoom_jbegin_client-1))*zoom_ni_client ;779 //780 // lon(n)=lonvalue(ind) ;781 // lat(n)=latvalue(ind) ;782 // if (hasBounds)783 // {784 // for(nv=0;nv<nvertex;nv++)785 // {786 // boundslon(nv,n)=bounds_lon(nv,ind);787 // boundslat(nv,n)=bounds_lat(nv,ind);788 // }789 // }790 // indi(n)=ibegin+i_index(i-ibegin+1,j-jbegin+1)-1 ;791 // indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1 ;792 // }793 //794 // list_indi.push_back(new CArray<int,1>(indi.copy())) ;795 // list_indj.push_back(new CArray<int,1>(indj.copy())) ;796 // list_lon.push_back(new CArray<double,1>(lon.copy())) ;797 // list_lat.push_back(new CArray<double,1>(lat.copy())) ;798 // if (hasBounds) list_boundslon.push_back(new CArray<double,2>(boundslon.copy())) ;799 // if (hasBounds) list_boundslat.push_back(new CArray<double,2>(boundslat.copy())) ;800 //801 // list_msgLon.push_back(shared_ptr<CMessage>(new CMessage)) ;802 // list_msgLat.push_back(shared_ptr<CMessage>(new CMessage)) ;803 //804 // *list_msgLon.back()<<this->getId()<<(int)type ; // enum ne fonctionne pour les message => ToFix805 // *list_msgLat.back()<<this->getId()<<(int)type ;806 // *list_msgLon.back()<<isCurvilinear ;807 // *list_msgLat.back()<<isCurvilinear ;808 // *list_msgLon.back()<<*list_indi.back()<<*list_indj.back()<<*list_lon.back() ;809 // *list_msgLat.back()<<*list_indi.back()<<*list_indj.back()<<*list_lat.back() ;810 //811 // if (hasBounds)812 // {813 // *list_msgLon.back()<<*list_boundslon.back();814 // *list_msgLat.back()<<*list_boundslat.back();815 // }816 // eventLon.push(connectedServer[ns],nbSenders[ns],*list_msgLon.back()) ;817 // eventLat.push(connectedServer[ns],nbSenders[ns],*list_msgLat.back()) ;818 // }819 //820 // client->sendEvent(eventLon) ;821 // client->sendEvent(eventLat) ;822 //823 //824 // for(list<CArray<int,1>* >::iterator it=list_indi.begin();it!=list_indi.end();it++) delete *it;825 // for(list<CArray<int,1>* >::iterator it=list_indj.begin();it!=list_indj.end();it++) delete *it;826 // for(list<CArray<double,1>* >::iterator it=list_lon.begin();it!=list_lon.end();it++) delete *it;827 // for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++) delete *it;828 // if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++) delete *it;829 // if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++) delete *it;830 //831 // }832 718 833 719 void CDomain::sendLonLat(void) 834 720 { 835 int ns,n,i,j,ind,nv 721 int ns,n,i,j,ind,nv, idx; 836 722 CContext* context = CContext::getCurrent() ; 837 723 CContextClient* client=context->client ; … … 847 733 list< CArray<double,2>* >list_boundslon,list_boundslat ; 848 734 849 for(int ns=0;ns<connectedServer.size();ns++) 735 std::map<int, std::vector<size_t> >::const_iterator it, itbMap, iteMap; 736 itbMap = indSrv_.begin(); 737 iteMap = indSrv_.end(); 738 for (it = itbMap; it != iteMap; ++it) 850 739 { 851 int nbData = nbDataSrv[ns] ; 740 int rank = it->first; 741 int nbData = (it->second).size(); 852 742 CArray<int,1> indi(nbData) ; 853 743 CArray<int,1> indj(nbData) ; 854 744 CArray<double,1> lon(nbData) ; 855 745 CArray<double,1> lat(nbData) ; 856 CArray<double,2> boundslon(nvertex,nbData) 857 CArray<double,2> boundslat(nvertex,nbData) 858 859 for (n=0;n<nbData;n++)860 { 861 i =i_indSrv[ns][n];862 j=j_indSrv[ns][n];863 // ind=(i-(zoom_ibegin_client))+(j-(zoom_jbegin_client-1))*zoom_ni_client;746 CArray<double,2> boundslon(nvertex,nbData); 747 CArray<double,2> boundslat(nvertex,nbData); 748 749 for (n = 0; n < nbData; ++n) 750 { 751 idx = static_cast<int>((it->second)[n]); 752 i = idx%ni_glo; 753 j = idx/ni_glo; 864 754 ind=(i-(zoom_ibegin_client))+(j-(zoom_jbegin_client))*zoom_ni_client ; 865 755 … … 876 766 indi(n)=ibegin+i_index(i-ibegin,j-jbegin) ; 877 767 indj(n)=jbegin+j_index(i-ibegin,j-jbegin) ; 878 // indi(n)=ibegin+i_index(i-ibegin+1,j-jbegin+1)-1 ;879 // indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1 ;880 768 } 881 769 … … 902 790 *list_msgLat.back()<<*list_boundslat.back(); 903 791 } 904 eventLon.push( connectedServer[ns],nbSenders[ns],*list_msgLon.back()) ;905 eventLat.push( connectedServer[ns],nbSenders[ns],*list_msgLat.back()) ;792 eventLon.push(rank,nbConnectedClients_[rank],*list_msgLon.back()) ; 793 eventLat.push(rank,nbConnectedClients_[rank],*list_msgLat.back()) ; 906 794 } 907 795 … … 916 804 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++) delete *it; 917 805 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++) delete *it; 918 919 806 } 920 807 … … 1052 939 if (hasBounds) buffer>>boundslat ; 1053 940 type.setValue((type_attr::t_enum)type_int) ; // probleme des type enum avec les buffers : ToFix 1054 1055 941 int i,j,ind_srv ; 1056 942 for(int ind=0;ind<indi.numElements();ind++) … … 1068 954 } 1069 955 } 1070 // void CDomain::recvLonLat(CEventServer& event) 1071 // { 1072 // list<CEventServer::SSubEvent>::iterator it ; 1073 // for (it=event.subEvents.begin();it!=event.subEvents.end();++it) 1074 // { 1075 // CBufferIn* buffer=it->buffer; 1076 // string domainId ; 1077 // *buffer>>domainId ; 1078 // get(domainId)->recvLonLat(*buffer) ; 1079 // } 1080 // } 1081 // 1082 // void CDomain::recvLonLat(CBufferIn& buffer) 1083 // { 1084 // CArray<int,1> indi ; 1085 // CArray<int,1> indj ; 1086 // CArray<double,1> lon ; 1087 // CArray<double,1> lat ; 1088 // CArray<double,2> boundslon ; 1089 // CArray<double,2> boundslat ; 1090 // 1091 // int type_int ; 1092 // buffer>>type_int>>isCurvilinear>>indi>>indj>>lon>>lat ; 1093 // if (hasBounds) buffer>>boundslon>>boundslat ; 1094 // type.setValue((type_attr::t_enum)type_int) ; // probleme des type enum avec les buffers : ToFix 1095 // 1096 // int i,j,ind_srv ; 1097 // for(int ind=0;ind<indi.numElements();ind++) 1098 // { 1099 // i=indi(ind) ; j=indj(ind) ; 1100 // ind_srv=(i-(zoom_ibegin_srv-1))+(j-(zoom_jbegin_srv-1))*zoom_ni_srv ; 1101 // lonvalue_srv(ind_srv)=lon(ind) ; 1102 // latvalue_srv(ind_srv)=lat(ind) ; 1103 // if (hasBounds) 1104 // { 1105 // for(int nv=0;nv<nvertex;nv++) 1106 // { 1107 // bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ; 1108 // bounds_lat_srv(nv,ind_srv)=boundslat(nv,ind) ; 1109 // } 1110 // } 1111 // } 1112 // } 956 1113 957 //---------------------------------------------------------------- 1114 958
Note: See TracChangeset
for help on using the changeset viewer.