hash_pmap.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2013 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Justus Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * hash_pmap.h
22  * May 4, 2012
23  *
24  */
25 
26 #ifndef TILEDARRAY_PMAP_HASH_PMAP_H__INCLUDED
27 #define TILEDARRAY_PMAP_HASH_PMAP_H__INCLUDED
28 
29 #include <TiledArray/pmap/pmap.h>
30 
31 namespace TiledArray {
32 namespace detail {
33 
35 class HashPmap : public Pmap {
36  protected:
37  // Import Pmap protected variables
38  using Pmap::procs_;
39  using Pmap::rank_;
40  using Pmap::size_;
41 
42  private:
43  const madness::hashT seed_;
44 
45  public:
47 
49 
53  HashPmap(World& world, const size_type size, madness::hashT seed = 0ul)
54  : Pmap(world, size), seed_(seed) {}
55 
56  virtual ~HashPmap() {}
57 
59 
62  virtual size_type owner(const size_type tile) const {
63  TA_ASSERT(tile < size_);
64  madness::hashT seed = seed_;
65  madness::hash_combine(seed, tile);
66  return (seed % procs_);
67  }
68 
70 
73  virtual bool is_local(const size_type tile) const {
74  return HashPmap::owner(tile) == rank_;
75  }
76 
77  virtual bool known_local_size() const { return false; }
78 
79 }; // class HashPmap
80 
81 } // namespace detail
82 } // namespace TiledArray
83 
84 #endif // TILEDARRAY_PMAP_HASH_PMAP_H__INCLUDED
Pmap::size_type size_type
Size type.
Definition: hash_pmap.h:46
HashPmap(World &world, const size_type size, madness::hashT seed=0ul)
Construct a hashed process map.
Definition: hash_pmap.h:53
virtual size_type owner(const size_type tile) const
Maps tile to the processor that owns it.
Definition: hash_pmap.h:62
#define TA_ASSERT(EXPR,...)
Definition: error.h:39
const size_type procs_
The number of processes.
Definition: pmap.h:61
const size_type procs_
The number of processes.
Definition: pmap.h:61
size_type size() const
Size accessor.
Definition: pmap.h:102
virtual bool known_local_size() const
Queries whether local size is known.
Definition: hash_pmap.h:77
Hashed process map.
Definition: hash_pmap.h:35
virtual bool is_local(const size_type tile) const
Check that the tile is owned by this process.
Definition: hash_pmap.h:73
const size_type rank_
The rank of this process.
Definition: pmap.h:60
const size_type rank_
< The number of processes
Definition: pmap.h:60
std::size_t size_type
Size type.
Definition: pmap.h:57
Process map.
Definition: pmap.h:55
const size_type size_
The number of tiles mapped among all processes.
Definition: pmap.h:62
const size_type size_
< The rank of this process
Definition: pmap.h:62