TiledArray  0.7.0
replicated_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  * replicated_pmap.h
22  * February 8, 2013
23  *
24  */
25 
26 #ifndef TILEDARRAY_PMAP_REPLICATED_PMAP_H__INCLUDED
27 #define TILEDARRAY_PMAP_REPLICATED_PMAP_H__INCLUDED
28 
29 #include <TiledArray/pmap/pmap.h>
30 
31 namespace TiledArray {
32  namespace detail {
33 
35 
37  class ReplicatedPmap : public Pmap {
38  protected:
39 
40  // Import Pmap protected variables
41  using Pmap::rank_;
42  using Pmap::procs_;
43  using Pmap::size_;
44  using Pmap::local_;
45 
46  public:
48 
50 
53  ReplicatedPmap(World& world, size_type size) :
54  Pmap(world, size)
55  {
56  // Construct a map of all local processes
57  local_.reserve(size_);
58  // Warning: This is non-scaling code because it iterates over all
59  // elements. However, it is for replicated data so the number of
60  // elements is assumed to be reasonable.
61  for(size_type i = 0; i < size_; ++i) {
63  local_.push_back(i);
64  }
65  }
66 
67  virtual ~ReplicatedPmap() { }
68 
70 
73  virtual size_type owner(const size_type tile) const {
74  TA_ASSERT(tile < size_);
75  return rank_;
76  }
77 
79 
82  virtual bool is_local(const size_type tile) const {
83  TA_ASSERT(tile < size_);
84  return true;
85  }
86 
88 
90  virtual bool is_replicated() const { return true; }
91 
92  }; // class MapByRow
93 
94  } // namespace detail
95 } // namespace TiledArray
96 
97 
98 #endif // TILEDARRAY_PMAP_REPLICATED_PMAP_H__INCLUDED
size_type size() const
Size accessor.
Definition: pmap.h:91
Pmap::size_type size_type
< A list of local tiles
const size_type procs_
The number of processes.
Definition: pmap.h:53
ReplicatedPmap(World &world, size_type size)
Construct Blocked map.
const size_type rank_
The rank of this process.
Definition: pmap.h:52
Process map.
Definition: pmap.h:46
virtual bool is_local(const size_type tile) const
Check that the tile is owned by this process.
A Replicated process map.
virtual bool is_replicated() const
Replicated array status.
#define TA_ASSERT(a)
Definition: error.h:107
const size_type size_
The number of tiles mapped among all processes.
Definition: pmap.h:54
virtual size_type owner(const size_type tile) const
Maps tile to the processor that owns it.
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