Skip to content

Commit 0e3a3c6

Browse files
committed
tests: break out lambdas into helper function
1 parent 85d7e23 commit 0e3a3c6

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

unit_tests/test_allgather.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "KokkosComm.hpp"
2020

21+
namespace {
22+
2123
template <typename T>
2224
class Allgather : public testing::Test {
2325
public:
@@ -27,17 +29,14 @@ class Allgather : public testing::Test {
2729
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
2830
TYPED_TEST_SUITE(Allgather, ScalarTypes);
2931

30-
TYPED_TEST(Allgather, 0D) {
31-
using TestScalar = typename TestFixture::Scalar;
32-
32+
template <typename Scalar>
33+
void test_allgather_0d() {
3334
int rank, size;
3435
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
3536
MPI_Comm_size(MPI_COMM_WORLD, &size);
3637

37-
const int nContrib = 10;
38-
39-
Kokkos::View<TestScalar> sv("sv");
40-
Kokkos::View<TestScalar *> rv("rv", size);
38+
Kokkos::View<Scalar> sv("sv");
39+
Kokkos::View<Scalar *> rv("rv", size);
4140

4241
// fill send buffer
4342
Kokkos::parallel_for(
@@ -51,17 +50,18 @@ TYPED_TEST(Allgather, 0D) {
5150
EXPECT_EQ(errs, 0);
5251
}
5352

54-
TYPED_TEST(Allgather, 1D_contig) {
55-
using TestScalar = typename TestFixture::Scalar;
53+
TYPED_TEST(Allgather, 0D) { test_allgather_0d<typename TestFixture::Scalar>(); }
5654

55+
template <typename Scalar>
56+
void test_allgather_1d_contig() {
5757
int rank, size;
5858
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5959
MPI_Comm_size(MPI_COMM_WORLD, &size);
6060

6161
const int nContrib = 10;
6262

63-
Kokkos::View<TestScalar *> sv("sv", nContrib);
64-
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
63+
Kokkos::View<Scalar *> sv("sv", nContrib);
64+
Kokkos::View<Scalar *> rv("rv", size * nContrib);
6565

6666
// fill send buffer
6767
Kokkos::parallel_for(
@@ -80,3 +80,7 @@ TYPED_TEST(Allgather, 1D_contig) {
8080
errs);
8181
EXPECT_EQ(errs, 0);
8282
}
83+
84+
TYPED_TEST(Allgather, 1D_contig) { test_allgather_1d_contig<typename TestFixture::Scalar>(); }
85+
86+
} // namespace

unit_tests/test_alltoall.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ class Alltoall : public testing::Test {
2929
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
3030
TYPED_TEST_SUITE(Alltoall, ScalarTypes);
3131

32-
TYPED_TEST(Alltoall, 1D_contig) {
33-
using TestScalar = typename TestFixture::Scalar;
34-
32+
template <typename Scalar>
33+
void test_alltoall_1d_contig() {
3534
int rank, size;
3635
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
3736
MPI_Comm_size(MPI_COMM_WORLD, &size);
3837

3938
const int nContrib = 10;
4039

41-
Kokkos::View<TestScalar *> sv("sv", size * nContrib);
42-
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
40+
Kokkos::View<Scalar *> sv("sv", size * nContrib);
41+
Kokkos::View<Scalar *> rv("rv", size * nContrib);
4342

4443
// fill send buffer
4544
Kokkos::parallel_for(
@@ -59,16 +58,17 @@ TYPED_TEST(Alltoall, 1D_contig) {
5958
EXPECT_EQ(errs, 0);
6059
}
6160

62-
TYPED_TEST(Alltoall, 1D_inplace_contig) {
63-
using TestScalar = typename TestFixture::Scalar;
61+
TYPED_TEST(Alltoall, 1D_contig) { test_alltoall_1d_contig<typename TestFixture::Scalar>(); }
6462

63+
template <typename Scalar>
64+
void test_alltoall_1d_inplace_contig() {
6565
int rank, size;
6666
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
6767
MPI_Comm_size(MPI_COMM_WORLD, &size);
6868

6969
const int nContrib = 10;
7070

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

7373
// fill send buffer
7474
Kokkos::parallel_for(
@@ -88,4 +88,6 @@ TYPED_TEST(Alltoall, 1D_inplace_contig) {
8888
EXPECT_EQ(errs, 0);
8989
}
9090

91+
TYPED_TEST(Alltoall, 1D_inplace_contig) { test_alltoall_1d_inplace_contig<typename TestFixture::Scalar>(); }
92+
9193
} // namespace

unit_tests/test_reduce.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "KokkosComm.hpp"
2020

21+
namespace {
22+
2123
template <typename T>
2224
class Reduce : public testing::Test {
2325
public:
@@ -31,17 +33,15 @@ TYPED_TEST_SUITE(Reduce, ScalarTypes);
3133
Each rank fills its sendbuf[i] with `rank + i`
3234
3335
operation is sum, so recvbuf[i] should be sum(0..size) + i * size
34-
3536
*/
36-
TYPED_TEST(Reduce, 1D_contig) {
37-
using TestScalar = typename TestFixture::Scalar;
38-
37+
template <typename Scalar>
38+
void test_reduce_1d_contig() {
3939
int rank, size;
4040
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4141
MPI_Comm_size(MPI_COMM_WORLD, &size);
4242

43-
Kokkos::View<TestScalar *> sendv("sendv", 10);
44-
Kokkos::View<TestScalar *> recvv;
43+
Kokkos::View<Scalar *> sendv("sendv", 10);
44+
Kokkos::View<Scalar *> recvv;
4545
if (0 == rank) {
4646
Kokkos::resize(recvv, sendv.extent(0));
4747
}
@@ -57,17 +57,17 @@ TYPED_TEST(Reduce, 1D_contig) {
5757
Kokkos::parallel_reduce(
5858
recvv.extent(0),
5959
KOKKOS_LAMBDA(const int &i, int &lsum) {
60-
TestScalar acc = 0;
60+
Scalar acc = 0;
6161
for (int r = 0; r < size; ++r) {
6262
acc += r + i;
6363
}
6464
lsum += recvv(i) != acc;
65-
// if (recvv(i) != acc) {
66-
// Kokkos::printf("%f != %f @ %lu\n", double(Kokkos::abs(recvv(i))),
67-
// double(Kokkos::abs(acc)), size_t(i));
68-
// }
6965
},
7066
errs);
7167
ASSERT_EQ(errs, 0);
7268
}
7369
}
70+
71+
TYPED_TEST(Reduce, 1D_contig) { test_reduce_1d_contig<typename TestFixture::Scalar>(); }
72+
73+
} // namespace

0 commit comments

Comments
 (0)