Skip to content

Commit

Permalink
#480: reduction: Test for vector of int reduction has been added
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrinel committed Oct 3, 2019
1 parent e44c861 commit 97c00ed
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tests/unit/collectives/test_collectives_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ struct SysMsg : ReduceTMsg<int> {
{}
};

struct ReduceVecBoolType : ReduceVecMsg<bool> {
explicit ReduceVecBoolType(std::vector<bool> vec)
: ReduceVecMsg<bool>(vec)
{}
};


struct TestReduce : TestParallelHarness {
using TestMsg = TestStaticBytesShortMsg<4>;

Expand Down Expand Up @@ -143,6 +136,16 @@ struct Verify {
EXPECT_EQ(value[0], false);
EXPECT_EQ(value[1], true);
}

void operator()(ReduceVecMsg<int>* msg) {
auto value = msg->getConstVal();

auto n = vt::theContext()->getNumNodes();

for(auto i = 0; i < value.size(); ++i) {
EXPECT_EQ(value[i], i * n);
}
}
};

TEST_F(TestReduce, test_reduce_op) {
Expand Down Expand Up @@ -190,7 +193,7 @@ TEST_F(TestReduce, test_reduce_min_default_op) {
>(root, msg);
}

TEST_F(TestReduce, test_reduce_vec_msg) {
TEST_F(TestReduce, test_reduce_vec_bool_msg) {

std::vector<bool> vecOfBool;
vecOfBool.push_back(false);
Expand All @@ -206,4 +209,22 @@ TEST_F(TestReduce, test_reduce_vec_msg) {
>(root, msg);
}

TEST_F(TestReduce, test_reduce_vec_int_msg) {

std::vector<int> vecOfInt;
vecOfInt.push_back(0);
vecOfInt.push_back(1);
vecOfInt.push_back(2);
vecOfInt.push_back(3);

auto const root = 0;

auto msg = makeSharedMessage<ReduceVecMsg<int>>(vecOfInt);

theCollective()->reduce<
ReduceVecMsg<int>,
ReduceVecMsg<int>::msgHandler<ReduceVecMsg<int>, PlusOp<std::vector<int>>, Verify<ReduceOP::Plus> >
>(root, msg);
}

}}} // end namespace vt::tests::unit

0 comments on commit 97c00ed

Please sign in to comment.