libMesh
message_tag.C
Go to the documentation of this file.
1 
2 // libMesh includes
3 // Using *shims* here to test backwards compatibility via those
4 #include <libmesh/communicator.h>
5 #include <libmesh/message_tag.h>
6 
7 #include "test_comm.h"
8 #include "libmesh_cppunit.h"
9 
10 
11 using namespace libMesh;
12 
13 class MessageTagTest : public CppUnit::TestCase {
14 public:
15  LIBMESH_CPPUNIT_TEST_SUITE( MessageTagTest );
16 
17  CPPUNIT_TEST( testGetUniqueTagAuto );
18  CPPUNIT_TEST( testGetUniqueTagManual );
19 
20  CPPUNIT_TEST_SUITE_END();
21 
22 private:
23  std::vector<std::string> _number;
24 
25 public:
26  void setUp()
27  {}
28 
29  void tearDown()
30  {}
31 
32 
33 
35  {
36  LOG_UNIT_TEST;
37 
38  // We need to explicitly duplicate the communicator first, because
39  // the original might already have tags used by other unit tests
40 
41  Parallel::Communicator newcomm;
42 
43  newcomm.duplicate(*TestCommWorld);
44 
45  const int n_vals = 5;
46  const int n_vals_in_scope = 3;
47  std::vector<int> vals(n_vals);
48 
49  {
50  std::vector<Parallel::MessageTag> tags(n_vals_in_scope);
51  for (int i=0; i != n_vals_in_scope; ++i)
52  {
53  tags[i] = newcomm.get_unique_tag();
54  vals[i] = tags[i].value();
55  for (int j=0; j != i; ++j)
56  {
57  CPPUNIT_ASSERT(vals[i] != vals[j]);
58  }
59  }
60  }
61 
62  // Even after we go out of scope those values should be used up
63  for (int i=n_vals_in_scope; i != n_vals; ++i)
64  {
65  Parallel::MessageTag another_tag = newcomm.get_unique_tag();
66  vals[i] = another_tag.value();
67  for (int j=0; j != i; ++j)
68  {
69  CPPUNIT_ASSERT(vals[i] != vals[j]);
70  }
71  }
72  }
73 
74 
75 
77  {
78  LOG_UNIT_TEST;
79 
80  // Here we'll use the standard communicator, because even if it
81  // used these tags in other contexts it should have freed them for
82  // reuse later.
83 
84  const int requests[] = {2, 4, 6, 8, 8, 6, 8, 123, 3141, 3142};
85 
86  for (const int i : requests)
87  {
88  Parallel::MessageTag manual_tag =
90  CPPUNIT_ASSERT_EQUAL(i, manual_tag.value());
91  }
92  }
93 
94 };
95 
CPPUNIT_TEST_SUITE_REGISTRATION(MessageTagTest)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
int value() const
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
The libMesh namespace provides an interface to certain functionality in the library.
void testGetUniqueTagManual()
void testGetUniqueTagAuto()
Definition: message_tag.C:34
void testGetUniqueTagManual()
Definition: message_tag.C:76
void tearDown()
Definition: message_tag.C:29
void duplicate(const Communicator &comm)
void testGetUniqueTagAuto()
std::vector< std::string > _number
Definition: message_tag.C:23