TiledArray  0.7.0
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 
38  // Import Pmap protected variables
39  using Pmap::rank_;
40  using Pmap::procs_;
41  using Pmap::size_;
42  using Pmap::local_;
43 
44  private:
45 
46  const madness::hashT seed_;
47 
48  public:
50 
52 
56  HashPmap(World& world, const size_type size, madness::hashT seed = 0ul) :
57  Pmap(world, size), seed_(seed)
58  {
59  // Construct a map of all local processes
60  // TODO: NON-SCALING!!!
61  // This code is non-scaling because it iterates over all elements
62  for(size_type i = 0ul; i < size_; ++i)
63  if(HashPmap::owner(i) == rank_)
64  local_.push_back(i);
65  }
66 
67  virtual ~HashPmap() { }
68 
70 
73  virtual size_type owner(const size_type tile) const {
74  TA_ASSERT(tile < size_);
75  madness::hashT seed = seed_;
76  madness::hash_combine(seed, tile);
77  return (seed % procs_);
78  }
79 
80 
82 
85  virtual bool is_local(const size_type tile) const {
86  return HashPmap::owner(tile) == rank_;
87  }
88 
89  }; // class HashPmap
90 
91  } // namespace detail
92 } // namespace TiledArray
93 
94 
95 #endif // TILEDARRAY_PMAP_HASH_PMAP_H__INCLUDED
size_type size() const
Size accessor.
Definition: pmap.h:91
const size_type procs_
The number of processes.
Definition: pmap.h:53
const size_type rank_
The rank of this process.
Definition: pmap.h:52
Process map.
Definition: pmap.h:46
Hashed process map.
Definition: hash_pmap.h:35
#define TA_ASSERT(a)
Definition: error.h:107
virtual bool is_local(const size_type tile) const
Check that the tile is owned by this process.
Definition: hash_pmap.h:85
HashPmap(World &world, const size_type size, madness::hashT seed=0ul)
Construct a hashed process map.
Definition: hash_pmap.h:56
const size_type size_
The number of tiles mapped among all processes.
Definition: pmap.h:54
Pmap::size_type size_type
Size type.
Definition: hash_pmap.h:49
std::size_t size_type
Size type.
Definition: pmap.h:48
virtual size_type owner(const size_type tile) const
Maps tile to the processor that owns it.
Definition: hash_pmap.h:73
std::vector< size_type > local_
A list of local tiles.
Definition: pmap.h:55