Skip to content

Commit

Permalink
Extended nview, copy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fuchsto committed Jun 7, 2017
1 parent 514e47c commit acccf22
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 52 deletions.
56 changes: 56 additions & 0 deletions dash/examples/ex.02.matrix-copy/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#include <libdash.h>

#include <vector>
#include <iostream>

using std::cout;
using std::endl;


int main(int argc, char **argv)
{
constexpr int elem_per_unit = 1000;
dash::init(&argc, &argv);

std::vector<double> vec(100);
std::fill(vec.begin(), vec.end(), dash::myid());

dash::NArray<double, 2> matrix;

dash::SizeSpec<2> sizespec(dash::size(), elem_per_unit);
dash::DistributionSpec<2> distspec(dash::BLOCKED, dash::NONE);
dash::TeamSpec<2> teamspec(dash::size(), 1);

matrix.allocate(sizespec, distspec, teamspec);

if (dash::myid() == 0) {
// ostream<< overload for iterators is broken
// std::cout << matrix.row(1).begin() << std::endl;
// dash::copy(&vec[0], &vec[0] + vec.size(), matrix.row(1).begin() + 100);

auto dest_range = dash::sub<0>(
1,2, matrix);

using globiter_t = decltype(matrix.begin());

cout << "matrix.row(1).begin() + 100: "
<< (matrix.row(1).begin() + 100)
<< endl;
cout << "sub... expression: "
<< (dest_range.begin() + 100)
<< endl;
cout << "view expr. cast to gptr: "
<< static_cast<globiter_t>(dest_range.begin() + 100)
<< endl;

dash::copy(&vec[0],
&vec[0] + vec.size(),
static_cast<globiter_t>(dest_range.begin()));
}

matrix.barrier();
dash::finalize();

return 0;
}
21 changes: 17 additions & 4 deletions dash/include/dash/algorithm/Copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,19 @@ GlobOutputIt copy(
auto in_blocks = dash::blocks(in_g_range);
DASH_LOG_TRACE_VAR("dash::copy()", in_blocks);

auto l_in_blocks = dash::local(in_blocks);
DASH_LOG_TRACE_VAR("dash::copy()", in_blocks);

auto out_blocks = dash::blocks(out_g_range);
DASH_LOG_TRACE_VAR("dash::copy()", out_blocks);

// Iterator to active output block:
auto out_block_it = out_blocks.begin();
// Iterator local blocks in input range:
for (auto l_in_block : l_in_blocks) {
DASH_LOG_TRACE_VAR("dash::copy()", l_in_block);
}

// local view on in/out ranges:
auto out_l_range = dash::local(out_g_range);
DASH_LOG_TRACE("dash::copy()", "local(range(out_gi, out_ge)):",
Expand All @@ -1192,10 +1202,13 @@ GlobOutputIt copy(
DASH_LOG_TRACE("dash::copy()", "index(local(range(in_gi, in_ge))):",
dash::index(in_l_range));

// copy local to global range:
auto out_l_end = std::copy(dash::begin(in_l_range),
dash::end(in_l_range),
dash::begin(out_l_range));
// Only sufficient if input- and output ranges have identical
// decomposition:
//
// auto out_l_end = std::copy(dash::begin(in_l_range),
// dash::end(in_l_range),
// dash::begin(out_l_range));

return out_first + num_elements;
}

Expand Down
4 changes: 2 additions & 2 deletions dash/include/dash/iterator/internal/IteratorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ class IndexIteratorBase
}

derived_t & operator++() {
_pos++;
++_pos;
return derived();
}

derived_t & operator--() {
_pos--;
++_pos;

This comment has been minimized.

Copy link
@devreal

devreal Jun 7, 2017

Member

That should be --_pos

This comment has been minimized.

Copy link
@fuchsto

fuchsto Jun 7, 2017

Author Member

Be praised!

return derived();
}

Expand Down
18 changes: 18 additions & 0 deletions dash/include/dash/view/IndexSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,24 @@ class IndexSetLocal
return this->pattern().local_extents()[shape_dim];
}

// ---- offsets ---------------------------------------------------------

#if TODO
constexpr std::array<index_type, NDim>
offsets() const {
return std::array<index_type, NDim> { };
}

template <std::size_t ShapeDim>
constexpr index_type offset() const {
return derived().offsets()[ShapeDim];
}

constexpr index_type offset(std::size_t shape_dim) const {
return derived().offsets()[shape_dim];
}
#endif

// ---- size ------------------------------------------------------------

constexpr size_type size(std::size_t sub_dim) const noexcept {
Expand Down
17 changes: 13 additions & 4 deletions dash/include/dash/view/Origin.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,25 @@ global_origin(const ViewT & view)

template <class ViewT>
constexpr auto
origin(const ViewT & view)
origin(ViewT && view)
-> typename std::enable_if<
( dash::view_traits<ViewT>::is_view::value &&
( dash::view_traits<
typename std::decay<ViewT>::type
>::is_view::value &&
dash::view_traits<
typename dash::view_traits<ViewT>::domain_type
typename dash::view_traits<
typename std::decay<ViewT>::type
>::domain_type
>::is_local::value ),
const typename dash::view_traits<ViewT>::origin_type::local_type &
// typename dash::view_traits<
// typename std::decay<ViewT>::type
// >::origin_type::local_type
>::type {
// Recurse to origin of local view:
return dash::local(dash::global_origin(view.domain()));
return dash::local(
dash::global_origin(
std::forward<ViewT>(view).domain()));
}

template <class ViewT>
Expand Down
11 changes: 6 additions & 5 deletions dash/include/dash/view/ViewIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ViewIterator
typedef typename base_t::value_type value_type;
typedef typename IndexSetType::index_type index_type;
typedef typename DomainIterator::pattern_type pattern_type;
typedef typename DomainIterator::local_type local_type;
private:
DomainIterator _domain_it;
IndexSetType _index_set;
Expand Down Expand Up @@ -91,11 +92,11 @@ class ViewIterator
return (_index_set)[this->pos()];
}

constexpr const value_type * local() const {
constexpr const local_type local() const {
return (_domain_it + (_index_set[this->pos()])).local();
}

inline value_type * local() {
inline local_type local() {
return (_domain_it + (_index_set[this->pos()])).local();
}

Expand All @@ -111,9 +112,9 @@ class ViewIterator
return (_domain_it + _index_set[this->pos()]);
}

// explicit operator DomainIterator() {
// return (_domain_it + _index_set[this->pos()]);
// }
explicit operator DomainIterator() {
return (_domain_it + _index_set[this->pos()]);
}

constexpr const pattern_type & pattern() const {
return _domain_it.pattern();
Expand Down
11 changes: 8 additions & 3 deletions dash/include/dash/view/ViewMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,12 @@ class ViewLocalMod
template <dim_t ShapeDim>
constexpr size_type extent() const {
return _index_set.template extent<ShapeDim>();
// return _index_set.extents()[ShapeDim];
}

constexpr size_type extent(dim_t shape_dim) const {
return _index_set.extent(shape_dim);
// return _index_set.extents()[shape_dim];
}

// ---- offsets ---------------------------------------------------------
Expand Down Expand Up @@ -483,7 +485,8 @@ class ViewLocalMod
return iterator(
dash::begin(
dash::local(
const_cast<origin_type &>(dash::origin(*this)) )),
const_cast<origin_type &>(
dash::origin(*this)) )),
_index_set, 0);
}

Expand All @@ -499,7 +502,8 @@ class ViewLocalMod
return iterator(
dash::begin(
dash::local(
const_cast<origin_type &>(dash::origin(*this)) )),
const_cast<origin_type &>(
dash::origin(*this)) )),
_index_set, _index_set.size());
}

Expand All @@ -515,7 +519,8 @@ class ViewLocalMod
return *iterator(
dash::begin(
dash::local(
const_cast<origin_type &>(dash::origin(*this)) )),
const_cast<origin_type &>(
dash::origin(*this)) )),
_index_set, offset);
}

Expand Down
32 changes: 14 additions & 18 deletions dash/include/dash/view/ViewMod1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ class ViewSubMod<DomainType, SubDim, 1>

constexpr const_iterator end() const {
return const_iterator(dash::origin(*this).begin(),
_index_set, _index_set.size());
_index_set, _index_set.size() - 1) + 1;
}

iterator end() {
return iterator(const_cast<origin_type &>(
dash::origin(*this)
).begin(),
_index_set, _index_set.size());
_index_set, _index_set.size() - 1) + 1;
}

constexpr const_reference operator[](int offset) const {
Expand Down Expand Up @@ -483,8 +483,6 @@ struct view_traits<IteratorRangeLocalOrigin<Iterator, Sentinel> > {
typedef IteratorRangeOrigin<Iterator, Sentinel> origin_type;
typedef RangeT image_type;

//typedef typename Iterator::pattern_type pattern_type;
//typedef std::integral_constant<dim_t, pattern_type::ndim()> rank;
typedef std::integral_constant<dim_t, 1> rank;

typedef RangeT local_type;
Expand Down Expand Up @@ -641,7 +639,7 @@ class IteratorRangeLocalOrigin
global_type & global() {
return dash::global(dash::domain(*this));
}
};
}; // IteratorRangeLocalOrigin

// -----------------------------------------------------------------------
// Iterator Range Origin
Expand All @@ -665,8 +663,6 @@ struct view_traits<IteratorRangeOrigin<Iterator, Sentinel> > {
typedef IteratorRangeOrigin<Iterator, Sentinel> origin_type;
typedef IteratorRangeOrigin<Iterator, Sentinel> image_type;

//typedef typename Iterator::pattern_type pattern_type;
//typedef std::integral_constant<dim_t, pattern_type::ndim()> rank;
typedef std::integral_constant<dim_t, 1> rank;

typedef RangeT global_type;
Expand Down Expand Up @@ -773,7 +769,7 @@ class IteratorRangeOrigin
self_t & global() {
return *this;
}
};
}; // IteratorRangeOrigin

// -----------------------------------------------------------------------
// Iterator Range Origin (local pointers)
Expand Down Expand Up @@ -975,7 +971,7 @@ class IteratorRangeOrigin<
constexpr size_type size() const {
return std::distance(_begin, _end);
}
};
}; // IteratorRangeOrigin<Iter *, Sent *>
#endif

// ----------------------------------------------------------------------
Expand All @@ -994,8 +990,6 @@ struct view_traits<IteratorRange<RangeOrigin> > {
typedef RangeOrigin origin_type;
typedef RangeT image_type;

//typedef typename RangeOrigin::pattern_type pattern_type;
//typedef std::integral_constant<dim_t, pattern_type::ndim()> rank;
typedef std::integral_constant<dim_t, RangeOrigin::rank::value> rank;

typedef RangeT global_type;
Expand Down Expand Up @@ -1047,8 +1041,6 @@ class IteratorRange
typedef self_t global_type;
typedef ViewLocalMod<self_t, 1> local_type;

//typedef typename RangeOrigin::pattern_type pattern_type;

typedef typename view_traits<
typename std::decay<RangeOrigin>::type
>::is_local is_local;
Expand All @@ -1073,7 +1065,9 @@ class IteratorRange
// Move begin iterator first position of its iteration scope:
begin - begin.pos(),
// Move end iterator to end position of its iteration scope:
begin + (begin.pattern().size() - begin.pos()) ))
begin + (begin.pattern().size() - begin.pos())
// end
))
// Convert iterator positions to sub-range index set:
, _index_set(this->domain(), begin.pos(), end.pos())
{ }
Expand All @@ -1083,7 +1077,9 @@ class IteratorRange
// Move begin iterator first position of its iteration scope:
std::move(begin) - begin.pos(),
// Move end iterator to end position of its iteration scope:
std::move(begin) + (begin.pattern().size() - begin.pos()) ))
std::move(begin) + (begin.pattern().size() - begin.pos())
// std::move(end)
))
// Convert iterator positions to sub-range index set:
, _index_set(this->domain(), begin.pos(), end.pos())
{ }
Expand Down Expand Up @@ -1177,7 +1173,9 @@ class IteratorRange
self_t & global() {
return *this;
}
};
}; // IteratorRange

#endif // DOXYGEN

// -----------------------------------------------------------------------
// dash::make_range
Expand All @@ -1197,8 +1195,6 @@ make_range(Iterator && begin, Sentinel && end) {
std::forward<Sentinel>(end));
}

#endif // DOXYGEN

} // namespace dash

#endif // DASH__VIEW__VIEW_MOD_1D_H__INCLUDED
Loading

0 comments on commit acccf22

Please sign in to comment.