OpenMPI  0.1.1
vt_unify_usrcom.h
1 /**
2  * VampirTrace
3  * http://www.tu-dresden.de/zih/vampirtrace
4  *
5  * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6  *
7  * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8  * Centre, Federal Republic of Germany
9  *
10  * See the file COPYING in the package base directory for details
11  **/
12 
13 #ifndef _VT_UNIFY_USRCOM_H_
14 #define _VT_UNIFY_USRCOM_H_
15 
16 #include "config.h"
17 
18 #include "vt_inttypes.h"
19 
20 #include <map>
21 #include <set>
22 
23 //
24 // UserComC class
25 //
26 class UserComC
27 {
28 public:
29 
30  //
31  // structure for user communication ids
32  //
33  struct ComIdS
34  {
35  // constructors
36  ComIdS()
37  : comm( 0 ), tag( 0 ) {}
38  ComIdS( const uint32_t & _comm, const uint32_t & _tag )
39  : comm( _comm ), tag( _tag ) {}
40 
41  // operator for searching
42  bool operator<( const ComIdS & a ) const
43  {
44  if( comm == a.comm )
45  return tag < a.tag;
46  else
47  return comm < a.comm;
48  }
49 
50  uint32_t comm; // communicator token
51  uint32_t tag; // unique tag
52 
53  };
54 
55  //
56  // structure for user communication pairs
57  //
58  struct ComPairS
59  {
60  // constructors
61  ComPairS()
62  : sender( 0 ), receiver( 0 ) {}
63  ComPairS( const uint32_t & _sender, const uint32_t & _receiver )
64  : sender( _sender ), receiver( _receiver ) {}
65 
66  uint32_t sender; // sender process id
67  uint32_t receiver; // receiver process id
68  };
69 
70  // constructor
71  UserComC();
72 
73  // destructor
74  ~UserComC();
75 
76  // add global user communicator token
77  void addUserComm( const uint32_t & comm )
78  {
79  m_userComms.insert( comm );
80  }
81 
82  // check whether process group token is an user communicator
83  bool isUserComm( const uint32_t & comm ) const
84  {
85  return ( m_userComms.find( comm ) != m_userComms.end() );
86  }
87 
88  // register sender process id for certain user communication id
89  bool addSender( const ComIdS & comId, const uint32_t & sender );
90 
91  // register receiver process id for certain user communication id
92  bool addReceiver( const ComIdS & comId, const uint32_t & receiver );
93 
94  // get sender process id by comm. and tag
95  uint32_t getSender( const uint32_t & comm, const uint32_t & tag ) const
96  {
97  uint32_t sender = 0;
98 
99  std::map<ComIdS, ComPairS>::const_iterator it =
100  m_comId2ComPair.find( ComIdS( comm, tag ) );
101  if( it != m_comId2ComPair.end() )
102  sender = it->second.sender;
103 
104  return sender;
105  }
106 
107  // get receiver process id by comm. and tag
108  uint32_t getReceiver( const uint32_t & comm, const uint32_t & tag ) const
109  {
110  uint32_t receiver = 0;
111 
112  std::map<ComIdS, ComPairS>::const_iterator it =
113  m_comId2ComPair.find( ComIdS( comm, tag ) );
114  if( it != m_comId2ComPair.end() )
115  receiver = it->second.receiver;
116 
117  return receiver;
118  }
119 
120 #ifdef VT_MPI
121  // share user communication ids and pairs all ranks
122  bool share();
123 #endif // VT_MPI
124 
125 private:
126 
127  // set of global user communicator tokens
128  std::set<uint32_t> m_userComms;
129 
130  // map user communication id <-> pair (sender/receiver process ids)
131  std::map<ComIdS, ComPairS> m_comId2ComPair;
132 
133 };
134 
135 // instance of class UserComC
136 extern UserComC * theUserCom;
137 
138 #endif // _VT_UNIFY_USRCOM_H_
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_usrcom.h:26
Definition: vt_unify_usrcom.h:33
Definition: vt_unify_usrcom.h:58