forked from kokkos/kokkos-comm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sendrecv.cpp
More file actions
86 lines (76 loc) · 2.61 KB
/
test_sendrecv.cpp
File metadata and controls
86 lines (76 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//@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 <gtest/gtest.h>
#include <KokkosComm.hpp>
template <typename T>
class SendRecv : public testing::Test {
public:
using Scalar = T;
};
using ScalarTypes =
::testing::Types<int, int64_t, float, double, Kokkos::complex<float>,
Kokkos::complex<double>>;
TYPED_TEST_SUITE(SendRecv, ScalarTypes);
TYPED_TEST(SendRecv, 1D_contig) {
Kokkos::View<typename TestFixture::Scalar *> 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 << " provieded)";
}
if (0 == rank) {
int dst = 1;
Kokkos::parallel_for(
a.extent(0), KOKKOS_LAMBDA(const int i) { a(i) = i; });
KokkosComm::send(Kokkos::DefaultExecutionSpace(), a, dst, 0,
MPI_COMM_WORLD);
} 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) != i; }, errs);
ASSERT_EQ(errs, 0);
}
}
TYPED_TEST(SendRecv, 1D_noncontig) {
// this is C-style layout, i.e. b(0,0) is next to b(0,1)
Kokkos::View<typename TestFixture::Scalar **, Kokkos::LayoutRight> 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::send(Kokkos::DefaultExecutionSpace(), a, dst, 0,
MPI_COMM_WORLD);
} 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) != i; }, errs);
ASSERT_EQ(errs, 0);
}
}