1 #ifndef DASH__HALO_REGION_H 2 #define DASH__HALO_REGION_H 4 #include <dash/halo/Types.h> 5 #include <dash/halo/Stencil.h> 6 #include <dash/iterator/GlobViewIter.h> 14 using namespace internal;
39 template <dim_t NumDimensions>
45 static constexpr
auto RegionsMax = NumRegionsMax<NumDimensions>;
48 using Coords_t = std::array<uint8_t, NumDimensions>;
49 using CoordsVec_t = std::vector<Self_t>;
50 using RegIndDepVec_t = std::vector<region_index_t>;
51 using RegIndexDim_t = std::pair<region_index_t, region_index_t>;
62 for(
dim_t i = 0; i < NumDimensions; ++i) {
71 template <
typename... Values>
80 this->_values = Self_t::coords(index);
83 static constexpr region_index_t center_index() {
84 return NumRegionsMax<NumDimensions> / 2;
87 static Coords_t center_coords() {
97 constexpr region_index_t
index()
const {
return index(this->_values); }
103 RegIndexDim_t index_dim = std::make_pair(0,0);
105 for(
dim_t d = 0; d < NumDimensions; ++d)
107 index_dim.first = index_dim.first * REGION_INDEX_BASE;
108 index_dim.second = 2 + index_dim.second * REGION_INDEX_BASE;
111 index_dim.first = 1 + index_dim.first * REGION_INDEX_BASE;
112 index_dim.second = 1 + index_dim.second * REGION_INDEX_BASE;
121 static constexpr region_index_t
index(
dim_t dim, RegionPos pos) {
122 region_coord_t coord = (pos == RegionPos::PRE) ? 0 : 2;
124 region_index_t
index = 0;
125 for(
dim_t d = 0; d < NumDimensions; ++d)
127 index = coord + index * REGION_INDEX_BASE;
129 index = 1 + index * REGION_INDEX_BASE;
137 template<
typename StencilPo
intT>
138 static constexpr region_index_t
index(
const StencilPointT& stencil) {
139 region_index_t
index = 0;
140 for(
dim_t d = 0; d < NumDimensions; ++d) {
142 index *= REGION_INDEX_BASE;
147 index = 2 + index * REGION_INDEX_BASE;
151 index = 1 + index * REGION_INDEX_BASE;
162 static region_index_t
index(
const Coords_t& coords) {
163 region_index_t
index = coords[0];
164 for(
dim_t d = 1; d < NumDimensions; ++d) {
167 index = coords[d] + index * REGION_INDEX_BASE;
169 index = coords[d] + index * REGION_INDEX_BASE;
183 region_index_t index_tmp =
index;
184 for(
auto i = (NumDimensions - 1); i >= 1; --i) {
185 auto res = std::div(static_cast<long>(index_tmp), static_cast<long>(REGION_INDEX_BASE));
187 index_tmp = res.quot;
189 coords[0] = index_tmp;
199 for(
auto d = 1; d < NumDimensions; ++d) {
215 for(
auto d = 0; d < NumDimensions; ++d) {
233 static RegIndDepVec_t boundary_dependencies(region_index_t
index) {
234 RegIndDepVec_t index_dep{};
236 if(index >= RegionsMax) {
237 DASH_LOG_ERROR(
"Invalid region index: %d", index);
242 auto region_coords =
Self_t(index);
243 auto level = region_coords.level();
250 index_dep.push_back(index);
255 CoordsVec_t found_coords{};
256 find_dep_regions(0, region_coords, found_coords);
258 for(
auto& reg_coords : found_coords) {
259 index_dep.push_back(reg_coords.index());
265 constexpr
bool operator==(
const Self_t& other)
const {
267 return this->_values == other._values;
270 constexpr
bool operator!=(
const Self_t& other)
const {
271 return !(*
this == other);
276 static void find_dep_regions(
dim_t dim_change,
const Self_t& current_coords, CoordsVec_t& dep_coords) {
277 dep_coords.push_back(current_coords);
279 for(
dim_t d = dim_change; d < NumDimensions; ++d) {
280 if(current_coords[d] != 1) {
281 auto new_coords = current_coords;
283 find_dep_regions(d+1, new_coords, dep_coords);
293 template <dim_t NumDimensions>
300 using region_extent_t = uint16_t;
307 : _coords(coords), _index(coords.
index()), _extent(extent),
320 : _coords(), _index(_coords.index()), _extent(0),
321 _rel_dim(RegionCoords_t::relevant_dim(_coords.values())),
322 _level(RegionCoords_t::level(_coords.values())) {}
327 template <
typename StencilT>
329 region_index_t
index = 0;
332 else if(stencil[0] > 0)
334 for(
auto d(1); d < NumDimensions; ++d) {
336 index *= REGION_INDEX_BASE;
337 else if(stencil[d] == 0)
338 index = 1 + index * REGION_INDEX_BASE;
340 index = 2 + index * REGION_INDEX_BASE;
349 constexpr region_index_t
index()
const {
return _index; }
359 constexpr region_extent_t
extent()
const {
return _extent; }
365 return _coords[
index];
368 constexpr
bool operator==(
const Self_t& other)
const {
369 return _coords.index() == other._coords.
index() && _extent == other._extent;
372 constexpr
bool operator!=(
const Self_t& other)
const {
373 return !(*
this == other);
389 region_index_t _index;
390 region_extent_t _extent = 0;
395 template <dim_t NumDimensions>
396 std::ostream& operator<<(std::ostream& os,
398 os <<
"dash::halo::RegionSpec<" << NumDimensions <<
">(" << (uint32_t) rs[0];
399 for(
auto i = 1; i < NumDimensions; ++i)
400 os <<
"," << (uint32_t) rs[i];
401 os <<
"), Extent:" << rs.
extent();
410 template <
typename ElementT,
typename PatternT,
typename GlobMemT>
420 using GlobMem_t = GlobMemT;
421 using ViewSpec_t =
typename PatternT::viewspec_type;
422 using extent_size_t =
typename ViewSpec_t::size_type;
423 using pattern_size_t =
typename PatternT::size_type;
424 using EnvRegInfo_t = EnvironmentRegionInfo<ViewSpec_t>;
425 using BorderPair_t =
typename EnvRegInfo_t::PrePostBool_t;
426 using RegBorders_t =
typename EnvRegInfo_t::RegionBorders_t;
430 GlobMem_t& globmem,
const PatternT& pattern,
431 const EnvRegInfo_t& env_reg_info)
432 : _region_spec(®ion_spec), _view(view),
433 _globmem(&globmem), _pattern(&pattern),
434 _env_reg_info(&env_reg_info),
435 _beg(&globmem, *_pattern, _view, 0),
436 _end(&globmem, *_pattern, _view, _view.size()) {
440 : _region_spec(other._region_spec),
442 _globmem(other._globmem),
443 _pattern(other._pattern),
444 _env_reg_info(other._env_reg_info),
445 _beg(_globmem, *_pattern, _view, 0),
446 _end(_globmem, *_pattern, _view, _view.size()) {
450 : _region_spec(std::move(other._region_spec)),
451 _view (std::move(other._view)),
452 _globmem(std::move(other._globmem)),
453 _pattern(std::move(other._pattern)),
454 _env_reg_info(std::move(other._env_reg_info)),
455 _beg(_globmem, *_pattern, _view, 0),
456 _end(_globmem, *_pattern, _view, _view.size()) {
460 _region_spec = other._region_spec;
462 _globmem = other._globmem;
463 _pattern = other._pattern;
464 _env_reg_info = other._env_reg_info;
465 _beg =
iterator(_globmem, *_pattern, _view, 0);
466 _end =
iterator(_globmem, *_pattern, _view, _view.size());
472 _region_spec = std::move(other._region_spec);
473 _view = std::move(other._view);
474 _globmem = std::move(other._globmem);
475 _pattern = std::move(other._pattern);
476 _env_reg_info = std::move(other._env_reg_info),
477 _beg =
iterator(_globmem, *_pattern, _view, 0);
478 _end =
iterator(_globmem, *_pattern, _view, _view.size());
483 const region_index_t
index()
const {
return _region_spec->index(); }
485 const RegionSpec_t& spec()
const {
return *_region_spec; }
487 const ViewSpec_t& view()
const {
return _view; }
489 pattern_size_t
size()
const {
return _view.size(); }
491 const RegBorders_t& border()
const {
return _env_reg_info->region_borders; }
493 bool is_border_region()
const {
return _env_reg_info->border_region; }
495 bool is_custom_region()
const {
496 return (_env_reg_info->border_region && _env_reg_info->boundary_prop == BoundaryProp::CUSTOM) ? true :
false;
505 BorderPair_t
border_dim(
dim_t dim)
const {
return _env_reg_info->region_borders[dim]; }
507 bool border_dim(
dim_t dim, RegionPos pos)
const {
508 if(pos == RegionPos::PRE) {
509 return _env_reg_info->region_borders[dim].first;
512 return _env_reg_info->region_borders[dim].second;
523 const PatternT* _pattern;
524 const EnvRegInfo_t* _env_reg_info;
529 template <
typename ElementT,
typename PatternT,
typename GlobMemT>
530 std::ostream& operator<<(std::ostream& os,
532 os <<
"dash::halo::Region<" <<
typeid(ElementT).name() <<
">" 533 <<
"( view: " << region.view() <<
"; region spec: " << region.spec()
534 <<
"; env_reg_info: {";
535 const auto& border = region.border();
536 for(
auto d = 0; d < border.size(); ++d) {
540 os <<
"(" << border[d].first << border[d].second <<
")";
543 <<
"; is border: " << region.is_border_region()
544 <<
"; is custom: " << region.is_custom_region();
555 #endif // DASH__HALO_REGION_H constexpr region_extent_t extent() const
Returns the extent.
RegionCoords(region_index_t index)
Constructor takes a region index to set up the region coordinates.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
static region_index_t index(const Coords_t &coords)
Returns the region index for a given RegionCoords.
size_t size()
Return the number of units in the global team.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
This class is a simple memory pool which holds allocates elements of size ValueType.
dim_t level() const
returns the number of coordinates unequal the center (1) for all dimensions
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
constexpr region_index_t index() const
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
dim_t level()
returns the number of coordinates unequal to the center (1) for all dimensions
dim_t relevant_dim() const
Returns the highest dimension with region values != 1.
static constexpr RegIndexDim_t index(dim_t dim)
Returns a region index for a given dimension and RegionPos.
RegionCoords(region_coord_t value, Values... values)
Constructor allows custom coordinate values and calculates the fitting region index.
Stencil point with raletive coordinates for N dimensions e.g.
N-Dimensional region coordinates and associated indices for all possible Halo/Boundary regions of a H...
static constexpr region_index_t index(const StencilPointT &stencil)
Returns a region index for a given dimension and RegionPos.
static dim_t level(const Coords_t &coords)
auto max = stencil.max(); level = 0 -> center (1,1) level = 1 -> main regions (e.g.
Base class for dimensional attributes, stores an n-dimensional value with identical type all dimensio...
constexpr dim_t ndim(const DimensionalType &d)
RegionSpec(const RegionCoords_t &coords, const region_extent_t extent)
Constructor using RegionCoords and the extent.
static dim_t relevant_dim(const Coords_t &coords)
Returns the highest dimension with region values != 1.
RegionCoords()
Default Constructor.
static constexpr region_index_t index(dim_t dim, RegionPos pos)
Returns a region index for a given dimension and RegionPos.
static region_index_t index(const StencilT &stencil)
Returns the region index for a given StencilPoint.
static Coords_t coords(const region_index_t index)
Provides RegionIter and some region metadata like RegionSpec, size etc.
constexpr region_coord_t operator[](const region_index_t index) const
Returns the RegionCoords for a given region index.
constexpr region_index_t index() const
Returns the region index.
constexpr const RegionCoords_t & coords() const
Returns the RegionCoords.
constexpr DimensionalType::extent_type extent(const DimensionalType &d)
Region specification connecting RegionCoords with an extent.
BorderPair_t border_dim(dim_t dim) const
Returns a pair of two booleans for a given dimension.
RegionSpec(region_index_t index, const region_extent_t extent)
Constructor using a region index and an extent.