preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParallelTest.cpp
Go to the documentation of this file.
1#include <memory>
2#include <string>
3#include <vector>
7#include "testing/Testing.hpp"
8#include "utils/IntraComm.hpp"
9#include "utils/Parallel.hpp"
10
11using namespace precice;
12
13BOOST_AUTO_TEST_SUITE(UtilsTests)
14
16
17#ifndef PRECICE_NO_MPI
18
19PRECICE_TEST_SETUP(""_on(2_ranks).setupIntraComm())
20BOOST_AUTO_TEST_CASE(Primary1SecondaryTest)
21{
23
24 BOOST_TEST(context.hasSize(2));
26 BOOST_TEST((com != nullptr));
27
28 if (context.isPrimary()) {
29 int first = 1001;
30 com->send(first, 1);
31
32 int answer = -1;
33 com->receive(answer, 1);
34 BOOST_TEST(answer == 1111);
35 } else {
36 int received = -1;
37 com->receive(received, 0);
38 BOOST_TEST(received == 1001);
39
40 received += 110;
41 BOOST_TEST(received == 1111);
42 com->send(received, 0);
43 }
44}
45
46PRECICE_TEST_SETUP(""_on(3_ranks).setupIntraComm())
47BOOST_AUTO_TEST_CASE(Primary2SecondaryTest)
48{
50
51 BOOST_TEST(context.hasSize(3));
53 BOOST_TEST((com != nullptr));
54
55 if (context.isPrimary()) {
56 int sum = 1001;
57
58 int message = -1;
59 com->receive(message, 1);
60 sum += message;
61 BOOST_TEST(sum == 1011);
62
63 message = -1;
64 com->receive(message, 2);
65 sum += message;
66 BOOST_TEST(sum == 1111);
67
68 com->send(sum, 1);
69 com->send(sum, 2);
70 } else {
71 int tosend = context.isRank(1) ? 10 : 100;
72 com->send(tosend, 0);
73
74 int received = -1;
75 com->receive(received, 0);
76 BOOST_TEST(received == 1111);
77 }
78}
79
80PRECICE_TEST_SETUP("Offset"_on(1_rank), "Test"_on(2_ranks).setupIntraComm())
81BOOST_AUTO_TEST_CASE(OffsetPrimary1SecondaryTest)
82{
84
85 if (context.isNamed("Offset"))
86 return;
87
88 BOOST_TEST(context.hasSize(2));
90 BOOST_TEST((com != nullptr));
91
92 if (context.isPrimary()) {
93 int first = 1001;
94
95 com->send(first, 1);
96
97 int answer = -1;
98 com->receive(answer, 1);
99 BOOST_TEST(answer == 1111);
100 } else {
101 int received = -1;
102 com->receive(received, 0);
103 BOOST_TEST(received == 1001);
104
105 received += 110;
106 com->send(received, 0);
107 }
108}
109
110PRECICE_TEST_SETUP("Offset"_on(1_rank), "Test"_on(3_ranks).setupIntraComm())
111BOOST_AUTO_TEST_CASE(OffsetPrimary2SecondaryTest)
112{
113 PRECICE_TEST();
114
115 if (context.isNamed("Offset"))
116 return;
117
118 BOOST_TEST(context.hasSize(3));
120 BOOST_TEST((com != nullptr));
121
122 if (context.isPrimary()) {
123 int sum = 1001;
124
125 int message = -1;
126 com->receive(message, 1);
127 sum += message;
128 BOOST_TEST(sum == 1011);
129
130 message = -1;
131 com->receive(message, 2);
132 sum += message;
133 BOOST_TEST(sum == 1111);
134
135 com->send(sum, 1);
136 com->send(sum, 2);
137 } else {
138 int tosend = context.isRank(1) ? 10 : 100;
139 com->send(tosend, 0);
140
141 int received = -1;
142 com->receive(received, 0);
143 BOOST_TEST(received == 1111);
144 }
145}
146
147#endif // not PRECICE_NO_MPI
148
150
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
static com::PtrCommunication & getCommunication()
Intra-participant communication.
Definition IntraComm.hpp:31
Main namespace of the precice library.