AUTH's THMMY "Parallel and distributed systems" course assignments.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
2.7 KiB

  1. /*!
  2. * \file
  3. * \brief Distributed bitonic implementation header
  4. *
  5. * \author
  6. * Christos Choutouridis AEM:8997
  7. * <cchoutou@ece.auth.gr>
  8. */
  9. #ifndef DISTBITONIC_H_
  10. #define DISTBITONIC_H_
  11. #if !defined DEBUG
  12. #define NDEBUG
  13. #endif
  14. #include <cassert>
  15. #include <vector>
  16. #if !defined TESTING
  17. #include <mpi.h>
  18. #endif
  19. /*!
  20. * Enumerator for the different versions of the sorting method
  21. */
  22. enum class SortMode {
  23. Bubbletonic, //!< The v0.5 of the algorithm where we use a bubble-sort like approach
  24. Bitonic //!< The v1.0 of the algorithm where we use the bitonic data-exchange approach
  25. };
  26. using Data_t = std::vector<uint8_t>;
  27. using AllData_t = std::vector<Data_t>;
  28. struct mpi_t {
  29. size_t world_size{};
  30. size_t world_rank{};
  31. std::string processor_name {};
  32. };
  33. extern mpi_t mpi;
  34. /*
  35. * ============================== Sort utilities ==============================
  36. */
  37. /*!
  38. * The primary function template of ascending(). It is DISABLED since , it is explicitly specialized
  39. * for each of the \c SortMode
  40. */
  41. template <SortMode Mode> bool ascending(size_t, [[maybe_unused]] size_t) noexcept = delete;
  42. template <> bool ascending<SortMode::Bubbletonic>(size_t node, [[maybe_unused]] size_t depth) noexcept;
  43. template <> bool ascending<SortMode::Bitonic>(size_t node, size_t depth) noexcept;
  44. /*!
  45. * The primary function template of partner(). It is DISABLED since , it is explicitly specialized
  46. * for each of the \c SortMode
  47. */
  48. template <SortMode Mode> size_t partner(size_t, size_t) noexcept = delete;
  49. template <> size_t partner<SortMode::Bubbletonic>(size_t node, size_t step) noexcept;
  50. template <> size_t partner<SortMode::Bitonic>(size_t node, size_t step) noexcept;
  51. /*!
  52. * The primary function template of keepsmall(). It is DISABLED since , it is explicitly specialized
  53. * for each of the \c SortMode
  54. */
  55. template<SortMode Mode> bool keepsmall(size_t, size_t, [[maybe_unused]] size_t) noexcept = delete;
  56. template<> bool keepsmall<SortMode::Bubbletonic>(size_t node, size_t partner, [[maybe_unused]] size_t depth) noexcept;
  57. template<> bool keepsmall<SortMode::Bitonic>(size_t node, size_t partner, size_t depth) noexcept;
  58. bool isActive(size_t node, size_t nodes) noexcept;
  59. /*
  60. * ============================== Data utilities ==============================
  61. */
  62. void exchange(size_t node, size_t partner);
  63. void minmax(AllData_t& data, size_t node, size_t partner, bool keepsmall);
  64. /*
  65. * ============================== Sort algorithms ==============================
  66. */
  67. void bubbletonic_network(AllData_t& data, size_t nodes);
  68. void distbubbletonic(size_t P, AllData_t& data);
  69. void bitonic_network(AllData_t& data, size_t nodes, size_t depth);
  70. void distbitonic(size_t P, AllData_t& data);
  71. #endif //DISTBITONIC_H_