Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Test that MPI can access view data #130

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading