|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- /**
- * \file
- * \brief PDS HW2 tests
- *
- * To run these test execute:
- * export OMP_NUM_THREADS=4 # optional to see parallelization speed-up
- * make tests
- * mpirun -np <N> ./out/tests
- *
- * Note:
- * Yes each process runs the entire test suite!!
- *
- * \author
- * Christos Choutouridis AEM:8997
- * <cchoutou@ece.auth.gr>
- */
-
- #include <gtest/gtest.h>
- #include <mpi.h>
- #include <random>
- #include "distsort.hpp"
- /*
- * Global fixtures
- */
-
- // MPI handler for the test session
- MPI_t<> ts_mpi;
-
- // Mersenne seeded from hw if possible. range: [type_min, type_max]
- std::random_device ts_rd;
- std::mt19937 ts_gen(ts_rd());
-
- class TMPIdistSort : public ::testing::Test {
- protected:
- static void SetUpTestSuite() {
- int argc = 0;
- char** argv = nullptr;
- ts_mpi.init(&argc, &argv);
- }
-
- static void TearDownTestSuite() {
- ts_mpi.finalize();
- }
- };
-
-
- /*
- * MPI: SysTest (acceptance)
- * Each process executes distBubbletonic for uin8_t [16]
- */
- TEST_F(TMPIdistSort, distBubbletonic_test1) {
- // Create and fill vector
- using tsValue_t = uint8_t; // Test parameters
- size_t ts_buffer_size = 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); });
-
- // 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]
- */
- TEST_F(TMPIdistSort, distBubbletonic_test2) {
- // 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); });
-
- // 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 pipeline
- */
- TEST_F(TMPIdistSort, distBubbletonic_test3) {
- // 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 pipeline
- 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 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]
- */
- TEST_F(TMPIdistSort, distBitonic_test1) {
- // Create and fill vector
- using tsValue_t = uint8_t; // Test parameters
- size_t ts_buffer_size = 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); });
-
- // 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]
- */
- TEST_F(TMPIdistSort, distBitonic_test2) {
- // 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); });
-
- // 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 pipeline
- */
- TEST_F(TMPIdistSort, distBitonic_test3) {
- // 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 pipeline
- 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]);
- }
- }
- }
-
- /*
- * 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]);
- }
- }
- }
|