blocked_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  * add.h
22  * April 24, 2012
23  *
24  */
25 
26 #ifndef TILEDARRAY_PMAP_BLOCKED_PMAP_H__INCLUDED
27 #define TILEDARRAY_PMAP_BLOCKED_PMAP_H__INCLUDED
28 
29 #include <TiledArray/pmap/pmap.h>
30 
31 namespace TiledArray {
32 namespace detail {
33 
35 
38 class BlockedPmap : public Pmap {
39  protected:
40  // Import Pmap protected variables
41  using Pmap::procs_;
42  using Pmap::rank_;
43  using Pmap::size_;
44 
45  private:
46  const size_type block_size_;
47  const size_type remainder_;
48  const size_type block_size_plus_1_;
49  const size_type block_size_plus_1_times_remainder_;
50  const size_type local_first_;
51  const size_type local_last_;
52 
53  public:
55 
57 
60  BlockedPmap(World& world, size_type size)
61  : Pmap(world, size),
62  block_size_(size_ / procs_),
63  remainder_(size_ % procs_),
64  block_size_plus_1_(block_size_ + 1),
65  block_size_plus_1_times_remainder_(remainder_ * block_size_plus_1_),
66  local_first_(rank_ * block_size_ +
67  std::min<size_type>(rank_, remainder_)),
68  local_last_((rank_ + 1) * block_size_ +
69  std::min<size_type>((rank_ + 1), remainder_)) {
70  this->local_size_ = local_last_ - local_first_;
71  }
72 
73  virtual ~BlockedPmap() {}
74 
76 
79  virtual size_type owner(const size_type tile) const {
80  TA_ASSERT(tile < size_);
81  return (tile < block_size_plus_1_times_remainder_
82  ? tile / block_size_plus_1_
83  : ((tile - block_size_plus_1_times_remainder_) / block_size_) +
84  remainder_);
85  }
86 
88 
91  virtual bool is_local(const size_type tile) const {
92  return ((tile >= local_first_) && (tile < local_last_));
93  }
94 
95  virtual const_iterator begin() const {
96  return Iterator(*this, local_first_, local_last_, local_first_, false);
97  }
98  virtual const_iterator end() const {
99  return Iterator(*this, local_first_, local_last_, local_last_, false);
100  }
101 
102 }; // class BlockedPmap
103 
104 } // namespace detail
105 } // namespace TiledArray
106 
107 #endif // TILEDARRAY_PMAP_BLOCKED_PMAP_H__INCLUDED
virtual bool is_local(const size_type tile) const
Check that the tile is owned by this process.
Definition: blocked_pmap.h:91
Pmap::size_type size_type
Key type.
Definition: blocked_pmap.h:54
virtual const_iterator end() const
End local element iterator.
Definition: blocked_pmap.h:98
const size_type rank_
< The number of processes
Definition: pmap.h:60
const size_type size_
< The rank of this process
Definition: pmap.h:62
BlockedPmap(World &world, size_type size)
Construct Blocked map.
Definition: blocked_pmap.h:60
decltype(auto) min(const Tile< Arg > &arg)
Minimum element of a tile.
Definition: tile.h:1559
#define TA_ASSERT(EXPR,...)
Definition: error.h:39
const size_type procs_
The number of processes.
Definition: pmap.h:61
Pmap iterator type.
Definition: pmap.h:161
size_type local_size_
Definition: pmap.h:65
size_type size() const
Size accessor.
Definition: pmap.h:102
const size_type rank_
The rank of this process.
Definition: pmap.h:60
std::size_t size_type
Size type.
Definition: pmap.h:57
virtual size_type owner(const size_type tile) const
Maps tile to the processor that owns it.
Definition: blocked_pmap.h:79
friend class Iterator
Iterator type.
Definition: pmap.h:280
A blocked process map.
Definition: blocked_pmap.h:38
const size_type procs_
The number of processes.
Definition: pmap.h:61
Process map.
Definition: pmap.h:55
const size_type size_
The number of tiles mapped among all processes.
Definition: pmap.h:62
virtual const_iterator begin() const
Begin local element iterator.
Definition: blocked_pmap.h:95