From 8f9ceed93b40b2c6d1846b0c68099cb58ea9ce55 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Santos Date: Thu, 11 Apr 2024 14:28:01 +0200 Subject: [PATCH] Add tests for Ready and Synchronous non-blocking send (isend) --- unit_tests/CMakeLists.txt | 2 + unit_tests/test_irsendrecv.cpp | 94 ++++++++++++++++++++++++++++++++++ unit_tests/test_issendrecv.cpp | 94 ++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 unit_tests/test_irsendrecv.cpp create mode 100644 unit_tests/test_issendrecv.cpp diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 04771b32..d8b8a146 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -44,6 +44,8 @@ target_link_libraries(test-mpi MPI::MPI_CXX) # Kokkos Comm tests add_executable(test-main test_main.cpp test_isendrecv.cpp + test_irsendrecv.cpp + test_issendrecv.cpp test_reduce.cpp test_sendrecv.cpp test_rsendrecv.cpp diff --git a/unit_tests/test_irsendrecv.cpp b/unit_tests/test_irsendrecv.cpp new file mode 100644 index 00000000..854a25d7 --- /dev/null +++ b/unit_tests/test_irsendrecv.cpp @@ -0,0 +1,94 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#include + +#include "KokkosComm.hpp" + +template +class IrsendRecv : public testing::Test { + public: + using Scalar = T; +}; + +using ScalarTypes = + ::testing::Types, + Kokkos::complex, int, unsigned, int64_t, size_t>; +TYPED_TEST_SUITE(IrsendRecv, ScalarTypes); + +TYPED_TEST(IrsendRecv, 1D_contig) { + Kokkos::View a("a", 1000); + + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size < 2) { + GTEST_SKIP() << "Requires >= 2 ranks (" << size << " provided)"; + } + + if (0 == rank) { + int dst = 1; + Kokkos::parallel_for( + a.extent(0), KOKKOS_LAMBDA(const int i) { a(i) = i; }); + KokkosComm::Req req = KokkosComm::isend( + Kokkos::DefaultExecutionSpace(), a, dst, 0, MPI_COMM_WORLD); + req.wait(); + } else if (1 == rank) { + int src = 0; + KokkosComm::recv(Kokkos::DefaultExecutionSpace(), a, src, 0, + MPI_COMM_WORLD); + int errs; + Kokkos::parallel_reduce( + a.extent(0), + KOKKOS_LAMBDA(const int &i, int &lsum) { + lsum += a(i) != typename TestFixture::Scalar(i); + }, + errs); + ASSERT_EQ(errs, 0); + } +} + +TYPED_TEST(IrsendRecv, 1D_noncontig) { + // this is C-style layout, i.e. b(0,0) is next to b(0,1) + Kokkos::View b("a", 10, + 10); + auto a = + Kokkos::subview(b, Kokkos::ALL, 2); // take column 2 (non-contiguous) + + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + if (0 == rank) { + int dst = 1; + Kokkos::parallel_for( + a.extent(0), KOKKOS_LAMBDA(const int i) { a(i) = i; }); + KokkosComm::Req req = KokkosComm::isend( + Kokkos::DefaultExecutionSpace(), a, dst, 0, MPI_COMM_WORLD); + req.wait(); + } else if (1 == rank) { + int src = 0; + KokkosComm::recv(Kokkos::DefaultExecutionSpace(), a, src, 0, + MPI_COMM_WORLD); + int errs; + Kokkos::parallel_reduce( + a.extent(0), + KOKKOS_LAMBDA(const int &i, int &lsum) { + lsum += a(i) != typename TestFixture::Scalar(i); + }, + errs); + ASSERT_EQ(errs, 0); + } +} diff --git a/unit_tests/test_issendrecv.cpp b/unit_tests/test_issendrecv.cpp new file mode 100644 index 00000000..1e00c12f --- /dev/null +++ b/unit_tests/test_issendrecv.cpp @@ -0,0 +1,94 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#include + +#include "KokkosComm.hpp" + +template +class IssendRecv : public testing::Test { + public: + using Scalar = T; +}; + +using ScalarTypes = + ::testing::Types, + Kokkos::complex, int, unsigned, int64_t, size_t>; +TYPED_TEST_SUITE(IssendRecv, ScalarTypes); + +TYPED_TEST(IssendRecv, 1D_contig) { + Kokkos::View a("a", 1000); + + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size < 2) { + GTEST_SKIP() << "Requires >= 2 ranks (" << size << " provided)"; + } + + if (0 == rank) { + int dst = 1; + Kokkos::parallel_for( + a.extent(0), KOKKOS_LAMBDA(const int i) { a(i) = i; }); + KokkosComm::Req req = KokkosComm::isend( + Kokkos::DefaultExecutionSpace(), a, dst, 0, MPI_COMM_WORLD); + req.wait(); + } else if (1 == rank) { + int src = 0; + KokkosComm::recv(Kokkos::DefaultExecutionSpace(), a, src, 0, + MPI_COMM_WORLD); + int errs; + Kokkos::parallel_reduce( + a.extent(0), + KOKKOS_LAMBDA(const int &i, int &lsum) { + lsum += a(i) != typename TestFixture::Scalar(i); + }, + errs); + ASSERT_EQ(errs, 0); + } +} + +TYPED_TEST(IssendRecv, 1D_noncontig) { + // this is C-style layout, i.e. b(0,0) is next to b(0,1) + Kokkos::View b("a", 10, + 10); + auto a = + Kokkos::subview(b, Kokkos::ALL, 2); // take column 2 (non-contiguous) + + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + if (0 == rank) { + int dst = 1; + Kokkos::parallel_for( + a.extent(0), KOKKOS_LAMBDA(const int i) { a(i) = i; }); + KokkosComm::Req req = KokkosComm::isend( + Kokkos::DefaultExecutionSpace(), a, dst, 0, MPI_COMM_WORLD); + req.wait(); + } else if (1 == rank) { + int src = 0; + KokkosComm::recv(Kokkos::DefaultExecutionSpace(), a, src, 0, + MPI_COMM_WORLD); + int errs; + Kokkos::parallel_reduce( + a.extent(0), + KOKKOS_LAMBDA(const int &i, int &lsum) { + lsum += a(i) != typename TestFixture::Scalar(i); + }, + errs); + ASSERT_EQ(errs, 0); + } +}