TIMPI
message_tag.h
Go to the documentation of this file.
1 // The TIMPI Message-Passing Parallelism Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef TIMPI_MESSAGE_TAG_H
20 #define TIMPI_MESSAGE_TAG_H
21 
22 // TIMPI Includes
23 #include "timpi/timpi_config.h"
24 
25 // C/C++ includes
26 #ifdef TIMPI_HAVE_MPI
27 # include "timpi/ignore_warnings.h"
28 # include "mpi.h"
29 # include "timpi/restore_warnings.h"
30 #endif // TIMPI_HAVE_MPI
31 
32 #include <climits> // INT_MIN
33 
34 namespace TIMPI
35 {
36 //-------------------------------------------------------------------
40 class Communicator;
41 
42 //-------------------------------------------------------------------
47 {
48 public:
49 
53  static const int invalid_tag = INT_MIN;
54 
59  explicit MessageTag(int tagvalue = invalid_tag)
60  : _tagvalue(tagvalue), _comm(nullptr) {}
61 
66  MessageTag(const MessageTag & other);
67 
72  MessageTag(MessageTag && other);
73 
78  MessageTag & operator = (const MessageTag & other);
79 
84  MessageTag & operator = (MessageTag && other);
85 
90  ~MessageTag();
91 
92  int value() const {
93  return _tagvalue;
94  }
95 
96 private:
97  int _tagvalue;
99 
100  // Constructor for reference-counted unique tags
101  MessageTag(int tagvalue, const Communicator * comm)
102  : _tagvalue(tagvalue), _comm(comm) {}
103 
104  // Let Communicator handle the reference counting
105  friend class Communicator;
106 };
107 
108 
109 //-------------------------------------------------------------------
113 #ifdef TIMPI_HAVE_MPI
114 const MessageTag any_tag = MessageTag(MPI_ANY_TAG);
115 #else
116 const MessageTag any_tag = MessageTag(-1);
117 #endif
118 
120 
121 } // namespace TIMPI
122 
123 #endif // TIMPI_MESSAGE_TAG_H
int value() const
Definition: message_tag.h:92
const MessageTag any_tag
Default message tag ids.
Definition: message_tag.h:114
~MessageTag()
Destructor.
Definition: message_tag.C:32
Encapsulates the MPI_Comm object.
Definition: communicator.h:108
const MessageTag no_tag
Definition: message_tag.h:119
static const int invalid_tag
Invalid tag, to allow for default construction.
Definition: message_tag.h:53
Encapsulates the MPI tag integers.
Definition: message_tag.h:46
MessageTag(int tagvalue=invalid_tag)
Explicit constructor, to discourage using "magic numbers" as tags.
Definition: message_tag.h:59
MessageTag & operator=(const MessageTag &other)
Copy assignment operator.
Definition: message_tag.C:55
MessageTag(int tagvalue, const Communicator *comm)
Definition: message_tag.h:101
const Communicator * _comm
Definition: message_tag.h:98