Ignore:
Timestamp:
01/31/19 12:12:52 (5 years ago)
Author:
yushan
Message:

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_trunk_omp/src/filter/spatial_transform_filter.cpp

    r1601 r1646  
    55#include "context_client.hpp" 
    66#include "timer.hpp" 
     7#ifdef _usingEP 
    78using namespace ep_lib; 
     9#endif 
    810 
    911namespace xios 
     
    197199     
    198200    CContextClient* client = CContext::getCurrent()->client; 
     201    int rank; 
     202    MPI_Comm_rank (client->intraComm, &rank); 
    199203 
    200204    // Get default value for output data 
     
    206210    const std::list<CGridTransformation::RecvIndexGridDestinationMap>& listLocalIndexToReceive = gridTransformation->getLocalIndexToReceiveOnGridDest(); 
    207211    const std::list<size_t>& listNbLocalIndexToReceive = gridTransformation->getNbLocalIndexToReceiveOnGridDest(); 
    208     const std::list<std::vector<bool> >& listLocalIndexMaskOnDest = gridTransformation->getLocalMaskIndexOnGridDest(); 
    209212    const std::vector<CGenericAlgorithmTransformation*>& listAlgos = gridTransformation->getAlgos(); 
    210213 
     
    215218    std::list<CGridTransformation::RecvIndexGridDestinationMap>::const_iterator itListRecv = listLocalIndexToReceive.begin(); 
    216219    std::list<size_t>::const_iterator itNbListRecv = listNbLocalIndexToReceive.begin(); 
    217     std::list<std::vector<bool> >::const_iterator itLocalMaskIndexOnDest = listLocalIndexMaskOnDest.begin(); 
    218220    std::vector<CGenericAlgorithmTransformation*>::const_iterator itAlgo = listAlgos.begin(); 
    219221 
    220     for (; itListSend != iteListSend; ++itListSend, ++itListRecv, ++itNbListRecv, ++itLocalMaskIndexOnDest, ++itAlgo) 
     222    for (; itListSend != iteListSend; ++itListSend, ++itListRecv, ++itNbListRecv, ++itAlgo) 
    221223    { 
    222224      CArray<double,1> dataCurrentSrc(dataCurrentDest); 
     
    228230      int idxSendBuff = 0; 
    229231      std::vector<double*> sendBuff(localIndexToSend.size()); 
     232      double* sendBuffRank; 
    230233      for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff) 
    231234      { 
     235        int destRank = itSend->first; 
    232236        if (0 != itSend->second.numElements()) 
    233           sendBuff[idxSendBuff] = new double[itSend->second.numElements()]; 
     237        { 
     238          if (rank != itSend->first) 
     239            sendBuff[idxSendBuff] = new double[itSend->second.numElements()]; 
     240          else 
     241            sendBuffRank = new double[itSend->second.numElements()]; 
     242        } 
    234243      } 
    235244 
     
    242251        const CArray<int,1>& localIndex_p = itSend->second; 
    243252        int countSize = localIndex_p.numElements(); 
    244         for (int idx = 0; idx < countSize; ++idx) 
    245         { 
    246           sendBuff[idxSendBuff][idx] = dataCurrentSrc(localIndex_p(idx)); 
    247         } 
    248         MPI_Isend(sendBuff[idxSendBuff], countSize, MPI_DOUBLE, destRank, 12, client->intraComm, &sendRecvRequest[position++]); 
     253        if (destRank != rank) 
     254        { 
     255          for (int idx = 0; idx < countSize; ++idx) 
     256          { 
     257            sendBuff[idxSendBuff][idx] = dataCurrentSrc(localIndex_p(idx)); 
     258          }   
     259          MPI_Isend(sendBuff[idxSendBuff], countSize, MPI_DOUBLE, destRank, 12, client->intraComm, &sendRecvRequest[position++]); 
     260           
     261        } 
     262        else 
     263        { 
     264          for (int idx = 0; idx < countSize; ++idx) 
     265          { 
     266            sendBuffRank[idx] = dataCurrentSrc(localIndex_p(idx)); 
     267          } 
     268        } 
    249269      } 
    250270 
     
    254274                                                                       iteRecv = localIndexToReceive.end(); 
    255275      int recvBuffSize = 0; 
    256       for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += itRecv->second.size(); //(recvBuffSize < itRecv->second.size()) 
    257                                                                        //? itRecv->second.size() : recvBuffSize; 
     276      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     277      { 
     278        if (itRecv->first != rank ) 
     279          recvBuffSize += itRecv->second.size(); 
     280      } 
     281      //(recvBuffSize < itRecv->second.size()) ? itRecv->second.size() : recvBuffSize; 
    258282      double* recvBuff; 
     283 
    259284      if (0 != recvBuffSize) recvBuff = new double[recvBuffSize]; 
    260285      int currentBuff = 0; 
     
    262287      { 
    263288        int srcRank = itRecv->first; 
    264         int countSize = itRecv->second.size(); 
    265         MPI_Irecv(recvBuff + currentBuff, countSize, MPI_DOUBLE, srcRank, 12, client->intraComm, &sendRecvRequest[position++]); 
    266         currentBuff += countSize; 
     289        if (srcRank != rank) 
     290        { 
     291          int countSize = itRecv->second.size(); 
     292          MPI_Irecv(recvBuff + currentBuff, countSize, MPI_DOUBLE, srcRank, 12, client->intraComm, &sendRecvRequest[position++]); 
     293          currentBuff += countSize; 
     294        } 
    267295      } 
    268296      std::vector<MPI_Status> status(sendRecvRequest.size()); 
    269       MPI_Waitall(sendRecvRequest.size(), &sendRecvRequest[0], &status[0]); 
     297      MPI_Waitall(position, &sendRecvRequest[0], &status[0]); 
     298 
     299 
    270300 
    271301      dataCurrentDest.resize(*itNbListRecv); 
    272       const std::vector<bool>& localMaskDest = *itLocalMaskIndexOnDest; 
    273       for (int i = 0; i < localMaskDest.size(); ++i) 
    274         if (localMaskDest[i]) dataCurrentDest(i) = 0.0; 
    275         else dataCurrentDest(i) = defaultValue; 
     302      dataCurrentDest = 0.0; 
    276303 
    277304      std::vector<bool> localInitFlag(dataCurrentDest.numElements(), true); 
     
    280307      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
    281308      { 
    282         int countSize = itRecv->second.size(); 
    283309        const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second; 
    284         (*itAlgo)->apply(localIndex_p, 
    285                          recvBuff+currentBuff, 
    286                          dataCurrentDest, 
    287                          localInitFlag, 
    288                          ignoreMissingValue,firstPass); 
    289  
    290         currentBuff += countSize; 
     310        int srcRank = itRecv->first; 
     311        if (srcRank != rank) 
     312        { 
     313          int countSize = itRecv->second.size(); 
     314          (*itAlgo)->apply(localIndex_p, 
     315                           recvBuff+currentBuff, 
     316                           dataCurrentDest, 
     317                           localInitFlag, 
     318                           ignoreMissingValue,firstPass); 
     319          currentBuff += countSize; 
     320        } 
     321        else 
     322        { 
     323          (*itAlgo)->apply(localIndex_p, 
     324                           sendBuffRank, 
     325                           dataCurrentDest, 
     326                           localInitFlag, 
     327                           ignoreMissingValue,firstPass); 
     328        } 
     329 
    291330        firstPass=false ; 
    292331      } 
     
    298337      { 
    299338        if (0 != itSend->second.numElements()) 
    300           delete [] sendBuff[idxSendBuff]; 
     339        { 
     340          if (rank != itSend->first) 
     341            delete [] sendBuff[idxSendBuff]; 
     342          else 
     343            delete [] sendBuffRank; 
     344        } 
    301345      } 
    302346      if (0 != recvBuffSize) delete [] recvBuff; 
Note: See TracChangeset for help on using the changeset viewer.