libMesh
Loading...
Searching...
No Matches
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
11using namespace libMesh;
12
13class MessageTagTest : public CppUnit::TestCase {
14public:
16
19
21
22private:
23 std::vector<std::string> _number;
24
25public:
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
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 =
89 TestCommWorld->get_unique_tag(i);
90 CPPUNIT_ASSERT_EQUAL(i, manual_tag.value());
91 }
92 }
93
94};
95
LIBMESH_CPPUNIT_TEST_SUITE(MessageTagTest)
CPPUNIT_TEST(testGetUniqueTagAuto)
CPPUNIT_TEST(testGetUniqueTagManual)
void testGetUniqueTagManual()
Definition message_tag.C:76
std::vector< std::string > _number
Definition message_tag.C:23
void testGetUniqueTagAuto()
Definition message_tag.C:34
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
void duplicate(const Communicator &comm)
int value() const
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(MessageTagTest)
The libMesh namespace provides an interface to certain functionality in the library.