-
Notifications
You must be signed in to change notification settings - Fork 1
/
shared_variable_test.cpp
58 lines (46 loc) · 1.26 KB
/
shared_variable_test.cpp
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
#include "internal/doctest.h"
#define MPI_USE_EXCEPTIONS
#include <mpi/all.hpp>
TEST_CASE("Shared Variable Test")
{
mpi::environment environment ;
const auto& communicator = mpi::world_communicator;
{
mpi::manual_shared_variable<std::int32_t> variable(communicator);
if (communicator.rank() == 0)
variable = 42;
variable.synchronize(); // :(
if (communicator.rank() != 0)
REQUIRE(variable == 42);
}
{
mpi::manual_shared_variable<std::array<std::int32_t, 3>> variable(communicator);
if (communicator.rank() == 0)
variable = {1, 2, 3};
variable.synchronize(); // :(
if (communicator.rank() != 0)
{
auto value = variable.get();
REQUIRE(value[0] == 1);
REQUIRE(value[1] == 2);
REQUIRE(value[2] == 3);
}
}
{
mpi::shared_variable<std::int32_t> variable(communicator);
variable.set_if_rank(42, 0);
if (communicator.rank() != 0)
REQUIRE(variable == 42);
}
{
mpi::shared_variable<std::array<std::int32_t, 3>> variable(communicator);
variable.set_if_rank({1, 2, 3}, 0);
if (communicator.rank() != 0)
{
auto value = variable.get();
REQUIRE(value[0] == 1);
REQUIRE(value[1] == 2);
REQUIRE(value[2] == 3);
}
}
}