HW2: Add an MPI wrapper for the basic functionality and update all types

This commit is contained in:
2024-12-28 17:36:00 +02:00
parent 496ee69f54
commit 1d6b271d2a
7 changed files with 271 additions and 261 deletions
+111 -111
View File
@@ -18,7 +18,7 @@
/* ================================== ascending ================================== */
/*
* bool ascending<SortMode::Bitonic>(size_t node, size_t depth);
* bool ascending<SortMode::Bitonic>(mpi_id_t node, size_t depth);
* depth 0 (the initial ascending pattern)
*/
TEST(TdistBitonic_UT, ascending_test1) {
@@ -32,13 +32,13 @@ TEST(TdistBitonic_UT, ascending_test1) {
EXPECT_EQ(ascending<SortMode::Bitonic>(6, 0), true);
EXPECT_EQ(ascending<SortMode::Bitonic>(7, 0), false);
for (size_t node = 0 ; node < 256 ; ++node) {
for (mpi_id_t node = 0 ; node < 256 ; ++node) {
EXPECT_EQ(ascending<SortMode::Bitonic>(node, 0), ((node % 2) ? false : true) );
}
}
/*
* bool ascending<SortMode::Bitonic>(size_t node, size_t depth);
* bool ascending<SortMode::Bitonic>(mpi_id_t node, size_t depth);
* depth 1
*/
TEST(TdistBitonic_UT, ascending_test2) {
@@ -52,14 +52,14 @@ TEST(TdistBitonic_UT, ascending_test2) {
EXPECT_EQ(ascending<SortMode::Bitonic>(6, 1), false);
EXPECT_EQ(ascending<SortMode::Bitonic>(7, 1), false);
for (size_t node = 0 ; node < 256 ; ++node) {
for (mpi_id_t node = 0 ; node < 256 ; ++node) {
EXPECT_EQ(ascending<SortMode::Bitonic>(2*node, 1), ((node % 2) ? false:true));
EXPECT_EQ(ascending<SortMode::Bitonic>(2*node+1, 1), ((node % 2) ? false:true));
}
}
/*
* bool ascending<SortMode::Bitonic>(size_t node, size_t depth);
* bool ascending<SortMode::Bitonic>(mpi_id_t node, size_t depth);
* various depths
*/
TEST(TdistBitonic_UT, ascending_test3) {
@@ -67,37 +67,37 @@ TEST(TdistBitonic_UT, ascending_test3) {
// Depth = 3
size_t ts_depth = 3;
for (size_t n = 0UL ; n < (1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 0 ; n < (1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), true);
for (size_t n = (1UL<<(ts_depth)) ; n < 2*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = (1<<(ts_depth)) ; n < 2*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), false);
for (size_t n = 2*(1UL<<(ts_depth)) ; n < 3*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 2*(1<<(ts_depth)) ; n < 3*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), true);
for (size_t n = 3*(1UL<<(ts_depth)) ; n < 4*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 3*(1<<(ts_depth)) ; n < 4*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), false);
// Depth = 4
ts_depth = 4;
for (size_t n = 0UL ; n < (1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 0L ; n < (1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), true);
for (size_t n = (1UL<<(ts_depth)) ; n < 2*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = (1<<(ts_depth)) ; n < 2*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), false);
for (size_t n = 2*(1UL<<(ts_depth)) ; n < 3*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 2*(1<<(ts_depth)) ; n < 3*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), true);
for (size_t n = 3*(1UL<<(ts_depth)) ; n < 4*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 3*(1<<(ts_depth)) ; n < 4*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), false);
// Depth = 8
ts_depth = 8;
for (size_t n = 0UL ; n < (1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 0L ; n < (1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), true);
for (size_t n = (1UL<<(ts_depth)) ; n < 2*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = (1<<(ts_depth)) ; n < 2*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), false);
for (size_t n = 2*(1UL<<(ts_depth)) ; n < 3*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 2*(1<<(ts_depth)) ; n < 3*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), true);
for (size_t n = 3*(1UL<<(ts_depth)) ; n < 4*(1UL<<(ts_depth)) ; ++n)
for (mpi_id_t n = 3*(1<<(ts_depth)) ; n < 4*(1<<(ts_depth)) ; ++n)
EXPECT_EQ(ascending<SortMode::Bitonic>(n, ts_depth), false);
}
@@ -107,59 +107,59 @@ TEST(TdistBitonic_UT, ascending_test3) {
/* ================================== partner ================================== */
/*
* size_t partner<SortMode::Bitonic>(size_t node, size_t step);
* mpi_id_t partner<SortMode::Bitonic>(mpi_id_t node, size_t step);
* step = 0
*/
TEST(TdistBitonic_UT, partner_test1) {
EXPECT_EQ(partner<SortMode::Bitonic>(0, 0), 1UL);
EXPECT_EQ(partner<SortMode::Bitonic>(1, 0), 0UL);
EXPECT_EQ(partner<SortMode::Bitonic>(2, 0), 3UL);
EXPECT_EQ(partner<SortMode::Bitonic>(3, 0), 2UL);
EXPECT_EQ(partner<SortMode::Bitonic>(4, 0), 5UL);
EXPECT_EQ(partner<SortMode::Bitonic>(5, 0), 4UL);
EXPECT_EQ(partner<SortMode::Bitonic>(6, 0), 7UL);
EXPECT_EQ(partner<SortMode::Bitonic>(7, 0), 6UL);
EXPECT_EQ(partner<SortMode::Bitonic>(0, 0), 1);
EXPECT_EQ(partner<SortMode::Bitonic>(1, 0), 0);
EXPECT_EQ(partner<SortMode::Bitonic>(2, 0), 3);
EXPECT_EQ(partner<SortMode::Bitonic>(3, 0), 2);
EXPECT_EQ(partner<SortMode::Bitonic>(4, 0), 5);
EXPECT_EQ(partner<SortMode::Bitonic>(5, 0), 4);
EXPECT_EQ(partner<SortMode::Bitonic>(6, 0), 7);
EXPECT_EQ(partner<SortMode::Bitonic>(7, 0), 6);
for (size_t node = 0 ; node < 256 ; ++node) {
for (mpi_id_t node = 0 ; node < 256 ; ++node) {
EXPECT_EQ(partner<SortMode::Bitonic>(node, 0), (node % 2) ? node-1 : node+1);
}
}
/*
* size_t partner<SortMode::Bitonic>(size_t node, size_t step);
* mpi_id_t partner<SortMode::Bitonic>(mpi_id_t node, size_t step);
* step = 1
*/
TEST(TdistBitonic_UT, partner_test2) {
EXPECT_EQ(partner<SortMode::Bitonic>(0, 1), 2UL);
EXPECT_EQ(partner<SortMode::Bitonic>(1, 1), 3UL);
EXPECT_EQ(partner<SortMode::Bitonic>(2, 1), 0UL);
EXPECT_EQ(partner<SortMode::Bitonic>(3, 1), 1UL);
EXPECT_EQ(partner<SortMode::Bitonic>(4, 1), 6UL);
EXPECT_EQ(partner<SortMode::Bitonic>(5, 1), 7UL);
EXPECT_EQ(partner<SortMode::Bitonic>(6, 1), 4UL);
EXPECT_EQ(partner<SortMode::Bitonic>(7, 1), 5UL);
EXPECT_EQ(partner<SortMode::Bitonic>(0, 1), 2);
EXPECT_EQ(partner<SortMode::Bitonic>(1, 1), 3);
EXPECT_EQ(partner<SortMode::Bitonic>(2, 1), 0);
EXPECT_EQ(partner<SortMode::Bitonic>(3, 1), 1);
EXPECT_EQ(partner<SortMode::Bitonic>(4, 1), 6);
EXPECT_EQ(partner<SortMode::Bitonic>(5, 1), 7);
EXPECT_EQ(partner<SortMode::Bitonic>(6, 1), 4);
EXPECT_EQ(partner<SortMode::Bitonic>(7, 1), 5);
for (size_t n1 = 0 ; n1 < 256 ; n1 += 2) {
auto n2 = n1 + 1UL;
for (mpi_id_t n1 = 0 ; n1 < 256 ; n1 += 2) {
auto n2 = n1 + 1;
EXPECT_EQ(partner<SortMode::Bitonic>(n1, 1), ((n1 % 4) ? n1-2 : n1+2));
EXPECT_EQ(partner<SortMode::Bitonic>(n2, 1), ((n1 % 4) ? n2-2 : n2+2));
}
}
/*
* size_t partner(size_t node, size_t step);
* mpi_id_t partner(mpi_id_t node, size_t step);
* various steps
*/
TEST(TdistBitonic_UT, partner_test3) {
// step = 2
size_t ts_step = 2;
for (size_t n1 = 0 ; n1 < 256 ; n1 += 4) {
auto n2 = n1 + 1UL;
auto n3 = n1 + 2UL;
auto n4 = n1 + 3UL;
for (mpi_id_t n1 = 0 ; n1 < 256 ; n1 += 4) {
auto n2 = n1 + 1;
auto n3 = n1 + 2;
auto n4 = n1 + 3;
EXPECT_EQ(partner<SortMode::Bitonic>(n1, ts_step), ((n1 % 8) ? n1-4 : n1+4));
EXPECT_EQ(partner<SortMode::Bitonic>(n2, ts_step), ((n1 % 8) ? n2-4 : n2+4));
EXPECT_EQ(partner<SortMode::Bitonic>(n3, ts_step), ((n1 % 8) ? n3-4 : n3+4));
@@ -169,14 +169,14 @@ TEST(TdistBitonic_UT, partner_test3) {
// step = 3
ts_step = 3;
for (size_t n1 = 0 ; n1 < 256 ; n1 += 8) {
auto n2 = n1 + 1UL;
auto n3 = n1 + 2UL;
auto n4 = n1 + 3UL;
auto n5 = n1 + 4UL;
auto n6 = n1 + 5UL;
auto n7 = n1 + 6UL;
auto n8 = n1 + 7UL;
for (mpi_id_t n1 = 0 ; n1 < 256 ; n1 += 8) {
auto n2 = n1 + 1;
auto n3 = n1 + 2;
auto n4 = n1 + 3;
auto n5 = n1 + 4;
auto n6 = n1 + 5;
auto n7 = n1 + 6;
auto n8 = n1 + 7;
EXPECT_EQ(partner<SortMode::Bitonic>(n1, ts_step), ((n1 % 16) ? n1-8 : n1+8));
EXPECT_EQ(partner<SortMode::Bitonic>(n2, ts_step), ((n1 % 16) ? n2-8 : n2+8));
EXPECT_EQ(partner<SortMode::Bitonic>(n3, ts_step), ((n1 % 16) ? n3-8 : n3+8));
@@ -190,22 +190,22 @@ TEST(TdistBitonic_UT, partner_test3) {
// step = 4
ts_step = 4;
for (size_t n1 = 0 ; n1 < 256 ; n1 += 16) {
auto n2 = n1 + 1UL;
auto n3 = n1 + 2UL;
auto n4 = n1 + 3UL;
auto n5 = n1 + 4UL;
auto n6 = n1 + 5UL;
auto n7 = n1 + 6UL;
auto n8 = n1 + 7UL;
auto n9 = n1 + 8UL;
auto n10 = n1 + 9UL;
auto n11 = n1 + 10UL;
auto n12 = n1 + 11UL;
auto n13 = n1 + 12UL;
auto n14 = n1 + 13UL;
auto n15 = n1 + 14UL;
auto n16 = n1 + 15UL;
for (mpi_id_t n1 = 0 ; n1 < 256 ; n1 += 16) {
auto n2 = n1 + 1;
auto n3 = n1 + 2;
auto n4 = n1 + 3;
auto n5 = n1 + 4;
auto n6 = n1 + 5;
auto n7 = n1 + 6;
auto n8 = n1 + 7;
auto n9 = n1 + 8;
auto n10 = n1 + 9;
auto n11 = n1 + 10;
auto n12 = n1 + 11;
auto n13 = n1 + 12;
auto n14 = n1 + 13;
auto n15 = n1 + 14;
auto n16 = n1 + 15;
EXPECT_EQ(partner<SortMode::Bitonic>(n1, ts_step), ((n1 % 32) ? n1-16 : n1+16));
EXPECT_EQ(partner<SortMode::Bitonic>(n2, ts_step), ((n1 % 32) ? n2-16 : n2+16));
EXPECT_EQ(partner<SortMode::Bitonic>(n3, ts_step), ((n1 % 32) ? n3-16 : n3+16));
@@ -227,108 +227,108 @@ TEST(TdistBitonic_UT, partner_test3) {
/* ================================== keepsmall ================================== */
/* ================================== keepSmall ================================== */
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepSmall(mpi_id_t node, mpi_id_t partner, size_t depth);
* Assertion check
*/
TEST(TdistBitonic_UT, keepsmall_test1) {
ASSERT_DEATH(keepsmall<SortMode::Bitonic>(0, 0, 0), "");
ASSERT_DEATH(keepsmall<SortMode::Bitonic>(1, 1, 42), "");
ASSERT_DEATH(keepsmall<SortMode::Bitonic>(7, 7, 42), "");
ASSERT_DEATH(keepSmall<SortMode::Bitonic>(0, 0, 0), "");
ASSERT_DEATH(keepSmall<SortMode::Bitonic>(1, 1, 42), "");
ASSERT_DEATH(keepSmall<SortMode::Bitonic>(7, 7, 42), "");
}
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepsmall(mpi_id_t node, mpi_id_t partner, size_t depth);
*
* depth: 1 | step: 0 | partner: [1, 0, 3, 2, 5, 4, 7, 6] | keepsmall: Bool[1, 0, 0, 1, 1, 0, 0, 1]
* depth: 1 | step: 0 | partner: [1, 0, 3, 2, 5, 4, 7, 6] | keepSmall: Bool[1, 0, 0, 1, 1, 0, 0, 1]
*/
TEST(TdistBitonic_UT, keepsmall_test2) {
size_t ts_depth = 1UL;
size_t ts_partner[] = {1, 0, 3, 2, 5, 4, 7, 6};
size_t ts_depth = 1;
mpi_id_t ts_partner[] = {1, 0, 3, 2, 5, 4, 7, 6};
bool ts_expected[] = {1, 0, 0, 1, 1, 0, 0, 1};
for (size_t node = 0 ; node < 8UL ; ++node ) {
EXPECT_EQ(ts_expected[node], keepsmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
for (mpi_id_t node = 0 ; node < 8 ; ++node ) {
EXPECT_EQ(ts_expected[node], keepSmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
}
}
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepsmall(mpi_id_t node, mpi_id_t partner, size_t depth);
*
* depth: 2 | step: 1 | partner: [2, 3, 0, 1, 6, 7, 4, 5] | keepsmall: Bool[1, 1, 0, 0, 0, 0, 1, 1]
* depth: 2 | step: 1 | partner: [2, 3, 0, 1, 6, 7, 4, 5] | keepSmall: Bool[1, 1, 0, 0, 0, 0, 1, 1]
*/
TEST(TdistBitonic_UT, keepsmall_test3) {
size_t ts_depth = 2UL;
size_t ts_partner[] = {2, 3, 0, 1, 6, 7, 4, 5};
size_t ts_depth = 2;
mpi_id_t ts_partner[] = {2, 3, 0, 1, 6, 7, 4, 5};
bool ts_expected[] = {1, 1, 0, 0, 0, 0, 1, 1};
for (size_t node = 0 ; node < 8UL ; ++node ) {
EXPECT_EQ(ts_expected[node], keepsmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
for (mpi_id_t node = 0 ; node < 8 ; ++node ) {
EXPECT_EQ(ts_expected[node], keepSmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
}
}
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepsmall(mpi_id_t node, mpi_id_t partner, size_t depth);
*
* depth: 2 | step: 0 | partner: [1, 0, 3, 2, 5, 4, 7, 6] | keepsmall: Bool[1, 0, 1, 0, 0, 1, 0, 1]
* depth: 2 | step: 0 | partner: [1, 0, 3, 2, 5, 4, 7, 6] | keepSmall: Bool[1, 0, 1, 0, 0, 1, 0, 1]
*/
TEST(TdistBitonic_UT, keepsmall_test4) {
size_t ts_depth = 2UL;
size_t ts_partner[] = {1, 0, 3, 2, 5, 4, 7, 6};
size_t ts_depth = 2;
mpi_id_t ts_partner[] = {1, 0, 3, 2, 5, 4, 7, 6};
bool ts_expected[] = {1, 0, 1, 0, 0, 1, 0, 1};
for (size_t node = 0 ; node < 8UL ; ++node ) {
EXPECT_EQ(ts_expected[node], keepsmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
for (mpi_id_t node = 0 ; node < 8 ; ++node ) {
EXPECT_EQ(ts_expected[node], keepSmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
}
}
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepSmall(mpi_id_t node, mpi_id_t partner, size_t depth);
*
* depth: 3 | step: 2 | partner: [4, 5, 6, 7, 0, 1, 2, 3] | keepsmall: Bool[1, 1, 1, 1, 0, 0, 0, 0]
*/
TEST(TdistBitonic_UT, keepsmall_test5) {
size_t ts_depth = 3UL;
size_t ts_partner[] = {4, 5, 6, 7, 0, 1, 2, 3};
size_t ts_depth = 3;
mpi_id_t ts_partner[] = {4, 5, 6, 7, 0, 1, 2, 3};
bool ts_expected[] = {1, 1, 1, 1, 0, 0, 0, 0};
for (size_t node = 0 ; node < 8UL ; ++node ) {
EXPECT_EQ(ts_expected[node], keepsmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
for (mpi_id_t node = 0 ; node < 8 ; ++node ) {
EXPECT_EQ(ts_expected[node], keepSmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
}
}
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepSmall(mpi_id_t node, mpi_id_t partner, size_t depth);
*
* depth: 3 | step: 1 | partner: [2, 3, 0, 1, 6, 7, 4, 5] | keepsmall: Bool[1, 1, 0, 0, 1, 1, 0, 0]
*/
TEST(TdistBitonic_UT, keepsmall_test6) {
size_t ts_depth = 3UL;
size_t ts_partner[] = {2, 3, 0, 1, 6, 7, 4, 5};
size_t ts_depth = 3;
mpi_id_t ts_partner[] = {2, 3, 0, 1, 6, 7, 4, 5};
bool ts_expected[] = {1, 1, 0, 0, 1, 1, 0, 0};
for (size_t node = 0 ; node < 8UL ; ++node ) {
EXPECT_EQ(ts_expected[node], keepsmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
for (mpi_id_t node = 0 ; node < 8 ; ++node ) {
EXPECT_EQ(ts_expected[node], keepSmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
}
}
/*
* bool keepsmall(size_t node, size_t partner, size_t depth);
* bool keepSmall(mpi_id_t node, mpi_id_t partner, size_t depth);
*
* depth: 3 | step: 0 | partner: [1, 0, 3, 2, 5, 4, 7, 6] | keepsmall: Bool[1, 0, 1, 0, 1, 0, 1, 0]
*/
TEST(TdistBitonic_UT, keepsmall_test7) {
size_t ts_depth = 3UL;
size_t ts_partner[] = {1, 0, 3, 2, 5, 4, 7, 6};
size_t ts_depth = 3;
mpi_id_t ts_partner[] = {1, 0, 3, 2, 5, 4, 7, 6};
bool ts_expected[] = {1, 0, 1, 0, 1, 0, 1, 0};
for (size_t node = 0 ; node < 8UL ; ++node ) {
EXPECT_EQ(ts_expected[node], keepsmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
for (mpi_id_t node = 0 ; node < 8 ; ++node ) {
EXPECT_EQ(ts_expected[node], keepSmall<SortMode::Bitonic>(node, ts_partner[node], ts_depth));
}
}
TEST(TdistBitonic_UT, distbitonic_test1) {
TEST(TdistBitonic_UT, distBitonic_test1) {
AllData_t ts_Data {
Data_t (8), Data_t (8)
};
@@ -338,7 +338,7 @@ TEST(TdistBitonic_UT, distbitonic_test1) {
std::generate(v.begin(), v.end(), std::rand);
}
distbitonic(2, ts_Data);
distBitonic(2, ts_Data);
auto max = std::numeric_limits<Data_t::value_type>::min();
for (auto& v : ts_Data) {
@@ -348,7 +348,7 @@ TEST(TdistBitonic_UT, distbitonic_test1) {
}
}
TEST(TdistBitonic_UT, distbitonic_test2) {
TEST(TdistBitonic_UT, distBitonic_test2) {
AllData_t ts_Data {
Data_t (8), Data_t (8), Data_t (8), Data_t (8)
};
@@ -358,7 +358,7 @@ TEST(TdistBitonic_UT, distbitonic_test2) {
std::generate(v.begin(), v.end(), std::rand);
}
distbitonic(4, ts_Data);
distBitonic(4, ts_Data);
auto max = std::numeric_limits<Data_t::value_type>::min();
for (auto& v : ts_Data) {
@@ -368,7 +368,7 @@ TEST(TdistBitonic_UT, distbitonic_test2) {
}
}
TEST(TdistBitonic_UT, distbitonic_test3) {
TEST(TdistBitonic_UT, distBitonic_test3) {
AllData_t ts_Data {
Data_t (32), Data_t (32), Data_t (32), Data_t (32),
Data_t (32), Data_t (32), Data_t (32), Data_t (32)
@@ -379,7 +379,7 @@ TEST(TdistBitonic_UT, distbitonic_test3) {
std::generate(v.begin(), v.end(), std::rand);
}
distbitonic(8, ts_Data);
distBitonic(8, ts_Data);
auto max = std::numeric_limits<Data_t::value_type>::min();
for (auto& v : ts_Data) {
+35 -35
View File
@@ -18,7 +18,7 @@
/* ================================== ascending ================================== */
/*
* bool ascending<SortMode::Bubbletonic>(size_t node, size_t depth);
* bool ascending<SortMode::Bubbletonic>(mpi_id_t node, size_t depth);
*/
TEST(TdistBubbletonic_UT, ascending_Bubbletonic_test1) {
EXPECT_EQ(ascending<SortMode::Bubbletonic>(0, 0), true);
@@ -30,7 +30,7 @@ TEST(TdistBubbletonic_UT, ascending_Bubbletonic_test1) {
EXPECT_EQ(ascending<SortMode::Bubbletonic>(6, 0), true);
EXPECT_EQ(ascending<SortMode::Bubbletonic>(7, 0), false);
for (size_t node = 0 ; node < 256 ; ++node) {
for (mpi_id_t node = 0 ; node < 256 ; ++node) {
EXPECT_EQ(ascending<SortMode::Bubbletonic>(node, 7), ((node % 2) ? false : true) );
}
}
@@ -39,52 +39,52 @@ TEST(TdistBubbletonic_UT, ascending_Bubbletonic_test1) {
/* ================================== partner ================================== */
/*
* size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
* mpi_id_t partner<SortMode::Bubbletonic>(mpi_id_t node, size_t step);
* step = 0
*/
TEST(TdistBubbletonic_UT, partner_Bubbletonic_test1) {
size_t ts_step = 0;
size_t ts_expected[] = {1, 0, 3, 2, 5, 4, 7, 6};
mpi_id_t ts_expected[] = {1, 0, 3, 2, 5, 4, 7, 6};
for (size_t node = 0 ; node < 8 ; ++node) {
for (mpi_id_t node = 0 ; node < 8 ; ++node) {
EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
}
}
/*
* size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
* mpi_id_t partner<SortMode::Bubbletonic>(mpi_id_t node, size_t step);
* step = 1
*/
TEST(TdistBubbletonic_UT, partner_Bubbletonic_test2) {
size_t ts_step = 1;
size_t ts_expected[] = {(size_t)-1, 2, 1, 4, 3, 6, 5, 8};
mpi_id_t ts_expected[] = {(mpi_id_t)-1, 2, 1, 4, 3, 6, 5, 8};
for (size_t node = 0 ; node < 8 ; ++node) {
for (mpi_id_t node = 0 ; node < 8 ; ++node) {
EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
}
}
/*
* size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
* mpi_id_t partner<SortMode::Bubbletonic>(mpi_id_t node, size_t step);
* various steps
*/
TEST(TdistBubbletonic_UT, partner_Bubbletonic_test3) {
size_t ts_even_expected[] = {
mpi_id_t ts_even_expected[] = {
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
};
size_t ts_odd_expected[] = {
(size_t)-1, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16
mpi_id_t ts_odd_expected[] = {
(mpi_id_t)-1, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16
};
for (size_t step = 0 ; step < 32 ; ++step) {
if (step % 2) {
for (size_t node = 0; node < 16; ++node) {
for (mpi_id_t node = 0; node < 16; ++node) {
EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_odd_expected[node]);
}
}
else {
for (size_t node = 0; node < 16; ++node) {
for (mpi_id_t node = 0; node < 16; ++node) {
EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_even_expected[node]);
}
}
@@ -92,36 +92,36 @@ TEST(TdistBubbletonic_UT, partner_Bubbletonic_test3) {
}
/* ================================== keepsmall ================================== */
/* ================================== keepSmall ================================== */
/*
* bool keepsmall<SortMode::Bubbletonic>(size_t node, size_t partner, size_t depth);
* bool keepSmall<SortMode::Bubbletonic>(mpi_id_t node, mpi_id_t partner, size_t depth);
* Assertion check
*/
TEST(TdistBubbletonic_UT, keepsmall_test1) {
ASSERT_DEATH(keepsmall<SortMode::Bubbletonic>(0, 0, 0), "");
ASSERT_DEATH(keepsmall<SortMode::Bubbletonic>(1, 1, 42), "");
ASSERT_DEATH(keepsmall<SortMode::Bubbletonic>(7, 7, 42), "");
ASSERT_DEATH(keepSmall<SortMode::Bubbletonic>(0, 0, 0), "");
ASSERT_DEATH(keepSmall<SortMode::Bubbletonic>(1, 1, 42), "");
ASSERT_DEATH(keepSmall<SortMode::Bubbletonic>(7, 7, 42), "");
}
/*
* bool keepsmall<SortMode::Bubbletonic>(size_t node, size_t partner, size_t depth);
* bool keepSmall<SortMode::Bubbletonic>(mpi_id_t node, mpi_id_t partner, size_t depth);
*/
TEST(TdistBubbletonic_UT, keepsmall_test2) {
// Check various combinations
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(0, 1, 42), true);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(0, 3, 42), true);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(2, 1, 42), false);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(7, 1, 42), false);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(0, 1, 42), true);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(7, 32,42), true);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(7, 1, 42), false);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(4, 0, 42), false);
EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(4, 9, 42), true);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 1, 42), true);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 3, 42), true);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(2, 1, 42), false);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 1, 42), false);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 1, 42), true);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 32, 42), true);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 1, 42), false);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(4, 0, 42), false);
EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(4, 9, 42), true);
}
TEST(TdistBubbletonic_UT, distbubbletonic_test1) {
TEST(TdistBubbletonic_UT, distBubbletonic_test1) {
AllData_t ts_Data {
Data_t (8), Data_t (8)
};
@@ -131,7 +131,7 @@ TEST(TdistBubbletonic_UT, distbubbletonic_test1) {
std::generate(v.begin(), v.end(), std::rand);
}
distbubbletonic(2, ts_Data);
distBubbletonic(2, ts_Data);
auto max = std::numeric_limits<Data_t::value_type>::min();
for (auto& v : ts_Data) {
@@ -142,7 +142,7 @@ TEST(TdistBubbletonic_UT, distbubbletonic_test1) {
}
TEST(TdistBubbletonic_UT, distbubbletonic_test2) {
TEST(TdistBubbletonic_UT, distBubbletonic_test2) {
AllData_t ts_Data {
Data_t (8), Data_t (8), Data_t (8), Data_t (8)
};
@@ -152,7 +152,7 @@ TEST(TdistBubbletonic_UT, distbubbletonic_test2) {
std::generate(v.begin(), v.end(), std::rand);
}
distbubbletonic(4, ts_Data);
distBubbletonic(4, ts_Data);
auto max = std::numeric_limits<Data_t::value_type>::min();
for (auto& v : ts_Data) {
@@ -162,7 +162,7 @@ TEST(TdistBubbletonic_UT, distbubbletonic_test2) {
}
}
TEST(TdistBubbletonic_UT, distbubbletonic_test3) {
TEST(TdistBubbletonic_UT, distBubbletonic_test3) {
AllData_t ts_Data {
Data_t (32), Data_t (32), Data_t (32), Data_t (32),
Data_t (32), Data_t (32), Data_t (32), Data_t (32)
@@ -173,7 +173,7 @@ TEST(TdistBubbletonic_UT, distbubbletonic_test3) {
std::generate(v.begin(), v.end(), std::rand);
}
distbubbletonic(8, ts_Data);
distBubbletonic(8, ts_Data);
auto max = std::numeric_limits<Data_t::value_type>::min();
for (auto& v : ts_Data) {