source: XIOS/trunk/src/dht_auto_indexing.cpp @ 892

Last change on this file since 892 was 892, checked in by mhnguyen, 8 years ago

Adding new class to auto-generate global index based on DHT

Test
+ NO

File size: 1.9 KB
Line 
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
11namespace 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.
17The constructor tries to assign this information to each process basing on their rank.
18The global index (information) are assigned across processes in the incremental manner.
19The 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
24CDHTAutoIndexing::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}
Note: See TracBrowser for help on using the repository browser.