Changeset 1640


Ignore:
Timestamp:
01/22/19 17:02:30 (5 years ago)
Author:
oabramkina
Message:

On spatial transformations, avoiding send/receive of data from a rank to itself. Double (send/recv) memory allocation is also eliminated in these cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/filter/spatial_transform_filter.cpp

    r1639 r1640  
    188188     
    189189    CContextClient* client = CContext::getCurrent()->client; 
     190    int rank; 
     191    MPI_Comm_rank (client->intraComm, &rank); 
    190192 
    191193    // Get default value for output data 
     
    217219      int idxSendBuff = 0; 
    218220      std::vector<double*> sendBuff(localIndexToSend.size()); 
     221      double* sendBuffRank; 
    219222      for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff) 
    220223      { 
     224        int destRank = itSend->first; 
    221225        if (0 != itSend->second.numElements()) 
    222           sendBuff[idxSendBuff] = new double[itSend->second.numElements()]; 
     226        { 
     227          if (rank != itSend->first) 
     228            sendBuff[idxSendBuff] = new double[itSend->second.numElements()]; 
     229          else 
     230            sendBuffRank = new double[itSend->second.numElements()]; 
     231        } 
    223232      } 
    224233 
     
    230239        const CArray<int,1>& localIndex_p = itSend->second; 
    231240        int countSize = localIndex_p.numElements(); 
    232         for (int idx = 0; idx < countSize; ++idx) 
    233         { 
    234           sendBuff[idxSendBuff][idx] = dataCurrentSrc(localIndex_p(idx)); 
    235         } 
    236         sendRecvRequest.push_back(MPI_Request()); 
    237         MPI_Isend(sendBuff[idxSendBuff], countSize, MPI_DOUBLE, destRank, 12, client->intraComm, &sendRecvRequest.back()); 
     241        if (destRank != rank) 
     242        { 
     243          for (int idx = 0; idx < countSize; ++idx) 
     244          { 
     245            sendBuff[idxSendBuff][idx] = dataCurrentSrc(localIndex_p(idx)); 
     246            sendRecvRequest.push_back(MPI_Request()); 
     247            MPI_Isend(sendBuff[idxSendBuff], countSize, MPI_DOUBLE, destRank, 12, client->intraComm, &sendRecvRequest.back()); 
     248          } 
     249        } 
     250        else 
     251        { 
     252          for (int idx = 0; idx < countSize; ++idx) 
     253          { 
     254            sendBuffRank[idx] = dataCurrentSrc(localIndex_p(idx)); 
     255          } 
     256        } 
    238257      } 
    239258 
     
    243262                                                                       iteRecv = localIndexToReceive.end(); 
    244263      int recvBuffSize = 0; 
    245       for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += itRecv->second.size(); //(recvBuffSize < itRecv->second.size()) 
    246                                                                        //? itRecv->second.size() : recvBuffSize; 
     264      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     265      { 
     266        if (itRecv->first != rank ) 
     267          recvBuffSize += itRecv->second.size(); 
     268      } 
     269      //(recvBuffSize < itRecv->second.size()) ? itRecv->second.size() : recvBuffSize; 
    247270      double* recvBuff; 
     271 
    248272      if (0 != recvBuffSize) recvBuff = new double[recvBuffSize]; 
    249273      int currentBuff = 0; 
     
    251275      { 
    252276        int srcRank = itRecv->first; 
    253         int countSize = itRecv->second.size(); 
    254         sendRecvRequest.push_back(MPI_Request()); 
    255         MPI_Irecv(recvBuff + currentBuff, countSize, MPI_DOUBLE, srcRank, 12, client->intraComm, &sendRecvRequest.back()); 
    256         currentBuff += countSize; 
     277        if (srcRank != rank) 
     278        { 
     279          int countSize = itRecv->second.size(); 
     280          sendRecvRequest.push_back(MPI_Request()); 
     281          MPI_Irecv(recvBuff + currentBuff, countSize, MPI_DOUBLE, srcRank, 12, client->intraComm, &sendRecvRequest.back()); 
     282          currentBuff += countSize; 
     283        } 
    257284      } 
    258285      std::vector<MPI_Status> status(sendRecvRequest.size()); 
     
    267294      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
    268295      { 
    269         int countSize = itRecv->second.size(); 
    270296        const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second; 
    271         (*itAlgo)->apply(localIndex_p, 
    272                          recvBuff+currentBuff, 
    273                          dataCurrentDest, 
    274                          localInitFlag, 
    275                          ignoreMissingValue,firstPass); 
    276  
    277         currentBuff += countSize; 
     297        int srcRank = itRecv->first; 
     298        if (srcRank != rank) 
     299        { 
     300          int countSize = itRecv->second.size(); 
     301          (*itAlgo)->apply(localIndex_p, 
     302                           recvBuff+currentBuff, 
     303                           dataCurrentDest, 
     304                           localInitFlag, 
     305                           ignoreMissingValue,firstPass); 
     306          currentBuff += countSize; 
     307        } 
     308        else 
     309        { 
     310          (*itAlgo)->apply(localIndex_p, 
     311                           sendBuffRank, 
     312                           dataCurrentDest, 
     313                           localInitFlag, 
     314                           ignoreMissingValue,firstPass); 
     315        } 
     316 
    278317        firstPass=false ; 
    279318      } 
     
    285324      { 
    286325        if (0 != itSend->second.numElements()) 
    287           delete [] sendBuff[idxSendBuff]; 
     326        { 
     327          if (rank != itSend->first) 
     328            delete [] sendBuff[idxSendBuff]; 
     329          else 
     330            delete [] sendBuffRank; 
     331        } 
    288332      } 
    289333      if (0 != recvBuffSize) delete [] recvBuff; 
Note: See TracChangeset for help on using the changeset viewer.