HW2: A local only version of the distbitonic
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* \file config,h
|
||||
* \file config.h
|
||||
* \brief Build configuration file.
|
||||
*
|
||||
* \author
|
||||
@@ -16,13 +16,13 @@
|
||||
/*
|
||||
* Defines for different version of the exercise
|
||||
*/
|
||||
#define V50 (50)
|
||||
#define V100 (100)
|
||||
#define BITONIC (1)
|
||||
#define BUBBLETONIC (2)
|
||||
|
||||
|
||||
// Fail-safe version selection
|
||||
#if !defined CODE_VERSION
|
||||
#define CODE_VERSION V1
|
||||
#define CODE_VERSION BITONIC
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,10 +30,11 @@
|
||||
* Session option for each invocation of the executable
|
||||
*/
|
||||
struct session_t {
|
||||
bool timing {false};
|
||||
bool verbose {false}; //!< Flag to enable verbose output to stdout
|
||||
bool timing{false};
|
||||
bool verbose{false}; //!< Flag to enable verbose output to stdout
|
||||
};
|
||||
|
||||
extern session_t session;
|
||||
|
||||
|
||||
#endif /* CONFIG_H_ */
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*!
|
||||
* \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
|
||||
|
||||
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;
|
||||
|
||||
|
||||
bool ascending(size_t node, size_t depth) noexcept;
|
||||
size_t partner(size_t node, size_t step) noexcept;
|
||||
bool keepsmall(size_t node, size_t partner, size_t depth) noexcept;
|
||||
|
||||
void exchange(size_t node, size_t partner);
|
||||
void minmax(AllData_t& data, size_t node, size_t partner, bool keepsmall);
|
||||
void sort_network(AllData_t& data, size_t nodes, size_t depth);
|
||||
void distbitonic(size_t P, AllData_t& data);
|
||||
|
||||
#endif //DISTBITONIC_H_
|
||||
@@ -0,0 +1,14 @@
|
||||
/*!
|
||||
* \file
|
||||
* \brief The distributed bitonic implementation header
|
||||
*
|
||||
* \author
|
||||
* Christos Choutouridis AEM:8997
|
||||
* <cchoutou@ece.auth.gr>
|
||||
*/
|
||||
|
||||
#ifndef IMPL_H_
|
||||
#define IMPL_H_
|
||||
|
||||
|
||||
#endif //IMPL_H_
|
||||
@@ -19,32 +19,36 @@
|
||||
/*!
|
||||
* A Logger for entire program.
|
||||
*/
|
||||
struct Log {
|
||||
struct Endl {} endl; //!< a tag object to to use it as a new line request.
|
||||
|
||||
//! We provide logging via << operator
|
||||
template<typename T>
|
||||
Log& operator<< (T&& t) {
|
||||
if (session.verbose) {
|
||||
if (line_) {
|
||||
std::cout << "[Log]: " << t;
|
||||
line_ = false;
|
||||
}
|
||||
else
|
||||
std::cout << t;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
// overload for special end line handling
|
||||
Log& operator<< (Endl e) { (void)e;
|
||||
if (session.verbose) {
|
||||
std::cout << '\n';
|
||||
line_ = true;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
struct Log {
|
||||
struct Endl {
|
||||
} endl; //!< a tag object to to use it as a new line request.
|
||||
|
||||
//! We provide logging via << operator
|
||||
template<typename T>
|
||||
Log &operator<<(T &&t) {
|
||||
if (session.verbose) {
|
||||
if (line_) {
|
||||
std::cout << "[Log]: " << t;
|
||||
line_ = false;
|
||||
} else
|
||||
std::cout << t;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// overload for special end line handling
|
||||
Log &operator<<(Endl e) {
|
||||
(void) e;
|
||||
if (session.verbose) {
|
||||
std::cout << '\n';
|
||||
line_ = true;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
bool line_ {true};
|
||||
bool line_{true};
|
||||
};
|
||||
|
||||
extern Log logger;
|
||||
@@ -52,36 +56,41 @@ extern Log logger;
|
||||
/*!
|
||||
* A small timing utility based on chrono.
|
||||
*/
|
||||
struct Timing{
|
||||
using Tpoint = std::chrono::steady_clock::time_point;
|
||||
using microseconds = std::chrono::microseconds;
|
||||
using milliseconds = std::chrono::milliseconds;
|
||||
using seconds = std::chrono::seconds;
|
||||
struct Timing {
|
||||
using Tpoint = std::chrono::steady_clock::time_point;
|
||||
using microseconds = std::chrono::microseconds;
|
||||
using milliseconds = std::chrono::milliseconds;
|
||||
using seconds = std::chrono::seconds;
|
||||
|
||||
//! tool to mark the starting point
|
||||
Tpoint start () noexcept { return start_ = std::chrono::steady_clock::now(); }
|
||||
//! tool to mark the ending point
|
||||
Tpoint stop () noexcept { return stop_ = std::chrono::steady_clock::now(); }
|
||||
//! tool to mark the starting point
|
||||
Tpoint start() noexcept { return start_ = std::chrono::steady_clock::now(); }
|
||||
|
||||
//! tool to mark the ending point
|
||||
Tpoint stop() noexcept { return stop_ = std::chrono::steady_clock::now(); }
|
||||
|
||||
auto dt() noexcept {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(stop_ - start_).count();
|
||||
}
|
||||
|
||||
//! tool to print the time interval
|
||||
void print_dt(const char *what) noexcept {
|
||||
if (session.timing) {
|
||||
auto t = stop_ - start_;
|
||||
if (std::chrono::duration_cast<microseconds>(t).count() < 10000)
|
||||
std::cout << "[Timing]: " << what << ": "
|
||||
<< std::to_string(std::chrono::duration_cast<microseconds>(t).count()) << " [usec]\n";
|
||||
else if (std::chrono::duration_cast<milliseconds>(t).count() < 10000)
|
||||
std::cout << "[Timing]: " << what << ": "
|
||||
<< std::to_string(std::chrono::duration_cast<milliseconds>(t).count()) << " [msec]\n";
|
||||
else
|
||||
std::cout << "[Timing]: " << what << ": "
|
||||
<< std::to_string(std::chrono::duration_cast<seconds>(t).count()) << " [sec]\n";
|
||||
}
|
||||
}
|
||||
|
||||
auto dt () noexcept {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(stop_ - start_).count();
|
||||
}
|
||||
//! tool to print the time interval
|
||||
void print_dt (const char* what) noexcept {
|
||||
if (session.timing) {
|
||||
auto t = stop_ - start_;
|
||||
if (std::chrono::duration_cast<microseconds>(t).count() < 10000)
|
||||
std::cout << "[Timing]: " << what << ": " << std::to_string(std::chrono::duration_cast<microseconds>(t).count()) << " [usec]\n";
|
||||
else if (std::chrono::duration_cast<milliseconds>(t).count() < 10000)
|
||||
std::cout << "[Timing]: " << what << ": " << std::to_string(std::chrono::duration_cast<milliseconds>(t).count()) << " [msec]\n";
|
||||
else
|
||||
std::cout << "[Timing]: " << what << ": " << std::to_string(std::chrono::duration_cast<seconds>(t).count()) << " [sec]\n";
|
||||
}
|
||||
}
|
||||
private:
|
||||
Tpoint start_;
|
||||
Tpoint stop_;
|
||||
Tpoint start_;
|
||||
Tpoint stop_;
|
||||
};
|
||||
|
||||
|
||||
#endif /* UTILS_HPP_ */
|
||||
|
||||
Reference in New Issue
Block a user