1 | #include "scatterer_connector.hpp" |
---|
2 | |
---|
3 | |
---|
4 | namespace xios |
---|
5 | { |
---|
6 | |
---|
7 | void CScattererConnector::computeConnector(void) |
---|
8 | { |
---|
9 | auto& srcGlobalIndex = srcView_->getGlobalIndex() ; |
---|
10 | auto& srcIndex = srcView_->getIndex() ; |
---|
11 | srcSize_=srcIndex.numElements() ; |
---|
12 | auto srcSize = srcView_->getSize() ; |
---|
13 | auto srcLocalSize = srcView_->getLocalSize() ; |
---|
14 | |
---|
15 | auto& dstIndex = dstView_->getIndex() ; |
---|
16 | for(auto& rankIndex : dstIndex) dstSize_[rankIndex.first]=rankIndex.second.numElements() ; |
---|
17 | auto& dstGlobalIndex = dstView_->getGlobalIndex() ; |
---|
18 | |
---|
19 | unordered_map<size_t,int> mapGlobalLocalIndex ; |
---|
20 | int globalIndexSize=srcGlobalIndex.size() ; |
---|
21 | |
---|
22 | for(int i=0 ; i<srcSize ; i++) |
---|
23 | if (srcIndex(i) >=0 && srcIndex(i) <srcLocalSize) mapGlobalLocalIndex[srcGlobalIndex(srcIndex(i))] = i ; |
---|
24 | |
---|
25 | for(auto& rankIndex : dstIndex) |
---|
26 | { |
---|
27 | int rank = rankIndex.first ; |
---|
28 | auto& index = rankIndex.second ; |
---|
29 | int size = index.numElements() ; |
---|
30 | auto& globalIndex = dstGlobalIndex[rank] ; |
---|
31 | int localSize = globalIndex.numElements() ; |
---|
32 | auto& connector = connector_[rank] ; |
---|
33 | auto& mask = mask_[rank] ; |
---|
34 | mask.resize(size) ; |
---|
35 | |
---|
36 | for(int i=0 ; i<size ; i++) |
---|
37 | { |
---|
38 | if (index(i) >= 0 && index(i) < localSize) |
---|
39 | { |
---|
40 | const auto& it = mapGlobalLocalIndex.find(globalIndex(index(i))) ; |
---|
41 | if (it != mapGlobalLocalIndex.end()) |
---|
42 | { |
---|
43 | connector.push_back(it->second) ; |
---|
44 | mask[i] = true ; |
---|
45 | } |
---|
46 | else mask[i]=false ; |
---|
47 | } |
---|
48 | else mask[i]=false ; |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | // compute the number of senders for a remote destination view |
---|
53 | vector<int> ranks(remoteCommSize_,0) ; |
---|
54 | for(auto& rank : connector_) ranks[rank.first] = 1 ; |
---|
55 | MPI_Allreduce(MPI_IN_PLACE,ranks.data(),remoteCommSize_,MPI_INT,MPI_SUM,localComm_) ; |
---|
56 | for(auto& rank : connector_) nbSenders_[rank.first] = ranks[rank.first] ; |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | } |
---|