Skip to content

Commit

Permalink
tests: break out lambdas into helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpearson committed Jun 5, 2024
1 parent 85d7e23 commit 0e3a3c6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
26 changes: 15 additions & 11 deletions unit_tests/test_allgather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "KokkosComm.hpp"

namespace {

template <typename T>
class Allgather : public testing::Test {
public:
Expand All @@ -27,17 +29,14 @@ class Allgather : public testing::Test {
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
TYPED_TEST_SUITE(Allgather, ScalarTypes);

TYPED_TEST(Allgather, 0D) {
using TestScalar = typename TestFixture::Scalar;

template <typename Scalar>
void test_allgather_0d() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar> sv("sv");
Kokkos::View<TestScalar *> rv("rv", size);
Kokkos::View<Scalar> sv("sv");
Kokkos::View<Scalar *> rv("rv", size);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -51,17 +50,18 @@ TYPED_TEST(Allgather, 0D) {
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Allgather, 1D_contig) {
using TestScalar = typename TestFixture::Scalar;
TYPED_TEST(Allgather, 0D) { test_allgather_0d<typename TestFixture::Scalar>(); }

template <typename Scalar>
void test_allgather_1d_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar *> sv("sv", nContrib);
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
Kokkos::View<Scalar *> sv("sv", nContrib);
Kokkos::View<Scalar *> rv("rv", size * nContrib);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -80,3 +80,7 @@ TYPED_TEST(Allgather, 1D_contig) {
errs);
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Allgather, 1D_contig) { test_allgather_1d_contig<typename TestFixture::Scalar>(); }

} // namespace
18 changes: 10 additions & 8 deletions unit_tests/test_alltoall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ class Alltoall : public testing::Test {
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
TYPED_TEST_SUITE(Alltoall, ScalarTypes);

TYPED_TEST(Alltoall, 1D_contig) {
using TestScalar = typename TestFixture::Scalar;

template <typename Scalar>
void test_alltoall_1d_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar *> sv("sv", size * nContrib);
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
Kokkos::View<Scalar *> sv("sv", size * nContrib);
Kokkos::View<Scalar *> rv("rv", size * nContrib);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -59,16 +58,17 @@ TYPED_TEST(Alltoall, 1D_contig) {
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Alltoall, 1D_inplace_contig) {
using TestScalar = typename TestFixture::Scalar;
TYPED_TEST(Alltoall, 1D_contig) { test_alltoall_1d_contig<typename TestFixture::Scalar>(); }

template <typename Scalar>
void test_alltoall_1d_inplace_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar *> rv("rv", size * nContrib);
Kokkos::View<Scalar *> rv("rv", size * nContrib);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -88,4 +88,6 @@ TYPED_TEST(Alltoall, 1D_inplace_contig) {
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Alltoall, 1D_inplace_contig) { test_alltoall_1d_inplace_contig<typename TestFixture::Scalar>(); }

} // namespace
22 changes: 11 additions & 11 deletions unit_tests/test_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "KokkosComm.hpp"

namespace {

template <typename T>
class Reduce : public testing::Test {
public:
Expand All @@ -31,17 +33,15 @@ TYPED_TEST_SUITE(Reduce, ScalarTypes);
Each rank fills its sendbuf[i] with `rank + i`
operation is sum, so recvbuf[i] should be sum(0..size) + i * size
*/
TYPED_TEST(Reduce, 1D_contig) {
using TestScalar = typename TestFixture::Scalar;

template <typename Scalar>
void test_reduce_1d_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

Kokkos::View<TestScalar *> sendv("sendv", 10);
Kokkos::View<TestScalar *> recvv;
Kokkos::View<Scalar *> sendv("sendv", 10);
Kokkos::View<Scalar *> recvv;
if (0 == rank) {
Kokkos::resize(recvv, sendv.extent(0));
}
Expand All @@ -57,17 +57,17 @@ TYPED_TEST(Reduce, 1D_contig) {
Kokkos::parallel_reduce(
recvv.extent(0),
KOKKOS_LAMBDA(const int &i, int &lsum) {
TestScalar acc = 0;
Scalar acc = 0;
for (int r = 0; r < size; ++r) {
acc += r + i;
}
lsum += recvv(i) != acc;
// if (recvv(i) != acc) {
// Kokkos::printf("%f != %f @ %lu\n", double(Kokkos::abs(recvv(i))),
// double(Kokkos::abs(acc)), size_t(i));
// }
},
errs);
ASSERT_EQ(errs, 0);
}
}

TYPED_TEST(Reduce, 1D_contig) { test_reduce_1d_contig<typename TestFixture::Scalar>(); }

} // namespace

0 comments on commit 0e3a3c6

Please sign in to comment.