From 0074ad7248b56d71130947f43c4b4903e26c59c9 Mon Sep 17 00:00:00 2001 From: Carl Pearson Date: Wed, 18 Dec 2024 15:45:23 -0700 Subject: [PATCH] tests: Test that MPI can access view data Signed-off-by: Carl Pearson --- unit_tests/CMakeLists.txt | 6 ++- unit_tests/mpi/test_mpi_view_access.cpp | 64 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 unit_tests/mpi/test_mpi_view_access.cpp diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 1a4ae48c..68b86eab 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -70,6 +70,7 @@ if(KOKKOSCOMM_ENABLE_MPI) COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./test-mpi ) + endif() # Tests using the MPI communication space, but not linking with MPI itself @@ -78,8 +79,9 @@ target_sources( test-main PRIVATE test_main.cpp - mpi/test_gtest_mpi.cpp - mpi/test_sendrecv.cpp + mpi/test_gtest_mpi.cpp # make sure gtest is working + mpi/test_mpi_view_access.cpp # make sure MPI can access Kokkos::View data + mpi/test_sendrecv.cpp # other tests... mpi/test_allgather.cpp mpi/test_alltoall.cpp mpi/test_isendrecv.cpp diff --git a/unit_tests/mpi/test_mpi_view_access.cpp b/unit_tests/mpi/test_mpi_view_access.cpp new file mode 100644 index 00000000..dee97b70 --- /dev/null +++ b/unit_tests/mpi/test_mpi_view_access.cpp @@ -0,0 +1,64 @@ +//@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 + +#include "KokkosComm/KokkosComm.hpp" + +namespace { + +using namespace KokkosComm::mpi; + +namespace { +void doit() { + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size < 2) { + GTEST_SKIP() << "requires at least 2 ranks"; + } + + const int n = 1024 * 1024; + Kokkos::View a("a", n); + + if (0 == rank) { + Kokkos::parallel_for( + n, KOKKOS_LAMBDA(const int i) { a(i) = i; }); + Kokkos::fence(); + + std::cerr << "sending buffer is " << a.data() << "-" << a.data() + n << std::endl; + MPI_Send(a.data(), n, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD); + } else if (1 == rank) { + std::cerr << "recving buffer is " << a.data() << "-" << a.data() + n << std::endl; + MPI_Recv(a.data(), n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + } + + auto a_h = Kokkos::create_mirror_view_and_copy(Kokkos::DefaultExecutionSpace{}, a); + Kokkos::fence(); + + for (int i = 0; i < n; ++i) { + if (a_h[i] != i) { + ASSERT_EQ(a_h[i], i); + } + } +} +} // namespace + +TEST(MpiViewAccess, Basic) { doit(); } + +} // namespace