1 #ifndef DASH__HALO_STENCIL_H 2 #define DASH__HALO_STENCIL_H 4 #include <dash/halo/Types.h> 6 #include <dash/Dimensional.h> 12 using namespace internal;
18 template <dim_t NumDimensions,
typename CoeffT =
double>
21 using coefficient_t = CoeffT;
34 for(
dim_t d = 0; d < NumDimensions; ++d) {
45 template <
typename... Values>
47 typename std::enable_if<
sizeof...(Values) == NumDimensions - 1,
48 spoint_value_t>::type value,
57 template <
typename... Values>
59 typename std::enable_if<
sizeof...(Values) == NumDimensions - 1,
60 CoeffT>::type coefficient,
61 spoint_value_t value, Values... values)
63 _coefficient(coefficient) {}
71 for(
dim_t d = 0; d < NumDimensions; ++d)
72 max = std::max(max, (
int) std::abs(this->_values[d]));
79 template <
typename ElementCoordsT>
87 template <
typename ElementCoordsT>
89 ElementCoordsT coords,
91 for(
dim_t d = 0; d < NumDimensions; ++d) {
92 coords[d] += stencilp[d];
103 template <
typename ElementCoordsT,
typename ViewSpecT>
105 ElementCoordsT coords,
const ViewSpecT& view)
const {
107 for(
dim_t d = 0; d < NumDimensions; ++d) {
108 coords[d] += this->_values[d];
109 if(coords[d] < view.offset(d) || coords[d] >= view.offset(d) + view.extent(d))
113 return std::make_pair(coords, halo);
124 template <
typename ElementCoordsT,
typename ViewSpecT>
126 ElementCoordsT coords,
const ViewSpecT& view)
const {
127 for(
dim_t d = 0; d < NumDimensions; ++d) {
128 coords[d] += this->_values[d];
129 if(coords[d] < view.offset(d) || coords[d] >= view.offset(d) + view.extent(d))
130 return std::make_pair(coords,
true);
133 return std::make_pair(coords,
false);
142 CoeffT _coefficient = 1.0;
145 template <dim_t NumDimensions,
typename CoeffT>
146 std::ostream& operator<<(
148 os <<
"dash::halo::StencilPoint<" << NumDimensions <<
">" 149 <<
"(coefficient = " << stencil_point.
coefficient() <<
" - points: ";
150 for(
auto d = 0; d < NumDimensions; ++d) {
154 os << stencil_point[d];
166 template <
typename StencilPo
intT, std::
size_t NumStencilPo
ints>
173 using stencil_size_t = std::size_t;
174 using stencil_index_t = std::size_t;
175 using StencilArray_t = std::array<StencilPointT, NumStencilPoints>;
176 using StencilPoint_t = StencilPointT;
177 using DistanceDim_t = std::pair<spoint_value_t, spoint_value_t>;
178 using DistanceAll_t = std::array<DistanceDim_t, NumDimensions>;
179 using DistanceTotal_t = std::array<spoint_distance_t, NumDimensions>;
187 constexpr
StencilSpec(
const StencilArray_t& specs) : _specs(specs) {}
195 template <
typename... Values>
196 constexpr
StencilSpec(
const StencilPointT& value,
const Values&... values)
197 : _specs{ { value, (StencilPointT) values... } } {
198 static_assert(
sizeof...(values) == NumStencilPoints - 1,
199 "Invalid number of stencil point arguments");
211 constexpr
const StencilArray_t&
specs()
const {
return _specs; }
217 return NumStencilPoints;
228 const std::pair<stencil_index_t, bool>
index(StencilPointT stencil)
const {
229 for(
auto i = 0; i < _specs.size(); ++i) {
230 if(_specs[i] == stencil)
231 return std::make_pair(i,
true);
234 return std::make_pair(0,
false);
243 DistanceTotal_t total_dist{};
244 auto minmax = minmax_distances();
245 for(
auto d = 0; d < NumDimensions; ++d) {
258 auto minmax = minmax_distances();
268 DistanceAll_t max_dist{};
269 for(
const auto& stencil_point : _specs) {
270 for(
auto d = 0; d < NumDimensions; ++d) {
271 if(stencil_point[d] < max_dist[d].
first) {
272 max_dist[d].first = stencil_point[d];
275 if(stencil_point[d] > max_dist[d].
second)
276 max_dist[d].second = stencil_point[d];
288 DistanceDim_t max_dist{};
289 for(
const auto& stencil_point : _specs) {
290 if(stencil_point[dim] < max_dist.first) {
291 max_dist.first = stencil_point[dim];
294 if(stencil_point[dim] > max_dist.second)
295 max_dist.second = stencil_point[dim];
304 return _specs[
index];
308 StencilArray_t _specs{};
311 template <
typename StencilPo
intT, std::
size_t NumStencilPo
ints>
312 std::ostream& operator<<(
314 os <<
"dash::halo::StencilSpec<" << NumStencilPoints <<
">" 316 for(
auto i = 0; i < NumStencilPoints; ++i) {
327 template <
typename StencilPo
intT>
330 using stencil_dist_t = spoint_value_t;
331 using StencilPerm_t = std::vector<StencilPointT>;
337 static constexpr decltype(
auto) full_stencil_spec(stencil_dist_t dist) {
340 using StencilArray_t =
typename StencilSpec_t::StencilArray_t;
342 StencilPerm_t stencil_perms;
343 StencilArray_t points;
344 StencilPointT start_stencil;
345 for(
dim_t d = 0; d < NumDimensions; ++d) {
346 start_stencil[d] = std::abs(dist);
348 permutate_stencil_points(0, start_stencil, stencil_perms, dist);
351 for(
const auto& elem : stencil_perms) {
353 for(
dim_t d = 0; d < NumDimensions; ++d) {
360 points[count] = elem;
369 static void permutate_stencil_points(
dim_t dim_change,
const StencilPointT& current_stencil, StencilPerm_t& perm_stencil, stencil_dist_t dist) {
370 perm_stencil.push_back(current_stencil);
372 for(
dim_t d = dim_change; d < NumDimensions; ++d) {
373 if(current_stencil[d] != 0) {
374 auto new_stencil = current_stencil;
376 permutate_stencil_points(d+1, new_stencil, perm_stencil, dist);
377 new_stencil[d] = -dist;
378 permutate_stencil_points(d+1, new_stencil, perm_stencil, dist);
389 #endif // DASH__HALO_STENCIL_H spoint_distance_t total_distances(dim_t dim) const
Returns the total distances of all stencil points for all dimensions.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
StencilSpec(const Self_t &other)
Copy Constructor.
This class is a simple memory pool which holds allocates elements of size ValueType.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
constexpr const StencilArray_t & specs() const
StencilPoint()
Default Contructor.
Reduce operands to their maximum value.
DistanceDim_t minmax_distances(dim_t dim) const
Returns the minimal and maximal distances of all stencil points for the given dimension.
Stencil point with raletive coordinates for N dimensions e.g.
static ElementCoordsT stencil_coords(ElementCoordsT coords, const StencilPoint< NumDimensions, CoeffT > &stencilp)
Returns coordinates adjusted by a given stencil point.
static constexpr stencil_size_t num_stencil_points()
constexpr const StencilPointT & operator[](stencil_index_t index) const
ElementCoordsT stencil_coords(ElementCoordsT &coords) const
Returns coordinates adjusted by stencil point.
CoeffT coefficient() const
Returns the coefficient for this stencil point.
int max() const
Returns maximum distance to center over all dimensions.
Base class for dimensional attributes, stores an n-dimensional value with identical type all dimensio...
constexpr dim_t ndim(const DimensionalType &d)
DistanceAll_t minmax_distances() const
Returns the minimal and maximal distances of all stencil points for all dimensions.
const std::pair< stencil_index_t, bool > index(StencilPointT stencil) const
Returns the stencil point index for a given StencilPoint.
constexpr StencilSpec(const StencilPointT &value, const Values &... values)
Constructor.
std::pair< ElementCoordsT, bool > stencil_coords_check_abort(ElementCoordsT coords, const ViewSpecT &view) const
Returns coordinates adjusted by a stencil point and a boolean to indicate a if the adjusted coordinat...
A collection of stencil points (Stencil) e.g.
std::pair< ElementCoordsT, bool > stencil_coords_check(ElementCoordsT coords, const ViewSpecT &view) const
Returns coordinates adjusted by a stencil point and a boolean to indicate a if the adjusted coordinat...
constexpr StencilPoint(typename std::enable_if< sizeof...(Values)==NumDimensions - 1, CoeffT >::type coefficient, spoint_value_t value, Values... values)
Constructor.
constexpr StencilPoint(typename std::enable_if< sizeof...(Values)==NumDimensions - 1, spoint_value_t >::type value, Values... values)
Constructor.
constexpr StencilSpec(const StencilArray_t &specs)
Constructor.
DistanceTotal_t total_distances() const
Returns the total distances of all stencil points for all dimensions.