Interface Documentation
Version: invalid
connectivity.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Los Alamos National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <cassert>
19 #include <cstdint>
20 #include <iostream>
21 
22 #include "entity_storage.hh"
23 #include "flecsi/util/array_ref.hh"
24 #include "flecsi/util/reorder.hh"
25 #include "index_space.hh"
26 #include "utility_types.hh"
27 
28 namespace flecsi {
29 namespace topo {
30 
31 /*----------------------------------------------------------------------------*
32  * class connectivity_t
33  *----------------------------------------------------------------------------*/
34 
35 //-----------------------------------------------------------------//
39 //-----------------------------------------------------------------//
40 
42 {
43 public:
44  using id_t = util::id_t;
45  using offset_t = util::offset_t;
46 
47  connectivity_t(const connectivity_t &) = delete;
48 
49  connectivity_t & operator=(const connectivity_t &) = delete;
50 
51  // allow move operations
52  connectivity_t(connectivity_t &&) = default;
53  connectivity_t & operator=(connectivity_t &&) = default;
54 
56  connectivity_t() : index_space_(false) {}
57 
58  auto entity_storage() {
59  return index_space_.storage();
60  }
61 
62  template<class STORAGE_TYPE>
63  void set_entity_storage(STORAGE_TYPE s) {
64  index_space_.set_storage(s);
65  }
66 
67  //-----------------------------------------------------------------//
69  //-----------------------------------------------------------------//
70  void clear() {
71  index_space_.clear();
72  offsets_.clear();
73  } // clear
74 
75  //-----------------------------------------------------------------//
80  //-----------------------------------------------------------------//
81  void init(const connection_vector_t & cv) {
82 
83  clear();
84 
85  // populate the to id's and add from offsets for each connectivity group
86 
87  size_t start = index_space_.begin_push_();
88 
89  size_t n = cv.size();
90 
91  for(size_t i = 0; i < n; ++i) {
92  const id_vector_t & iv = cv[i];
93 
94  for(id_t id : iv) {
95  index_space_.batch_push_(id);
96  } // for
97 
98  offsets_.add_count(static_cast<std::uint32_t>(iv.size()));
99  } // for
100 
101  index_space_.end_push_(start);
102  } // init
103 
104  //-----------------------------------------------------------------//
108  //-----------------------------------------------------------------//
109  void resize(index_vector_t & num_conns) {
110  clear();
111 
112  size_t n = num_conns.size();
113 
114  uint64_t size = 0;
115 
116  for(size_t i = 0; i < n; ++i) {
117  uint32_t count = static_cast<std::uint32_t>(num_conns[i]);
118  offsets_.add_count(count);
119  size += count;
120  } // for
121 
122  index_space_.resize_(size);
123  index_space_.fill_(id_t(0));
124  } // resize
125 
126  //-----------------------------------------------------------------//
128  //-----------------------------------------------------------------//
129  void push(id_t id) {
130  index_space_.push_(id);
131  } // push
132 
133  //-----------------------------------------------------------------//
135  //-----------------------------------------------------------------//
136  std::ostream & dump(std::ostream & stream) {
137  for(size_t i = 0; i < offsets_.size(); ++i) {
138  offset_t oi = offsets_[i];
139  for(size_t j = 0; j < oi.count(); ++j) {
140  stream << index_space_(oi.start() + j).entity() << std::endl;
141  }
142  stream << std::endl;
143  }
144 
145  stream << "=== indices" << std::endl;
146  for(id_t id : index_space_.ids()) {
147  stream << id.entity() << std::endl;
148  } // for
149 
150  stream << "=== offsets" << std::endl;
151  for(size_t i = 0; i < offsets_.size(); ++i) {
152  offset_t oi = offsets_[i];
153  stream << oi.start() << " : " << oi.count() << std::endl;
154  } // for
155  return stream;
156  } // dump
157 
158  void dump() {
159  dump(std::cout);
160  } // dump
161 
162  //-----------------------------------------------------------------//
164  //-----------------------------------------------------------------//
165  const auto & get_entities() const {
166  return index_space_.id_storage();
167  }
168  //-----------------------------------------------------------------//
170  //-----------------------------------------------------------------//
171  id_t * get_entities(size_t index) {
172  assert(index < offsets_.size());
173  return index_space_.id_array() + offsets_[index].start();
174  }
175 
176  //-----------------------------------------------------------------//
178  //-----------------------------------------------------------------//
179  id_t * get_entities(size_t index, size_t & count) {
180  assert(index < offsets_.size());
181  offset_t o = offsets_[index];
182  count = o.count();
183  return index_space_.id_array() + o.start();
184  }
185 
186  //-----------------------------------------------------------------//
188  //-----------------------------------------------------------------//
189  auto get_entity_vec(size_t index) const {
190  assert(index < offsets_.size());
191  offset_t o = offsets_[index];
192  return util::make_array_ref(index_space_.id_array() + o.start(), o.count());
193  }
194 
195  //-----------------------------------------------------------------//
197  //-----------------------------------------------------------------//
198  void reverse_entities(size_t index) {
199  assert(index < offsets_.size());
200  offset_t o = offsets_[index];
201  std::reverse(index_space_.index_begin_() + o.start(),
202  index_space_.index_begin_() + o.end());
203  }
204 
205  //-----------------------------------------------------------------//
207  //-----------------------------------------------------------------//
208  template<class U>
209  void reorder_entities(size_t index, U && order) {
210  assert(index < offsets_.size());
211  offset_t o = offsets_[index];
212  assert(order.size() == o.count());
213  util::reorder(
214  order.begin(), order.end(), index_space_.id_array() + o.start());
215  }
216 
217  //-----------------------------------------------------------------//
219  //-----------------------------------------------------------------//
220  bool empty() const {
221  return index_space_.empty();
222  }
223 
224  //-----------------------------------------------------------------//
226  //-----------------------------------------------------------------//
227  void set(size_t from_local_id, id_t to_id, size_t pos) {
228  index_space_(offsets_[from_local_id].start() + pos) = to_id;
229  }
230 
231  //-----------------------------------------------------------------//
233  //-----------------------------------------------------------------//
234  size_t from_size() const {
235  return offsets_.size();
236  }
237 
238  //-----------------------------------------------------------------//
240  //-----------------------------------------------------------------//
241  size_t to_size() const {
242  return index_space_.size();
243  }
244 
245  //-----------------------------------------------------------------//
247  //-----------------------------------------------------------------//
248  template<size_t DOM, size_t NUM_DOMAINS>
249  void set(entity_vector_t<NUM_DOMAINS> & ev, connection_vector_t & conns) {
250  clear();
251 
252  size_t n = conns.size();
253 
254  size_t size = 0;
255 
256  for(size_t i = 0; i < n; i++) {
257  uint32_t count = conns[i].size();
258  offsets_.add_count(count);
259  size += count;
260  }
261 
262  index_space_.begin_push_(size);
263 
264  for(size_t i = 0; i < n; ++i) {
265  const id_vector_t & conn = conns[i];
266  uint64_t m = conn.size();
267 
268  for(size_t j = 0; j < m; ++j) {
269  index_space_.batch_push_(ev[conn[j]]->template global_id<DOM>());
270  }
271  }
272  }
273 
274  const auto & to_id_storage() const {
275  return index_space_.id_storage();
276  }
277 
278  auto & to_id_storage() {
279  return index_space_.id_storage_();
280  }
281 
282  auto & get_index_space() {
283  return index_space_;
284  }
285 
286  auto & get_index_space() const {
287  return index_space_;
288  }
289 
290  auto range(size_t i) const {
291  return offsets_.range(i);
292  }
293 
294  auto & offsets() {
295  return offsets_;
296  }
297 
298  const auto & offsets() const {
299  return offsets_;
300  }
301 
302  void add_count(uint32_t count) {
303  offsets_.add_count(count);
304  }
305 
306  //-----------------------------------------------------------------//
309  //-----------------------------------------------------------------//
310  void end_from() {
311  offsets_.add_end(index_space_.size());
312  } // end_from
313 
315  index_space_;
316 
317  offset_storage_t offsets_;
318 }; // class connectivity_t
319 
320 } // namespace topo
321 } // namespace flecsi
connectivity_t()
Constructor.
Definition: connectivity.hh:56
size_t to_size() const
Return the number of to entities.
Definition: connectivity.hh:241
void reorder_entities(size_t index, U &&order)
Get the entities of the specified from index and return the count.
Definition: connectivity.hh:209
Definition: entity_storage.hh:28
uint32_t count() const
Get the count (number) of elements represented by this offset range.
Definition: offset.hh:91
Definition: id.hh:36
void push(id_t id)
Push a single id into the current from group.
Definition: connectivity.hh:129
auto get_entity_vec(size_t index) const
Get the entities of the specified from index and return the count.
Definition: connectivity.hh:189
std::ostream & dump(std::ostream &stream)
Debugging method. Dump the raw vectors of the connection.
Definition: connectivity.hh:136
offset represents an offset range (a start index plus a count of elements) in a single uint64_t...
Definition: offset.hh:34
bool empty() const
True if the connectivity is empty (hasn&#39;t been populated).
Definition: connectivity.hh:220
void resize(index_vector_t &num_conns)
Definition: connectivity.hh:109
uint64_t start() const
Get the start index of the offset range.
Definition: offset.hh:82
int start(const std::function< int()> &action)
Definition: execution.hh:69
id_t * get_entities(size_t index, size_t &count)
Get the entities of the specified from index and return the count.
Definition: connectivity.hh:179
Definition: index_space.hh:85
void reverse_entities(size_t index)
Get the entities of the specified from index and return the count.
Definition: connectivity.hh:198
void init(const connection_vector_t &cv)
Definition: connectivity.hh:81
std::vector< entity_base< NUM_DOMAINS > * > entity_vector_t
Definition: utility_types.hh:167
Definition: index.hh:64
size_t from_size() const
Return the number of from entities.
Definition: connectivity.hh:234
const auto & get_entities() const
Get the to id&#39;s vector.
Definition: connectivity.hh:165
connectivity_t provides basic connectivity information in a compressed storage format.
Definition: connectivity.hh:41
id_t * get_entities(size_t index)
Get the entities of the specified from index.
Definition: connectivity.hh:171
void clear()
Clear the storage arrays for this instance.
Definition: connectivity.hh:70
void end_from()
Definition: connectivity.hh:310
Definition: control.hh:31