[2019] | 1 | #include "grid_transform_connector.hpp" |
---|
| 2 | #include "element.hpp" |
---|
| 3 | #include "scatterer_connector.hpp" |
---|
| 4 | #include "gatherer_connector.hpp" |
---|
| 5 | #include "grid_remote_connector.hpp" |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | namespace xios |
---|
| 9 | { |
---|
| 10 | void CGridTransformConnector::computeConnector(void) |
---|
| 11 | { |
---|
| 12 | int commSize ; |
---|
| 13 | int commRank ; |
---|
| 14 | MPI_Comm_size(localComm_, &commSize) ; |
---|
| 15 | MPI_Comm_rank(localComm_, &commRank) ; |
---|
| 16 | int nElements = srcViews_.size() ; |
---|
| 17 | |
---|
| 18 | CGridRemoteConnector remoteConnector(srcViews_, remoteViews_, localComm_, commSize) ; |
---|
| 19 | remoteConnector.computeConnector() ; |
---|
| 20 | |
---|
| 21 | vector<CDistributedElement*> sendElements(nElements) ; |
---|
| 22 | scattererConnector_.resize(nElements) ; |
---|
| 23 | gathererConnector_.resize(nElements) ; |
---|
| 24 | |
---|
| 25 | for(int i=0;i<nElements;i++) |
---|
| 26 | { |
---|
| 27 | sendElements[i] = new CDistributedElement(srcViews_[i]->getGlobalSize(), remoteConnector.getDistributedGlobalIndex(i)) ; |
---|
| 28 | sendElements[i]->addFullView() ; |
---|
| 29 | scattererConnector_[i] = new CScattererConnector(srcViews_[i], sendElements[i]->getView(CElementView::FULL), localComm_, commSize) ; |
---|
| 30 | scattererConnector_[i]->computeConnector() ; |
---|
| 31 | std::map<int, CArray<size_t,1>>& sendIndex = sendElements[i]->getGlobalIndex() ; |
---|
| 32 | |
---|
| 33 | // how much sender ? |
---|
| 34 | vector<int> nbSenders(commSize) ; |
---|
| 35 | int nbSender ; |
---|
| 36 | for(auto& it : sendIndex) nbSenders[it.first]=1 ; |
---|
| 37 | vector<int> recvCounts(commSize,1) ; |
---|
| 38 | MPI_Reduce_scatter(nbSenders.data(), &nbSender, recvCounts.data(), MPI_INT, MPI_SUM, localComm_) ; |
---|
| 39 | |
---|
| 40 | // transfer global index |
---|
| 41 | // send Index |
---|
| 42 | vector<MPI_Request> sendReq ; |
---|
| 43 | for(auto& it : sendIndex) |
---|
| 44 | { |
---|
| 45 | MPI_Request req ; |
---|
| 46 | MPI_Isend(it.second.dataFirst(), it.second.numElements(), MPI_SIZE_T, it.first,0, localComm_, &req) ; |
---|
| 47 | sendReq.push_back(req) ; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | // receive index |
---|
| 51 | map<int,CArray<size_t,1>> recvIndex ; |
---|
| 52 | |
---|
| 53 | for(int j=0; j<nbSender; j++) |
---|
| 54 | { |
---|
| 55 | int size ; |
---|
| 56 | MPI_Status status ; |
---|
| 57 | MPI_Probe(MPI_ANY_SOURCE, 0, localComm_, &status ) ; |
---|
| 58 | MPI_Get_count(&status, MPI_SIZE_T, &size) ; |
---|
| 59 | vector<size_t> recvBuff(size) ; |
---|
| 60 | MPI_Recv(recvBuff.data(), size, MPI_SIZE_T, status.MPI_SOURCE,0, localComm_,&status) ; |
---|
[2030] | 61 | if(size) |
---|
| 62 | { |
---|
| 63 | CArray<size_t,1> arrayTmp(recvBuff.data(), shape(recvBuff.size()), duplicateData) ; |
---|
| 64 | recvIndex[status.MPI_SOURCE].reference(arrayTmp) ; |
---|
| 65 | } |
---|
[2019] | 66 | if (recvRankSize_.count(status.MPI_SOURCE)==0) recvRankSize_[status.MPI_SOURCE] = size ; |
---|
| 67 | else recvRankSize_[status.MPI_SOURCE] *= size ; |
---|
| 68 | } |
---|
| 69 | vector<MPI_Status> sendStatus(sendReq.size()) ; |
---|
| 70 | MPI_Waitall(sendReq.size(),sendReq.data(),sendStatus.data()) ; |
---|
| 71 | |
---|
| 72 | // create gatherer connector |
---|
| 73 | |
---|
| 74 | CDistributedElement recvElement(remoteViews_[i]->getGlobalSize(), recvIndex) ; |
---|
| 75 | recvElement.addFullView() ; |
---|
| 76 | gathererConnector_[i] = new CGathererConnector(recvElement.getView(CElementView::FULL), remoteViews_[i]) ; |
---|
| 77 | gathererConnector_[i]->computeConnector() ; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | gridScattererConnector_ = new CGridScattererConnector(scattererConnector_) ; |
---|
| 81 | gridGathererConnector_ = new CGridGathererConnector(gathererConnector_) ; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|