preCICE v3.1.1
Loading...
Searching...
No Matches
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
19BOOST_AUTO_TEST_CASE(Primary1SecondaryTest)
20{
21 PRECICE_TEST(""_on(2_ranks).setupIntraComm());
22
23 BOOST_TEST(context.hasSize(2));
25 BOOST_TEST((com != nullptr));
26
27 if (context.isPrimary()) {
28 int first = 1001;
29 com->send(first, 1);
30
31 int answer = -1;
32 com->receive(answer, 1);
33 BOOST_TEST(answer == 1111);
34 } else {
35 int received = -1;
36 com->receive(received, 0);
37 BOOST_TEST(received == 1001);
38
39 received += 110;
40 BOOST_TEST(received == 1111);
41 com->send(received, 0);
42 }
43}
44
45BOOST_AUTO_TEST_CASE(Primary2SecondaryTest)
46{
47 PRECICE_TEST(""_on(3_ranks).setupIntraComm());
48
49 BOOST_TEST(context.hasSize(3));
51 BOOST_TEST((com != nullptr));
52
53 if (context.isPrimary()) {
54 int sum = 1001;
55
56 int message = -1;
57 com->receive(message, 1);
58 sum += message;
59 BOOST_TEST(sum == 1011);
60
61 message = -1;
62 com->receive(message, 2);
63 sum += message;
64 BOOST_TEST(sum == 1111);
65
66 com->send(sum, 1);
67 com->send(sum, 2);
68 } else {
69 int tosend = context.isRank(1) ? 10 : 100;
70 com->send(tosend, 0);
71
72 int received = -1;
73 com->receive(received, 0);
74 BOOST_TEST(received == 1111);
75 }
76}
77
78BOOST_AUTO_TEST_CASE(OffsetPrimary1SecondaryTest)
79{
80 PRECICE_TEST("Offset"_on(1_rank), "Test"_on(2_ranks).setupIntraComm());
81
82 if (context.isNamed("Offset"))
83 return;
84
85 BOOST_TEST(context.hasSize(2));
87 BOOST_TEST((com != nullptr));
88
89 if (context.isPrimary()) {
90 int first = 1001;
91
92 com->send(first, 1);
93
94 int answer = -1;
95 com->receive(answer, 1);
96 BOOST_TEST(answer == 1111);
97 } else {
98 int received = -1;
99 com->receive(received, 0);
100 BOOST_TEST(received == 1001);
101
102 received += 110;
103 com->send(received, 0);
104 }
105}
106
107BOOST_AUTO_TEST_CASE(OffsetPrimary2SecondaryTest)
108{
109 PRECICE_TEST("Offset"_on(1_rank), "Test"_on(3_ranks).setupIntraComm());
110
111 if (context.isNamed("Offset"))
112 return;
113
114 BOOST_TEST(context.hasSize(3));
116 BOOST_TEST((com != nullptr));
117
118 if (context.isPrimary()) {
119 int sum = 1001;
120
121 int message = -1;
122 com->receive(message, 1);
123 sum += message;
124 BOOST_TEST(sum == 1011);
125
126 message = -1;
127 com->receive(message, 2);
128 sum += message;
129 BOOST_TEST(sum == 1111);
130
131 com->send(sum, 1);
132 com->send(sum, 2);
133 } else {
134 int tosend = context.isRank(1) ? 10 : 100;
135 com->send(tosend, 0);
136
137 int received = -1;
138 com->receive(received, 0);
139 BOOST_TEST(received == 1111);
140 }
141}
142
143#endif // not PRECICE_NO_MPI
144
146
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Primary1SecondaryTest)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
static com::PtrCommunication & getCommunication()
Intra-participant communication.
Definition IntraComm.hpp:31
Main namespace of the precice library.