9 #include "serialization.hpp"
10 #include "assigner.hpp"
20 int size()
const {
return static_cast<int>(neighbors_.size()); }
22 int size_unique()
const;
23 BlockID target(
int i)
const {
return neighbors_[
static_cast<size_t>(i)]; }
24 BlockID& target(
int i) {
return neighbors_[
static_cast<size_t>(i)]; }
26 int find(
int gid)
const;
28 void add_neighbor(
const BlockID& block) { neighbors_.push_back(block); }
30 void fix(
const Assigner& assigner) {
for (
unsigned i = 0; i < neighbors_.size(); ++i) { neighbors_[i].proc = assigner.
rank(neighbors_[i].gid); } }
32 void swap(
Link& other) { neighbors_.swap(other.neighbors_); }
37 virtual size_t id()
const {
return 0; }
40 std::vector<BlockID> neighbors_;
43 template<
class Bounds_>
50 template<
class Bounds_>
57 static const size_t id = 1;
64 static const size_t id = 2;
70 template<
class Bounds_>
76 typedef std::map<Direction, int> DirMap;
77 typedef std::vector<Direction> DirVec;
81 dim_(dim), core_(core__), bounds_(bounds__) {}
84 int dimension()
const {
return dim_; }
87 int direction(Direction dir)
const;
88 Direction direction(
int i)
const {
return dir_vec_[i]; }
89 void add_direction(Direction dir) {
int c = dir_map_.size(); dir_map_[dir] = c; dir_vec_.push_back(dir); }
92 void add_wrap(Direction dir) { wrap_.push_back(dir); }
93 Direction wrap(
int i)
const {
return wrap_[i]; }
94 Direction& wrap(
int i) {
return wrap_[i]; }
97 const Bounds& core()
const {
return core_; }
98 Bounds& core() {
return core_; }
99 const Bounds& bounds()
const {
return bounds_; }
100 Bounds& bounds() {
return bounds_; }
101 const Bounds& bounds(
int i)
const {
return nbr_bounds_[i]; }
102 void add_bounds(
const Bounds& bounds__) { nbr_bounds_.push_back(bounds__); }
104 void swap(RegularLink& other) { Link::swap(other); dir_map_.swap(other.dir_map_); dir_vec_.swap(other.dir_vec_); nbr_bounds_.swap(other.nbr_bounds_); std::swap(dim_, other.dim_); wrap_.swap(other.wrap_); std::swap(core_, other.core_); std::swap(bounds_, other.bounds_); }
106 void save(BinaryBuffer& bb)
const
118 void load(BinaryBuffer& bb)
130 virtual size_t id()
const {
return RegularLinkSelector<Bounds>::id; }
140 std::vector<Bounds> nbr_bounds_;
141 std::vector<Direction> wrap_;
149 static Link* create(
size_t id)
170 save(BinaryBuffer& bb,
const Link* l)
178 load(BinaryBuffer& bb)
182 Link* l = create(
id);
191 for (
int i = 0; i < size(); ++i)
193 if (target(i).gid == gid)
202 std::vector<BlockID> tmp(neighbors_.begin(), neighbors_.end());
204 return static_cast<int>(std::unique(tmp.begin(), tmp.end()) - tmp.begin());
207 template<
class Bounds>
212 DirMap::const_iterator it = dir_map_.find(dir);
213 if (it == dir_map_.end())
void load(BinaryBuffer &bb, T &x)
Loads x from bb by calling diy::Serialization<T>::load(bb,x).
Definition: serialization.hpp:106
void save(BinaryBuffer &bb, const T &x)
Saves x to bb by calling diy::Serialization<T>::save(bb,x).
Definition: serialization.hpp:102
virtual int rank(int gid) const =0
returns the process rank of the block with global id gid (need not be local)
Definition: assigner.hpp:11
A serialization buffer.
Definition: serialization.hpp:19
void sort(Master &master, const Assigner &assigner, std::vector< T > Block::*values, std::vector< T > Block::*samples, size_t num_samples, const Cmp &cmp, int k=2, bool samples_only=false)
sample sort values of each block, store the boundaries between blocks in samples
Definition: algorithms.hpp:25