Ignore:
Timestamp:
09/29/15 14:01:53 (9 years ago)
Author:
mhnguyen
Message:

Correcting a bug in interpolation domain

+) Replace shared send buffer by seperate buffer for each proc
+) Remove some redundant codes

Test
+) On Curie
+) test_client, test_complete and test_remap pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp

    r689 r709  
    7676  { 
    7777    nVertexSrc = constNVertex; 
     78    domainSrc_->fillInRectilinearBoundLonLat(boundsLonSrc, boundsLatSrc); 
    7879  } 
    7980 
     
    114115  } 
    115116 
     117 
     118 
    116119  // Ok, now use mapper to calculate 
    117120  int nSrcLocal = domainSrc_->i_index.numElements(); 
    118121  int nDstLocal = domainDest_->i_index.numElements(); 
     122  long int * globalSrc = new long int [nSrcLocal]; 
     123  long int * globalDst = new long int [nDstLocal]; 
     124 
     125  long int globalIndex; 
     126  int i_ind, j_ind; 
     127  for (int idx = 0; idx < nSrcLocal; ++idx) 
     128  { 
     129    i_ind=domainSrc_->i_index(idx) ; 
     130    j_ind=domainSrc_->j_index(idx) ; 
     131 
     132    globalIndex = i_ind + j_ind * domainSrc_->ni_glo; 
     133    globalSrc[idx] = globalIndex; 
     134  } 
     135 
     136  for (int idx = 0; idx < nDstLocal; ++idx) 
     137  { 
     138    i_ind=domainDest_->i_index(idx) ; 
     139    j_ind=domainDest_->j_index(idx) ; 
     140 
     141    globalIndex = i_ind + j_ind * domainDest_->ni_glo; 
     142    globalDst[idx] = globalIndex; 
     143  } 
     144 
     145 
     146  // Calculate weight index 
    119147  Mapper mapper(client->intraComm); 
    120148  mapper.setVerbosity(PROGRESS) ; 
    121   mapper.setSourceMesh(boundsLonSrc.dataFirst(), boundsLatSrc.dataFirst(), nVertexSrc, nSrcLocal, &srcPole[0]); 
    122   mapper.setTargetMesh(boundsLonDest.dataFirst(), boundsLatDest.dataFirst(), nVertexDest, nDstLocal, &dstPole[0]); 
     149  mapper.setSourceMesh(boundsLonSrc.dataFirst(), boundsLatSrc.dataFirst(), nVertexSrc, nSrcLocal, &srcPole[0], globalSrc); 
     150  mapper.setTargetMesh(boundsLonDest.dataFirst(), boundsLatDest.dataFirst(), nVertexDest, nDstLocal, &dstPole[0], globalDst); 
    123151  std::vector<double> timings = mapper.computeWeights(orderInterp); 
    124152 
     153  std::map<int,std::vector<std::pair<int,double> > > interpMapValue; 
    125154  for (int idx = 0;  idx < mapper.nWeights; ++idx) 
    126155  { 
    127     transformationMapping_[mapper.targetWeightId[idx]].push_back(mapper.sourceWeightId[idx]); 
    128     transformationWeight_[mapper.targetWeightId[idx]].push_back(mapper.remapMatrix[idx]); 
    129   } 
     156    interpMapValue[mapper.targetWeightId[idx]].push_back(make_pair(mapper.sourceWeightId[idx],mapper.remapMatrix[idx])); 
     157  } 
     158  exchangeRemapInfo(interpMapValue); 
     159 
     160  delete [] globalSrc; 
     161  delete [] globalDst; 
    130162} 
    131163 
     
    141173} 
    142174 
     175void CDomainAlgorithmInterpolate::readRemapInfo() 
     176{ 
     177  CContext* context = CContext::getCurrent(); 
     178  CContextClient* client=context->client; 
     179  int clientRank = client->clientRank; 
     180 
     181  std::string filename = interpDomain_->file.getValue(); 
     182  std::map<int,std::vector<std::pair<int,double> > > interpMapValue; 
     183  readInterpolationInfo(filename, interpMapValue); 
     184 
     185  exchangeRemapInfo(interpMapValue); 
     186} 
     187 
     188 
    143189/*! 
    144190  Read remap information from file then distribute it among clients 
    145191*/ 
    146 void CDomainAlgorithmInterpolate::readRemapInfo() 
     192void CDomainAlgorithmInterpolate::exchangeRemapInfo(const std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 
    147193{ 
    148194  CContext* context = CContext::getCurrent(); 
    149195  CContextClient* client=context->client; 
    150196  int clientRank = client->clientRank; 
    151  
    152   std::string filename = interpDomain_->file.getValue(); 
    153   std::map<int,std::vector<std::pair<int,double> > > interpMapValue; 
    154   readInterpolationInfo(filename, interpMapValue); 
    155197 
    156198  boost::unordered_map<size_t,int> globalIndexOfDomainDest; 
     
    189231  int* sendBuff = new int[nbClient]; 
    190232  int* recvBuff = new int[nbClient]; 
    191   for (int i = 0; i < nbClient; ++i) sendBuff[i] = 0; 
     233  for (int i = 0; i < nbClient; ++i) 
     234  { 
     235    sendBuff[i] = 0; 
     236    recvBuff[i] = 0; 
     237  } 
    192238  int sendBuffSize = 0; 
    193239  std::map<int, std::vector<size_t> >::const_iterator itbMap = globalIndexInterpSendToClient.begin(), itMap, 
     
    195241  for (itMap = itbMap; itMap != iteMap; ++itMap) 
    196242  { 
     243    const std::vector<size_t>& tmp = itMap->second; 
    197244    int sizeIndex = 0, mapSize = (itMap->second).size(); 
    198245    for (int idx = 0; idx < mapSize; ++idx) 
    199246    { 
    200       sizeIndex += interpMapValue[(itMap->second)[idx]].size(); 
     247      sizeIndex += interpMapValue.at((itMap->second)[idx]).size(); 
    201248    } 
    202249    sendBuff[itMap->first] = sizeIndex; 
    203250    sendBuffSize += sizeIndex; 
    204251  } 
     252 
    205253 
    206254  MPI_Allreduce(sendBuff, recvBuff, nbClient, MPI_INT, MPI_SUM, client->intraComm); 
     
    211259 
    212260  std::vector<MPI_Request> sendRequest; 
    213   // Now send index and weight 
    214   int sendOffSet = 0; 
     261 
     262  int sendOffSet = 0, l = 0; 
    215263  for (itMap = itbMap; itMap != iteMap; ++itMap) 
    216264  { 
     265    const std::vector<size_t>& indexToSend = itMap->second; 
     266    int mapSize = indexToSend.size(); 
    217267    int k = 0; 
    218     int mapSize = (itMap->second).size(); 
    219  
    220268    for (int idx = 0; idx < mapSize; ++idx) 
    221269    { 
    222       std::vector<std::pair<int,double> >& interpMap = interpMapValue[(itMap->second)[idx]]; 
     270      const std::vector<std::pair<int,double> >& interpMap = interpMapValue.at(indexToSend[idx]); 
    223271      for (int i = 0; i < interpMap.size(); ++i) 
    224272      { 
    225         sendIndexDestBuff[k] = (itMap->second)[idx]; 
    226         sendIndexSrcBuff[k]  = interpMap[i].first; 
    227         sendWeightBuff[k]    = interpMap[i].second; 
     273        sendIndexDestBuff[l] = indexToSend[idx]; 
     274        sendIndexSrcBuff[l]  = interpMap[i].first; 
     275        sendWeightBuff[l]    = interpMap[i].second; 
    228276        ++k; 
     277        ++l; 
    229278      } 
    230279    } 
     
    303352 
    304353  std::vector<MPI_Status> requestStatus(sendRequest.size()); 
    305   MPI_Wait(&sendRequest[0], &requestStatus[0]); 
     354  MPI_Waitall(sendRequest.size(), &sendRequest[0], MPI_STATUS_IGNORE); 
    306355 
    307356  delete [] sendIndexDestBuff; 
     
    322371*/ 
    323372void CDomainAlgorithmInterpolate::readInterpolationInfo(std::string& filename, 
    324                                                                 std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 
     373                                                        std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 
    325374{ 
    326375  int ncid ; 
Note: See TracChangeset for help on using the changeset viewer.