HW2: RC4 - Measurements version
This commit is contained in:
@@ -91,3 +91,29 @@ TEST(TdistCommonUT, elbowSort_test3) {
|
||||
EXPECT_EQ((ts_data == ts_expected_des), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tag generator test without stage calls
|
||||
*/
|
||||
TEST(TdistCommonUT, tagGenerator_test1) {
|
||||
// The maximum MPI size we support
|
||||
// static constexpr size_t MAX_MPI_SIZE = 1024UL;
|
||||
// The maximum pipeline size we support
|
||||
// static constexpr size_t MAX_PIPELINE_SIZE = 64UL;
|
||||
|
||||
std::vector<int> ts_tags;
|
||||
auto ts_logSize = static_cast<uint32_t>(std::log2(MAX_MPI_SIZE));
|
||||
|
||||
for (size_t depth = 0; depth <= ts_logSize; ++depth) {
|
||||
for (size_t step = 0 ; step < MAX_MPI_SIZE; ++step) {
|
||||
int tag = static_cast<int>(tagGenerator(depth, step));
|
||||
ts_tags.push_back(tag); // Exchange optimization
|
||||
for (size_t stage = 0; stage < MAX_PIPELINE_SIZE; ++stage) {
|
||||
ts_tags.push_back(++tag); // stages
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(ts_tags.begin(), ts_tags.end());
|
||||
for (size_t i = 0 ; i < ts_tags.size() - 1 ; ++i)
|
||||
EXPECT_NE(ts_tags[i], ts_tags[i+1]);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
MPI_t<> ts_mpi;
|
||||
|
||||
// Mersenne seeded from hw if possible. range: [type_min, type_max]
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::random_device ts_rd;
|
||||
std::mt19937 ts_gen(ts_rd());
|
||||
|
||||
class TMPIdistSort : public ::testing::Test {
|
||||
protected:
|
||||
@@ -59,7 +59,7 @@ TEST_F(TMPIdistSort, distBubbletonic_test1) {
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(gen); });
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBubbletonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
@@ -100,7 +100,7 @@ TEST_F(TMPIdistSort, distBubbletonic_test2) {
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(gen); });
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBubbletonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
@@ -141,7 +141,7 @@ TEST_F(TMPIdistSort, distBubbletonic_test3) {
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(gen); });
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Set pipeline
|
||||
config.pipeline = 8;
|
||||
@@ -170,6 +170,96 @@ TEST_F(TMPIdistSort, distBubbletonic_test3) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MPI: SysTest (acceptance)
|
||||
* Each process executes distBubbletonic for uin32_t [1 << 16] with exchange optimization
|
||||
*/
|
||||
TEST_F(TMPIdistSort, distBubbletonic_test4) {
|
||||
// Create and fill vector
|
||||
using tsValue_t = uint32_t; // Test parameters
|
||||
size_t ts_buffer_size = 1 << 16;
|
||||
|
||||
ShadowedVec_t<tsValue_t> ts_Data;
|
||||
std::uniform_int_distribution<tsValue_t > dis(
|
||||
std::numeric_limits<tsValue_t>::min(),
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Set exchange optimization
|
||||
config.exchangeOpt = true;
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBubbletonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
|
||||
// Local min and max
|
||||
auto local_min = *std::min_element(ts_Data.begin(), ts_Data.end());
|
||||
auto local_max = *std::max_element(ts_Data.begin(), ts_Data.end());
|
||||
|
||||
// Gather min/max to rank 0
|
||||
std::vector<tsValue_t> global_mins(ts_mpi.size());
|
||||
std::vector<tsValue_t> global_maxes(ts_mpi.size());
|
||||
MPI_Datatype datatype = MPI_TypeMapper<tsValue_t>::getType();
|
||||
|
||||
MPI_Gather(&local_min, 1, datatype, global_mins.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
MPI_Gather(&local_max, 1, datatype, global_maxes.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
|
||||
// Check results
|
||||
EXPECT_EQ(std::is_sorted(ts_Data.begin(), ts_Data.end()), true);
|
||||
if (ts_mpi.rank() == 0) {
|
||||
for (size_t i = 1; i < global_mins.size(); ++i) {
|
||||
EXPECT_LE(global_maxes[i - 1], global_mins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MPI: SysTest (acceptance)
|
||||
* Each process executes distBubbletonic for uin32_t [1 << 16] with
|
||||
* exchange optimization and pipeline
|
||||
*/
|
||||
TEST_F(TMPIdistSort, distBubbletonic_test5) {
|
||||
// Create and fill vector
|
||||
using tsValue_t = uint32_t; // Test parameters
|
||||
size_t ts_buffer_size = 1 << 16;
|
||||
|
||||
ShadowedVec_t<tsValue_t> ts_Data;
|
||||
std::uniform_int_distribution<tsValue_t > dis(
|
||||
std::numeric_limits<tsValue_t>::min(),
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Set exchange optimization + pipeline
|
||||
config.exchangeOpt = true;
|
||||
config.pipeline = 8;
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBubbletonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
|
||||
// Local min and max
|
||||
auto local_min = *std::min_element(ts_Data.begin(), ts_Data.end());
|
||||
auto local_max = *std::max_element(ts_Data.begin(), ts_Data.end());
|
||||
|
||||
// Gather min/max to rank 0
|
||||
std::vector<tsValue_t> global_mins(ts_mpi.size());
|
||||
std::vector<tsValue_t> global_maxes(ts_mpi.size());
|
||||
MPI_Datatype datatype = MPI_TypeMapper<tsValue_t>::getType();
|
||||
|
||||
MPI_Gather(&local_min, 1, datatype, global_mins.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
MPI_Gather(&local_max, 1, datatype, global_maxes.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
|
||||
// Check results
|
||||
EXPECT_EQ(std::is_sorted(ts_Data.begin(), ts_Data.end()), true);
|
||||
if (ts_mpi.rank() == 0) {
|
||||
for (size_t i = 1; i < global_mins.size(); ++i) {
|
||||
EXPECT_LE(global_maxes[i - 1], global_mins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MPI: SysTest (acceptance)
|
||||
* Each process executes distBitonic for uin8_t [16]
|
||||
@@ -185,7 +275,7 @@ TEST_F(TMPIdistSort, distBitonic_test1) {
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(gen); });
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBitonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
@@ -226,7 +316,7 @@ TEST_F(TMPIdistSort, distBitonic_test2) {
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(gen); });
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBitonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
@@ -267,7 +357,7 @@ TEST_F(TMPIdistSort, distBitonic_test3) {
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(gen); });
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Set pipeline
|
||||
config.pipeline = 8;
|
||||
@@ -295,3 +385,93 @@ TEST_F(TMPIdistSort, distBitonic_test3) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MPI: SysTest (acceptance)
|
||||
* Each process executes distBitonic for uin32_t [1 << 16] with exchange optimization
|
||||
*/
|
||||
TEST_F(TMPIdistSort, distBitonic_test4) {
|
||||
// Create and fill vector
|
||||
using tsValue_t = uint32_t; // Test parameters
|
||||
size_t ts_buffer_size = 1 << 16;
|
||||
|
||||
ShadowedVec_t<tsValue_t> ts_Data;
|
||||
std::uniform_int_distribution<tsValue_t > dis(
|
||||
std::numeric_limits<tsValue_t>::min(),
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Set exchange optimization
|
||||
config.exchangeOpt = true;
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBitonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
|
||||
// Local min and max
|
||||
auto local_min = *std::min_element(ts_Data.begin(), ts_Data.end());
|
||||
auto local_max = *std::max_element(ts_Data.begin(), ts_Data.end());
|
||||
|
||||
// Gather min/max to rank 0
|
||||
std::vector<tsValue_t> global_mins(ts_mpi.size());
|
||||
std::vector<tsValue_t> global_maxes(ts_mpi.size());
|
||||
MPI_Datatype datatype = MPI_TypeMapper<tsValue_t>::getType();
|
||||
|
||||
MPI_Gather(&local_min, 1, datatype, global_mins.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
MPI_Gather(&local_max, 1, datatype, global_maxes.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
|
||||
// Check results
|
||||
EXPECT_EQ(std::is_sorted(ts_Data.begin(), ts_Data.end()), true);
|
||||
if (ts_mpi.rank() == 0) {
|
||||
for (size_t i = 1; i < global_mins.size(); ++i) {
|
||||
EXPECT_LE(global_maxes[i - 1], global_mins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MPI: SysTest (acceptance)
|
||||
* Each process executes distBitonic for uin32_t [1 << 16] with
|
||||
* exchange optimization and pipeline
|
||||
*/
|
||||
TEST_F(TMPIdistSort, distBitonic_test5) {
|
||||
// Create and fill vector
|
||||
using tsValue_t = uint32_t; // Test parameters
|
||||
size_t ts_buffer_size = 1 << 16;
|
||||
|
||||
ShadowedVec_t<tsValue_t> ts_Data;
|
||||
std::uniform_int_distribution<tsValue_t > dis(
|
||||
std::numeric_limits<tsValue_t>::min(),
|
||||
std::numeric_limits<tsValue_t>::max()
|
||||
);
|
||||
ts_Data.resize(ts_buffer_size);
|
||||
std::generate(ts_Data.begin(), ts_Data.end(), [&]() { return dis(ts_gen); });
|
||||
|
||||
// Set exchange optimization + pipeline
|
||||
config.exchangeOpt = true;
|
||||
config.pipeline = 8;
|
||||
|
||||
// Execute function under test in all processes
|
||||
distBitonic(ts_Data, ts_mpi.size(), ts_mpi.rank());
|
||||
|
||||
// Local min and max
|
||||
auto local_min = *std::min_element(ts_Data.begin(), ts_Data.end());
|
||||
auto local_max = *std::max_element(ts_Data.begin(), ts_Data.end());
|
||||
|
||||
// Gather min/max to rank 0
|
||||
std::vector<tsValue_t> global_mins(ts_mpi.size());
|
||||
std::vector<tsValue_t> global_maxes(ts_mpi.size());
|
||||
MPI_Datatype datatype = MPI_TypeMapper<tsValue_t>::getType();
|
||||
|
||||
MPI_Gather(&local_min, 1, datatype, global_mins.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
MPI_Gather(&local_max, 1, datatype, global_maxes.data(), 1, datatype, 0, MPI_COMM_WORLD);
|
||||
|
||||
// Check results
|
||||
EXPECT_EQ(std::is_sorted(ts_Data.begin(), ts_Data.end()), true);
|
||||
if (ts_mpi.rank() == 0) {
|
||||
for (size_t i = 1; i < global_mins.size(); ++i) {
|
||||
EXPECT_LE(global_maxes[i - 1], global_mins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user