preCICE v3.1.1
Loading...
Searching...
No Matches
GenericTestFunctions.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <boost/test/unit_test.hpp>
5#include <string>
6#include <vector>
7
9#include "testing/Testing.hpp"
10
13
14namespace precice {
15namespace testing {
16namespace com {
17
18namespace primaryprimary {
19
24
25template <typename T>
27{
28 T com;
29
30 if (context.isNamed("A")) {
31 com.acceptConnection("process0", "process1", "", 0);
32 {
33 std::string msg("testOne");
34 com.send(msg, 0);
35 com.receive(msg, 0);
36 BOOST_TEST(msg == std::string("testTwo"));
37 }
38 {
39 double msg = 0.0;
40 com.send(msg, 0);
41 com.receive(msg, 0);
42 BOOST_TEST(msg == 1.0);
43 }
44 {
45 int msg = 1;
46 com.send(msg, 0);
47 com.receive(msg, 0);
48 BOOST_TEST(msg == 2);
49 }
50 {
51 bool msg = true;
52 com.send(msg, 0);
53 com.receive(msg, 0);
54 BOOST_TEST(msg == false);
55 }
56 com.closeConnection();
57 } else {
58 com.requestConnection("process0", "process1", "", 0, 1);
59 {
60 std::string msg;
61 com.receive(msg, 0);
62 BOOST_TEST(msg == std::string("testOne"));
63 msg = "testTwo";
64 com.send(msg, 0);
65 }
66 {
67 double msg = 1.0;
68 com.receive(msg, 0);
69 BOOST_TEST(msg == 0.0);
70 msg = 1.0;
71 com.send(msg, 0);
72 }
73 {
74 int msg = 0;
75 com.receive(msg, 0);
76 BOOST_TEST(msg == 1);
77 msg = 2;
78 com.send(msg, 0);
79 }
80 {
81 bool msg = false;
82 com.receive(msg, 0);
83 BOOST_TEST(msg == true);
84 msg = false;
85 com.send(msg, 0);
86 }
87 com.closeConnection();
88 }
89}
90
91template <typename T>
93{
94 T com;
95
96 if (context.isNamed("A")) {
97 com.acceptConnection("process0", "process1", "", 0);
98 {
99 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
100 com.receive(msg, 0);
101 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(1)));
102 msg = Eigen::Vector3d::Constant(2);
103 com.send(msg, 0);
104 }
105 {
106 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
107 com.receive(msg, 0);
108 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(1)));
109 msg = Eigen::Vector4i::Constant(0);
110 com.send(msg, 0);
111 }
112 com.closeConnection();
113 } else {
114 com.requestConnection("process0", "process1", "", 0, 1);
115 {
116 Eigen::Vector3d msg = Eigen::Vector3d::Constant(1);
117 com.send(msg, 0);
118 com.receive(msg, 0);
119 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(2)));
120 }
121 {
122 Eigen::Vector4i msg = Eigen::Vector4i::Constant(1);
123 com.send(msg, 0);
124 com.receive(msg, 0);
125 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Zero()));
126 }
127 com.closeConnection();
128 }
129}
130
131template <typename T>
133{
135 T com;
136
137 if (context.isNamed("A")) {
138 com.acceptConnection("process0", "process1", "", 0);
139 {
140 std::vector<int> recv{1, 2, 3};
141 std::vector<int> msg = com.receiveRange(0, AsVectorTag<int>{});
142 BOOST_TEST(msg == recv);
143 com.sendRange(msg, 0);
144 }
145 {
146 std::vector<double> msg = com.receiveRange(0, AsVectorTag<double>{});
147 BOOST_TEST(msg == std::vector<double>({1.1, 2.2, 3.3}));
148 com.sendRange(msg, 0);
149 }
150 com.closeConnection();
151 } else {
152 com.requestConnection("process0", "process1", "", 0, 1);
153 {
154 std::vector<int> msg{1, 2, 3};
155 com.sendRange(msg, 0);
156 msg = com.receiveRange(0, AsVectorTag<int>{});
157 BOOST_CHECK(msg == std::vector<int>({1, 2, 3}));
158 }
159 {
160 std::vector<double> msg{1.1, 2.2, 3.3};
161 com.sendRange(msg, 0);
162 msg = com.receiveRange(0, AsVectorTag<double>{});
163 BOOST_CHECK(msg == std::vector<double>({1.1, 2.2, 3.3}));
164 }
165 com.closeConnection();
166 }
167}
168
169template <typename T>
171{
172 T communication;
173 int message = -1;
174
175 if (context.isNamed("A")) {
176 if (context.isPrimary()) {
177 communication.acceptConnection("A", "B", "", 0);
178
179 communication.send(10, 0);
180 communication.receive(message, 0);
181 BOOST_TEST(message == 20);
182
183 communication.send(20, 1);
184 communication.receive(message, 1);
185 BOOST_TEST(message == 40);
186
187 communication.closeConnection();
188 }
189 } else {
190 if (context.isPrimary()) {
191 communication.requestConnection("A", "B", "", 0, 2);
192
193 communication.receive(message, 0);
194 BOOST_TEST(message == 10);
195 message *= 2;
196 communication.send(message, 0);
197
198 communication.closeConnection();
199 } else {
200 communication.requestConnection("A", "B", "", 1, 2);
201
202 communication.receive(message, 0);
203 BOOST_TEST(message == 20);
204 message *= 2;
205 communication.send(message, 0);
206
207 communication.closeConnection();
208 }
209 }
210}
211
212template <typename T>
214{
215 T com;
216
217 if (context.isNamed("A")) {
218 com.acceptConnection("process0", "process1", "", 0);
219 {
220 double msg = 0.0;
221 com.broadcast(msg);
222 }
223 {
224 int msg = 1;
225 com.broadcast(msg);
226 }
227 {
228 bool msg = true;
229 com.broadcast(msg);
230 }
231 com.closeConnection();
232 } else {
233 com.requestConnection("process0", "process1", "", 0, 1);
234 {
235 double msg = 1.0;
236 com.broadcast(msg, 0);
237 BOOST_TEST(msg == 0.0);
238 }
239 {
240 int msg = 0;
241 com.broadcast(msg, 0);
242 BOOST_TEST(msg == 1);
243 }
244 {
245 bool msg = false;
246 com.broadcast(msg, 0);
247 BOOST_TEST(msg == true);
248 }
249 com.closeConnection();
250 }
251}
252
253template <typename T>
254void TestBroadcastEigen(TestContext const &context)
255{
256 T com;
257
258 if (context.isNamed("A")) {
259 com.acceptConnection("process0", "process1", "", 0);
260 {
261 Eigen::Vector3d msg = Eigen::Vector3d::Constant(3.1415);
262 com.broadcast(msg);
263 }
264 {
265 Eigen::Vector4i msg = Eigen::Vector4i::Constant(21);
266 com.broadcast(msg);
267 }
268 com.closeConnection();
269 } else {
270 com.requestConnection("process0", "process1", "", 0, 1);
271 {
272 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
273 com.broadcast(msg, 0);
274 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(3.1415)));
275 }
276 {
277 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
278 com.broadcast(msg, 0);
279 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(21)));
280 }
281 com.closeConnection();
282 }
283}
284
285template <typename T>
287{
288 T com;
289 if (context.isNamed("A")) {
290 com.acceptConnection("process0", "process1", "", 0);
291 {
292 std::vector<int> msg{2, 3, 5, 8};
293 com.broadcast(msg);
294 }
295 {
296 std::vector<double> msg{1.2, 2.3, 3.5, 4.8};
297 com.broadcast(msg);
298 }
299 com.closeConnection();
300 } else {
301 com.requestConnection("process0", "process1", "", 0, 1);
302 {
303 std::vector<int> msg(4);
304 com.broadcast(msg, 0);
305 BOOST_CHECK(msg == std::vector<int>({2, 3, 5, 8}));
306 }
307 {
308 std::vector<double> msg(4);
309 com.broadcast(msg, 0);
310 BOOST_CHECK(msg == std::vector<double>({1.2, 2.3, 3.5, 4.8}));
311 }
312 com.closeConnection();
313 }
314}
315
316template <typename T>
318{
319 T com;
320
321 if (context.isNamed("A")) {
322 com.acceptConnection("process0", "process1", "", 0);
323 {
324 int msg = 1;
325 int rcv = 0;
326 com.reduceSum(msg, rcv);
327 BOOST_TEST(msg == 1);
328 BOOST_TEST(rcv == 4);
329 }
330 {
331 int msg = 1;
332 int rcv = 0;
333 com.allreduceSum(msg, rcv);
334 BOOST_TEST(msg == 1);
335 BOOST_TEST(rcv == 4);
336 }
337 {
338 double msg = 3;
339 double rcv = 0;
340 com.allreduceSum(msg, rcv);
341 BOOST_TEST(msg == 3);
342 BOOST_TEST(rcv == 3.1415);
343 }
344
345 com.closeConnection();
346 } else {
347 com.requestConnection("process0", "process1", "", 0, 1);
348 {
349 int msg = 3;
350 int rcv = 0;
351 com.reduceSum(msg, rcv, 0);
352 BOOST_TEST(msg == 3);
353 BOOST_TEST(rcv == 0);
354 }
355 {
356 int msg = 3;
357 int rcv = 0;
358 com.allreduceSum(msg, rcv, 0);
359 BOOST_TEST(msg == 3);
360 BOOST_TEST(rcv == 4);
361 }
362 {
363 double msg = 0.1415;
364 double rcv = 0;
365 com.allreduceSum(msg, rcv, 0);
366 BOOST_TEST(msg == 0.1415);
367 BOOST_TEST(rcv == 3.1415);
368 }
369 com.closeConnection();
370 }
371}
372
373template <typename T>
374void TestReduceVectors(TestContext const &context)
375{
376 T com;
377
378 if (context.isNamed("A")) {
379 com.acceptConnection("process0", "process1", "", 0);
380 {
381 std::vector<double> msg{0.1, 0.2, 0.3};
382 std::vector<double> rcv{0, 0, 0};
383 com.reduceSum(msg, rcv);
384 std::vector<double> msg_expected{0.1, 0.2, 0.3};
385 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
386 msg_expected.begin(), msg_expected.end());
387 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
388 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
389 rcv_expected.begin(), rcv_expected.end());
390 }
391 {
392 std::vector<double> msg{0.1, 0.2, 0.3};
393 std::vector<double> rcv{0, 0, 0};
394 com.allreduceSum(msg, rcv);
395 std::vector<double> msg_expected{0.1, 0.2, 0.3};
396 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
397 msg_expected.begin(), msg_expected.end());
398 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
399 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
400 rcv_expected.begin(), rcv_expected.end());
401 }
402 com.closeConnection();
403 } else {
404 com.requestConnection("process0", "process1", "", 0, 1);
405 {
406 std::vector<double> msg{1, 2, 3};
407 std::vector<double> rcv{0, 0, 0};
408 com.reduceSum(msg, rcv, 0);
409 std::vector<double> msg_expected{1, 2, 3};
410 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
411 msg_expected.begin(), msg_expected.end());
412 std::vector<double> rcv_expected{0, 0, 0};
413 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
414 rcv_expected.begin(), rcv_expected.end());
415 }
416 {
417 std::vector<double> msg{1, 2, 3};
418 std::vector<double> rcv{0, 0, 0};
419 com.allreduceSum(msg, rcv, 0);
420 std::vector<double> msg_expected{1, 2, 3};
421 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
422 msg_expected.begin(), msg_expected.end());
423 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
424 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
425 rcv_expected.begin(), rcv_expected.end());
426 }
427 com.closeConnection();
428 }
429}
430
431} // namespace primaryprimary
432
433namespace intracomm {
434
439
440template <typename T>
442{
443 T com;
444
445 if (context.isPrimary()) {
446 com.acceptConnection("Primary", "Secondary", "", 0, 1);
447 {
448 std::string msg("testOne");
449 com.send(msg, 1);
450 com.receive(msg, 1);
451 BOOST_TEST(msg == std::string("testTwo"));
452 }
453 {
454 double msg = 0.0;
455 com.send(msg, 1);
456 com.receive(msg, 1);
457 BOOST_TEST(msg == 1.0);
458 }
459 {
460 int msg = 1;
461 com.send(msg, 1);
462 com.receive(msg, 1);
463 BOOST_TEST(msg == 2);
464 }
465 {
466 bool msg = true;
467 com.send(msg, 1);
468 com.receive(msg, 1);
469 BOOST_TEST(msg == false);
470 }
471 com.closeConnection();
472 } else {
473 com.requestConnection("Primary", "Secondary", "", 0, 1);
474 {
475 std::string msg;
476 com.receive(msg, 0);
477 BOOST_TEST(msg == std::string("testOne"));
478 msg = "testTwo";
479 com.send(msg, 0);
480 }
481 {
482 double msg = 1.0;
483 com.receive(msg, 0);
484 BOOST_TEST(msg == 0.0);
485 msg = 1.0;
486 com.send(msg, 0);
487 }
488 {
489 int msg = 0;
490 com.receive(msg, 0);
491 BOOST_TEST(msg == 1);
492 msg = 2;
493 com.send(msg, 0);
494 }
495 {
496 bool msg = false;
497 com.receive(msg, 0);
498 BOOST_TEST(msg == true);
499 msg = false;
500 com.send(msg, 0);
501 }
502 com.closeConnection();
503 }
504}
505
506template <typename T>
508{
509 T com;
510
511 if (context.isPrimary()) {
512 com.acceptConnection("Primary", "Secondary", "", 0, 1);
513 {
514 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
515 com.receive(msg, 1);
516 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(1)));
517 msg = Eigen::Vector3d::Constant(2);
518 com.send(msg, 1);
519 }
520 {
521 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
522 com.receive(msg, 1);
523 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(1)));
524 msg = Eigen::Vector4i::Constant(0);
525 com.send(msg, 1);
526 }
527 com.closeConnection();
528 } else {
529 com.requestConnection("Primary", "Secondary", "", 0, 1);
530 {
531 Eigen::Vector3d msg = Eigen::Vector3d::Constant(1);
532 com.send(msg, 0);
533 com.receive(msg, 0);
534 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(2)));
535 }
536 {
537 Eigen::Vector4i msg = Eigen::Vector4i::Constant(1);
538 com.send(msg, 0);
539 com.receive(msg, 0);
540 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Zero()));
541 }
542 com.closeConnection();
543 }
544}
545
546template <typename T>
548{
549 T com;
551
552 if (context.isPrimary()) {
553 com.acceptConnection("Primary", "Secondary", "", 0, 1);
554 {
555 std::vector<int> recv{1, 2, 3};
556 std::vector<int> msg = com.receiveRange(1, AsVectorTag<int>{});
557 BOOST_TEST(msg == recv);
558 com.sendRange(msg, 1);
559 }
560 {
561 std::vector<double> msg = com.receiveRange(1, AsVectorTag<double>{});
562 BOOST_TEST(msg == std::vector<double>({1.1, 2.2, 3.3}));
563 com.sendRange(msg, 1);
564 }
565 com.closeConnection();
566 } else {
567 com.requestConnection("Primary", "Secondary", "", 0, 1);
568 {
569 std::vector<int> msg{1, 2, 3};
570 com.sendRange(msg, 0);
571 msg = com.receiveRange(0, AsVectorTag<int>{});
572 BOOST_CHECK(msg == std::vector<int>({1, 2, 3}));
573 }
574 {
575 std::vector<double> msg{1.1, 2.2, 3.3};
576 com.sendRange(msg, 0);
577 msg = com.receiveRange(0, AsVectorTag<double>{});
578 BOOST_CHECK(msg == std::vector<double>({1.1, 2.2, 3.3}));
579 }
580 com.closeConnection();
581 }
582}
583
584template <typename T>
586{
587 T com;
588
589 if (context.isPrimary()) {
590 com.acceptConnection("Primary", "Secondary", "", 0, 1);
591 {
592 double msg = 0.0;
593 com.broadcast(msg);
594 }
595 {
596 int msg = 1;
597 com.broadcast(msg);
598 }
599 {
600 bool msg = true;
601 com.broadcast(msg);
602 }
603 com.closeConnection();
604 } else {
605 com.requestConnection("Primary", "Secondary", "", 0, 1);
606 {
607 double msg = 1.0;
608 com.broadcast(msg, 0);
609 BOOST_TEST(msg == 0.0);
610 }
611 {
612 int msg = 0;
613 com.broadcast(msg, 0);
614 BOOST_TEST(msg == 1);
615 }
616 {
617 bool msg = false;
618 com.broadcast(msg, 0);
619 BOOST_TEST(msg == true);
620 }
621 com.closeConnection();
622 }
623}
624
625template <typename T>
627{
628 T com;
629
630 if (context.isPrimary()) {
631 com.acceptConnection("Primary", "Secondary", "", 0, 1);
632 {
633 Eigen::Vector3d msg = Eigen::Vector3d::Constant(3.1415);
634 com.broadcast(msg);
635 }
636 {
637 Eigen::Vector4i msg = Eigen::Vector4i::Constant(21);
638 com.broadcast(msg);
639 }
640 {
641 std::vector<int> msg{2, 3, 5, 8};
642 com.broadcast(msg);
643 }
644 {
645 std::vector<double> msg{1.2, 2.3, 3.5, 4.8};
646 com.broadcast(msg);
647 }
648 com.closeConnection();
649 } else {
650 com.requestConnection("Primary", "Secondary", "", 0, 1);
651 {
652 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
653 com.broadcast(msg, 0);
654 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(3.1415)));
655 }
656 {
657 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
658 com.broadcast(msg, 0);
659 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(21)));
660 }
661 {
662 std::vector<int> msg(4);
663 com.broadcast(msg, 0);
664 BOOST_CHECK(msg == std::vector<int>({2, 3, 5, 8}));
665 }
666 {
667 std::vector<double> msg(4);
668 com.broadcast(msg, 0);
669 BOOST_CHECK(msg == std::vector<double>({1.2, 2.3, 3.5, 4.8}));
670 }
671 com.closeConnection();
672 }
673}
674
675template <typename T>
677{
678 T com;
679
680 if (context.isPrimary()) {
681 com.acceptConnection("Primary", "Secondary", "", 0, 1);
682 {
683 int msg = 1;
684 int rcv = 0;
685 com.reduceSum(msg, rcv);
686 BOOST_TEST(msg == 1);
687 BOOST_TEST(rcv == 4);
688 }
689 {
690 int msg = 1;
691 int rcv = 0;
692 com.allreduceSum(msg, rcv);
693 BOOST_TEST(msg == 1);
694 BOOST_TEST(rcv == 4);
695 }
696 {
697 double msg = 3;
698 double rcv = 0;
699 com.allreduceSum(msg, rcv);
700 BOOST_TEST(msg == 3);
701 BOOST_TEST(rcv == 3.1415);
702 }
703
704 com.closeConnection();
705 } else {
706 com.requestConnection("Primary", "Secondary", "", 0, 1);
707 {
708 int msg = 3;
709 int rcv = 0;
710 com.reduceSum(msg, rcv, 0);
711 BOOST_TEST(msg == 3);
712 BOOST_TEST(rcv == 0);
713 }
714 {
715 int msg = 3;
716 int rcv = 0;
717 com.allreduceSum(msg, rcv, 0);
718 BOOST_TEST(msg == 3);
719 BOOST_TEST(rcv == 4);
720 }
721 {
722 double msg = 0.1415;
723 double rcv = 0;
724 com.allreduceSum(msg, rcv, 0);
725 BOOST_TEST(msg == 0.1415);
726 BOOST_TEST(rcv == 3.1415);
727 }
728 com.closeConnection();
729 }
730}
731
732template <typename T>
733void TestReduceVectors(TestContext const &context)
734{
735 T com;
736
737 if (context.isPrimary()) {
738 com.acceptConnection("Primary", "Secondary", "", 0, 1);
739 {
740 std::vector<double> msg{0.1, 0.2, 0.3};
741 std::vector<double> rcv{0, 0, 0};
742 com.reduceSum(msg, rcv);
743 std::vector<double> msg_expected{0.1, 0.2, 0.3};
744 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
745 msg_expected.begin(), msg_expected.end());
746 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
747 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
748 rcv_expected.begin(), rcv_expected.end());
749 }
750 {
751 std::vector<double> msg{0.1, 0.2, 0.3};
752 std::vector<double> rcv{0, 0, 0};
753 com.allreduceSum(msg, rcv);
754 std::vector<double> msg_expected{0.1, 0.2, 0.3};
755 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
756 msg_expected.begin(), msg_expected.end());
757 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
758 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
759 rcv_expected.begin(), rcv_expected.end());
760 }
761 com.closeConnection();
762 } else {
763 com.requestConnection("Primary", "Secondary", "", 0, 1);
764 {
765 std::vector<double> msg{1, 2, 3};
766 std::vector<double> rcv{0, 0, 0};
767 com.reduceSum(msg, rcv, 0);
768 std::vector<double> msg_expected{1, 2, 3};
769 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
770 msg_expected.begin(), msg_expected.end());
771 std::vector<double> rcv_expected{0, 0, 0};
772 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
773 rcv_expected.begin(), rcv_expected.end());
774 }
775 {
776 std::vector<double> msg{1, 2, 3};
777 std::vector<double> rcv{0, 0, 0};
778 com.allreduceSum(msg, rcv, 0);
779 std::vector<double> msg_expected{1, 2, 3};
780 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
781 msg_expected.begin(), msg_expected.end());
782 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
783 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
784 rcv_expected.begin(), rcv_expected.end());
785 }
786 com.closeConnection();
787 }
788}
789
790} // namespace intracomm
791
792namespace serverclient {
793
799
802template <typename T>
804{
805 T communication;
806 int message = 1;
807 BOOST_REQUIRE(context.hasSize(1));
808
809 if (context.isNamed("A")) {
810 communication.acceptConnectionAsServer("A", "B", "", 0, 1);
811 communication.send(message, 0);
812 communication.receive(message, 0);
813 BOOST_TEST(message == 2);
814 communication.closeConnection();
815 } else {
816 BOOST_REQUIRE(context.isNamed("B"));
817 communication.requestConnectionAsClient("A", "B", "", {0}, 0);
818 communication.receive(message, 0);
819 BOOST_TEST(message == 1);
820 message = 2;
821 communication.send(message, 0);
822 communication.closeConnection();
823 }
824}
825
826template <typename T>
828{
829 T communication;
830 int message = -1;
831 BOOST_REQUIRE(context.hasSize(2));
832
833 if (context.isNamed("A")) {
834 if (context.isPrimary()) {
835 communication.acceptConnectionAsServer("A", "B", "", context.rank, 2);
836
837 communication.send(10, 0);
838 communication.receive(message, 0);
839 BOOST_TEST(message == 20);
840
841 communication.send(20, 1);
842 communication.receive(message, 1);
843 BOOST_TEST(message == 40);
844
845 communication.closeConnection();
846 } else {
847 communication.acceptConnectionAsServer("A", "B", "", context.rank, 0);
848 communication.closeConnection();
849 }
850 } else {
851 BOOST_REQUIRE(context.isNamed("B"));
852 if (context.isPrimary()) {
853 communication.requestConnectionAsClient("A", "B", "", {0}, context.rank);
854
855 communication.receive(message, 0);
856 BOOST_TEST(message == 10);
857 message *= 2;
858 communication.send(message, 0);
859
860 communication.closeConnection();
861 } else {
862 communication.requestConnectionAsClient("A", "B", "", {0}, context.rank);
863
864 communication.receive(message, 0);
865 BOOST_TEST(message == 20);
866 message *= 2;
867 communication.send(message, 0);
868
869 communication.closeConnection();
870 }
871 }
872}
873
874template <typename T>
876{
877 T communication;
878 int message = -1;
879
880 BOOST_REQUIRE(context.hasSize(2));
881
882 if (context.isNamed("A")) {
883 if (context.isPrimary()) {
884
885 communication.acceptConnectionAsServer("A", "B", "", 0, 2);
886
887 communication.send(10, 0);
888 communication.receive(message, 0);
889 BOOST_TEST(message == 20);
890
891 communication.send(100, 1);
892 communication.receive(message, 1);
893 BOOST_TEST(message == 200);
894
895 communication.closeConnection();
896 } else {
897 communication.acceptConnectionAsServer("A", "B", "", 1, 2);
898
899 communication.send(20, 0);
900 communication.receive(message, 0);
901 BOOST_TEST(message == 40);
902
903 communication.send(200, 1);
904 communication.receive(message, 1);
905 BOOST_TEST(message == 400);
906
907 communication.closeConnection();
908 }
909
910 } else {
911 BOOST_REQUIRE(context.isNamed("B"));
912
913 if (context.isPrimary()) {
914 communication.requestConnectionAsClient("A", "B", "", {0, 1}, 0);
915
916 communication.receive(message, 0);
917 BOOST_TEST(message == 10);
918 communication.send(20, 0);
919
920 communication.receive(message, 1);
921 BOOST_TEST(message == 20);
922 communication.send(40, 1);
923
924 communication.closeConnection();
925 } else {
926 communication.requestConnectionAsClient("A", "B", "", {0, 1}, 1);
927
928 communication.receive(message, 0);
929 BOOST_TEST(message == 100);
930 communication.send(200, 0);
931
932 communication.receive(message, 1);
933 BOOST_TEST(message == 200);
934 communication.send(400, 1);
935
936 communication.closeConnection();
937 }
938 }
939}
940
941} // namespace serverclient
942
943} // namespace com
944} // namespace testing
945} // namespace precice
bool isNamed(const std::string &name) const
Check whether this context has a given name.
bool hasSize(int size) const
Check whether this context has a given size.
Rank rank
the rank of the current participant
void TestSendAndReceiveEigen(TestContext const &context)
void TestReducePrimitiveTypes(TestContext const &context)
void TestSendAndReceiveRanges(TestContext const &context)
void TestBroadcastVectors(TestContext const &context)
void TestBroadcastPrimitiveTypes(TestContext const &context)
void TestSendAndReceivePrimitiveTypes(TestContext const &context)
void TestReduceVectors(TestContext const &context)
void TestSendAndReceiveRanges(TestContext const &context)
void TestSendReceiveFourProcesses(TestContext const &context)
void TestReducePrimitiveTypes(TestContext const &context)
void TestBroadcastVectors(TestContext const &context)
void TestSendAndReceiveEigen(TestContext const &context)
void TestReduceVectors(TestContext const &context)
void TestBroadcastEigen(TestContext const &context)
void TestBroadcastPrimitiveTypes(TestContext const &context)
void TestSendAndReceivePrimitiveTypes(TestContext const &context)
void TestSendReceiveTwoProcessesServerClient(TestContext const &context)
void TestSendReceiveFourProcessesServerClientV2(TestContext const &context)
void TestSendReceiveFourProcessesServerClient(TestContext const &context)
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:65
Main namespace of the precice library.