libMesh
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 
9 using namespace libMesh;
10 
11 class PackedRangeTest : public CppUnit::TestCase {
12 public:
13  LIBMESH_CPPUNIT_TEST_SUITE( PackedRangeTest );
14 
15  CPPUNIT_TEST( testNullAllGather );
16  CPPUNIT_TEST( testNullSendReceive );
17  CPPUNIT_TEST( testContainerSendReceive );
18  // CPPUNIT_TEST( testAdapterSendReceive );
19  // CPPUNIT_TEST( testPointerAdapterSendReceive );
20 
21  CPPUNIT_TEST_SUITE_END();
22 
23 private:
24 
25 public:
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 
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 
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 
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 
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
processor_id_type rank() const
void allgather_packed_range(Context *context, Iter range_begin, const Iter range_end, OutputIter out, std::size_t approx_buffer_size=1000000) const
The libMesh namespace provides an interface to certain functionality in the library.
void testNullSendReceive()
processor_id_type size() const
void testContainerSendReceive()
void testNullAllGather()
A do-nothing class for templated methods that expect output iterator arguments.
void testContainerSendReceive()
void send_receive_packed_range(const unsigned int dest_processor_id, const Context1 *context1, RangeIter send_begin, const RangeIter send_end, const unsigned int source_processor_id, Context2 *context2, OutputIter out, const T *output_type, const MessageTag &send_tag=no_tag, const MessageTag &recv_tag=any_tag, std::size_t approx_buffer_size=1000000) const
CPPUNIT_TEST_SUITE_REGISTRATION(PackedRangeTest)