[892] | 1 | /*! |
---|
| 2 | \file dht_auto_indexing.cpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 6 Jul 2016 |
---|
| 5 | \date 6 Jul 2016 |
---|
| 6 | |
---|
| 7 | \brief Auto assign global index across processes. |
---|
| 8 | */ |
---|
| 9 | #include "dht_auto_indexing.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios |
---|
| 12 | { |
---|
| 13 | |
---|
[924] | 14 | CDHTAutoIndexing::~CDHTAutoIndexing() |
---|
| 15 | { |
---|
| 16 | } |
---|
[892] | 17 | |
---|
[924] | 18 | /*! |
---|
| 19 | \param [in] |
---|
| 20 | \param [in] |
---|
| 21 | */ |
---|
[892] | 22 | |
---|
[924] | 23 | CDHTAutoIndexing::CDHTAutoIndexing(const CArray<size_t,1>& hashValue, |
---|
| 24 | const MPI_Comm& clientIntraComm) |
---|
| 25 | : CClientClientDHTTemplate<size_t>(clientIntraComm) |
---|
[892] | 26 | { |
---|
[924] | 27 | |
---|
| 28 | nbIndexOnProc_ = hashValue.size(); |
---|
| 29 | size_t nbIndexAccum; |
---|
| 30 | MPI_Scan(&nbIndexOnProc_, &nbIndexAccum, 1, MPI_UNSIGNED_LONG, MPI_SUM, clientIntraComm); |
---|
| 31 | |
---|
| 32 | // Broadcasting the total number of indexes |
---|
| 33 | int rank, size; |
---|
| 34 | MPI_Comm_rank(clientIntraComm, &rank); |
---|
| 35 | MPI_Comm_size(clientIntraComm, &size); |
---|
| 36 | if (rank == (size-1)) nbIndexesGlobal_ = nbIndexAccum; |
---|
| 37 | MPI_Bcast(&nbIndexesGlobal_, 1, MPI_UNSIGNED_LONG, size-1, clientIntraComm); |
---|
| 38 | |
---|
| 39 | CArray<size_t,1>::const_iterator itbIdx = hashValue.begin(), itIdx, |
---|
| 40 | iteIdx = hashValue.end(); |
---|
| 41 | |
---|
| 42 | size_t idx = 0; |
---|
| 43 | beginIndexOnProc_ = nbIndexAccum - nbIndexOnProc_; |
---|
| 44 | globalIndex_.resize(nbIndexOnProc_); |
---|
| 45 | for (itIdx = itbIdx; itIdx != iteIdx; ++itIdx) |
---|
| 46 | { |
---|
| 47 | globalIndex_[idx] = beginIndexOnProc_ + idx; |
---|
| 48 | ++idx ; |
---|
| 49 | } |
---|
[892] | 50 | } |
---|
| 51 | |
---|
[924] | 52 | /*! |
---|
| 53 | * \fn void CDHTAutoIndexing::CDHTAutoIndexing(Index2VectorInfoTypeMap& hashInitMap, const MPI_Comm& clientIntraComm) |
---|
| 54 | * Assigns a global index to unique input indexes. |
---|
| 55 | * The returned map has unique indexes as a key and global indexes as a mapped value. |
---|
| 56 | * \param [in] hashInitMap map<size_t, vector<size_t>> is a map of unique indexes. |
---|
| 57 | * \param [in] clientIntraComm |
---|
| 58 | */ |
---|
| 59 | CDHTAutoIndexing::CDHTAutoIndexing(Index2VectorInfoTypeMap& hashInitMap, |
---|
| 60 | const MPI_Comm& clientIntraComm) |
---|
| 61 | : CClientClientDHTTemplate<size_t>(clientIntraComm) |
---|
| 62 | { |
---|
[892] | 63 | |
---|
[924] | 64 | nbIndexOnProc_ = hashInitMap.size(); |
---|
| 65 | size_t nbIndexAccum; |
---|
| 66 | MPI_Scan(&nbIndexOnProc_, &nbIndexAccum, 1, MPI_UNSIGNED_LONG, MPI_SUM, clientIntraComm); |
---|
[892] | 67 | |
---|
[924] | 68 | int rank, size; |
---|
| 69 | MPI_Comm_rank(clientIntraComm, &rank); |
---|
| 70 | MPI_Comm_size(clientIntraComm, &size); |
---|
| 71 | if (rank == (size-1)) nbIndexesGlobal_ = nbIndexAccum; |
---|
| 72 | MPI_Bcast(&nbIndexesGlobal_, 1, MPI_UNSIGNED_LONG, size-1, clientIntraComm); |
---|
| 73 | |
---|
| 74 | Index2VectorInfoTypeMap::iterator itbIdx = hashInitMap.begin(), itIdx, |
---|
| 75 | iteIdx = hashInitMap.end(); |
---|
| 76 | size_t idx = 0; |
---|
| 77 | beginIndexOnProc_ = nbIndexAccum - nbIndexOnProc_; |
---|
| 78 | globalIndex_.resize(nbIndexOnProc_); |
---|
| 79 | for (itIdx = itbIdx; itIdx != iteIdx; ++itIdx) |
---|
| 80 | { |
---|
[1158] | 81 | // (itIdx->second)[0] = beginIndexOnProc_ + idx; |
---|
| 82 | (itIdx->second)[1] = beginIndexOnProc_ + idx; |
---|
[924] | 83 | globalIndex_[idx] = beginIndexOnProc_ + idx; |
---|
| 84 | ++idx ; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /*! |
---|
| 89 | * \fn size_t CDHTAutoIndexing::getNbIndexesGlobal() const |
---|
| 90 | * Returns the total number of global indexes. |
---|
| 91 | */ |
---|
| 92 | size_t CDHTAutoIndexing::getNbIndexesGlobal() const |
---|
[892] | 93 | { |
---|
[924] | 94 | return nbIndexesGlobal_; |
---|
[892] | 95 | } |
---|
| 96 | |
---|
[924] | 97 | /*! |
---|
| 98 | * \fn size_t CDHTAutoIndexing::getIndexStart() const |
---|
| 99 | * Returns the starting global index for a proc. |
---|
| 100 | */ |
---|
| 101 | size_t CDHTAutoIndexing::getIndexStart() const |
---|
| 102 | { |
---|
| 103 | return beginIndexOnProc_; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /*! |
---|
| 107 | * \fn size_t CDHTAutoIndexing::getIndexCount() const |
---|
| 108 | * Returns the number of global indexes on a proc. |
---|
| 109 | */ |
---|
| 110 | size_t CDHTAutoIndexing::getIndexCount() const |
---|
| 111 | { |
---|
| 112 | return nbIndexOnProc_; |
---|
| 113 | } |
---|
| 114 | |
---|
[892] | 115 | } |
---|