dht_auto_indexing.cpp 3.4 KB

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