libMesh
Loading...
Searching...
No Matches
tests
parallel
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
34
void
testGetUniqueTagAuto
()
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
76
void
testGetUniqueTagManual
()
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
96
CPPUNIT_TEST_SUITE_REGISTRATION
(
MessageTagTest
);
MessageTagTest
Definition
message_tag.C:13
MessageTagTest::LIBMESH_CPPUNIT_TEST_SUITE
LIBMESH_CPPUNIT_TEST_SUITE(MessageTagTest)
MessageTagTest::CPPUNIT_TEST_SUITE_END
CPPUNIT_TEST_SUITE_END()
MessageTagTest::CPPUNIT_TEST
CPPUNIT_TEST(testGetUniqueTagAuto)
MessageTagTest::CPPUNIT_TEST
CPPUNIT_TEST(testGetUniqueTagManual)
MessageTagTest::testGetUniqueTagManual
void testGetUniqueTagManual()
Definition
message_tag.C:76
MessageTagTest::tearDown
void tearDown()
Definition
message_tag.C:29
MessageTagTest::_number
std::vector< std::string > _number
Definition
message_tag.C:23
MessageTagTest::setUp
void setUp()
Definition
message_tag.C:26
MessageTagTest::testGetUniqueTagAuto
void testGetUniqueTagAuto()
Definition
message_tag.C:34
libMesh::Parallel::Communicator::get_unique_tag
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
libMesh::Parallel::Communicator::duplicate
void duplicate(const Communicator &comm)
TIMPI::MessageTag
TIMPI::MessageTag::value
int value() const
libMesh::Parallel::Communicator
TestCommWorld
Communicator * TestCommWorld
libmesh_cppunit.h
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(MessageTagTest)
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
test_comm.h
Generated on Fri Aug 21 2026 13:32:31 for libMesh by
1.9.8