Interface Documentation
Version: invalid
storage.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 #if !defined(__FLECSI_PRIVATE__)
19 #error Do not include this file directly!
20 #endif
21 
22 #include "../entity_storage.hh"
23 #include "../index_space.hh"
24 #include "flecsi/run/backend.hh"
27 #include "flecsi/util/id.hh"
28 
29 #include <array>
30 
31 namespace flecsi {
32 namespace topo {
33 
34 template<size_t, size_t>
36 
40 template<size_t NUM_DIMS, size_t NUM_DOMAINS, size_t NUM_INDEX_SUBSPACES>
41 struct mesh_storage {
42  static constexpr size_t num_partitions = 5;
43 
44  using id_t = util::id_t;
45 
46  using index_spaces_t = std::array<
48  NUM_DIMS + 1>;
49 
50  using index_subspaces_t = std::array<index_space<mesh_entity_base_ *,
51  false,
52  true,
53  false,
54  void,
56  NUM_INDEX_SUBSPACES>;
57 
58  using partition_index_spaces_t = std::array<index_space<mesh_entity_base_ *,
59  false,
60  false,
61  true,
62  void,
63  topology_storage>,
64  NUM_DIMS + 1>;
65 
66  // array of array of domain_connectivity
67  std::array<std::array<domain_connectivity<NUM_DIMS>, NUM_DOMAINS>,
68  NUM_DOMAINS>
69  topology;
70 
71  std::array<index_spaces_t, NUM_DOMAINS> index_spaces;
72 
73  index_subspaces_t index_subspaces;
74 
75  std::array<std::array<partition_index_spaces_t, NUM_DOMAINS>, num_partitions>
76  partition_index_spaces;
77 
78  size_t color;
79 
80  mesh_storage() {
81  auto & context_ = run::context::instance();
82  color = context_.color();
83  } // mesh_storage
84 
85  void init_entities(size_t domain,
86  size_t dim,
87  mesh_entity_base_ * entities,
88  util::id_t * ids,
89  size_t,
90  size_t num_entities,
91  size_t num_exclusive,
92  size_t num_shared,
93  size_t num_ghost,
94  bool read) {
95  auto & is = index_spaces[domain][dim];
96 
97  auto s = is.storage();
98  s->set_buffer(entities, num_entities, read);
99 
100  auto & id_storage = is.id_storage();
101  id_storage.set_buffer(ids, num_entities, true);
102 
103  for(auto & domain_connectivities : topology) {
104  auto & domain_connectivity = domain_connectivities[domain];
105  for(size_t d = 0; d <= NUM_DIMS; ++d) {
106  domain_connectivity.get(d, dim).set_entity_storage(s);
107  } // for
108  } // for
109 
110  if(!read) {
111  return;
112  }
113 
114  is.set_end(num_entities);
115 
116  size_t shared_end = num_exclusive + num_shared;
117  size_t ghost_end = shared_end + num_ghost;
118 
119  for(size_t partition = 0; partition < num_partitions; ++partition) {
120  auto & isp = partition_index_spaces[partition][domain][dim];
121  isp.set_storage(s);
122  isp.set_id_storage(&id_storage);
123 
124  switch(partition_t(partition)) {
125  case exclusive:
126  isp.set_begin(0);
127  isp.set_end(num_exclusive);
128  break;
129  case shared:
130  isp.set_begin(num_exclusive);
131  isp.set_end(shared_end);
132  break;
133  case ghost:
134  isp.set_begin(shared_end);
135  isp.set_end(ghost_end);
136  break;
137  case owned:
138  isp.set_begin(0);
139  isp.set_end(shared_end);
140  break;
141  default:
142  break;
143  }
144  }
145  } // init_entities
146 
147  void init_index_subspace(size_t,
148  size_t index_subspace,
149  size_t domain,
150  size_t dim,
151  util::id_t * ids,
152  size_t,
153  bool read) {
154 
155  auto & context_ = run::context::instance();
156  auto & ssm = context_.index_subspace_info();
157  auto itr = ssm.find(index_subspace);
158  flog_assert(itr != ssm.end(), "invalid index subspace");
159  const run::context_t::index_subspace_info_t & si = itr->second;
160 
161  auto & is = index_spaces[domain][dim];
162  auto & iss = index_subspaces[index_subspace];
163 
164  iss.set_storage(is.storage());
165 
166  auto & id_storage = iss.id_storage();
167  id_storage.set_buffer(ids, si.capacity, si.size);
168 
169  if(!read) {
170  return;
171  }
172 
173  iss.set_end(si.size);
174  } // init_index_subspaces
175 
176  void init_connectivity(size_t from_domain,
177  size_t to_domain,
178  size_t from_dim,
179  size_t to_dim,
180  util::offset_t * offsets,
181  size_t num_offsets,
182  util::id_t * indices,
183  size_t num_indices,
184  bool read) {
185  // TODO - this is an initial implementation for testing purposes.
186  // We may wish to store the buffer pointers coming from Legion directly
187  // into the connectivity
188 
189  auto & conn = topology[from_domain][to_domain].get(from_dim, to_dim);
190 
191  auto & id_storage = conn.get_index_space().id_storage();
192  id_storage.set_buffer(indices, num_indices, read);
193 
194  conn.offsets().storage().set_buffer(offsets, num_offsets, read);
195 
196  if(read) {
197  conn.get_index_space().set_end(num_indices);
198  }
199  } // init_connectivities
200 
201  template<class T, size_t DOM, class... ARG_TYPES>
202  T * make(ARG_TYPES &&... args) {
203  using dtype = domain_entity<DOM, T>;
204 
205  auto & is = index_spaces[DOM][T::dimension].template cast<dtype>();
206  size_t entity = is.size();
207 
208  auto placement_ptr = static_cast<T *>(is.storage()->buffer()) + entity;
209  auto ent = new(placement_ptr) T(std::forward<ARG_TYPES>(args)...);
210 
211  id_t global_id = id_t::make<T::dimension, DOM>(entity, color);
212  ent->template set_global_id<DOM>(global_id);
213 
214  auto & id_storage = is.id_storage();
215 
216  id_storage[entity] = global_id;
217 
218  is.pushed();
219 
220  return ent;
221  } // make
222 
223  template<class T, size_t DOM, class... ARG_TYPES>
224  T * make(const id_t & id, ARG_TYPES &&... args) {
225  using dtype = domain_entity<DOM, T>;
226 
227  auto & is = index_spaces[DOM][T::dimension].template cast<dtype>();
228 
229  size_t entity = id.entity();
230 
231  auto placement_ptr = static_cast<T *>(is.storage()->buffer()) + entity;
232  auto ent = new(placement_ptr) T(std::forward<ARG_TYPES>(args)...);
233 
234  ent->template set_global_id<DOM>(id);
235 
236  auto & id_storage = is.id_storage();
237 
238  id_storage[entity] = id;
239 
240  is.pushed();
241 
242  return ent;
243  } // make
244 
245 }; // class mesh_storage
246 
247 } // namespace topo
248 } // namespace flecsi
Definition: id.hh:36
Definition: types.hh:173
Definition: typeify.hh:31
offset represents an offset range (a start index plus a count of elements) in a single uint64_t...
Definition: offset.hh:34
Definition: array_buffer.hh:71
#define flog_assert(test, message)
Definition: flog.hh:411
mesh_entity parameterizes a mesh entity base with its dimension and number of domains ...
Definition: storage.hh:35
Definition: index_space.hh:85
Definition: storage.hh:41
domain_entity is a simple wrapper to mesh entity that associates with its a domain id ...
Definition: array_buffer.hh:24
Definition: utility_types.hh:95
Definition: control.hh:31