Changeset 300 for XMLIO_V2/dev/common/src/node/domain.cpp
- Timestamp:
- 02/13/12 19:35:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/common/src/node/domain.cpp
r286 r300 8 8 9 9 #include "tree_manager.hpp" 10 11 #include <algorithm> 10 #include "xmlioserver_spl.hpp" 11 #include "event_client.hpp" 12 #include "event_server.hpp" 13 #include "buffer_in.hpp" 12 14 13 15 namespace xmlioserver { … … 21 23 , ibegin_sub(), iend_sub(), jbegin_sub(), jend_sub() 22 24 , ibegin_zoom_sub(), jbegin_zoom_sub(), ni_zoom_sub(), nj_zoom_sub() 23 , lonvalue_sub(), latvalue_sub() 25 , lonvalue_sub(), latvalue_sub(),lonvalue_srv(new CArray<double,1>()) 26 , latvalue_srv(new CArray<double,1>()) 24 27 { /* Ne rien faire de plus */ } 25 28 … … 29 32 , ibegin_sub(), iend_sub(), jbegin_sub(), jend_sub() 30 33 , ibegin_zoom_sub(), jbegin_zoom_sub(),ni_zoom_sub(), nj_zoom_sub() 31 , lonvalue_sub(), latvalue_sub() 34 , lonvalue_sub(), latvalue_sub(),lonvalue_srv(new CArray<double,1>()) 35 , latvalue_srv(new CArray<double,1>()) 32 36 { /* Ne rien faire de plus */ } 33 37 … … 61 65 bool CDomain::isEmpty(void) const 62 66 { 63 return ((this->zoom_ni_ loc.getValue()== 0) ||64 (this->zoom_nj_ loc.getValue()== 0));67 return ((this->zoom_ni_srv == 0) || 68 (this->zoom_nj_srv == 0)); 65 69 } 66 70 … … 258 262 } 259 263 260 //~ std::cout << "-------------------" << std::endl261 //~ << "zoom : " << std::boolalpha << this->hasZoom() << std::endl262 //~ << "size : " << ni.getValue() << " X " << nj.getValue() << std::endl263 //~ << "it : " << ibegin.getValue() << ", " << iend.getValue() << std::endl264 //~ << "jt : " << jbegin.getValue() << ", " << jend.getValue() << std::endl265 //~ << "im : " << ibegin_mask << ", " << iend_mask << std::endl266 //~ << "jm : " << jbegin_mask << ", " << jend_mask << std::endl267 //~ << "-------------------" << std::endl;268 264 269 265 if (!mask.isEmpty()) … … 498 494 jbegin_zoom_srv = zoom_jbegin_loc.getValue(); 499 495 500 /*std::cout << "Rang du serveur :" << comm::CMPIManager::GetCommRank() << std::endl501 << "Begin serv : " << ibegin_serv << ", " << jbegin_serv << std::endl502 << "End serv : " << iend_serv << ", " << jend_serv << std::endl503 << "Zoom_loc begin : " << zoom_ibegin_loc << ", " << zoom_jbegin_loc << std::endl504 << "Zoom_loc size : " << zoom_ni_loc << ", " << zoom_nj_loc << std::endl;*/505 496 506 497 if (this->data_dim.getValue() == 2) … … 647 638 { 648 639 if (this->isChecked) return; 640 shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 649 641 650 642 this->checkGlobalDomain(); … … 653 645 654 646 this->checkZoom(); 655 656 if ( this->latvalue_sub.size() == 0)647 648 if (context->hasClient) 657 649 { // CÃŽté client uniquement 658 650 this->checkMask(); … … 678 670 this->completeLonLatClient(); 679 671 // } 672 this->completeMask(); 673 680 674 } 681 675 else 682 676 { // CÃŽté serveur uniquement 683 677 // if (!this->isEmpty()) 684 this->completeLonLatServer(); 685 } 686 this->completeMask(); 687 678 // ne sert plus // this->completeLonLatServer(); 679 } 680 681 if (context->hasClient) 682 { 683 computeConnectedServer() ; 684 sendServerAttribut() ; 685 sendLonLat() ; 686 } 687 688 688 this->isChecked = true; 689 689 } 690 690 691 void CDomain::sendServerAttribut(void) 692 { 693 int ni_srv=ni_glo.getValue() ; 694 int ibegin_srv=1 ; 695 int iend_srv=ni_glo.getValue() ; 696 697 int nj_srv ; 698 int jbegin_srv ; 699 int jend_srv ; 700 701 shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 702 CContextClient* client=context->client ; 703 int nbServer=client->serverSize ; 704 int serverRank=client->getServerLeader() ; 705 706 jend_srv=0 ; 707 for(int i=0;i<=serverRank;i++) 708 { 709 jbegin_srv=jend_srv+1 ; 710 nj_srv=nj_glo.getValue()/nbServer ; 711 if (i<nj_glo.getValue()%nbServer) nj_srv++ ; 712 jend_srv=jbegin_srv+nj_srv-1 ; 713 } 714 715 CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 716 if (client->isServerLeader()) 717 { 718 CMessage msg ; 719 msg<<this->getId() ; 720 msg<<ni_srv<<ibegin_srv<<iend_srv<<nj_srv<<jbegin_srv<<jend_srv; 721 event.push(client->getServerLeader(),1,msg) ; 722 client->sendEvent(event) ; 723 } 724 else client->sendEvent(event) ; 725 } 726 727 void CDomain::computeConnectedServer(void) 728 { 729 int ib,ie,in; 730 int jb,je,jn ; 731 732 int ni_srv=ni_glo.getValue() ; 733 int ibegin_srv=1 ; 734 int iend_srv=ni_glo.getValue() ; 735 736 int nj_serv,jbegin_srv, jend_srv ; 737 int zoom_ibegin_srv,zoom_iend_srv,zoom_ni_srv ; 738 int zoom_jbegin_srv,zoom_jend_srv,zoom_nj_srv ; 739 740 ibegin_client=ibegin.getValue() ; iend_client=iend.getValue() ; ni_client=ni.getValue() ; 741 jbegin_client=jbegin.getValue() ; jend_client=jend.getValue() ; nj_client=nj.getValue() ; 742 743 shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 744 CContextClient* client=context->client ; 745 int nbServer=client->serverSize ; 746 747 // compute client zoom indices 748 int zoom_iend=zoom_ibegin.getValue()+zoom_ni.getValue()-1 ; 749 zoom_ibegin_client = ibegin_client > zoom_ibegin.getValue() ? ibegin_client : zoom_ibegin.getValue() ; 750 zoom_iend_client = iend_client < zoom_iend ? iend_client : zoom_iend ; 751 zoom_ni_client=zoom_iend_client-zoom_ibegin_client+1 ; 752 if (zoom_ni_client<0) zoom_ni_client=0 ; 753 754 int zoom_jend=zoom_jbegin.getValue()+zoom_nj.getValue()-1 ; 755 zoom_jbegin_client = jbegin_client > zoom_jbegin.getValue() ? jbegin_client : zoom_jbegin.getValue() ; 756 zoom_jend_client = jend_client < zoom_jend ? jend_client : zoom_jend ; 757 zoom_nj_client=zoom_jend_client-zoom_jbegin_client+1 ; 758 if (zoom_nj_client<0) zoom_nj_client=0 ; 759 760 // find how much client are connected to a server 761 jend_srv=0 ; 762 for(int ns=0;ns<nbServer;ns++) 763 { 764 jbegin_srv=jend_srv+1 ; 765 nj_srv=nj_glo.getValue()/nbServer ; 766 if (ns<nj_glo.getValue()%nbServer) nj_srv++ ; 767 jend_srv=jbegin_srv+nj_srv-1 ; 768 769 ib = ibegin_client>ibegin_srv ? ibegin_client : ibegin_srv ; 770 ie= iend_client< iend_srv? iend_client : iend_srv ; 771 in=ie-ib+1 ; 772 if (in<0) in=0 ; 773 774 jb= jbegin_client>jbegin_srv ? jbegin_client : jbegin_srv ; 775 je= jend_client<jend_srv ? jend_client : jend_srv ; 776 jn=je-jb+1 ; 777 if (jn<0) jn=0 ; 778 779 if (in>0 && jn>0) 780 { 781 zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 782 zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 783 zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 784 if (zoom_ni_srv<0) zoom_ni_srv=0 ; 785 786 zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 787 zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 788 zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 789 if (zoom_nj_srv<0) zoom_nj_srv=0 ; 790 791 if (zoom_ni_srv>0 && zoom_nj_srv>0 && zoom_ni_client>0 && zoom_nj_client>0) 792 { 793 ib = zoom_ibegin_client>zoom_ibegin_srv ? zoom_ibegin_client : zoom_ibegin_srv ; 794 ie=zoom_iend_client<zoom_iend_srv?zoom_iend_client:zoom_iend_srv ; 795 in=ie-ib+1 ; 796 if (in<0) in=0 ; 797 798 jb=zoom_jbegin_client>zoom_jbegin_srv?zoom_jbegin_client:zoom_jbegin_srv ; 799 je=zoom_jend_client<zoom_jend_srv?zoom_jend_client:zoom_jend_srv ; 800 jn=je-jb+1 ; 801 if (jn<0) jn=0 ; 802 } 803 else 804 { 805 ib=1 ; ie=0 ; in=0 ; 806 jb=1 ; je=0 ; jn=0 ; 807 } 808 809 // if (in>0 && jn>0) 810 // { 811 connectedServer.push_back(ns) ; 812 ib_srv.push_back(ib) ; 813 ie_srv.push_back(ie) ; 814 in_srv.push_back(in) ; 815 jb_srv.push_back(jb) ; 816 je_srv.push_back(je) ; 817 jn_srv.push_back(jn) ; 818 // } 819 820 } 821 } 822 int nbConnectedServer=connectedServer.size() ; 823 int* recvCount=new int[client->clientSize] ; 824 int* displ=new int[client->clientSize] ; 825 int* sendBuff=new int[nbConnectedServer] ; 826 valarray<int> nbClient(0,client->serverSize) ; 827 828 for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 829 830 // get connected server for everybody 831 MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,client->intraComm) ; 832 833 displ[0]=0 ; 834 for(int n=1;n<client->clientSize;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 835 int recvSize=displ[client->clientSize-1]+recvCount[client->clientSize-1] ; 836 int* recvBuff=new int[recvSize] ; 837 838 839 MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,client->intraComm) ; 840 for(int n=0;n<recvSize;n++) nbClient[recvBuff[n]]++ ; 841 842 for(int n=0;n<nbConnectedServer;n++) nbSenders.push_back(nbClient[connectedServer[n]]) ; 843 844 delete [] recvCount ; 845 delete [] displ ; 846 delete [] sendBuff ; 847 delete [] recvBuff ; 848 } 849 850 void CDomain::sendLonLat(void) 851 { 852 shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 853 CContextClient* client=context->client ; 854 // send lon lat for each connected server 855 CEventClient event(getType(),EVENT_ID_LON_LAT) ; 856 857 ARRAY(double, 1) lonvalue_client = lonvalue.getValue(), 858 latvalue_client = latvalue.getValue(); 859 860 int ib,ie,in ; 861 int jb,je,jn ; 862 863 list<shared_ptr<CMessage> > list_msg ; 864 list<ARRAY(double,1)> list_indi,list_indj,list_lon,list_lat ; 865 866 for(int ns=0;ns<connectedServer.size();ns++) 867 { 868 ib=ib_srv[ns] ; ie=ie_srv[ns] ; in=in_srv[ns] ; 869 jb=jb_srv[ns] ; je=je_srv[ns] ; jn=jn_srv[ns] ; 870 871 ARRAY_CREATE(indi,double,1,[in*jn]) ; 872 ARRAY_CREATE(indj,double,1,[in*jn]) ; 873 ARRAY_CREATE(lon,double,1,[in*jn]) ; 874 ARRAY_CREATE(lat,double,1,[in*jn]) ; 875 876 877 int ind_client,ind_loc ; 878 879 for(int j=jb;j<=je;j++) 880 for(int i=ib;i<=ie;i++) 881 { 882 ind_client=(i-zoom_ibegin_client)+(j-zoom_jbegin_client)*zoom_ni_client ; 883 ind_loc=(i-ib)+(j-jb)*in ; 884 (*lon)[ind_loc]=(*lonvalue_client)[ind_client] ; 885 (*lat)[ind_loc]=(*latvalue_client)[ind_client] ; 886 (*indi)[ind_loc]=i ; 887 (*indj)[ind_loc]=j ; 888 } 889 890 list_indi.push_back(indi) ; list_indj.push_back(indj) ; 891 list_lon.push_back(lon) ; list_lat.push_back(lat) ; 892 list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 893 894 *list_msg.back()<<this->getId() ; 895 *list_msg.back()<<list_indi.back()<<list_indj.back()<<list_lon.back()<<list_lat.back() ; 896 event.push(connectedServer[ns],nbSenders[ns],*list_msg.back()) ; 897 } 898 899 client->sendEvent(event) ; 900 } 901 902 bool CDomain::dispatchEvent(CEventServer& event) 903 { 904 905 if (SuperClass::dispatchEvent(event)) return true ; 906 else 907 { 908 switch(event.type) 909 { 910 case EVENT_ID_SERVER_ATTRIBUT : 911 recvServerAttribut(event) ; 912 return true ; 913 break ; 914 case EVENT_ID_LON_LAT : 915 recvLonLat(event) ; 916 return true ; 917 break ; 918 default : 919 ERROR("bool CContext::dispatchEvent(CEventServer& event)", 920 <<"Unknown Event") ; 921 return false ; 922 } 923 } 924 } 925 926 void CDomain::recvServerAttribut(CEventServer& event) 927 { 928 CBufferIn* buffer=event.subEvents.begin()->buffer; 929 string domainId ; 930 *buffer>>domainId ; 931 get(domainId)->recvServerAttribut(*buffer) ; 932 } 933 934 void CDomain::recvServerAttribut(CBufferIn& buffer) 935 { 936 int zoom_iend=zoom_ibegin.getValue()+zoom_ni.getValue()-1 ; 937 int zoom_jend=zoom_jbegin.getValue()+zoom_nj.getValue()-1 ; 938 939 buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv; 940 941 zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 942 zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 943 zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 944 945 zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 946 zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 947 zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 948 949 if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 950 { 951 zoom_ibegin_srv=1 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; 952 zoom_jbegin_srv=1 ; zoom_jend_srv=0 ; zoom_nj_srv=0 ; 953 } 954 955 lonvalue_srv->resize(extents[zoom_ni_srv*zoom_nj_srv]) ; 956 latvalue_srv->resize(extents[zoom_ni_srv*zoom_nj_srv]) ; 957 } 958 959 void CDomain::recvLonLat(CEventServer& event) 960 { 961 list<CEventServer::SSubEvent>::iterator it ; 962 for (it=event.subEvents.begin();it!=event.subEvents.end();++it) 963 { 964 CBufferIn* buffer=it->buffer; 965 string domainId ; 966 *buffer>>domainId ; 967 get(domainId)->recvLonLat(*buffer) ; 968 } 969 } 970 971 void CDomain::recvLonLat(CBufferIn& buffer) 972 { 973 ARRAY_CREATE(indi,double,1,[0]) ; 974 ARRAY_CREATE(indj,double,1,[0]) ; 975 ARRAY_CREATE(lon,double,1,[0]) ; 976 ARRAY_CREATE(lat,double,1,[0]) ; 977 978 buffer>>indi>>indj>>lon>>lat ; 979 int i,j,ind_srv ; 980 981 for(int ind=0;ind<indi->num_elements();ind++) 982 { 983 i=(*indi)[ind] ; j=(*indj)[ind] ; 984 ind_srv=(i-zoom_ibegin_srv)+(j-zoom_jbegin_srv)*zoom_ni_srv ; 985 (*lonvalue_srv)[ind_srv]=(*lon)[ind] ; 986 (*latvalue_srv)[ind_srv]=(*lat)[ind] ; 987 } 988 } 691 989 //---------------------------------------------------------------- 692 990
Note: See TracChangeset
for help on using the changeset viewer.