Skip to content

Commit

Permalink
tests: Test that MPI can access view data
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Pearson <cwpears@sandia.gov>
  • Loading branch information
cwpearson committed Dec 18, 2024
1 parent b153676 commit 0074ad7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
6 changes: 4 additions & 2 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
64 changes: 64 additions & 0 deletions unit_tests/mpi/test_mpi_view_access.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

#include <gtest/gtest.h>

#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<double *> 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

0 comments on commit 0074ad7

Please sign in to comment.