HW2: First locally working version of the 2 variations
This commit is contained in:
@@ -6,26 +6,16 @@
|
||||
* Christos Choutouridis AEM:8997
|
||||
* <cchoutou@ece.auth.gr>
|
||||
*/
|
||||
|
||||
#if !defined DEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
#include <cassert>
|
||||
|
||||
#include "utils.hpp"
|
||||
#include "distsort.hpp"
|
||||
|
||||
|
||||
/*!
|
||||
* Predicate to check if the node is active in the current iteration of the bubbletonic
|
||||
* sort exchange.
|
||||
*
|
||||
* @param node The node to check
|
||||
* @param nodes The total number of nodes
|
||||
* @return True if the node is active, false otherwise
|
||||
*/
|
||||
bool isActive(mpi_id_t node, size_t nodes) noexcept {
|
||||
assert(nodes > 0);
|
||||
return (node >= 0) && (node < (nodes-1));
|
||||
bool isActive(mpi_id_t node, size_t nodes) {
|
||||
if (!((nodes > 0) &&
|
||||
(nodes <= std::numeric_limits<mpi_id_t>::max()) ))
|
||||
throw std::runtime_error("(isActive) Non-acceptable value of MPI Nodes\n");
|
||||
// ^ Assert that mpi_id_t can hold nodes, and thus we can cast without data loss!
|
||||
|
||||
return (node >= 0) && (node < static_cast<mpi_id_t>(nodes));
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -10,6 +10,7 @@
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
#include "utils.hpp"
|
||||
#include "config.h"
|
||||
@@ -121,9 +122,15 @@ int main(int argc, char* argv[]) try {
|
||||
#endif
|
||||
|
||||
logger << "Initialize local array of " << session.arraySize << " elements" << logger.endl;
|
||||
std::srand(unsigned(std::time(nullptr)));
|
||||
std::random_device rd; // Mersenne seeded from hw if possible. range: [type_min, type_max]
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<distValue_t > dis(
|
||||
std::numeric_limits<distValue_t>::min(),
|
||||
std::numeric_limits<distValue_t>::max()
|
||||
);
|
||||
// Fill vector
|
||||
Data.resize(session.arraySize);
|
||||
std::generate(Data.begin(), Data.end(), std::rand);
|
||||
std::generate(Data.begin(), Data.end(), [&]() { return dis(gen); });
|
||||
|
||||
if (mpi.rank() == 0)
|
||||
logger << "Starting distributed sorting ... ";
|
||||
@@ -139,7 +146,7 @@ int main(int argc, char* argv[]) try {
|
||||
std::string timeMsg = "rank " + std::to_string(mpi.rank());
|
||||
timer.print_dt(timeMsg.c_str());
|
||||
|
||||
std::cout << "[Data]: Rank " << mpi.rank() << ": [" << (int)Data.front() << " .. " << (int)Data.back() << "]" << std::endl;
|
||||
std::cout << "[Data]: Rank " << mpi.rank() << ": [" << +Data.front() << " .. " << +Data.back() << "]" << std::endl;
|
||||
mpi.finalize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user