Changeset 553


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

Location:
XIOS/trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/inputs/Version2/iodef.xml

    r551 r553  
    2020 
    2121   <axis_definition> 
    22      <axis id="axis_A" /> 
     22     <axis id="axis_A" zoom_size="2" zoom_end="2"/> 
    2323     <axis id="axis_B" zoom_size="2" zoom_end="3" /> 
    2424   </axis_definition> 
  • XIOS/trunk/src/distribution.cpp

    r552 r553  
     1/*! 
     2   \file distribution.hpp 
     3   \author Ha NGUYEN 
     4   \since 13 Jan 2015 
     5   \date 09 Feb 2015 
     6 
     7   \brief Index distribution on server side. 
     8 */ 
    19#include "distribution.hpp" 
    210 
     
    1826} 
    1927 
    20 //const CArray<size_t,1>* CDistribution::getGlobalIndex() const 
    21 //{ 
    22 //  return globalIndex_; 
    23 //} 
     28const CArray<size_t,1>& CDistribution::getGlobalIndex() const 
     29{ 
     30  return (*globalIndex_); 
     31} 
    2432 
    2533int CDistribution::getDims() const 
  • XIOS/trunk/src/distribution.hpp

    r552 r553  
     1/*! 
     2   \file distribution.hpp 
     3   \author Ha NGUYEN 
     4   \since 13 Jan 2015 
     5   \date 09 Feb 2015 
     6 
     7   \brief Index distribution on server side. 
     8 */ 
    19#ifndef __XIOS_DISTRIBUTION_HPP__ 
    210#define __XIOS_DISTRIBUTION_HPP__ 
     
    614 
    715namespace xios { 
     16/*! 
     17 \class CDistribution 
     18 The parent class of CDistributionClient and CDistributionServer, which declares and defines 
     19some basic methods and properties for its children. This class allows its descendants to calculate 
     20distribution of index on client or server side. 
     21*/ 
    822class CDistribution 
    923{ 
     
    1529    virtual ~CDistribution(); 
    1630 
    17     int getDims() const; 
    18     int getRank() const; 
     31    int getDims() const; //! Get dimension size 
     32    int getRank() const; //! Get rank of current process 
     33 
     34    //! Get global index 
     35    const CArray<size_t,1>& getGlobalIndex() const; 
    1936  protected: 
    2037    virtual void createGlobalIndex() = 0; 
     
    2340    int dims_; 
    2441    int rank_; 
    25   private: 
    2642}; 
    2743 
  • XIOS/trunk/src/node/axis.cpp

    r551 r553  
    7575      StdSize zoom_begin,zoom_end, zoom_size ; 
    7676 
    77 //      zoom_begin = (this->zoom_begin.isEmpty()) ?  1 : this->zoom_begin.getValue() ; 
    78 //      zoom_end = (this->zoom_end.isEmpty()) ?  size : this->zoom_end.getValue() ; 
    79 //      zoom_size = (this->zoom_size.isEmpty()) ?  size : this->zoom_size.getValue() ; 
    80  
    8177      // Maybe index begins at 0 (zero) 
    8278      zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue() ; 
     
    8783      if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1 ; 
    8884      if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1 ; 
    89 // 
    90 //      if ( (zoom_begin < 1) || (zoom_begin > size) || (zoom_end<1) || (zoom_end>size) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) 
    91 //        ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ; 
    9285 
    93       if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<1) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) 
     86      if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) 
    9487        ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ; 
    9588 
     
    117110      } 
    118111      else if (data_n.isEmpty()) 
    119         data_n.setValue(zoom_size.getValue()); 
     112        data_n.setValue(ni.getValue()); 
    120113 
    121114      if (data_index.isEmpty()) 
  • XIOS/trunk/src/node/distribution_client.cpp

    r552 r553  
     1/*! 
     2   \file distribution_client.cpp 
     3   \author Ha NGUYEN 
     4   \since 13 Jan 2015 
     5   \date 09 Feb 2015 
     6 
     7   \brief Index distribution on client side. 
     8 */ 
    19#include "distribution_client.hpp" 
    210 
     
    513CDistributionClient::CDistributionClient(int rank, int dims, CArray<size_t,1>* globalIndex) 
    614   : CDistribution(rank, dims, globalIndex), 
    7    localDataIndex_(0), indexGlobalOnServer_(), localIndexSend2Server_(), axisDomainOrder_(), 
     15   localDataIndex_(0), axisDomainOrder_(), 
    816   nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 
    917   dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 
    10    gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), connectedClients_(), 
    11    isConnectedServerComputed_(false), indexDomainData_() 
     18   gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 
    1219{ 
    1320} 
     
    1522CDistributionClient::CDistributionClient(int rank, CGrid* grid) 
    1623   : CDistribution(rank, 0, 0), 
    17    localDataIndex_(0), indexGlobalOnServer_(), localIndexSend2Server_(), axisDomainOrder_(), 
     24   localDataIndex_(0), axisDomainOrder_(), 
    1825   nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 
    1926   dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 
    20    gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), connectedClients_(), 
    21    isConnectedServerComputed_(false), indexDomainData_() 
     27   gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 
    2228{ 
    2329  readDistributionInfo(grid); 
     
    193199    else // So it's an axis 
    194200    { 
    195       nLocal_.at(indexMap_[idx]) = axisList[axisIndex]->zoom_size.getValue(); 
     201      nLocal_.at(indexMap_[idx]) = axisList[axisIndex]->ni.getValue(); 
    196202      nGlob_.at(indexMap_[idx]) = axisList[axisIndex]->size.getValue(); 
    197       nBeginLocal_.at(indexMap_[idx]) = axisList[axisIndex]->zoom_begin.getValue(); //ibegin.getValue(); 
     203      nBeginLocal_.at(indexMap_[idx]) = 0; 
    198204      nBeginGlobal_.at(indexMap_[idx]) = axisList[axisIndex]->ibegin.getValue(); 
    199205      nZoomBegin_.at((indexMap_[idx])) = axisList[axisIndex]->zoom_begin; 
     
    263269 
    264270  localAxisIndex_.resize(numAxis); 
     271  indexAxisData_.resize(numAxis); 
    265272 
    266273  int idxAxis = 0; 
     
    270277    { 
    271278      int iIdx = 0; 
     279      indexAxisData_[idxAxis].resize(dataNIndex_[i], false); 
    272280      for (int j = 0; j < dataNIndex_[i]; ++j) 
    273281      { 
     
    277285        { 
    278286          localAxisIndex_[idxAxis].push_back(iIdx); 
     287          indexAxisData_[idxAxis][j] = true; 
    279288        } 
    280289      } 
     
    333342    } 
    334343 
    335     // Outer index 
     344    // Find out outer index 
    336345    idxDomain = idxAxis = 0; 
    337346    for (int i = 1; i < numElement_; ++i) 
     
    376385  } 
    377386 
    378   // Fill in the global index 
     387 
     388  // Now allocate these arrays 
    379389  this->globalIndex_ = new CArray<size_t,1>(indexSend2ServerCount); 
    380390  localDataIndex_ = new CArray<int,1>(indexLocalDataOnClientCount); 
    381391 
    382   eachElementSize = dataNIndex_; 
    383   innerLoopSize = eachElementSize[0]; 
    384   ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i]; 
     392  // We need to loop with data index 
     393  innerLoopSize = dataNIndex_[0]; 
     394  ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 
    385395  idxLoop.assign(numElement_,0); 
    386396  idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0; 
    387   int count = 0; 
     397  int count = 0, correctOuterIndexDomain = 0, correctOuterIndexAxis = 0; 
    388398  while (idx < ssize) 
    389399  { 
    390400    for (int i = 0; i < numElement_-1; ++i) 
    391401    { 
    392       if (idxLoop[i] == eachElementSize[i]) 
     402      if (idxLoop[i] == dataNIndex_[i]) 
    393403      { 
    394404        idxLoop[i] = 0; 
     
    399409    // Outer index 
    400410    idxDomain = idxAxis = 0; 
    401     bool isIndexDataCorrect = false; 
     411    bool isIndexDomainDataCorrect = false; 
     412    bool isIndexAxisDataCorrect = false; 
     413 
    402414    for (int i = 1; i < numElement_; ++i) 
    403415    { 
     
    406418        if (indexDomainData_[idxDomain][idxLoop[i]]) 
    407419        { 
    408           currentIndex[indexMap_[i]]   = localDomainIndex_[idxDomain][idxLoop[i]]; 
    409           currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain*2+1][idxLoop[i]]; 
    410           isIndexDataCorrect = true; 
     420          currentIndex[indexMap_[i]]   = localDomainIndex_[idxDomain][correctOuterIndexDomain]; 
     421          currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain*2+1][correctOuterIndexDomain]; 
     422          isIndexDomainDataCorrect = true; 
     423          ++correctOuterIndexDomain; 
    411424        } 
    412425        ++idxDomain; 
     
    414427      else 
    415428      { 
    416         currentIndex[indexMap_[i]]   = localAxisIndex_[idxAxis][idxLoop[i]]; 
     429        if (indexAxisData_[idxAxis][idxLoop[i]]) 
     430        { 
     431          currentIndex[indexMap_[i]]   = localAxisIndex_[idxAxis][correctOuterIndexAxis]; 
     432          isIndexAxisDataCorrect = true; 
     433          ++correctOuterIndexAxis; 
     434        } 
    417435        ++idxAxis; 
    418436      } 
     
    421439    // Inner most index 
    422440    idxDomain = idxAxis = 0; 
    423     int correctIndexDomain = 0; 
     441    int correctIndexDomain = 0, correctIndexAxis = 0; 
    424442    for (int i = 0; i < innerLoopSize; ++i) 
    425443    { 
     
    430448          currentIndex[0] = localDomainIndex_[idxDomain][correctIndexDomain]; 
    431449          currentIndex[1] = localDomainIndex_[idxDomain+1][correctIndexDomain]; 
    432           isIndexDataCorrect = true; 
     450          isIndexDomainDataCorrect = true; 
    433451          ++correctIndexDomain; 
    434         } else isIndexDataCorrect = false; 
     452        } 
     453        else isIndexDomainDataCorrect = false; 
    435454      } 
    436455      else 
    437456      { 
    438         currentIndex[0]   = localAxisIndex_[idxAxis][i]; 
    439       } 
    440  
    441       if (isIndexDataCorrect && gridMask_(currentIndex[0], currentIndex[1], currentIndex[2])) 
     457        if (indexAxisData_[idxAxis][i]) 
     458        { 
     459          currentIndex[0] = localAxisIndex_[idxAxis][correctIndexAxis]; 
     460          isIndexAxisDataCorrect = true; 
     461          ++correctIndexAxis; 
     462        } 
     463        else isIndexAxisDataCorrect = false; 
     464      } 
     465 
     466      if (isIndexDomainDataCorrect && 
     467          isIndexAxisDataCorrect && 
     468          gridMask_(currentIndex[0], currentIndex[1], currentIndex[2])) 
    442469      { 
    443470        (*localDataIndex_)(indexLocalDataOnClientCount) = count; 
     
    446473        bool isIndexOnServer = true; 
    447474        for (int j = 0; j < this->dims_; ++j) 
    448           isIndexOnServer = isIndexOnServer && ((currentIndex[j]+nBeginGlobal_[j]) <= nZoomEnd_[j]) 
    449                                             && (nZoomBegin_[j] <= (currentIndex[j]+nBeginGlobal_[j])); 
     475          isIndexOnServer = isIndexOnServer && 
     476                            ((currentIndex[j]+nBeginGlobal_[j]) <= nZoomEnd_[j]) && 
     477                            (nZoomBegin_[j] <= (currentIndex[j]+nBeginGlobal_[j])); 
    450478        if (isIndexOnServer) 
    451479        { 
     480          size_t globalIndex = currentIndex[0] + nBeginGlobal_[0]; 
    452481          size_t mulDim = 1; 
    453           size_t globalIndex = currentIndex[0] + nBeginGlobal_[0]; 
    454482          for (int k = 1; k < this->dims_; ++k) 
    455483          { 
     
    466494    idx += innerLoopSize; 
    467495  } 
    468  
    469 //  std::cout << "global index " << *this->globalIndex_ << std::endl; 
    470 //  std::cout << "local index " << *localDataIndex_ << std::endl; 
    471496} 
    472497 
     
    511536   int tempI = dataIndex + dataBegin; 
    512537   return ((tempI-1)%ni); 
    513 //   return ((tempI)%ni); 
    514 } 
    515  
    516 /*! 
    517   Compute global index of each server distributed by band 
    518   The classic distribution of servers: each server takes charges of writing data divided 
    519 into blocks on the second dimension of grid. If the grid contain a domain, this second dimension is nj. 
    520   \param [in] nServer number of server 
    521   \return vector of pointer to array of global index of servers 
    522 */ 
    523 std::vector<CArray<size_t,1>* > CDistributionClient::computeServerBandDistribution(int nServer) 
    524 { 
    525   // It's not intelligent to allocate dynamic memory inside one function and dellocate in another 
    526   // but it's a way to free a large amount of unnecessary memory 
    527   // This function must NEVER made into public. 
    528   size_t ssize = 1, idx = 0; 
    529   for (int i = 0; i < nGlob_.size(); ++i) ssize *= nGlob_[i]; 
    530   std::vector<int> idxLoop(this->dims_,0); 
    531   std::vector<int> indexServer(nServer,0); 
    532   int njRangeSize; 
    533   std::vector<int> njRangeBegin(nServer,0); 
    534   std::vector<int> njRangeEnd(nServer,0); 
    535   std::vector<CArray<size_t,1>* > globalIndexServer(nServer); 
    536  
    537   int innerLoopSize = nGlob_[0], idxServer; 
    538   if (1<nGlob_.size()) 
    539   { 
    540     for (int i = 0; i < nServer; ++i) 
    541     { 
    542       if (0 < i) njRangeBegin[i] = njRangeEnd[i-1]; 
    543       njRangeSize = nGlob_[1] / nServer; 
    544       if (i < nGlob_[1]%nServer) ++njRangeSize; 
    545       njRangeEnd[i] = njRangeSize + njRangeBegin[i]; 
    546     } 
    547     njRangeEnd[nServer-1] = nGlob_[1]; 
    548  
    549     // Compute size of each global index server array 
    550     while (idx < ssize) 
    551     { 
    552       for (int i = 0; i < this->dims_-1; ++i) 
    553       { 
    554         if (idxLoop[i] == nGlob_[i]) 
    555         { 
    556           idxLoop[i] = 0; 
    557           ++idxLoop[i+1]; 
    558         } 
    559       } 
    560  
    561       for (int i = 0; i < nServer; ++i) 
    562         if ((njRangeBegin[i]<=idxLoop[1]) && (idxLoop[1] < njRangeEnd[i])) 
    563         { 
    564           idxServer = i; 
    565           break; 
    566         } 
    567  
    568       indexServer[idxServer] += innerLoopSize; 
    569       idxLoop[0] += innerLoopSize; 
    570       idx += innerLoopSize; 
    571     } 
    572  
    573  
    574     for (int i = 0; i < nServer; ++i) globalIndexServer[i] = new CArray<size_t,1>(indexServer[i]); 
    575  
    576     // Fill in each global index server array 
    577     idx = 0; 
    578     idxLoop.assign(this->dims_,0); 
    579     indexServer.assign(nServer,0); 
    580     size_t globalIndex = 0; 
    581     while (idx < ssize) 
    582     { 
    583       for (int i = 0; i < this->dims_-1; ++i) 
    584       { 
    585         if (idxLoop[i] == nGlob_[i]) 
    586         { 
    587           idxLoop[i] = 0; 
    588           ++idxLoop[i+1]; 
    589         } 
    590       } 
    591  
    592       for (int i = 0; i < nServer; ++i) 
    593         if ((njRangeBegin[i]<=idxLoop[1]) && (idxLoop[1] < njRangeEnd[i])) 
    594         { 
    595           idxServer = i; 
    596           break; 
    597         } 
    598  
    599       for (int i = 0; i < innerLoopSize; ++i) 
    600       { 
    601         (*globalIndexServer[idxServer])(indexServer[idxServer]) = globalIndex; 
    602         ++indexServer[idxServer]; 
    603         ++globalIndex; 
    604       } 
    605       idxLoop[0] += innerLoopSize; 
    606       idx += innerLoopSize; 
    607     } 
    608   } 
    609  
    610   return globalIndexServer; 
    611 } 
    612  
    613 /*! 
    614   Compute index mapping between cliens and servers 
    615   On using global index of data on clients and servers, each client calculates which part 
    616 of data will be sent to the corresponding server. After the functions is called, client can use 
    617 all computed information to send correct data to server 
    618   \param [in] nServer number of server 
    619   \param [in] distributionType type of distribution, like band or plan 
    620 */ 
    621 void CDistributionClient::computeServerIndexMapping(int nServer, ServerDistributionType distributionType) 
    622 { 
    623   std::vector<CArray<size_t,1>* > globalIndexServer; 
    624  
    625   switch (distributionType) 
    626   { 
    627     case BAND_DISTRIBUTION: 
    628       globalIndexServer = computeServerBandDistribution(nServer); 
    629       break; 
    630     default: 
    631       break; 
    632   } 
    633  
    634   std::vector<CArray<size_t,1>::const_iterator> itBegin(nServer), itEnd(nServer), it(nServer); 
    635   for (int i = 0; i < nServer; ++i) 
    636   { 
    637     itBegin[i] = it[i] = globalIndexServer[i]->begin(); 
    638     itEnd[i]   = globalIndexServer[i]->end(); 
    639   } 
    640  
    641   size_t ssize = (this->globalIndex_)->numElements(); 
    642   for (int i = 0; i < ssize; ++i) 
    643   { 
    644     for (int j = 0; j < nServer; ++j) 
    645     { 
    646       // Just temporarily, it's bad. 
    647  
    648       if (std::binary_search(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 
    649       { 
    650         // Just try to calculate local index server on client side 
    651         (indexGlobalOnServer_[j]).push_back((*this->globalIndex_)(i)); 
    652         (localIndexSend2Server_[j]).push_back(i); 
    653         continue; 
    654       } 
    655     } 
    656   } 
    657  
    658   for (int i = 0; i < nServer; ++i) 
    659     if (0 != globalIndexServer[i]) delete globalIndexServer[i]; 
    660 } 
    661  
    662 /*! 
    663   Compute how many clients each server will receive data from 
    664   On client can send data to several servers as well as one server can receive data originated from 
    665 some clients. In order to write data correctly, each server must know from how many clients it receives data 
    666   \param [in] nbServer number of servers 
    667   \param [in] nClient number of clients 
    668   \param [in] clientIntraComm MPI communication of clients 
    669   \return mapping of server rank and the number of connected clients 
    670 */ 
    671 std::map<int,int> CDistributionClient::computeConnectedClients(int nbServer, int nbClient, MPI_Comm& clientIntraComm) 
    672 { 
    673   if (isConnectedServerComputed_) return connectedClients_; 
    674   std::map<int, std::vector<size_t> >::const_iterator itbMap, iteMap, it; 
    675   itbMap = it = indexGlobalOnServer_.begin(); 
    676   iteMap = indexGlobalOnServer_.end(); 
    677  
    678   std::vector<int> connectedServer; 
    679   std::vector<bool> isConnected(nbServer,false); 
    680  
    681   for (it = itbMap; it != iteMap; ++it) 
    682   { 
    683     for (int serverNum = 0; serverNum < nbServer; ++serverNum) 
    684       if (it->first == serverNum) isConnected[serverNum] = true; 
    685   } 
    686  
    687   for(int serverNum = 0; serverNum<nbServer; ++serverNum) 
    688     if (isConnected[serverNum]) 
    689       connectedServer.push_back(serverNum); 
    690  
    691  
    692   int nbConnectedServer=connectedServer.size(); 
    693   int* recvCount=new int[nbClient]; 
    694   int* displ=new int[nbClient]; 
    695   int* sendBuff=new int[nbConnectedServer]; 
    696   valarray<int> clientRes(0,nbServer); 
    697  
    698   for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 
    699  
    700   // get connected server for everybody 
    701   MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,clientIntraComm) ; 
    702  
    703   displ[0]=0 ; 
    704   for(int n=1;n<nbClient;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 
    705   int recvSize=displ[nbClient-1]+recvCount[nbClient-1] ; 
    706   int* recvBuff=new int[recvSize] ; 
    707  
    708  
    709   MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,clientIntraComm) ; 
    710   for(int n=0;n<recvSize;n++) clientRes[recvBuff[n]]++ ; 
    711  
    712 //  std::map<int,int> nbSenders; 
    713   for(int n=0;n<nbConnectedServer;n++) 
    714   { 
    715     connectedClients_[connectedServer[n]] = clientRes[connectedServer[n]]; 
    716   } 
    717  
    718   isConnectedServerComputed_ = true; 
    719  
    720   delete [] recvCount ; 
    721   delete [] displ ; 
    722   delete [] sendBuff ; 
    723   delete [] recvBuff ; 
    724  
    725   return connectedClients_; 
    726 } 
    727  
    728 /*! 
    729   Return local index of data that is send to server 
    730   \return mapping of server rank and local index of sending data on the client 
    731 */ 
    732 const std::map<int, std::vector<int> >& CDistributionClient::getLocalIndexSendToServer() const 
    733 { 
    734   return localIndexSend2Server_; 
    735538} 
    736539 
     
    743546} 
    744547 
    745 /*! 
    746   Return global index of data on each connected server. 
    747   On receiving data sent from client(s), each server with this global index, is able to 
    748 know where the data should be written. 
    749   \return mapping of server rank and its global index. 
    750 */ 
    751 const std::map<int, std::vector<size_t> >& CDistributionClient::getGlobalIndexOnServer() const 
    752 { 
    753   return indexGlobalOnServer_; 
    754 } 
    755  
    756548} // namespace xios 
  • XIOS/trunk/src/node/distribution_client.hpp

    r552 r553  
     1/*! 
     2   \file distribution_client.hpp 
     3   \author Ha NGUYEN 
     4   \since 13 Jan 2015 
     5   \date 09 Feb 2015 
     6 
     7   \brief Index distribution on client side. 
     8 */ 
    19#ifndef __XIOS_DISTRIBUTIONCLIENT_HPP__ 
    210#define __XIOS_DISTRIBUTIONCLIENT_HPP__ 
     
    1523/*! 
    1624  \class CDistributionClient 
    17   This class bases on the knowledge of distribution on client side as well as on server side 
    18 to calculate the index mapping between client and server. Each client awaring of the existences of other clients 
    19 and servers, firstly, computes the global index of its local data then use this information on taking into account of 
    20 distribution of servers to calculate to which server(s) it connects (sends data) 
     25  This class bases on the knowledge of distribution on client side (decided by users) 
     26to calculate the global index of its local data. 
    2127*/ 
    2228class CDistributionClient : public CDistribution 
    2329{ 
    2430  public: 
    25     enum ServerDistributionType 
    26     { 
    27       BAND_DISTRIBUTION, PLAN_DISTRIBUTION 
    28     }; 
    29  
    3031    /** Default constructor */ 
    3132    CDistributionClient(int rank, int dims, CArray<size_t,1>* globalIndex = 0); 
    3233    CDistributionClient(int rank, CGrid* grid); 
    33     CDistributionClient(const CDistributionClient& distClient); //! Not implement 
    3434 
    3535    /** Default destructor */ 
    3636    virtual ~CDistributionClient(); 
    3737 
    38     void computeServerIndexMapping(int nServer, ServerDistributionType distType = BAND_DISTRIBUTION); 
    39     std::map<int,int> computeConnectedClients(int nbServer, int nbClient, MPI_Comm& clientIntraComm); 
    40  
    4138    const CArray<int,1>& getLocalDataIndexOnClient() const; 
    42     const std::map<int, std::vector<size_t> >& getGlobalIndexOnServer() const; 
    43     const std::map<int, std::vector<int> >& getLocalIndexSendToServer() const; 
     39    std::vector<int> getNGlob() { return nGlob_; } 
    4440 
    4541  protected: 
     
    5147                              const CArray<bool,3>& gridMask); 
    5248 
     49  private: 
     50    //! Create local index of a domain 
     51    void createLocalDomainDataIndex(); 
     52 
     53    //! Create local index of an axis 
     54    void createLocalAxisDataIndex(); 
     55 
    5356    inline int getDomainIndex(const int& dataIIndex, const int& dataJIndex, 
    5457                              const int& dataIBegin, const int& dataJBegin, 
     
    5760 
    5861  private: 
    59     //! Create local index of a domain 
    60     void createLocalDomainDataIndex(); 
    61     //! Create local index of an axis 
    62     void createLocalAxisDataIndex(); 
    63  
    64     //! Compute band distribution on server 
    65     std::vector<CArray<size_t,1>* > computeServerBandDistribution(int nServer); 
    66   private: 
    6762    //!< LocalData index on client 
    6863    CArray<int,1>* localDataIndex_; 
    6964 
    70     //! Index of the local data which will be sent to the corresponding server(s) 
    71     std::map<int, std::vector<int> >  localIndexSend2Server_; 
    72  
    73     //! Global index of data on SERVER, which are calculated by client(s) 
    74     std::map<int, std::vector<size_t> > indexGlobalOnServer_; 
    7565  private: 
    7666    /*! Domains and axis are considered elements. 
    7767     * A grid composed of 1 domain and 1 axis has 2 elements */ 
    7868    int numElement_; 
    79     CArray<bool,1> axisDomainOrder_; //!< 
     69    CArray<bool,1> axisDomainOrder_; //!< Order of axis and domain of a grid 
    8070 
    8171    std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...) 
     
    10292    std::vector<int> indexMap_; //!< Mapping element index to dimension index 
    10393 
    104     std::map<int, int> connectedClients_; //!< number of clients connected to a server 
    105     bool isConnectedServerComputed_; //!< Guard flag 
     94    // The correct index of a domain has true value, the ghost one has false value 
     95    std::vector<std::vector<bool> > indexDomainData_; 
     96    std::vector<std::vector<bool> > indexAxisData_; 
    10697 
    107     // The real index of a domain has true value, the ghost one has false value 
    108     std::vector<std::vector<bool> > indexDomainData_; 
     98  private: 
     99    CDistributionClient(const CDistributionClient& distClient); //! Not implement 
    109100}; 
    110101 
  • XIOS/trunk/src/node/distribution_server.cpp

    r552 r553  
     1/*! 
     2   \file distribution_server.cpp 
     3   \author Ha NGUYEN 
     4   \since 13 Jan 2015 
     5   \date 04 Feb 2015 
     6 
     7   \brief Index distribution on server side. 
     8 */ 
    19#include "distribution_server.hpp" 
    210 
    311namespace xios { 
     12 
    413CDistributionServer::CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex) 
    514  : CDistribution(rank, dims, globalIndex), nGlobal_(), nZoomSize_(), nZoomBegin_() 
  • XIOS/trunk/src/node/distribution_server.hpp

    r552 r553  
     1/*! 
     2   \file distribution_server.hpp 
     3   \author Ha NGUYEN 
     4   \since 13 Jan 2015 
     5   \date 04 Feb 2015 
     6 
     7   \brief Index distribution on server side. 
     8 */ 
     9 
    110#ifndef __XIOS_DISTRIBUTION_SERVER_HPP__ 
    211#define __XIOS_DISTRIBUTION_SERVER_HPP__ 
     
    514 
    615namespace xios { 
     16 
    717/*! 
    8 \class CDistributionServer 
    9  The class, for now, plays a role of computing local index for writing data on server 
     18  \class CDistributionServer 
     19  The class, for now, plays a role of computing local index for writing data on server 
    1020*/ 
    1121class CDistributionServer : public CDistribution 
  • 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 
  • XIOS/trunk/src/node/domain.hpp

    r551 r553  
    113113        vector< vector<int> > j_indSrv ; // for each server, j global index to send 
    114114 
     115 
    115116        CArray<int,2> mapConnectedServer ;  // (ni,nj) => mapped to connected server number, -1 if no server is target 
     117 
    116118 
    117119//        vector<int> ib_srv, ie_srv, in_srv ; 
     
    152154         std::set<StdString> relFiles; 
    153155         bool isClientChecked; // Verify whether all attributes of domain on the client side are good 
     156         std::map<int,int> nbConnectedClients_; // Mapping of number of communicating client to a server 
     157         std::map<int, vector<size_t> > indSrv_; // Global index of each client sent to server 
    154158 
    155159         DECLARE_REF_FUNC(Domain,domain) 
  • XIOS/trunk/src/node/grid.cpp

    r552 r553  
    2323      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    2424      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    25       , serverDistribution_(0) 
     25      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_() 
    2626   { 
    2727     setVirtualDomainGroup(); 
     
    3434      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    3535      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    36       , serverDistribution_(0) 
     36      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_() 
    3737   { 
    3838     setVirtualDomainGroup(); 
     
    5959    if (0 != clientDistribution_) delete clientDistribution_; 
    6060    if (0 != serverDistribution_) delete serverDistribution_; 
     61    if (0 != serverDistributionDescription_) delete serverDistributionDescription_; 
    6162 
    6263   } 
     
    187188     StdSize retVal; 
    188189     std::map<int, StdSize> ret; 
    189      const std::map<int, std::vector<int> >& distribution = clientDistribution_->getLocalIndexSendToServer(); 
     190     const std::map<int, std::vector<int> >& distribution = clientServerMap_.getLocalIndexSendToServer(); 
    190191     std::map<int, std::vector<int> >::const_iterator it = distribution.begin(), itE = distribution.end(); 
    191192     for (; it != itE; ++it) 
     
    405406     CContext* context = CContext::getCurrent() ; 
    406407     CContextClient* client=context->client ; 
     408 
     409     // First of all, compute distribution on client side 
    407410     clientDistribution_ = new CDistributionClient(client->clientRank, this); 
    408      clientDistribution_->computeServerIndexMapping(client->serverSize); 
    409      nbSenders = clientDistribution_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm); 
    410  
     411 
     412     // Then compute distribution on server side 
     413     serverDistributionDescription_ = new CServerDistributionDescription(clientDistribution_->getNGlob()); 
     414     serverDistributionDescription_->computeServerDistribution(client->serverSize, true); 
     415 
     416     // Finally, compute index mapping between client(s) and server(s) 
     417     clientServerMap_.computeServerIndexMapping(clientDistribution_->getGlobalIndex(),serverDistributionDescription_->getGlobalIndex()); 
     418     const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_.getGlobalIndexOnServer(); 
     419     std::vector<int> connectedServerRank; 
     420     for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { 
     421       connectedServerRank.push_back(it->first); 
     422     } 
     423     nbSenders = clientServerMap_.computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank); 
     424 
     425     // Get local data index on client 
    411426     storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); 
    412427     storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 
     
    715730    list<shared_ptr<CMessage> > list_msg ; 
    716731    list< CArray<size_t,1>* > listOutIndex; 
    717  
    718     const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientDistribution_->getGlobalIndexOnServer(); 
    719     const std::map<int, std::vector<int> >& localIndexSendToServer  = clientDistribution_->getLocalIndexSendToServer(); 
     732    const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_.getGlobalIndexOnServer(); 
     733    const std::map<int, std::vector<int> >& localIndexSendToServer  = clientServerMap_.getLocalIndexSendToServer(); 
    720734 
    721735    std::map<int, std::vector<size_t> >::const_iterator iteMap, itbMap, itGlobal; 
     
    724738    iteMap = globalIndexOnServer.end(); 
    725739    itLocal = localIndexSendToServer.begin(); 
    726  
    727740 
    728741    for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) 
  • XIOS/trunk/src/node/grid.hpp

    r552 r553  
    1313#include "distribution_client.hpp" 
    1414#include "distribution_server.hpp" 
     15#include "server_distribution_description.hpp" 
     16#include "client_server_mapping.hpp" 
    1517 
    1618namespace xios { 
     
    2527   class CDistributionClient; 
    2628   class CDistributionServer; 
     29   class CServerDistributionDescription; 
     30   class CClientServerMapping; 
    2731 
    2832   ///-------------------------------------------------------------- 
     
    220224        CDistributionClient* clientDistribution_; 
    221225        CDistributionServer* serverDistribution_; 
     226        CServerDistributionDescription* serverDistributionDescription_; 
     227        CClientServerMapping clientServerMap_; 
    222228   }; // class CGrid 
    223229 
  • XIOS/trunk/src/test/test_new_features.f90

    • Property svn:executable set to *
    r551 r553  
    1313  TYPE(xios_duration)      :: dtime 
    1414  TYPE(xios_context) :: ctx_hdl 
    15   INTEGER,PARAMETER :: ni_glo=100 
    16   INTEGER,PARAMETER :: nj_glo=100 
     15  INTEGER,PARAMETER :: ni_glo=5 
     16  INTEGER,PARAMETER :: nj_glo=5 
    1717  INTEGER,PARAMETER :: llm=5 
    1818  DOUBLE PRECISION  :: lval(llm)=1 
     
    7070  ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni*nj)) 
    7171! ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm,llm),lonvalue(ni*nj)) 
    72   lon(:,:)=lon_glo(ibegin:iend,jbegin:jend) 
    73   lat(:,:)=lat_glo(ibegin:iend,jbegin:jend) 
     72  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1) 
     73  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1) 
    7474  field_A(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) 
    7575 
Note: See TracChangeset for help on using the changeset viewer.