88 lines
2.7 KiB
C++
88 lines
2.7 KiB
C++
/*!
|
|
* \file
|
|
* \brief Distributed bitonic implementation header
|
|
*
|
|
* \author
|
|
* Christos Choutouridis AEM:8997
|
|
* <cchoutou@ece.auth.gr>
|
|
*/
|
|
|
|
#ifndef DISTBITONIC_H_
|
|
#define DISTBITONIC_H_
|
|
|
|
#if !defined DEBUG
|
|
#define NDEBUG
|
|
#endif
|
|
#include <cassert>
|
|
|
|
#include <vector>
|
|
#if !defined TESTING
|
|
#include <mpi.h>
|
|
#endif
|
|
|
|
/*!
|
|
* Enumerator for the different versions of the sorting method
|
|
*/
|
|
enum class SortMode {
|
|
Bubbletonic, //!< The v0.5 of the algorithm where we use a bubble-sort like approach
|
|
Bitonic //!< The v1.0 of the algorithm where we use the bitonic data-exchange approach
|
|
};
|
|
|
|
using Data_t = std::vector<uint8_t>;
|
|
using AllData_t = std::vector<Data_t>;
|
|
|
|
struct mpi_t {
|
|
size_t world_size{};
|
|
size_t world_rank{};
|
|
std::string processor_name {};
|
|
};
|
|
|
|
extern mpi_t mpi;
|
|
|
|
/*
|
|
* ============================== Sort utilities ==============================
|
|
*/
|
|
|
|
/*!
|
|
* The primary function template of ascending(). It is DISABLED since , it is explicitly specialized
|
|
* for each of the \c SortMode
|
|
*/
|
|
template <SortMode Mode> bool ascending(size_t, [[maybe_unused]] size_t) noexcept = delete;
|
|
template <> bool ascending<SortMode::Bubbletonic>(size_t node, [[maybe_unused]] size_t depth) noexcept;
|
|
template <> bool ascending<SortMode::Bitonic>(size_t node, size_t depth) noexcept;
|
|
|
|
/*!
|
|
* The primary function template of partner(). It is DISABLED since , it is explicitly specialized
|
|
* for each of the \c SortMode
|
|
*/
|
|
template <SortMode Mode> size_t partner(size_t, size_t) noexcept = delete;
|
|
template <> size_t partner<SortMode::Bubbletonic>(size_t node, size_t step) noexcept;
|
|
template <> size_t partner<SortMode::Bitonic>(size_t node, size_t step) noexcept;
|
|
|
|
/*!
|
|
* The primary function template of keepsmall(). It is DISABLED since , it is explicitly specialized
|
|
* for each of the \c SortMode
|
|
*/
|
|
template<SortMode Mode> bool keepsmall(size_t, size_t, [[maybe_unused]] size_t) noexcept = delete;
|
|
template<> bool keepsmall<SortMode::Bubbletonic>(size_t node, size_t partner, [[maybe_unused]] size_t depth) noexcept;
|
|
template<> bool keepsmall<SortMode::Bitonic>(size_t node, size_t partner, size_t depth) noexcept;
|
|
|
|
bool isActive(size_t node, size_t nodes) noexcept;
|
|
|
|
/*
|
|
* ============================== Data utilities ==============================
|
|
*/
|
|
void exchange(size_t node, size_t partner);
|
|
void minmax(AllData_t& data, size_t node, size_t partner, bool keepsmall);
|
|
|
|
/*
|
|
* ============================== Sort algorithms ==============================
|
|
*/
|
|
void bubbletonic_network(AllData_t& data, size_t nodes);
|
|
void distbubbletonic(size_t P, AllData_t& data);
|
|
|
|
void bitonic_network(AllData_t& data, size_t nodes, size_t depth);
|
|
void distbitonic(size_t P, AllData_t& data);
|
|
|
|
#endif //DISTBITONIC_H_
|