Ignore:
Timestamp:
02/11/15 16:23:12 (9 years ago)
Author:
mhnguyen
Message:

Seperating global index computation on client and server side

+) Create a class which do mapping in general manner, between client and server index global
+) Remove some redundant functions and variables
+) Add some comments to code

Test
+) On Curie. Only test_new_features.f90
+) Test passes and results are correct.
+) Need to change index from 1 to 0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/domain.cpp

    r551 r553  
    1414#include "context_client.hpp" 
    1515#include "array_new.hpp" 
     16#include "server_distribution_description.hpp" 
    1617 
    1718namespace xios { 
     
    2122   CDomain::CDomain(void) 
    2223      : CObjectTemplate<CDomain>(), CDomainAttributes() 
    23       , isChecked(false), relFiles(), isClientChecked(false) 
     24      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_() 
    2425   { /* Ne rien faire de plus */ } 
    2526 
    2627   CDomain::CDomain(const StdString & id) 
    2728      : CObjectTemplate<CDomain>(id), CDomainAttributes() 
    28       , isChecked(false), relFiles(), isClientChecked(false) 
     29      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_() 
    2930         { /* Ne rien faire de plus */ } 
    3031 
     
    612613  void CDomain::sendServerAttribut(void) 
    613614  { 
     615    std::vector<int> nGlobDomain(2); 
     616    nGlobDomain[0] = ni_glo.getValue(); 
     617    nGlobDomain[1] = nj_glo.getValue(); 
     618    CServerDistributionDescription serverDescription(nGlobDomain); 
     619 
    614620    int ni_srv=ni_glo.getValue() ; 
    615621    int ibegin_srv=0 ; 
     
    625631    int serverRank=client->getServerLeader() ; 
    626632 
    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; 
    636642 
    637643     CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 
     
    649655  void CDomain::computeConnectedServer(void) 
    650656  { 
    651     int i,j,i_ind,j_ind ; 
    652  
    653657    ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 
    654658    jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 
    655659 
    656     CContext* context = CContext::getCurrent() ; 
     660    CContext* context=CContext::getCurrent() ; 
    657661    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 ; 
    661666    int zoom_iend=zoom_ibegin+zoom_ni-1 ; 
    662667    int zoom_jend=zoom_jbegin+zoom_nj-1 ; 
    663668 
    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; 
    675677    for(j=0;j<nj;j++) 
    676678      for(i=0;i<ni;i++) 
     
    679681        j_ind=jbegin+j_index(i,j) ; 
    680682 
    681         if (j_ind<pos) serverNum=j_ind/(blockSize+1) ; 
    682         else serverNum=ns+(j_ind-pos)/blockSize ; 
    683         IsConnected[serverNum]=true ; 
    684  
    685683        if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend) 
    686684        { 
    687           mapConnectedServer(i,j)=serverNum ; 
    688           nbData[serverNum]++ ; 
     685          ++globalIndexCount; 
    689686        } 
    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++) 
    707695      for(i=0;i<ni;i++) 
    708696      { 
    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) 
    710701        { 
    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; 
    715705        } 
    716706      } 
    717707 
    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; 
    745717  } 
    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 server 
    754 // 
    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 => ToFix 
    805 //      *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 //  } 
    832718 
    833719  void CDomain::sendLonLat(void) 
    834720  { 
    835     int ns,n,i,j,ind,nv ; 
     721    int ns,n,i,j,ind,nv, idx; 
    836722    CContext* context = CContext::getCurrent() ; 
    837723    CContextClient* client=context->client ; 
     
    847733    list< CArray<double,2>* >list_boundslon,list_boundslat ; 
    848734 
    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) 
    850739    { 
    851       int nbData = nbDataSrv[ns] ; 
     740      int rank = it->first; 
     741      int nbData = (it->second).size(); 
    852742      CArray<int,1> indi(nbData) ; 
    853743      CArray<int,1> indj(nbData) ; 
    854744      CArray<double,1> lon(nbData) ; 
    855745      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; 
    864754        ind=(i-(zoom_ibegin_client))+(j-(zoom_jbegin_client))*zoom_ni_client ; 
    865755 
     
    876766        indi(n)=ibegin+i_index(i-ibegin,j-jbegin)  ; 
    877767        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  ; 
    880768      } 
    881769 
     
    902790        *list_msgLat.back()<<*list_boundslat.back(); 
    903791      } 
    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()) ; 
    906794    } 
    907795 
     
    916804    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++)   delete *it; 
    917805    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++)   delete *it; 
    918  
    919806  } 
    920807 
     
    1052939    if (hasBounds) buffer>>boundslat ; 
    1053940    type.setValue((type_attr::t_enum)type_int) ; // probleme des type enum avec les buffers : ToFix 
    1054  
    1055941    int i,j,ind_srv ; 
    1056942    for(int ind=0;ind<indi.numElements();ind++) 
     
    1068954    } 
    1069955  } 
    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 
    1113957   //---------------------------------------------------------------- 
    1114958 
Note: See TracChangeset for help on using the changeset viewer.