libMesh
Loading...
Searching...
No Matches
packed_range_test.C
Go to the documentation of this file.
1#include <libmesh/parallel.h>
2#include <libmesh/null_output_iterator.h>
3
4#include <vector>
5
6#include "test_comm.h"
7#include "libmesh_cppunit.h"
8
9using namespace libMesh;
10
11class PackedRangeTest : public CppUnit::TestCase {
12public:
14
18 // CPPUNIT_TEST( testAdapterSendReceive );
19 // CPPUNIT_TEST( testPointerAdapterSendReceive );
20
22
23private:
24
25public:
26 void setUp()
27 {}
28
29 void tearDown()
30 {}
31
32
33
35 {
36 LOG_UNIT_TEST;
37
38 std::vector<processor_id_type> vals;
39
40 std::vector<std::string> send(1);
41 if (TestCommWorld->rank() == 0)
42 send[0].assign("Hello");
43 else
44 send[0].assign("Goodbye");
45
46 TestCommWorld->allgather_packed_range
47 ((void *)(NULL), send.begin(), send.end(),
49 }
50
51
53 {
54 LOG_UNIT_TEST;
55
56 std::vector<processor_id_type> vals;
57
58 std::vector<std::string> send(1);
59 const unsigned int my_rank = TestCommWorld->rank();
60 const unsigned int dest_rank =
61 (my_rank + 1) % TestCommWorld->size();
62 const unsigned int source_rank =
63 (my_rank + TestCommWorld->size() - 1) % TestCommWorld->size();
64
65 {
66 std::ostringstream os;
67 os << my_rank;
68 send[0] = os.str();
69 }
70
71 TestCommWorld->send_receive_packed_range
72 (dest_rank, (void *)(NULL), send.begin(), send.end(),
73 source_rank, (void *)(NULL),
75 (std::string*)NULL);
76 }
77
78
80 {
81 LOG_UNIT_TEST;
82
83 std::vector<processor_id_type> vals;
84
85 std::vector<std::string> send(1), recv;
86
87 const unsigned int my_rank = TestCommWorld->rank();
88 const unsigned int dest_rank =
89 (my_rank + 1) % TestCommWorld->size();
90 const unsigned int source_rank =
91 (my_rank + TestCommWorld->size() - 1) % TestCommWorld->size();
92
93 {
94 std::ostringstream os;
95 os << my_rank;
96 send[0] = os.str();
97 }
98
99 TestCommWorld->send_receive_packed_range
100 (dest_rank, (void *)(NULL), send.begin(), send.end(),
101 source_rank, (void *)(NULL),
102 std::back_inserter(recv),
103 (std::string*)NULL);
104
105 CPPUNIT_ASSERT_EQUAL(recv.size(), std::size_t(1));
106
107 std::string check;
108 {
109 std::ostringstream os;
110 os << source_rank;
111 check = os.str();
112 }
113
114 CPPUNIT_ASSERT_EQUAL(recv[0], check);
115 }
116
117};
118
CPPUNIT_TEST(testNullAllGather)
CPPUNIT_TEST(testContainerSendReceive)
CPPUNIT_TEST(testNullSendReceive)
LIBMESH_CPPUNIT_TEST_SUITE(PackedRangeTest)
void testContainerSendReceive()
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
CPPUNIT_TEST_SUITE_REGISTRATION(PackedRangeTest)
A do-nothing class for templated methods that expect output iterator arguments.