TiledArray  0.7.0
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  * pmap.h
22  * April 24, 2012
23  *
24  */
25 
26 #ifndef TILEDARRAY_PMAP_H__INCLUDED
27 #define TILEDARRAY_PMAP_H__INCLUDED
28 
29 #include <TiledArray/madness.h>
30 #include <TiledArray/error.h>
31 
32 namespace TiledArray {
33 
35 
46  class Pmap {
47  public:
48  typedef std::size_t size_type;
49  typedef std::vector<size_type>::const_iterator const_iterator;
50 
51  protected:
52  const size_type rank_;
53  const size_type procs_;
54  const size_type size_;
55  std::vector<size_type> local_;
56 
57  private:
58  // Not allowed
59  Pmap(const Pmap&);
60  Pmap& operator=(const Pmap&);
61 
62  public:
63 
65 
68  Pmap(World& world, const size_type size) :
69  rank_(world.rank()), procs_(world.size()), size_(size), local_()
70  {
71  TA_ASSERT(size_ > 0ul);
72  }
73 
74  virtual ~Pmap() { }
75 
77 
80  virtual size_type owner(const size_type tile) const = 0;
81 
83 
86  virtual bool is_local(const size_type tile) const = 0;
87 
89 
91  size_type size() const { return size_; }
92 
94 
96  size_type rank() const { return rank_; }
97 
99 
101  size_type procs() const { return procs_; }
102 
104 
106  size_type local_size() const { return local_.size(); }
107 
109 
111  bool empty() const { return local_.empty(); }
112 
114 
116  virtual bool is_replicated() const { return false; }
117 
119 
121  const_iterator begin() const { return local_.begin(); }
122 
124 
126  const_iterator end() const { return local_.end(); }
127 
128  }; // class Pmap
129 
130 } // namespace TiledArray
131 
132 
133 #endif // TILEDARRAY_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_iterator end() const
End local element iterator.
Definition: pmap.h:126
size_type procs() const
Process count accessor.
Definition: pmap.h:101
const size_type rank_
The rank of this process.
Definition: pmap.h:52
Process map.
Definition: pmap.h:46
bool empty() const
Check if there are any local elements.
Definition: pmap.h:111
virtual bool is_replicated() const
Replicated array status.
Definition: pmap.h:116
Pmap(World &world, const size_type size)
Process map constructor.
Definition: pmap.h:68
virtual bool is_local(const size_type tile) const =0
Check that the tile is owned by this process.
virtual size_type owner(const size_type tile) const =0
Maps tile to the processor that owns it.
#define TA_ASSERT(a)
Definition: error.h:107
std::vector< size_type >::const_iterator const_iterator
Iterator type.
Definition: pmap.h:49
size_type rank() const
Process rank accessor.
Definition: pmap.h:96
virtual ~Pmap()
Definition: pmap.h:74
const size_type size_
The number of tiles mapped among all processes.
Definition: pmap.h:54
size_type local_size() const
Local size accessor.
Definition: pmap.h:106
const_iterator begin() const
Begin local element iterator.
Definition: pmap.h:121
std::size_t size_type
Size type.
Definition: pmap.h:48
std::vector< size_type > local_
A list of local tiles.
Definition: pmap.h:55