[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 | |
---|
| 14 | /*! |
---|
| 15 | Constructor with initial distribution information and the corresponding index |
---|
| 16 | Each process holds a piece of hash value, which has no information (global index) associated. |
---|
| 17 | The constructor tries to assign this information to each process basing on their rank. |
---|
| 18 | The global index (information) are assigned across processes in the incremental manner. |
---|
| 19 | The process has lower rank will have low global index. |
---|
| 20 | \param [in] hashValue Carray contains hash value |
---|
| 21 | \param [in] clientIntraComm communicator of clients |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | CDHTAutoIndexing::CDHTAutoIndexing(const CArray<size_t,1>& hashValue, |
---|
| 25 | const MPI_Comm& clientIntraComm) |
---|
| 26 | : CClientClientDHTTemplate<size_t>(clientIntraComm) |
---|
| 27 | { |
---|
| 28 | Index2VectorInfoTypeMap indexToVecInfoMap; |
---|
| 29 | indexToVecInfoMap.rehash(std::ceil(hashValue.size()/indexToVecInfoMap.max_load_factor())); |
---|
| 30 | CArray<size_t,1>::const_iterator it = hashValue.begin(), ite = hashValue.end(); |
---|
| 31 | |
---|
| 32 | // Just use a dummy value to initialize |
---|
| 33 | int nbLvl = this->getNbLevel(); |
---|
| 34 | for (; it != ite; ++it) |
---|
| 35 | { |
---|
| 36 | indexToVecInfoMap[*it].resize(1); |
---|
| 37 | indexToVecInfoMap[*it][0] = 0; |
---|
| 38 | } |
---|
| 39 | computeDistributedIndex(indexToVecInfoMap, clientIntraComm, nbLvl-1); |
---|
| 40 | |
---|
| 41 | // Find out number of index on other proc |
---|
| 42 | size_t nbIndexOnProc = index2InfoMapping_.size(); |
---|
| 43 | size_t nbIndexAccum; |
---|
| 44 | |
---|
| 45 | MPI_Scan(&nbIndexOnProc, &nbIndexAccum, 1, MPI_UNSIGNED_LONG, MPI_SUM, clientIntraComm); |
---|
| 46 | |
---|
| 47 | Index2VectorInfoTypeMap::iterator itbIdx = index2InfoMapping_.begin(), itIdx, |
---|
| 48 | iteIdx = index2InfoMapping_.end(); |
---|
| 49 | size_t idx = 0; |
---|
| 50 | size_t idxBegin = nbIndexAccum - nbIndexOnProc; |
---|
| 51 | for (itIdx = itbIdx; itIdx != iteIdx; ++itIdx) |
---|
| 52 | { |
---|
| 53 | (itIdx->second)[0] = idxBegin + idx; |
---|
| 54 | ++idx ; |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | } |
---|