diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 8cb9d1d2..93ea170f 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -18,13 +18,13 @@ endif() FetchContent_Declare( googletest - URL https://github.com/google/googletest/archive/530d5c8c84abd2a46f38583ee817743c9b3a42b4.zip # 12-18-2023 + URL https://github.com/google/googletest/archive/a7f443b80b105f940225332ed3c31f2790092f47.zip # 05-28-2024 ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -# FetchContent_MakeAvailable(googletest) -# was making install install googletest as well +# FetchContent_MakeAvailable(googletest) was making install install googletest as well # EXCLUDE_FROM_ALL here seems to be the magic +FetchContent_GetProperties(googletest) if (NOT googletest_POPULATED) FetchContent_Populate(googletest) add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) diff --git a/unit_tests/test_allgather.cpp b/unit_tests/test_allgather.cpp index 926134af..0627bfb5 100644 --- a/unit_tests/test_allgather.cpp +++ b/unit_tests/test_allgather.cpp @@ -18,6 +18,8 @@ #include "KokkosComm.hpp" +namespace { + template class Allgather : public testing::Test { public: @@ -27,17 +29,14 @@ class Allgather : public testing::Test { using ScalarTypes = ::testing::Types, Kokkos::complex>; TYPED_TEST_SUITE(Allgather, ScalarTypes); -TYPED_TEST(Allgather, 0D) { - using TestScalar = typename TestFixture::Scalar; - +template +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 sv("sv"); - Kokkos::View rv("rv", size); + Kokkos::View sv("sv"); + Kokkos::View rv("rv", size); // fill send buffer Kokkos::parallel_for( @@ -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(); } +template +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 sv("sv", nContrib); - Kokkos::View rv("rv", size * nContrib); + Kokkos::View sv("sv", nContrib); + Kokkos::View rv("rv", size * nContrib); // fill send buffer Kokkos::parallel_for( @@ -80,3 +80,7 @@ TYPED_TEST(Allgather, 1D_contig) { errs); EXPECT_EQ(errs, 0); } + +TYPED_TEST(Allgather, 1D_contig) { test_allgather_1d_contig(); } + +} // namespace diff --git a/unit_tests/test_alltoall.cpp b/unit_tests/test_alltoall.cpp index 61397734..db0103c2 100644 --- a/unit_tests/test_alltoall.cpp +++ b/unit_tests/test_alltoall.cpp @@ -29,17 +29,16 @@ class Alltoall : public testing::Test { using ScalarTypes = ::testing::Types, Kokkos::complex>; TYPED_TEST_SUITE(Alltoall, ScalarTypes); -TYPED_TEST(Alltoall, 1D_contig) { - using TestScalar = typename TestFixture::Scalar; - +template +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 sv("sv", size * nContrib); - Kokkos::View rv("rv", size * nContrib); + Kokkos::View sv("sv", size * nContrib); + Kokkos::View rv("rv", size * nContrib); // fill send buffer Kokkos::parallel_for( @@ -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(); } +template +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 rv("rv", size * nContrib); + Kokkos::View rv("rv", size * nContrib); // fill send buffer Kokkos::parallel_for( @@ -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(); } + } // namespace diff --git a/unit_tests/test_reduce.cpp b/unit_tests/test_reduce.cpp index f538f64a..a8d33efe 100644 --- a/unit_tests/test_reduce.cpp +++ b/unit_tests/test_reduce.cpp @@ -18,6 +18,8 @@ #include "KokkosComm.hpp" +namespace { + template class Reduce : public testing::Test { public: @@ -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 +void test_reduce_1d_contig() { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - Kokkos::View sendv("sendv", 10); - Kokkos::View recvv; + Kokkos::View sendv("sendv", 10); + Kokkos::View recvv; if (0 == rank) { Kokkos::resize(recvv, sendv.extent(0)); } @@ -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(); } + +} // namespace