TIMPI
Loading...
Searching...
No Matches
message_tag_unit.C
Go to the documentation of this file.
2#include <timpi/message_tag.h>
3#include <timpi/timpi_init.h>
4
5#define TIMPI_UNIT_ASSERT(expr) \
6 if (!(expr)) \
7 timpi_error();
8
9using namespace TIMPI;
10
12
14 {
15 // We need to duplicate the communicator first, because the
16 // original might already have tags used by other unit tests
17
19
21
22 const int n_vals = 5;
23 const int n_vals_in_scope = 3;
24 std::vector<int> vals(n_vals);
25
26 {
27 std::vector<TIMPI::MessageTag> tags(n_vals_in_scope);
28 for (int i=0; i != n_vals_in_scope; ++i)
29 {
30 tags[i] = newcomm.get_unique_tag();
31 vals[i] = tags[i].value();
32 for (int j=0; j != i; ++j)
33 {
35 }
36 }
37 }
38
39 // Even after we go out of scope those values should be used up
40 for (int i=n_vals_in_scope; i != n_vals; ++i)
41 {
42 TIMPI::MessageTag another_tag = newcomm.get_unique_tag();
44 for (int j=0; j != i; ++j)
45 {
47 }
48 }
49 }
50
51
52
54 {
55 // Here we'll use the standard communicator, because even if it
56 // used these tags in other contexts it should have freed them for
57 // reuse later.
58
59 const int requests[] = {2, 4, 6, 8, 8, 6, 8, 123, 3141, 3142};
60
61 for (const int i : requests)
62 {
65 TIMPI_UNIT_ASSERT(i == manual_tag.value());
66
68 TIMPI_UNIT_ASSERT(i == tag_copy.value());
69
71 TIMPI_UNIT_ASSERT(i == tag_move.value());
72
75 }
76 }
77
78
80 {
81 // Try to request the same tag twice, make sure we don't get it
82 // the second time.
83
84 const int requests[] = {2, 4, 6, 8, 8, 6, 8, 123, 3141, 3142};
85
86 for (const int i : requests)
87 {
90 TIMPI_UNIT_ASSERT(i == manual_tag.value());
91
95
97 TIMPI_UNIT_ASSERT(i == tag_copy.value());
98
100 TIMPI_UNIT_ASSERT(i == tag_move.value());
101 }
102 }
103
104int main(int argc, const char * const * argv)
105{
107 TestCommWorld = &init.comm();
108
112
113 return 0;
114}
Encapsulates the MPI_Comm object.
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
Get a tag that is unique to this Communicator.
void duplicate(const Communicator &comm)
Encapsulates the MPI tag integers.
Definition message_tag.h:47
int value() const
Definition message_tag.h:92
The TIMPIInit class, when constructed, initializes any dependent libraries (e.g.
Definition timpi_init.h:58
Communicator * TestCommWorld
void testGetUniqueTagManual()
void testGetUniqueTagAuto()
void testGetUniqueTagOverlap()
Tnew cast_int(Told oldvar)
int main()
Definition version.C:20