TIMPI
Functions | Variables
message_tag_unit.C File Reference

Go to the source code of this file.

Functions

void testGetUniqueTagAuto ()
 
void testGetUniqueTagManual ()
 
void testGetUniqueTagOverlap ()
 
int main (int argc, const char *const *argv)
 

Variables

CommunicatorTestCommWorld
 

Function Documentation

◆ main()

int main ( int  argc,
const char *const *  argv 
)

Definition at line 104 of file message_tag_unit.C.

References TIMPI::TIMPIInit::comm(), TestCommWorld, testGetUniqueTagAuto(), testGetUniqueTagManual(), and testGetUniqueTagOverlap().

105 {
106  TIMPI::TIMPIInit init(argc, argv);
107  TestCommWorld = &init.comm();
108 
112 
113  return 0;
114 }
The TIMPIInit class, when constructed, initializes any dependent libraries (e.g.
Definition: timpi_init.h:57
Communicator * TestCommWorld
void testGetUniqueTagManual()
void testGetUniqueTagOverlap()
void testGetUniqueTagAuto()

◆ testGetUniqueTagAuto()

void testGetUniqueTagAuto ( )

Definition at line 13 of file message_tag_unit.C.

References TIMPI::Communicator::duplicate(), TIMPI::Communicator::get_unique_tag(), TestCommWorld, and TIMPI::MessageTag::value().

Referenced by main().

14  {
15  // We need to duplicate the communicator first, because the
16  // original might already have tags used by other unit tests
17 
18  TIMPI::Communicator newcomm;
19 
20  TestCommWorld->duplicate(newcomm);
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  {
34  TIMPI_UNIT_ASSERT(vals[i] != vals[j]);
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();
43  vals[i] = another_tag.value();
44  for (int j=0; j != i; ++j)
45  {
46  TIMPI_UNIT_ASSERT(vals[i] != vals[j]);
47  }
48  }
49  }
int value() const
Definition: message_tag.h:92
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
Get a tag that is unique to this Communicator.
Definition: communicator.C:251
Communicator * TestCommWorld
Encapsulates the MPI_Comm object.
Definition: communicator.h:108
Encapsulates the MPI tag integers.
Definition: message_tag.h:46
void duplicate(const Communicator &comm)
Definition: communicator.C:137

◆ testGetUniqueTagManual()

void testGetUniqueTagManual ( )

Definition at line 53 of file message_tag_unit.C.

References TIMPI::Communicator::get_unique_tag(), TestCommWorld, and TIMPI::MessageTag::value().

Referenced by main().

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  {
63  TIMPI::MessageTag manual_tag =
65  TIMPI_UNIT_ASSERT(i == manual_tag.value());
66 
67  TIMPI::MessageTag tag_copy = manual_tag;
68  TIMPI_UNIT_ASSERT(i == tag_copy.value());
69 
70  TIMPI::MessageTag tag_move = std::move(tag_copy);
71  TIMPI_UNIT_ASSERT(i == tag_move.value());
72 
73  TIMPI::MessageTag stupidly_manual_tag(i);
74  TIMPI_UNIT_ASSERT(i == stupidly_manual_tag.value());
75  }
76  }
int value() const
Definition: message_tag.h:92
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
Get a tag that is unique to this Communicator.
Definition: communicator.C:251
Communicator * TestCommWorld
Encapsulates the MPI tag integers.
Definition: message_tag.h:46

◆ testGetUniqueTagOverlap()

void testGetUniqueTagOverlap ( )

Definition at line 79 of file message_tag_unit.C.

References TIMPI::Communicator::get_unique_tag(), TestCommWorld, and TIMPI::MessageTag::value().

Referenced by main().

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  {
88  TIMPI::MessageTag manual_tag =
90  TIMPI_UNIT_ASSERT(i == manual_tag.value());
91 
92  TIMPI::MessageTag dup_manual_tag =
94  TIMPI_UNIT_ASSERT(i != dup_manual_tag.value());
95 
96  TIMPI::MessageTag tag_copy = manual_tag;
97  TIMPI_UNIT_ASSERT(i == tag_copy.value());
98 
99  TIMPI::MessageTag tag_move = std::move(tag_copy);
100  TIMPI_UNIT_ASSERT(i == tag_move.value());
101  }
102  }
int value() const
Definition: message_tag.h:92
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
Get a tag that is unique to this Communicator.
Definition: communicator.C:251
Communicator * TestCommWorld
Encapsulates the MPI tag integers.
Definition: message_tag.h:46

Variable Documentation

◆ TestCommWorld

Communicator* TestCommWorld