MADNESS  version 0.9
dist_keys.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2013 Virginia Tech
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33  */
34 
35 #ifndef MADNESS_WORLD_DISTRIBUTED_ID_H__INCLUDED
36 #define MADNESS_WORLD_DISTRIBUTED_ID_H__INCLUDED
37 
38 #include <madness/world/uniqueid.h>
40 
41 namespace madness {
42 
44  typedef std::pair<uniqueidT, std::size_t> DistributedID;
45 
47 
52  inline bool operator==(const DistributedID& left, const DistributedID& right) {
53  return (left.first == right.first) && (left.second == right.second);
54  }
55 
57 
62  inline bool operator!=(const DistributedID& left, const DistributedID& right) {
63  return (left.first != right.first) || (left.second != right.second);
64  }
65 
67 
70  template <typename Key, typename Tag = void>
71  class ProcessKey {
72  private:
73  Key key_;
74  ProcessID proc_;
75 
76  public:
77 
79  ProcessKey() : key_(), proc_(-1) { }
80 
82 
85  ProcessKey(const Key& key, const ProcessID proc) :
86  key_(key), proc_(proc)
87  { }
88 
90 
93  key_(other.key_), proc_(other.proc_)
94  { }
95 
97 
101  key_ = other.key_;
102  proc_ = other.proc_;
103  return *this;
104  }
105 
107 
109  const Key& key() const { return key_; }
110 
112 
114  ProcessID proc() const { return proc_; }
115 
117 
121  bool operator==(const ProcessKey<Key, Tag>& other) const {
122  return ((key_ == other.key_) && (proc_ == other.proc_));
123  }
124 
126 
130  bool operator!=(const ProcessKey<Key, Tag>& other) const {
131  return ((key_ != other.key_) || (proc_ != other.proc_));
132  }
133 
135 
138  template <typename Archive>
139  void serialize(const Archive& ar) {
140  ar & key_ & proc_;
141  }
142 
144 
148  Hash<Key> hasher;
149  hashT seed = hasher(key.key_);
150  madness::detail::combine_hash(seed, key.proc_);
151  return seed;
152  }
153 
154  }; // class ProcessKey
155 
157 
160  template <typename Key, typename Tag>
161  class TaggedKey {
162  private:
163  Key key_;
164 
165  public:
166 
168  TaggedKey() : key_() { }
169 
171 
174  TaggedKey(const Key& key) : key_(key) { }
175 
177 
179  TaggedKey(const TaggedKey<Key, Tag>& other) : key_(other.key_) { }
180 
182 
186  key_ = other.key_;
187  return *this;
188  }
189 
191 
193  const Key& key() const { return key_; }
194 
196 
200  bool operator==(const TaggedKey<Key, Tag>& other) const {
201  return (key_ == other.key_);
202  }
203 
205 
209  bool operator!=(const TaggedKey<Key, Tag>& other) const {
210  return (key_ != other.key_);
211  }
212 
214 
217  template <typename Archive>
218  void serialize(const Archive& ar) { ar & key_; }
219 
221 
225  Hash<Key> hasher;
226  return hasher(key.key_);
227  }
228 
229  }; // class TagKey
230 
231 } // namespace madness
232 
233 namespace std {
234 
236 
240  madness::hashT seed = madness::hash_value(id.first);
242 
243  return seed;
244  }
245 
246 } // namespace std
247 
248 #endif // MADNESS_WORLD_DISTRIBUTED_ID_H__INCLUDED
void serialize(const Archive &ar)
Serialize this key.
Definition: dist_keys.h:218
ProcessKey()
Default constructor.
Definition: dist_keys.h:79
TaggedKey< Key, Tag > & operator=(const TaggedKey< Key, Tag > &other)
Copy assignment operator.
Definition: dist_keys.h:185
Definition: mpreal.h:3066
ProcessKey< Key, Tag > & operator=(const ProcessKey< Key, Tag > &other)
Copy assignment operator.
Definition: dist_keys.h:100
Key object that included the process information.
Definition: dist_keys.h:71
ProcessID proc() const
Process id accessor.
Definition: dist_keys.h:114
TaggedKey(const Key &key)
Constructor.
Definition: dist_keys.h:174
friend hashT hash_value(const ProcessKey< Key, Tag > &key)
Hashing function.
Definition: dist_keys.h:147
const Key & key() const
Base key accessor.
Definition: dist_keys.h:109
void combine_hash(hashT &seed, hashT hash)
Internal use only.
Definition: worldhash.h:247
bool operator!=(const ProcessKey< Key, Tag > &other) const
Inequality comparison.
Definition: dist_keys.h:130
bool operator==(const ProcessKey< Key, Tag > &other) const
Equality comparison.
Definition: dist_keys.h:121
const Key & key() const
Base key accessor.
Definition: dist_keys.h:193
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness::Hash.
Definition: array.h:62
TaggedKey()
Default constructor.
Definition: dist_keys.h:168
ProcessKey(const ProcessKey< Key, Tag > &other)
Copy constructor.
Definition: dist_keys.h:92
std::size_t hashT
The hash value type.
Definition: worldhash.h:148
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
std::pair< uniqueidT, std::size_t > DistributedID
Distributed ID which is used to identify objects.
Definition: dist_keys.h:44
madness::hashT hash_value(const madness::DistributedID &id)
Hash a DistributedID.
Definition: dist_keys.h:239
bool operator==(const TaggedKey< Key, Tag > &other) const
Equality comparison.
Definition: dist_keys.h:200
friend hashT hash_value(const TaggedKey< Key, Tag > &key)
Hashing function.
Definition: dist_keys.h:224
ProcessKey(const Key &key, const ProcessID proc)
Constructor.
Definition: dist_keys.h:85
TaggedKey(const TaggedKey< Key, Tag > &other)
Copy constructor.
Definition: dist_keys.h:179
bool operator==(const DistributedID &left, const DistributedID &right)
Distributed ID equality comparison operator.
Definition: dist_keys.h:52
bool operator!=(const DistributedID &left, const DistributedID &right)
Distributed ID inequality comparison operator.
Definition: dist_keys.h:62
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Key object that uses a tag to differentiate keys.
Definition: dist_keys.h:161
Hash functor.
Definition: shared_ptr_bits.h:32
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
void serialize(const Archive &ar)
Serialize this key.
Definition: dist_keys.h:139
bool operator!=(const TaggedKey< Key, Tag > &other) const
Inequality comparison.
Definition: dist_keys.h:209