round_robin_pmap.h
Go to the documentation of this file.
1 //
2 // Created by Karl Pierce on 7/26/20.
3 //
4 
5 #ifndef TILEDARRAY_PMAP_ROUND_ROBIN_PMAP_H__INCLUDED
6 #define TILEDARRAY_PMAP_ROUND_ROBIN_PMAP_H__INCLUDED
7 
8 #include <TiledArray/pmap/pmap.h>
9 
10 namespace TiledArray {
11 namespace detail {
12 
14 
17 class RoundRobinPmap : public Pmap {
18  protected:
19  // Import Pmap protected variables
20  using Pmap::procs_;
21  using Pmap::rank_;
22  using Pmap::size_;
23 
24  private:
25  const size_type remainder_;
26 
27  public:
29 
31 
34  RoundRobinPmap(World& world, size_type size)
35  : Pmap(world, size), remainder_(size_ % procs_) {
36  auto num_tiles_per_proc = size / procs_;
37  if (remainder_ == 0 || rank_ >= remainder_)
38  this->local_size_ = num_tiles_per_proc;
39  else
40  this->local_size_ = num_tiles_per_proc + 1;
41  }
42 
43  virtual ~RoundRobinPmap() {}
44 
46 
49  virtual size_type owner(const size_type tile) const {
50  TA_ASSERT(tile < size_);
51  return (tile % procs_);
52  }
53 
55 
58  virtual bool is_local(const size_type tile) const {
59  return (tile % procs_ == rank_);
60  }
61 
62 }; // class RoundRobinPmap
63 
64 } // namespace detail
65 } // namespace TiledArray
66 
67 #endif // TILEDARRAY_PMAP_ROUND_ROBIN_PMAP_H__INCLUDED
virtual bool is_local(const size_type tile) const
Check that the tile is owned by this process.
virtual size_type owner(const size_type tile) const
Maps tile to the processor that owns it.
const size_type rank_
< The number of processes
Definition: pmap.h:60
const size_type procs_
The number of processes.
Definition: pmap.h:61
#define TA_ASSERT(EXPR,...)
Definition: error.h:39
const size_type procs_
The number of processes.
Definition: pmap.h:61
RoundRobinPmap(World &world, size_type size)
Construct Round Robin map.
const size_type size_
< The rank of this process
Definition: pmap.h:62
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
Process map.
Definition: pmap.h:55
const size_type size_
The number of tiles mapped among all processes.
Definition: pmap.h:62
Pmap::size_type size_type
Key type.