From eea0c28255542500a759306092fd409c7e4da4d3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 18 Mar 2017 02:47:31 +0100 Subject: [PATCH 001/161] Extending n-dim view tests --- dash/include/dash/Cartesian.h | 15 +++-- dash/include/dash/pattern/SeqTilePattern.h | 29 +++++++++ dash/include/dash/view/ViewMod.h | 14 +---- dash/include/dash/view/ViewMod1D.h | 72 ---------------------- dash/test/view/NViewTest.cc | 10 ++- 5 files changed, 44 insertions(+), 96 deletions(-) diff --git a/dash/include/dash/Cartesian.h b/dash/include/dash/Cartesian.h index 8ed374ecb..721248b81 100644 --- a/dash/include/dash/Cartesian.h +++ b/dash/include/dash/Cartesian.h @@ -251,10 +251,10 @@ class CartesianIndexSpace typedef SizeType size_type; typedef std::array extents_type; - template + template friend std::ostream & operator<<( - std::ostream & os, - const CartesianIndexSpace & cartesian_space); + std::ostream & os, + const CartesianIndexSpace & cartesian_space); protected: /// Number of elements in the cartesian space spanned by this instance. @@ -805,17 +805,16 @@ std::ostream & operator<<( return operator<<(os, ss.str()); } -template < - dash::dim_t NumDimensions > +template std::ostream & operator<<( - std::ostream & os, - const dash::CartesianIndexSpace & cartesian_space) + std::ostream & os, + const CartesianIndexSpace & cartesian_space) { std::ostringstream ss; ss << dash::typestr(cartesian_space) << ": " << "extents("; - for (auto dim = 0; dim < NumDimensions; ++dim) { + for (auto dim = 0; dim < NDim_; ++dim) { if (dim > 0) { ss << ","; } diff --git a/dash/include/dash/pattern/SeqTilePattern.h b/dash/include/dash/pattern/SeqTilePattern.h index 4f48346b5..3fbcc9741 100644 --- a/dash/include/dash/pattern/SeqTilePattern.h +++ b/dash/include/dash/pattern/SeqTilePattern.h @@ -1197,6 +1197,35 @@ class SeqTilePattern return block_idx; } + /** + * Local index of block at given global coordinates. + * + * \see DashPatternConcept + */ + local_index_t local_block_at( + /// Global coordinates of element + const std::array & g_coords) const + { + std::array block_coords; + // Coord to block coord to unit coord: + for (auto d = 0; d < NumDimensions; ++d) { + block_coords[d] = g_coords[d] / _blocksize_spec.extent(d); + } + // Block coord to block index: + auto block_idx = _blockspec.at(block_coords); + DASH_LOG_TRACE("SeqTilePattern.block_at", + "coords", g_coords, + "> block index", block_idx); + return local_index_t { + // unit id: + static_cast( + block_idx % _teamspec.size()), + // local block index: + static_cast( + block_idx / _teamspec.size()) + }; + } + /** * View spec (offset and extents) of block at global linear block index * in global cartesian element space. diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index bd660ee93..f7a501265 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -169,19 +169,8 @@ class ViewModBase >::type domain_member_type; - // TODO: BUG! - // For example, assume - // domain = sub(local(array)) - // then view_traits::is_local resolves to `true` - // and domain_type is defined as ViewSub> - // instead of ViewLocal or Array::local_type. - // - // Note that the origin of ViewLocalMod is the global origin - // while the origin of and view on ViewLocalMod is the local - // origin. typedef typename std::conditional< view_traits::is_local::value, - // domain_type, typename view_traits< typename view_traits::origin_type >::local_type, @@ -328,7 +317,7 @@ struct view_traits > { typedef typename view_traits::origin_type origin_type; typedef typename view_traits::pattern_type pattern_type; typedef typename domain_type::local_type image_type; - typedef ViewLocalMod local_type; + typedef ViewLocalMod local_type; typedef domain_type global_type; typedef typename view_traits::index_type index_type; @@ -547,7 +536,6 @@ struct view_traits > { typedef typename view_traits::origin_type origin_type; typedef typename view_traits::pattern_type pattern_type; typedef ViewSubMod image_type; -//typedef ViewSubMod local_type; typedef ViewLocalMod< ViewSubMod, NDim> local_type; typedef ViewSubMod global_type; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index dc4859fa2..2f82b2c8b 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -27,34 +27,6 @@ namespace dash { // ViewSubMod // ------------------------------------------------------------------------ -template < - class DomainType, - dim_t SubDim > -struct view_traits > { - typedef DomainType domain_type; - typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; - typedef ViewSubMod image_type; -//typedef ViewSubMod local_type; - typedef ViewLocalMod< - ViewSubMod, 1> local_type; - typedef ViewSubMod global_type; - - typedef typename DomainType::index_type index_type; - typedef typename DomainType::size_type size_type; - typedef dash::IndexSetSub index_set_type; - - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - - typedef std::integral_constant::is_local::value > is_local; - - typedef std::integral_constant rank; -}; - - template < class DomainType, dim_t SubDim > @@ -167,28 +139,6 @@ class ViewSubMod // ViewLocalMod // ------------------------------------------------------------------------ -template < - class DomainType > -struct view_traits > { - typedef DomainType domain_type; - typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; - typedef typename domain_type::local_type image_type; - typedef ViewLocalMod local_type; - typedef domain_type global_type; - - typedef typename view_traits::index_type index_type; - typedef typename view_traits::size_type size_type; - typedef dash::IndexSetLocal index_set_type; - - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; - - typedef std::integral_constant rank; -}; - template < class DomainType > class ViewLocalMod @@ -349,28 +299,6 @@ class ViewLocalMod // ViewGlobalMod // ------------------------------------------------------------------------ -template < - class DomainType > -struct view_traits > { - typedef DomainType domain_type; - typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; - typedef typename domain_type::global_type image_type; - typedef typename domain_type::local_type local_type; - typedef ViewGlobalMod global_type; - - typedef typename DomainType::index_type index_type; - typedef typename DomainType::size_type size_type; - typedef dash::IndexSetLocal< DomainType > index_set_type; - - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; - - typedef std::integral_constant rank; -}; - template < class DomainType > class ViewGlobalMod diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 9e537facb..aa88f4575 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -823,7 +824,7 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) int block_cols = 2; int nrows = nunits * block_rows; - int ncols = nunits * block_cols * 2; + int ncols = nunits * block_cols * 2 - block_cols; if (nunits % 2 == 0 && nunits > 2) { nrows /= 2; @@ -834,7 +835,7 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) 1); team_spec.balance_extents(); - auto pattern = dash::TilePattern<2>( + auto pattern = dash::SeqTilePattern<2>( dash::SizeSpec<2>( nrows, ncols), @@ -860,11 +861,14 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) dash::test::initialize_matrix(mat); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat.extents()); - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", team_spec.extents()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat.pattern().local_extents()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat.pattern().local_size()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().blockspec()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().teamspec()); if (dash::myid() == 0) { auto all_sub = dash::sub<0>( From 949fb7b69c6684a7adb9ae2354cf23e388a43ccc Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 18 Mar 2017 05:11:17 +0100 Subject: [PATCH 002/161] Fixed rank in cartesian index space, SeqTilePattern.local_blockspec --- dash/include/dash/Cartesian.h | 21 ++- dash/include/dash/pattern/SeqTilePattern.h | 53 +++++-- dash/include/dash/view/IndexSet.h | 162 +++++++++++---------- dash/include/dash/view/ViewMod.h | 62 ++++---- dash/test/view/NViewTest.cc | 40 ++++- 5 files changed, 216 insertions(+), 122 deletions(-) diff --git a/dash/include/dash/Cartesian.h b/dash/include/dash/Cartesian.h index 721248b81..db6e67ee1 100644 --- a/dash/include/dash/Cartesian.h +++ b/dash/include/dash/Cartesian.h @@ -260,7 +260,7 @@ class CartesianIndexSpace /// Number of elements in the cartesian space spanned by this instance. SizeType _size = 0; /// Number of dimensions in the cartesian space. - SizeType _rank = NumDimensions; + SizeType _rank = 0; /// Extents of the cartesian space by dimension. extents_type _extents = { }; /// Cumulative index offsets of the index space by dimension respective @@ -348,12 +348,10 @@ class CartesianIndexSpace */ template void resize(SizeType arg, Args... args) { - static_assert( - sizeof...(Args) == NumDimensions-1, - "Invalid number of arguments"); - std::array extents = - {{ arg, (SizeType)(args)... }}; - resize(extents); + resize( + std::array {{ + arg, (SizeType)(args)... + }} ); } /** @@ -363,9 +361,18 @@ class CartesianIndexSpace void resize(const std::array & extents) { // Update size: _size = 1; + _rank = 0; for(auto i = 0; i < NumDimensions; i++ ) { _extents[i] = static_cast(extents[i]); _size *= _extents[i]; + if (_extents[i] > 1) { + ++_rank; + } + } + if (_size == 0) { + _rank = 0; + } else if (_rank == 0) { + _rank = 1; } // Update offsets: _offset_row_major[NumDimensions-1] = 1; diff --git a/dash/include/dash/pattern/SeqTilePattern.h b/dash/include/dash/pattern/SeqTilePattern.h index 3fbcc9741..dc05dd9d1 100644 --- a/dash/include/dash/pattern/SeqTilePattern.h +++ b/dash/include/dash/pattern/SeqTilePattern.h @@ -41,9 +41,9 @@ namespace dash { * */ template< - dim_t NumDimensions, - MemArrange Arrangement = ROW_MAJOR, - typename IndexType = dash::default_index_t> + dim_t NumDimensions, + MemArrange Arrangement = ROW_MAJOR, + typename IndexType = dash::default_index_t> class SeqTilePattern { public: @@ -218,7 +218,7 @@ class SeqTilePattern _blocksize_spec, _teamspec)), _local_memory_layout( - initialize_local_extents(_myid)), + initialize_local_extents(_local_blockspec)), _local_capacity( initialize_local_capacity(_local_memory_layout)) { DASH_LOG_TRACE("SeqTilePattern()", "Constructor with Argument list"); @@ -292,7 +292,7 @@ class SeqTilePattern _blocksize_spec, _teamspec)), _local_memory_layout( - initialize_local_extents(_myid)), + initialize_local_extents(_local_blockspec)), _local_capacity( initialize_local_capacity(_local_memory_layout)) { DASH_LOG_TRACE("SeqTilePattern()", "(sizespec, dist, teamspec, team)"); @@ -361,7 +361,7 @@ class SeqTilePattern _blocksize_spec, _teamspec)), _local_memory_layout( - initialize_local_extents(_myid)), + initialize_local_extents(_local_blockspec)), _local_capacity( initialize_local_capacity(_local_memory_layout)) { DASH_LOG_TRACE("SeqTilePattern()", "(sizespec, dist, team)"); @@ -1600,12 +1600,22 @@ class SeqTilePattern // Number of local blocks in all dimensions: std::array l_blocks; auto min_local_blocks = num_blocks_total / _nunits; - l_blocks[0] = min_local_blocks; - if (unit_id < num_blocks_total % _nunits) { - l_blocks[0]++; - } - for (auto d = 1; d < NumDimensions; ++d) { - l_blocks[d] = 1; + if (Arrangement == dash::COL_MAJOR) { + l_blocks[0] = min_local_blocks; + if (unit_id < num_blocks_total % _nunits) { + l_blocks[0]++; + } + for (auto d = 1; d < NumDimensions; ++d) { + l_blocks[d] = 1; + } + } else { + l_blocks[NumDimensions - 1] = min_local_blocks; + if (unit_id < num_blocks_total % _nunits) { + l_blocks[NumDimensions - 1]++; + } + for (auto d = NumDimensions - 2; d >= 0; --d) { + l_blocks[d] = 1; + } } DASH_LOG_TRACE_VAR("SeqTilePattern.init_local_blockspec >", l_blocks); return BlockSpec_t(l_blocks); @@ -1652,9 +1662,8 @@ class SeqTilePattern * Resolve extents of local memory layout for a specified unit. */ std::array initialize_local_extents( - team_unit_t unit) const + team_unit_t unit) const { - DASH_LOG_DEBUG_VAR("SeqTilePattern.init_local_extents()", unit); auto l_blockspec = initialize_local_blockspec( _blockspec, _blocksize_spec, _teamspec, unit); @@ -1667,6 +1676,22 @@ class SeqTilePattern DASH_LOG_DEBUG_VAR("SeqTilePattern.init_local_extents >", l_extents); return l_extents; } + + /** + * Resolve extents of local memory layout for a specified local blockspec. + */ + std::array initialize_local_extents( + const BlockSpec_t & l_blockspec) const + { + DASH_LOG_DEBUG_VAR("SeqTilePattern.init_local_extents()", + l_blockspec.extents()); + ::std::array l_extents; + for (auto d = 0; d < NumDimensions; ++d) { + l_extents[d] = _blocksize_spec.extent(d) * l_blockspec.extent(d); + } + DASH_LOG_DEBUG_VAR("SeqTilePattern.init_local_extents >", l_extents); + return l_extents; + } }; template< diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index bdb9679dd..1bc8a18fc 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -386,6 +386,19 @@ class IndexSetBase ); } + constexpr bool is_sub() const noexcept { + return ( + derived().size() < this->pattern().size() + ); + } + + constexpr bool is_shifted() const noexcept { + typedef typename dash::pattern_mapping_traits::type + pat_mapping_traits; + return pat_mapping_traits::shifted || + pat_mapping_traits::diagonal; + } + // ---- extents --------------------------------------------------------- constexpr std::array @@ -813,11 +826,6 @@ class IndexSetLocal typedef self_t local_type; typedef IndexSetGlobal global_type; -//typedef decltype( -// dash::global( -// dash::index( -// std::declval()) -// )) global_type; typedef global_type preimage_type; typedef typename base_t::iterator iterator; @@ -908,6 +916,8 @@ class IndexSetLocal constexpr index_type calc_size() const noexcept { typedef typename dash::pattern_partitioning_traits::type pat_partitioning_traits; + typedef typename dash::pattern_mapping_traits::type + pat_mapping_traits; static_assert( pat_partitioning_traits::rectangular, @@ -923,74 +933,80 @@ class IndexSetLocal ); */ return ( - !this->is_strided() - // blocked (not blockcyclic) distribution: single local - // element space with contiguous global index range - ? this->index_range_size( - this->index_range_intersect( - // local range in global index space: - { this->pattern().lbegin(), - this->pattern().lend() - 1 }, - // domain range in global index space; - { this->domain().first(), - this->domain().last() } - )) + 1 - // blockcyclic distribution: local element space chunked - // in global index range - : this->index_range_size( - this->index_range_g2l( - this->pattern(), - // intersection of local range and domain range: - this->index_range_intersect( - // local range in global index space: - { - this->pattern().lbegin(), - ( this->pattern().lend() < this->domain().last() - // domain range contains end of local range: - ? this->pattern().lend() - 1 - // domain range ends in local range, determine last - // local index contained in domain from last local - // block contained in domain range: - // - // gbi: 0 1 2 3 4 5 - // lbi: 0 0 1 1 2 2 - // : : - // [ | |xxxx| |xxxx| | |xxxx] - // '---------------------' - // - // --> domain.end.gbi = 4 ------------. - // domain.end.lbi = 2 -. | - // | | - // v | - // local.lblock(lbi = 2).gbi = 5 | - // | | - // ! 5 > domain.end.gbi = 4 <-----'-' - // --> local.lblock(lbi = 1) - // - // Resolve global index past the last element: - // - : ( domain_block_gidx_last() >= local_block_gidx_last() - // Last local block is included in domain: - ? this->pattern().block( - local_block_gidx_last() - ).range(0).end - 1 - // Domain ends before last local block: - : local_block_gidx_at_block_lidx( - domain_block_lidx_last()) - > domain_block_gidx_last() - ? this->pattern().local_block( - domain_block_lidx_last() - 1 - ).range(0).end - 1 - : this->pattern().local_block( - domain_block_lidx_last() - ).range(0).end - 1 ) - ) - }, - // domain range in global index space; - { this->domain().first(), - this->domain().last() - }) - )) + 1 + !this->domain().is_sub() + // parent domain is not a sub-range, use full local size: + ? this->pattern().local_size() + // parent domain is sub-space, calculate size from sub-range: + : ( !this->is_strided() + // blocked (not blockcyclic) distribution: single local + // element space with contiguous global index range + ? this->index_range_size( + this->index_range_intersect( + // local range in global index space: + { this->pattern().lbegin(), + this->pattern().lend() - 1 }, + // domain range in global index space; + { this->domain().first(), + this->domain().last() } + )) + 1 + // blockcyclic distribution: local element space chunked + // in global index range + : this->index_range_size( + this->index_range_g2l( + this->pattern(), + // intersection of local range and domain range: + this->index_range_intersect( + // local range in global index space: + { + this->pattern().lbegin(), + ( this->pattern().lend() < this->domain().last() + // domain range contains end of local range: + ? this->pattern().lend() - 1 + // domain range ends in local range, determine last + // local index contained in domain from last local + // block contained in domain range: + // + // gbi: 0 1 2 3 4 5 + // lbi: 0 0 1 1 2 2 + // : : + // [ | |xxxx| |xxxx| | |xxxx] + // '---------------------' + // + // --> domain.end.gbi = 4 ------------. + // domain.end.lbi = 2 -. | + // | | + // v | + // local.lblock(lbi = 2).gbi = 5 | + // | | + // ! 5 > domain.end.gbi = 4 <-----'-' + // --> local.lblock(lbi = 1) + // + // Resolve global index past the last element: + // + : ( domain_block_gidx_last() + >= local_block_gidx_last() + // Last local block is included in domain: + ? this->pattern().block( + local_block_gidx_last() + ).range(0).end - 1 + // Domain ends before last local block: + : local_block_gidx_at_block_lidx( + domain_block_lidx_last()) + > domain_block_gidx_last() + ? this->pattern().local_block( + domain_block_lidx_last() - 1 + ).range(0).end - 1 + : this->pattern().local_block( + domain_block_lidx_last() + ).range(0).end - 1 ) + ) + }, + // domain range in global index space; + { this->domain().first(), + this->domain().last() + }) + )) + 1 + ) // domain.is_sub() ); } diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index f7a501265..c19f96842 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -364,7 +364,7 @@ class ViewLocalMod std::declval< typename std::add_lvalue_reference::type >() )))) - iterator; + origin_iterator; typedef decltype( @@ -373,6 +373,13 @@ class ViewLocalMod std::declval< typename std::add_lvalue_reference::type >() )))) + const_origin_iterator; + + typedef ViewIterator< + origin_iterator, index_set_type > + iterator; + typedef ViewIterator< + const_origin_iterator, index_set_type > const_iterator; typedef @@ -461,48 +468,51 @@ class ViewLocalMod // ---- access ---------------------------------------------------------- constexpr const_iterator begin() const { - return dash::begin( - dash::local( - dash::origin(*this) )) - + _index_set[0]; + return const_iterator( + dash::begin( + dash::local( + dash::origin(*this) )), + _index_set, 0); } iterator begin() { - return dash::begin( - dash::local( - const_cast(dash::origin(*this)) - )) - + _index_set[0]; + return iterator( + dash::begin( + dash::local( + const_cast(dash::origin(*this)) )), + _index_set, 0); } constexpr const_iterator end() const { - return dash::begin( - dash::local( - dash::origin(*this) )) - + _index_set[_index_set.size() - 1] + 1; + return const_iterator( + dash::begin( + dash::local( + dash::origin(*this) )), + _index_set, _index_set.size()); } iterator end() { - return dash::begin( - dash::local( - const_cast(dash::origin(*this)) - )) - + _index_set[_index_set.size() - 1] + 1; + return iterator( + dash::begin( + dash::local( + const_cast(dash::origin(*this)) )), + _index_set, _index_set.size()); } constexpr const_reference operator[](int offset) const { - return *(dash::begin( + return *const_iterator( + dash::begin( dash::local( - dash::origin(*this) )) - + _index_set[offset]); + dash::origin(*this) )), + _index_set, offset); } reference operator[](int offset) { - return *(dash::begin( + return *iterator( + dash::begin( dash::local( - const_cast(dash::origin(*this)) - )) - + _index_set[offset]); + const_cast(dash::origin(*this)) )), + _index_set, offset); } constexpr const local_type & local() const { diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index aa88f4575..dde055be6 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -820,7 +820,7 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) { auto nunits = dash::size(); - int block_rows = 2; + int block_rows = 3; int block_cols = 2; int nrows = nunits * block_rows; @@ -867,6 +867,16 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) mat.pattern().local_size()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat.pattern().blockspec()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().blockspec().rank()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().blocksize(0)); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().blocksize(1)); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().local_blockspec()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + mat.pattern().local_blockspec().rank()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat.pattern().teamspec()); @@ -883,8 +893,34 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", index(all_sub).size()); - dash::test::print_nview("mat_view", all_sub); + dash::test::print_nview("mat_global", all_sub); + } + mat.barrier(); + + auto mat_local = dash::local( + dash::sub<0>( + 0, mat.extents()[0], + mat)); + EXPECT_TRUE_U(index(mat_local).is_strided()); + EXPECT_TRUE_U(index(mat_local).is_shifted()); + EXPECT_TRUE_U(index(mat_local).is_sub()); + EXPECT_FALSE_U(index(dash::domain(mat_local)).is_sub()); + + EXPECT_EQ_U(mat.pattern().local_size(), mat_local.size()); + EXPECT_EQ_U(mat.pattern().local_extents(), mat_local.extents()); + + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.offsets()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.extents()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.size()); + + dash::test::print_nview("mat_local", mat_local); + + mat.barrier(); + + return; + + if (dash::myid() == 0) { auto nview_rows = dash::sub<0>(1, mat.extent(0) - 1, mat); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", From 8586b3fe48d829090eb8c954e5905486d4760115 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 18 Mar 2017 05:12:00 +0100 Subject: [PATCH 003/161] Skipping WIP test case --- dash/test/view/NViewTest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index dde055be6..2b733c055 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -914,12 +914,12 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.extents()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.size()); + return; + dash::test::print_nview("mat_local", mat_local); mat.barrier(); - return; - if (dash::myid() == 0) { auto nview_rows = dash::sub<0>(1, mat.extent(0) - 1, mat); From 92e2a34fd301d07d6b40dfadba62917e87b1c31e Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 18 Mar 2017 06:26:22 +0100 Subject: [PATCH 004/161] Implementing n-dim block views --- dash/include/dash/view/IndexSet.h | 27 ++++++++++---- dash/include/dash/view/ViewBlocksMod.h | 29 ++++++++++++++- dash/test/view/NViewTest.cc | 49 ++++++++++++++------------ 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 1bc8a18fc..a398e134f 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -196,8 +196,6 @@ constexpr auto local( const IndexSetBase & index_set) -> decltype(index_set.local()) { -// -> typename view_traits>::global_type & { -// -> const IndexSetLocal & { return index_set.local(); } @@ -208,9 +206,7 @@ template < constexpr auto global( const IndexSetBase & index_set) - -> decltype(index_set.global()) { -// -> typename view_traits>::global_type & { -// -> const IndexSetGlobal & { + -> decltype(index_set.global()) { return index_set.global(); } @@ -1206,7 +1202,8 @@ class IndexSetBlocks typedef IndexSetBlocks self_t; typedef IndexSetBase base_t; public: - typedef typename DomainType::index_type index_type; + typedef typename base_t::index_type index_type; + typedef typename base_t::size_type size_type; typedef self_t local_type; typedef IndexSetGlobal global_type; @@ -1252,6 +1249,24 @@ class IndexSetBlocks , _size(calc_size()) { } + // ---- extents --------------------------------------------------------- + + constexpr std::array + extents() const { + return ( this->is_local() + ? this->pattern().local_blockspec().extents() + : this->pattern().blockspec().extents() ); + } + + // ---- offsets --------------------------------------------------------- + + constexpr std::array + offsets() const { + return std::array { }; + } + + // ---- access ---------------------------------------------------------- + constexpr iterator begin() const { return iterator(*this, 0); } diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 433b90f99..a3a445a03 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -80,7 +80,6 @@ class ViewBlockMod public: typedef DomainType domain_type; typedef typename view_traits::index_type index_type; -//typedef typename view_traits::origin_type origin_type; typedef typename base_t::origin_type origin_type; public: // TODO: Defaulting to SubDim = 0 here, clarify @@ -414,8 +413,36 @@ class ViewBlocksMod , _index_set(this->domain()) { } + // ---- extents --------------------------------------------------------- + + constexpr std::array extents() const { + return _index_set.extents(); + } + + template + constexpr size_type extent() const { + return _index_set.template extent(); + } + + constexpr size_type extent(dim_t shape_dim) const { + return _index_set.extent(shape_dim); + } + // ---- offsets --------------------------------------------------------- + template + constexpr index_type offset() const { + return _index_set.template offset(); + } + + constexpr std::array offsets() const { + return _index_set.offsets(); + } + + constexpr index_type offset(dim_t shape_dim) const { + return _index_set.offset(shape_dim); + } + // ---- size ------------------------------------------------------------ constexpr size_type size() const { diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 2b733c055..cb0387539 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -897,29 +897,6 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) } mat.barrier(); - auto mat_local = dash::local( - dash::sub<0>( - 0, mat.extents()[0], - mat)); - - EXPECT_TRUE_U(index(mat_local).is_strided()); - EXPECT_TRUE_U(index(mat_local).is_shifted()); - EXPECT_TRUE_U(index(mat_local).is_sub()); - EXPECT_FALSE_U(index(dash::domain(mat_local)).is_sub()); - - EXPECT_EQ_U(mat.pattern().local_size(), mat_local.size()); - EXPECT_EQ_U(mat.pattern().local_extents(), mat_local.extents()); - - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.offsets()); - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.extents()); - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.size()); - - return; - - dash::test::print_nview("mat_local", mat_local); - - mat.barrier(); - if (dash::myid() == 0) { auto nview_rows = dash::sub<0>(1, mat.extent(0) - 1, mat); @@ -945,6 +922,13 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) auto nview_blocks = dash::blocks(mat); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + nview_blocks.size()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + nview_blocks.offsets()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + nview_blocks.extents()); + int bi = 0; for (const auto & block : nview_blocks) { DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSingle", @@ -954,4 +938,23 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) } } mat.barrier(); + + auto mat_local = dash::local( + dash::sub<0>( + 0, mat.extents()[0], + mat)); + + EXPECT_TRUE_U(index(mat_local).is_strided()); + EXPECT_TRUE_U(index(mat_local).is_shifted()); + EXPECT_TRUE_U(index(mat_local).is_sub()); + EXPECT_FALSE_U(index(dash::domain(mat_local)).is_sub()); + + EXPECT_EQ_U(mat.pattern().local_size(), mat_local.size()); + EXPECT_EQ_U(mat.pattern().local_extents(), mat_local.extents()); + + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.offsets()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.extents()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", mat_local.size()); + + dash::test::print_nview("mat_local", mat_local); } From 09c0a772e97c6cefc07e6755b6870283eefcdce4 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 18 Mar 2017 06:56:15 +0100 Subject: [PATCH 005/161] Implementing n-dim block views --- dash/include/dash/view/Chunked.h | 36 ++--- dash/include/dash/view/IndexSet.h | 23 ++-- dash/include/dash/view/ViewBlocksMod.h | 175 ++++++++++++++++++++++--- dash/test/view/NViewTest.cc | 7 + 4 files changed, 192 insertions(+), 49 deletions(-) diff --git a/dash/include/dash/view/Chunked.h b/dash/include/dash/view/Chunked.h index 188be233f..b4ab172db 100644 --- a/dash/include/dash/view/Chunked.h +++ b/dash/include/dash/view/Chunked.h @@ -19,7 +19,9 @@ namespace dash { // ------------------------------------------------------------------------ template < - class DomainType > + class DomainType, + dim_t NDim = dash::view_traits< + typename std::decay::type>::rank::value > class ViewBlockMod; #if 0 @@ -30,11 +32,11 @@ constexpr auto block( OffsetT block_idx, const ContainerType & container) --> typename std::enable_if< - !dash::view_traits::is_view::value, - decltype(container.block(0)) - >::type { - return container.block(block_idx); + -> typename std::enable_if< + !dash::view_traits::is_view::value, + decltype(container.blocks()[0]) + >::type { + return container.blocks()[block_idx]; } #endif @@ -47,13 +49,13 @@ template < class OffsetT > constexpr auto block( - OffsetT block_idx, + OffsetT block_idx, const ViewType & view) --> typename std::enable_if< - (// dash::view_traits::is_view::value && - !dash::view_traits::is_local::value ), - ViewBlockMod - >::type { + -> typename std::enable_if< + (// dash::view_traits::is_view::value && + !dash::view_traits::is_local::value ), + ViewBlockMod + >::type { return ViewBlockMod(view, block_idx); } @@ -68,11 +70,11 @@ constexpr auto block( OffsetT block_idx, const ViewType & view) --> typename std::enable_if< - (// dash::view_traits::is_view::value && - dash::view_traits::is_local::value ), - decltype(dash::block(block_idx, dash::local(dash::origin(view)))) - >::type { + -> typename std::enable_if< + (// dash::view_traits::is_view::value && + dash::view_traits::is_local::value ), + decltype(dash::block(block_idx, dash::local(dash::origin(view)))) + >::type { return dash::local(dash::origin(view)).block(block_idx); } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index a398e134f..f110d4faf 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1352,33 +1352,31 @@ class IndexSetBlocks } }; // class IndexSetBlocks + // ----------------------------------------------------------------------- // IndexSetBlock // ----------------------------------------------------------------------- -#if 0 -// Currently using IndexSetSub instead -// + template class IndexSetBlock : public IndexSetBase< IndexSetBlock, - DomainType, - 1 > + DomainType > { typedef IndexSetBlock self_t; typedef IndexSetBase base_t; public: typedef typename DomainType::index_type index_type; - typedef self_t local_type; + typedef self_t local_type; typedef IndexSetGlobal global_type; - typedef global_type preimage_type; + typedef global_type preimage_type; - typedef typename base_t::iterator iterator; - typedef typename base_t::pattern_type pattern_type; + typedef typename base_t::iterator iterator; + typedef typename base_t::pattern_type pattern_type; - typedef dash::local_index_t local_index_type; - typedef dash::global_index_t global_index_type; + typedef dash::local_index_t local_index_type; + typedef dash::global_index_t global_index_type; private: index_type _block_idx; @@ -1398,7 +1396,7 @@ class IndexSetBlock public: constexpr explicit IndexSetBlock( const DomainType & view, - index_type block_idx) + index_type block_idx) : base_t(view) , _block_idx(block_idx) , _size(calc_size()) @@ -1469,7 +1467,6 @@ class IndexSetBlock ); } }; // class IndexSetBlock -#endif } // namespace dash #endif // DOXYGEN diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index a3a445a03..3a6f55f3c 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -34,23 +34,28 @@ template < typename std::decay::type>::rank::value > class ViewBlocksMod; + // ------------------------------------------------------------------------ // ViewBlockMod // ------------------------------------------------------------------------ template < - class DomainType > -struct view_traits > { + class DomainType, + dim_t NDim > +struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; typedef typename view_traits::pattern_type pattern_type; - typedef ViewBlockMod image_type; - typedef ViewBlockMod local_type; - typedef ViewBlockMod global_type; + typedef ViewBlockMod image_type; + typedef ViewBlockMod local_type; + typedef ViewBlockMod global_type; typedef typename DomainType::index_type index_type; - // TODO: Defaulting to SubDim = 0 here, clarify - typedef dash::IndexSetSub index_set_type; + typedef typename std::conditional< + NDim == 1, + dash::IndexSetSub, + dash::IndexSetBlock + >::type index_set_type; typedef std::integral_constant is_projection; typedef std::integral_constant is_view; @@ -58,31 +63,165 @@ struct view_traits > { typedef std::integral_constant::is_local::value > is_local; - typedef std::integral_constant rank; + typedef std::integral_constant rank; }; +// ------------------------------------------------------------------------ +// ViewBlockMod +// ------------------------------------------------------------------------ + template < - class DomainType > + class DomainType, + dim_t NDim > class ViewBlockMod +: public ViewModBase < + ViewBlockMod, + DomainType, + NDim > +{ + private: + typedef ViewBlockMod self_t; + typedef ViewModBase< + ViewBlockMod, DomainType, NDim> base_t; + public: + typedef DomainType domain_type; + typedef typename view_traits::index_type index_type; + typedef typename base_t::origin_type origin_type; + public: + typedef dash::IndexSetBlock index_set_type; + typedef ViewLocalMod local_type; + typedef self_t global_type; + + typedef std::integral_constant is_local; + + typedef decltype( + dash::begin( + std::declval< + typename std::add_lvalue_reference::type + >() )) + origin_iterator; + + typedef decltype( + dash::begin( + std::declval< + typename std::add_lvalue_reference::type + >() )) + const_origin_iterator; + + typedef ViewIterator + iterator; + typedef ViewIterator + const_iterator; + + typedef + decltype(*dash::begin( + std::declval< + typename std::add_lvalue_reference::type + >() )) + reference; + + typedef + decltype(*dash::begin( + std::declval< + typename std::add_lvalue_reference::type + >() )) + const_reference; + + private: + index_set_type _index_set; + + public: + constexpr ViewBlockMod() = delete; + constexpr ViewBlockMod(self_t &&) = default; + constexpr ViewBlockMod(const self_t &) = default; + ~ViewBlockMod() = default; + self_t & operator=(self_t &&) = default; + self_t & operator=(const self_t &) = default; + + constexpr ViewBlockMod( + const domain_type & domain, + index_type block_idx) + : base_t(domain) + , _index_set(domain, + block_idx) + { } + + /** + * Constructor, creates a view on a block in the specified domain. + */ + constexpr ViewBlockMod( + domain_type && domain, + index_type block_idx) + : base_t(std::forward(domain)) + , _index_set(this->domain(), + block_idx) + { } + + constexpr const_iterator begin() const { + return const_iterator(dash::origin(*this).begin(), + _index_set, 0); + } + + iterator begin() { + return iterator(const_cast( + dash::origin(*this) + ).begin(), + _index_set, 0); + } + + constexpr const_iterator end() const { + return const_iterator(dash::origin(*this).begin(), + _index_set, _index_set.size()); + } + + iterator end() { + return iterator(const_cast( + dash::origin(*this) + ).begin(), + _index_set, _index_set.size()); + } + + constexpr const_reference operator[](int offset) const { + return *(const_iterator(dash::origin(*this).begin(), + _index_set, offset)); + } + + constexpr const index_set_type & index_set() const { + return _index_set; + } + + constexpr local_type local() const { + return local_type(*this); + } +}; // class ViewBlockMod + + +// ------------------------------------------------------------------------ +// ViewBlockMod<1> +// ------------------------------------------------------------------------ + +template < + class DomainType > +class ViewBlockMod // Actually just an adapter for block_idx -> sub(begin_idx, end_idx), // should sublass // // public ViewSubMod // : public ViewModBase < - ViewBlockMod, - DomainType > + ViewBlockMod, + DomainType, + 1 > { private: - typedef ViewBlockMod self_t; - typedef ViewModBase< ViewBlockMod, DomainType > base_t; + typedef ViewBlockMod self_t; + typedef ViewModBase< ViewBlockMod, DomainType, 1 > base_t; public: typedef DomainType domain_type; typedef typename view_traits::index_type index_type; typedef typename base_t::origin_type origin_type; public: - // TODO: Defaulting to SubDim = 0 here, clarify typedef dash::IndexSetSub< DomainType, 0 > index_set_type; typedef ViewLocalMod local_type; typedef self_t global_type; @@ -248,7 +387,7 @@ class ViewBlockMod ) - dash::index(vdomain).first(); } -}; +}; // class ViewBlockMod<1> // ------------------------------------------------------------------------ // ViewBlocksMod @@ -309,7 +448,7 @@ class ViewBlocksMod typedef typename view_traits::index_type index_type; typedef typename view_traits::size_type size_type; private: - typedef ViewBlockMod block_type; + typedef ViewBlockMod block_type; typedef typename domain_type::local_type domain_local_type; public: typedef dash::IndexSetBlocks index_set_type; @@ -377,9 +516,7 @@ class ViewBlocksMod // with iterator position. // Note that block index is relative to the domain and is // translated to global block index in IndexSetBlocks. - return ViewBlockMod( - _blocks_view_domain, - idx); + return block_type(_blocks_view_domain, idx); } }; diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index cb0387539..527bfe1e3 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -929,6 +929,13 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", nview_blocks.extents()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + nview_blocks[0].size()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + nview_blocks[0].offsets()); + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", + nview_blocks[0].extents()); + int bi = 0; for (const auto & block : nview_blocks) { DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSingle", From 6a7de46b25a250c49d413df37187b12341d16632 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 20 Mar 2017 11:22:58 +0100 Subject: [PATCH 006/161] Minor, added notes --- dash/include/dash/view/ViewMod.h | 1 + dash/test/view/ViewTest.cc | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index c19f96842..7903bfabb 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -163,6 +163,7 @@ class ViewModBase typedef DomainType domain_type; typedef typename std::conditional< + // try is_copyable, is_moveable view_traits::is_origin::value, const domain_type &, domain_type diff --git a/dash/test/view/ViewTest.cc b/dash/test/view/ViewTest.cc index 6468a244c..11cb7b104 100644 --- a/dash/test/view/ViewTest.cc +++ b/dash/test/view/ViewTest.cc @@ -1068,7 +1068,6 @@ TEST_F(ViewTest, LocalBlocksView1Dim) std::vector block_indices(block_index.begin(), block_index.end()); DASH_LOG_DEBUG_VAR("ViewTest.LocalBlocksView1Dim", block_indices); - //DASH_LOG_DEBUG_VAR("ViewTest.LocalBlocksView1Dim", block); std::vector block_values(block.begin(), block.end()); DASH_LOG_DEBUG_VAR("ViewTest.LocalBlocksView1Dim", block_values); From 8d614200747bfbc398bb0efb8c86e784e12162ef Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Wed, 10 May 2017 08:13:53 +0200 Subject: [PATCH 007/161] Intermediate commit, likely broken --- dash/include/dash/algorithm/Transform.h | 66 +++++++++++++++++++++---- dash/test/algorithm/TransformTest.cc | 27 ++++++++++ 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/dash/include/dash/algorithm/Transform.h b/dash/include/dash/algorithm/Transform.h index 4090082e2..edf52d30d 100644 --- a/dash/include/dash/algorithm/Transform.h +++ b/dash/include/dash/algorithm/Transform.h @@ -48,8 +48,33 @@ inline dart_ret_t transform_blocking_impl( return result; } +/** + * Wrapper of the non-blocking DART accumulate operation with local completion. + * Allows re-use of \c values pointer after the call returns. + */ +template< typename ValueType > +dart_ret_t transform_local_blocking_impl( + dart_gptr_t dest, + ValueType * values, + size_t nvalues, + dart_operation_t op) +{ + static_assert(dash::dart_datatype::value != DART_TYPE_UNDEFINED, + "Cannot accumulate unknown type!"); + + dart_ret_t result = dart_accumulate( + dest, + reinterpret_cast(values), + nvalues, + dash::dart_datatype::value, + op); + dart_flush_local(dest); + return result; +} + /** * Wrapper of the non-blocking DART accumulate operation. + * The pointer \c values should not be re-used before the operation completed. */ template< typename ValueType > dart_ret_t transform_impl( @@ -67,7 +92,6 @@ dart_ret_t transform_impl( nvalues, dash::dart_datatype::value, op); - dart_flush_local(dest); return result; } @@ -272,8 +296,8 @@ GlobOutputIt transform( { DASH_LOG_DEBUG("dash::transform(af, al, bf, outf, binop)"); // Outut range different from rhs input range is not supported yet - auto in_first = in_a_first; - auto in_last = in_a_last; + ValueType* in_first = &(*in_a_first); + ValueType* in_last = &(*in_a_last); std::vector in_range; if (in_b_first == out_first) { // Output range is rhs input range: C += A @@ -281,9 +305,11 @@ GlobOutputIt transform( } else { // Output range different from rhs input range: C = A+B // Input is (in_a_first, in_a_last) + (in_b_first, in_b_last): + auto lpos = in_b_first.lpos(); std::transform( in_a_first, in_a_last, - in_b_first, + in_b_first.globmem().lbegin() + + (lpos.unit == dash::myid()) ? lpos.index : 0, std::back_inserter(in_range), binary_op); in_first = in_range.data(); @@ -292,19 +318,39 @@ GlobOutputIt transform( dash::util::Trace trace("transform"); - // Resolve local range from global range: // Number of elements in local range: size_t num_local_elements = std::distance(in_first, in_last); // Global iterator to dart_gptr_t: dart_gptr_t dest_gptr = out_first.dart_gptr(); // Send accumulate message: - trace.enter_state("transform_blocking"); - dash::internal::transform_blocking_impl( + auto &pattern = out_first.pattern(); + auto &team = pattern.team(); + size_t towrite = num_local_elements; + while (towrite > 0) { + auto lpos = out_first.lpos(); + size_t lsize = pattern.local_size(lpos.unit); + size_t num_values = std::min(lsize - lpos.index, towrite); + std::cout << dash::myid() << ": lpos={" << lpos.index << ", " << lpos.unit << "}; num_values=" << num_values << " lsize=" << lsize << std::endl; + dart_gptr_t dest_gptr = out_first.dart_gptr(); + dash::internal::transform_impl( dest_gptr, in_first, - num_local_elements, + num_values, binary_op.dart_operation()); - trace.exit_state("transform_blocking"); + out_first += num_values; + towrite -= num_values; + } + + dart_flush_all(out_first.dart_gptr()); + + +// trace.enter_state("transform_blocking"); +// dash::internal::transform_blocking_impl( +// dest_gptr, +// in_first, +// num_local_elements, +// binary_op.dart_operation()); +// trace.exit_state("transform_blocking"); // The position past the last element transformed in global element space // cannot be resolved from the size of the local range if the local range // spans over more than one block. Otherwise, the difference of two global @@ -320,7 +366,7 @@ GlobOutputIt transform( // For ranges over block borders, we would have to resolve the global // position past the last element transformed from the iterator's pattern // (see dash::PatternIterator). - return out_first + num_local_elements; + return out_first; } /** diff --git a/dash/test/algorithm/TransformTest.cc b/dash/test/algorithm/TransformTest.cc index 4a9d6e4c9..5cefd721a 100644 --- a/dash/test/algorithm/TransformTest.cc +++ b/dash/test/algorithm/TransformTest.cc @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -221,3 +223,28 @@ TEST_F(TransformTest, MatrixGlobalPlusGlobalBlocking) EXPECT_EQ_U(first_l_block_a_begin, first_l_block_a_offsets); } + + +TEST_F(TransformTest, LocalIteratorInput) +{ + using value_t = int; + std::vector local_v(100); + std::fill(local_v.begin(), local_v.end(), (value_t)dash::myid()); + dash::Array global_v(local_v.size() + 1); + dash::fill(global_v.begin(), global_v.end(), 0.0); + // start from the second element + auto it = dash::transform( + local_v.begin(), + local_v.end(), + global_v.begin() + 1, + global_v.begin() + 1, + dash::max() + ); + + ASSERT_EQ_U(it, global_v.end() - 1); + + dash::for_each(global_v.begin() + 1, global_v.end(), + [](value_t val){ ASSERT_EQ_U(val, dash::size() - 1); }); + + global_v.barrier(); +} From 1b431e0c2b923b626d6a976d4800dbe8da5acaac Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Wed, 10 May 2017 14:44:23 +0200 Subject: [PATCH 008/161] Implement global-to-global dash::copy --- dash/include/dash/algorithm/Copy.h | 22 +++++++++++++---- dash/test/algorithm/CopyTest.cc | 38 ++++++++++++++++++++++++++++++ dash/test/container/MatrixTest.cc | 7 +++--- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 368d58ed9..132a1cf5c 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1186,7 +1186,6 @@ copy_async( * \ingroup DashAlgorithms */ template < - typename ValueType, class GlobInputIt, class GlobOutputIt > GlobOutputIt copy( @@ -1196,11 +1195,24 @@ GlobOutputIt copy( { DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); - // TODO: - // - Implement adapter for local-to-global dash::copy here - // - Return if global input range has no local sub-range + auto num_elements = dash::distance(in_first, in_last); + + auto li_range_in = local_index_range(in_first, in_last); + auto num_local_elem = li_range_in.end - li_range_in.begin; + auto pattern = in_first.pattern(); + + auto local_in_first = in_first + pattern.global(li_range_in.begin); + auto local_in_last = in_first + pattern.global(li_range_in.end - 1); + + // copy our local portion into the global output range + if (num_elements > 0) { + dash::copy( + local_in_first.local(), + local_in_last.local() + 1, + out_first + pattern.global(li_range_in.begin)); + } - return GlobOutputIt(); + return (out_first + num_elements); } #endif // DOXYGEN diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index c27b60f70..c5cb5c2ed 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -5,6 +5,9 @@ #include #include +#include +#include +#include #include #include #include @@ -803,6 +806,41 @@ TEST_F(CopyTest, AsyncGlobalToLocalBlock) } } + +TEST_F(CopyTest, GlobalToGlobal) +{ + using value_t = int; + constexpr int elem_per_unit = 100; + dash::Array source(dash::size() * elem_per_unit); + dash::Array target(dash::size() * elem_per_unit); + + dash::fill(target.begin(), target.end(), 0); + dash::generate_with_index(source.begin(), source.end(), + [](size_t idx) { + return dash::myid() * 1000 + idx; + } + ); + + source.barrier(); + + + // copy the first local range with an offset + dash::copy(source.begin(), source.end() + 1, target.begin()); + + dash::for_each_with_index(source.begin(), source.end(), + [](value_t val, size_t idx) { + ASSERT_EQ_U(val, dash::myid() * 1000 + idx); + } + ); + + dash::for_each_with_index(target.begin() + 1, target.end(), + [](value_t val, size_t idx) { + ASSERT_EQ_U(val, dash::myid() * 1000 + idx); + } + ); + +} + #if 0 // TODO TEST_F(CopyTest, AsyncAllToLocalVector) diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 10f609986..043e5c32c 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -736,10 +736,11 @@ TEST_F(MatrixTest, BlockCopy) LOG_MESSAGE("Team barrier passed"); // Copy block 1 of matrix_a to block 0 of matrix_b: - dash::copy(matrix_a.block(1).begin(), - matrix_a.block(1).end(), - matrix_b.block(0).begin()); + dash::copy(matrix_a.block(1).begin(), + matrix_a.block(1).end(), + matrix_b.block(0).begin()); + // TODO: Add checks here! LOG_MESSAGE("Wait for team barrier ..."); dash::barrier(); LOG_MESSAGE("Team barrier passed"); From b0b07b3d6a60e700d9311bf7053900ab8807b642 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Wed, 10 May 2017 14:46:07 +0200 Subject: [PATCH 009/161] Honor distribution in dash::transform --- dash/include/dash/algorithm/Transform.h | 44 ++++++++++++++----------- dash/test/algorithm/TransformTest.cc | 19 +++++++++-- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/dash/include/dash/algorithm/Transform.h b/dash/include/dash/algorithm/Transform.h index edf52d30d..f5364557c 100644 --- a/dash/include/dash/algorithm/Transform.h +++ b/dash/include/dash/algorithm/Transform.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -295,52 +296,55 @@ GlobOutputIt transform( BinaryOperation binary_op) { DASH_LOG_DEBUG("dash::transform(af, al, bf, outf, binop)"); + auto &pattern = out_first.pattern(); // Outut range different from rhs input range is not supported yet ValueType* in_first = &(*in_a_first); ValueType* in_last = &(*in_a_last); - std::vector in_range; + // Number of elements in local range: + size_t num_local_elements = std::distance(in_first, in_last); + auto out_last = out_first + num_local_elements; + if (out_last.gpos() > pattern.size()) { + DASH_THROW(dash::exception::OutOfRange, + "Too many input elements in dash::transform"); + } if (in_b_first == out_first) { // Output range is rhs input range: C += A // Input is (in_a_first, in_a_last). } else { // Output range different from rhs input range: C = A+B // Input is (in_a_first, in_a_last) + (in_b_first, in_b_last): - auto lpos = in_b_first.lpos(); - std::transform( - in_a_first, in_a_last, - in_b_first.globmem().lbegin() - + (lpos.unit == dash::myid()) ? lpos.index : 0, - std::back_inserter(in_range), - binary_op); - in_first = in_range.data(); - in_last = in_first + in_range.size(); + dash::copy( + in_b_first, + in_b_first + std::distance(in_a_first, in_a_last), + out_first); } dash::util::Trace trace("transform"); - // Number of elements in local range: - size_t num_local_elements = std::distance(in_first, in_last); // Global iterator to dart_gptr_t: dart_gptr_t dest_gptr = out_first.dart_gptr(); // Send accumulate message: - auto &pattern = out_first.pattern(); auto &team = pattern.team(); size_t towrite = num_local_elements; + auto out_it = out_first; + auto in_it = in_first; while (towrite > 0) { - auto lpos = out_first.lpos(); + auto lpos = out_it.lpos(); size_t lsize = pattern.local_size(lpos.unit); size_t num_values = std::min(lsize - lpos.index, towrite); - std::cout << dash::myid() << ": lpos={" << lpos.index << ", " << lpos.unit << "}; num_values=" << num_values << " lsize=" << lsize << std::endl; - dart_gptr_t dest_gptr = out_first.dart_gptr(); + dart_gptr_t dest_gptr = out_it.dart_gptr(); + // use non-blocking transform and wait for all at the end dash::internal::transform_impl( dest_gptr, - in_first, + in_it, num_values, binary_op.dart_operation()); - out_first += num_values; - towrite -= num_values; + out_it += num_values; + in_it += num_values; + towrite -= num_values; } +// out_first.team().barrier(); dart_flush_all(out_first.dart_gptr()); @@ -366,7 +370,7 @@ GlobOutputIt transform( // For ranges over block borders, we would have to resolve the global // position past the last element transformed from the iterator's pattern // (see dash::PatternIterator). - return out_first; + return out_it; } /** diff --git a/dash/test/algorithm/TransformTest.cc b/dash/test/algorithm/TransformTest.cc index 5cefd721a..85370ec0c 100644 --- a/dash/test/algorithm/TransformTest.cc +++ b/dash/test/algorithm/TransformTest.cc @@ -229,9 +229,15 @@ TEST_F(TransformTest, LocalIteratorInput) { using value_t = int; std::vector local_v(100); + size_t idx = 0; std::fill(local_v.begin(), local_v.end(), (value_t)dash::myid()); + for (auto& elem : local_v) { + elem = dash::myid() * 1000 + idx; + idx++; + } dash::Array global_v(local_v.size() + 1); dash::fill(global_v.begin(), global_v.end(), 0.0); + global_v.barrier(); // start from the second element auto it = dash::transform( local_v.begin(), @@ -241,10 +247,17 @@ TEST_F(TransformTest, LocalIteratorInput) dash::max() ); - ASSERT_EQ_U(it, global_v.end() - 1); + global_v.barrier(); + + ASSERT_EQ_U(it, global_v.end()); + +// size_t idx = 0; - dash::for_each(global_v.begin() + 1, global_v.end(), - [](value_t val){ ASSERT_EQ_U(val, dash::size() - 1); }); + dash::for_each_with_index(global_v.begin() + 1, global_v.end(), + [](value_t val, size_t idx){ + ASSERT_EQ_U(val, (dash::size() - 1) * 1000 + (idx - 1)); + ++idx; + }); global_v.barrier(); } From 7fa405e0d65f6a79e87215cdd12b4a3cd19df505 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Wed, 10 May 2017 16:58:54 +0200 Subject: [PATCH 010/161] Make g2g dash::copy work with matrix blocks and adapt test --- dash/include/dash/algorithm/Copy.h | 34 +++++++++++++++---- dash/include/dash/iterator/GlobViewIter.h | 4 +-- dash/test/algorithm/CopyTest.cc | 25 ++++++++++---- dash/test/container/MatrixTest.cc | 40 ++++++++++++++--------- 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 132a1cf5c..87e5f4732 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1195,22 +1195,44 @@ GlobOutputIt copy( { DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); - auto num_elements = dash::distance(in_first, in_last); + DASH_LOG_TRACE_VAR("dash::copy()", in_first); + DASH_LOG_TRACE_VAR("dash::copy()", in_last); + DASH_LOG_TRACE_VAR("dash::copy()", out_first); + auto num_elements = dash::distance(in_first, in_last); auto li_range_in = local_index_range(in_first, in_last); auto num_local_elem = li_range_in.end - li_range_in.begin; - auto pattern = in_first.pattern(); + DASH_LOG_TRACE_VAR("dash::copy()", num_elements); + DASH_LOG_TRACE_VAR("dash::copy()", num_local_elem); - auto local_in_first = in_first + pattern.global(li_range_in.begin); - auto local_in_last = in_first + pattern.global(li_range_in.end - 1); // copy our local portion into the global output range - if (num_elements > 0) { + if (num_local_elem > 0) { + auto pattern = in_first.pattern(); + // the distance from the first local element to the in_first iterator + auto in_offset = pattern.global(li_range_in.begin) + - in_first.global().gpos(); + + // the first local element + auto local_in_first = in_first + in_offset; + // the last local element + auto local_in_last = in_first + (num_local_elem + in_offset - 1); + auto local_out_first = out_first + in_offset; + + DASH_LOG_TRACE("Copying from range \n [", + pattern.global(li_range_in.begin), ", ", + pattern.global(li_range_in.end - 1), "] \n [", local_in_first, + "] to \n ", local_out_first, " (global offset ", in_offset, ") "); + dash::copy( local_in_first.local(), + // pointer one past the last element local_in_last.local() + 1, - out_first + pattern.global(li_range_in.begin)); + local_out_first); } + // TODO: + // - Implement adapter for local-to-global dash::copy here + // - Return if global input range has no local sub-range return (out_first + num_elements); } diff --git a/dash/include/dash/iterator/GlobViewIter.h b/dash/include/dash/iterator/GlobViewIter.h index e568719aa..8cd19022a 100644 --- a/dash/include/dash/iterator/GlobViewIter.h +++ b/dash/include/dash/iterator/GlobViewIter.h @@ -1091,10 +1091,10 @@ std::ostream & operator<<( ElementType, Pattern, GlobStaticMem, Pointer, Reference> & it) { std::ostringstream ss; - dash::GlobPtr ptr(it); +// dash::GlobPtr ptr(it); ss << "dash::GlobViewIter<" << typeid(ElementType).name() << ">(" << "idx:" << it._idx << ", " - << "gptr:" << ptr << ")"; + << "gptr:" << it.global().dart_gptr() << ")"; return operator<<(os, ss.str()); } diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index c5cb5c2ed..3b00107eb 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -823,19 +823,32 @@ TEST_F(CopyTest, GlobalToGlobal) source.barrier(); + // copy the full range + dash::copy(source.begin(), source.end(), target.begin()); + source.barrier(); - // copy the first local range with an offset - dash::copy(source.begin(), source.end() + 1, target.begin()); - - dash::for_each_with_index(source.begin(), source.end(), + dash::for_each_with_index(target.begin(), target.end(), [](value_t val, size_t idx) { ASSERT_EQ_U(val, dash::myid() * 1000 + idx); } ); - dash::for_each_with_index(target.begin() + 1, target.end(), + // copy the range with an offset (effectively moving the input + // range to the left by 1) + dash::copy(source.begin() + 1, source.end(), target.begin()); + source.barrier(); + + dash::for_each_with_index(target.begin(), target.end() - 1, [](value_t val, size_t idx) { - ASSERT_EQ_U(val, dash::myid() * 1000 + idx); + std::cout << idx << ": " << val << std::endl; + // the array has shifted so the last element is different + if ((idx % elem_per_unit) == (elem_per_unit - 1)) { + // the last element comes from the next unit + // this element has not been copied on the last unit + ASSERT_EQ_U(val, (dash::myid() + 1) * 1000 + idx + 1); + } else { + ASSERT_EQ_U(val, dash::myid() * 1000 + idx + 1); + } } ); diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 043e5c32c..f99603ecc 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -721,29 +721,39 @@ TEST_F(MatrixTest, BlockCopy) dash::Team::All(), team_spec); // Fill matrix + auto block_a = matrix_a.block(1); + auto block_b = matrix_b.block(0); if (myid == 0) { LOG_MESSAGE("Assigning matrix values"); - for(size_t col = 0; col < matrix_a.extent(0); ++col) { - for(size_t row = 0; row < matrix_a.extent(1); ++row) { - auto value = (row * matrix_a.extent(0)) + col; - matrix_a[col][row] = value; - matrix_b[col][row] = value; + for(size_t row = 0; row < matrix_a.extent(0); ++row) { + for(size_t col = 0; col < matrix_a.extent(1); ++col) { + auto value = (row * 1000) + col; + matrix_a[row][col] = value; + matrix_b[row][col] = value; } } } - LOG_MESSAGE("Wait for team barrier ..."); - dash::barrier(); - LOG_MESSAGE("Team barrier passed"); + + matrix_b.barrier(); + + LOG_MESSAGE("Copying block"); // Copy block 1 of matrix_a to block 0 of matrix_b: - dash::copy(matrix_a.block(1).begin(), - matrix_a.block(1).end(), - matrix_b.block(0).begin()); + dash::copy(block_a.begin(), + block_a.end(), + block_b.begin()); + matrix_b.barrier(); - // TODO: Add checks here! - LOG_MESSAGE("Wait for team barrier ..."); - dash::barrier(); - LOG_MESSAGE("Team barrier passed"); + LOG_MESSAGE("Checking copy result"); + if (myid == 0) { + LOG_MESSAGE("Checking copied matrix block values"); + for(size_t col = 0; col < block_a.extent(0); ++col) { + for(size_t row = 0; row < block_a.extent(1); ++row) { + ASSERT_EQ_U(static_cast(block_b[col][row]), + static_cast(block_a[col][row])); + } + } + } } TEST_F(MatrixTest, StorageOrder) From 02452171ead11bdabde64b033a8a1050309bcc40 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 20 May 2017 03:28:02 +0200 Subject: [PATCH 011/161] Added test on local view of cyclic array --- dash/test/view/ViewTest.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/dash/test/view/ViewTest.cc b/dash/test/view/ViewTest.cc index 11cb7b104..2fa55bfea 100644 --- a/dash/test/view/ViewTest.cc +++ b/dash/test/view/ViewTest.cc @@ -539,6 +539,41 @@ TEST_F(ViewTest, ArrayBlockCyclicPatternLocalSub) a.barrier(); } +TEST_F(ViewTest, ArrayCyclicPatternLocalSub) +{ + int elem_per_unit = 7; + int elem_additional = 2; + int array_size = dash::size() * elem_per_unit + elem_additional; + int num_local_elem = elem_per_unit + + ( dash::size() < elem_additional + ? elem_additional + : 0 ); + + dash::Array a(array_size, dash::CYCLIC); + dash::test::initialize_array(a); + + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternLocalSub", + "array:", range_str(a)); + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternLocalSub", + "local(array):", range_str(dash::local(a))); + + // sub(local(array)) + // + { + auto s_l_view = dash::sub( + 2, a.lsize() - 2, + dash::local( + a)); + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternLocalSub", + range_str(s_l_view)); + DASH_ASSERT( + std::equal(a.lbegin() + 2, + a.lbegin() + a.lsize() - 2, + s_l_view.begin())); + } + +} + TEST_F(ViewTest, ArrayBlockCyclicPatternLocalBlocks) { int block_size = 5; From 4f24fb04b7bf849fdd9bd3394d8e48fdd92d240e Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 20 May 2017 12:36:17 +0200 Subject: [PATCH 012/161] Using view expressions in dash::copy, added unit tests, extended range and view traits --- .gitignore | 2 +- dash/include/dash/Exception.h | 8 +- dash/include/dash/GlobPtr.h | 130 ++++++------- dash/include/dash/Meta.h | 6 + dash/include/dash/Range.h | 148 +++++++++++--- dash/include/dash/algorithm/Copy.h | 182 +++++++++++------- dash/include/dash/iterator/GlobIter.h | 2 +- dash/include/dash/pattern/CSRPattern.h | 28 +++ .../dash/pattern/internal/LocalPattern.h | 58 ++++++ dash/include/dash/view/ViewBlocksMod.h | 4 + dash/include/dash/view/ViewIterator.h | 12 ++ dash/include/dash/view/ViewTraits.h | 2 +- dash/test/TestBase.h | 24 +++ dash/test/meta/RangeTest.cc | 3 + dash/test/view/ViewTest.cc | 76 +++++++- 15 files changed, 504 insertions(+), 181 deletions(-) create mode 100644 dash/include/dash/pattern/internal/LocalPattern.h diff --git a/.gitignore b/.gitignore index c3f4f534c..2e326af81 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ dash/include/dash/util/StaticConfig.h *.log *.out ipm/*/GEN.* -my.*.sh +my.* .syntastic* .clang* tags diff --git a/dash/include/dash/Exception.h b/dash/include/dash/Exception.h index 547d707f5..c871b4da1 100644 --- a/dash/include/dash/Exception.h +++ b/dash/include/dash/Exception.h @@ -1,6 +1,9 @@ #ifndef DASH__EXCEPTION_H_ #define DASH__EXCEPTION_H_ +#include +#include + #include #include #include @@ -8,10 +11,11 @@ #include #include -#include -#include +#include #include +#include + #define DASH_STACK_TRACE() do { \ dash__print_stacktrace(); \ diff --git a/dash/include/dash/GlobPtr.h b/dash/include/dash/GlobPtr.h index cc21e0bf4..a3a12f4d3 100644 --- a/dash/include/dash/GlobPtr.h +++ b/dash/include/dash/GlobPtr.h @@ -39,14 +39,6 @@ template class GlobConstPtr; template class GlobPtr; -template -dash::gptrdiff_t distance( - const GlobPtr & gbegin, - const GlobPtr & gend); - /** * Pointer in global memory space with random access arithmetics. * @@ -72,7 +64,11 @@ class GlobPtr typedef GlobPtr const_type; typedef typename dash::default_index_t index_type; + typedef value_type * local_type; + typedef self_t global_type; + typedef index_type gptrdiff_t; + typedef index_type difference_type; public: template @@ -269,10 +265,57 @@ class GlobPtr /** * Pointer offset difference operator. + * + * Defined with independent value types allow calculation + * of distance between \c GlobPtr and \c GlobPtr. + * Refernced value types must have identical size. + * + * \todo + * Validate compatibility of memory space types using memory space traits + * once they are available. + * + * \return Global pointer distance between the first and second + * global pointer, corresponds to pointer distance + * \c (gend - gbegin) + * + * \concept{DashMemorySpaceConcept} */ - constexpr index_type operator-(const self_t & rhs) const noexcept + template + difference_type operator-( + const GlobPtr & rhs) const noexcept { - return dash::distance(rhs, *this); + using val_type_b = typename std::decay::type::value_type; + using val_type_e = value_type; + + static_assert( + sizeof(val_type_b) == sizeof(val_type_e), + "value types of global pointers are not compatible for dash::distance"); + + // Both pointers in same unit space: + if (rhs._rbegin_gptr.unitid == _rbegin_gptr.unitid || + rhs._mem_space == nullptr) { + return ( _rbegin_gptr.addr_or_offs.offset - + rhs._rbegin_gptr.addr_or_offs.offset ) + / sizeof(value_type); + } + // If unit of begin pointer is after unit of end pointer, + // return negative distance with swapped argument order: + if (rhs._rbegin_gptr.unitid > _rbegin_gptr.unitid) { + return -(rhs - *this); + } + // Pointers span multiple unit spaces, accumulate sizes of + // local unit memory ranges in the pointer range: + index_type dist = rhs._mem_space->local_size( + dart_team_unit_t { rhs.dart_gptr().unitid }) + - (rhs.dart_gptr().addr_or_offs.offset + / sizeof(value_type)) + + (dart_gptr().addr_or_offs.offset + / sizeof(value_type)); + for (int u = rhs.dart_gptr().unitid+1; + u < dart_gptr().unitid; ++u) { + dist += _mem_space->local_size(dart_team_unit_t { u }); + } + return dist; } /** @@ -581,6 +624,9 @@ class GlobConstPtr typedef typename base_t::index_type index_type; typedef typename base_t::gptrdiff_t gptrdiff_t; + typedef value_type * local_type; + typedef self_t global_type; + template friend std::ostream & operator<<( std::ostream & os, @@ -766,70 +812,6 @@ std::ostream & operator<<( #endif // DOXYGEN -/** - * Specialization of \c dash::distance for \c dash::GlobPtr as default - * definition of pointer distance in global memory spaces. - * - * Equivalent to \c (gend - gbegin). - * - * \note - * Defined with independent value types T1 and T2 to allow calculation - * of distance between \c GlobPtr and \c GlobPtr. - * The pointer value types must have identical size. - * - * \todo - * Validate compatibility of memory space types using memory space traits - * once they are available. - * - * \return Number of elements in the range between the first and second - * global pointer - * - * \concept{DashMemorySpaceConcept} - */ -template -dash::gptrdiff_t distance( - // First global pointer in range - const GlobPtr & gbegin, - // Final global pointer in range - const GlobPtr & gend) { - using index_type = dash::gptrdiff_t; - using val_type_b = typename std::decay::type::value_type; - using val_type_e = typename std::decay::type::value_type; - using value_type = val_type_b; - - static_assert( - sizeof(val_type_b) == sizeof(val_type_e), - "value types of global pointers are not compatible for dash::distance"); - - // Both pointers in same unit space: - if (gbegin._rbegin_gptr.unitid == gend._rbegin_gptr.unitid || - gbegin._mem_space == nullptr) { - return ( gend._rbegin_gptr.addr_or_offs.offset - - gbegin._rbegin_gptr.addr_or_offs.offset ) - / sizeof(value_type); - } - // If unit of begin pointer is after unit of end pointer, - // return negative distance with swapped argument order: - if (gbegin._rbegin_gptr.unitid > gend._rbegin_gptr.unitid) { - return -(dash::distance(gend, gbegin)); - } - // Pointers span multiple unit spaces, accumulate sizes of - // local unit memory ranges in the pointer range: - index_type dist = gbegin._mem_space->local_size( - dart_team_unit_t { gbegin.dart_gptr().unitid }) - - (gbegin.dart_gptr().addr_or_offs.offset - / sizeof(value_type)) - + (gend.dart_gptr().addr_or_offs.offset - / sizeof(value_type)); - for (int u = gbegin.dart_gptr().unitid+1; - u < gend.dart_gptr().unitid; ++u) { - dist += gend._mem_space->local_size(dart_team_unit_t { u }); - } - return dist; -} /** * Resolve the number of elements between two global pointers. diff --git a/dash/include/dash/Meta.h b/dash/include/dash/Meta.h index 152ec7e64..9929ab224 100644 --- a/dash/include/dash/Meta.h +++ b/dash/include/dash/Meta.h @@ -71,6 +71,12 @@ DASH__META__DEFINE_TRAIT__HAS_TYPE(const_reference); */ DASH__META__DEFINE_TRAIT__HAS_TYPE(value_type); +/** + * Definition of type trait \c dash::detail::has_type_pattern_type + * with static member \c value indicating whether type \c T provides + * dependent type \c pattern_type. + */ +DASH__META__DEFINE_TRAIT__HAS_TYPE(pattern_type); } // namespace dash diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 490f9f4ca..bb7c21741 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -49,6 +49,8 @@ #include #include +#include + #include @@ -209,7 +211,7 @@ struct _is_range_type * * * Example: - * + *: * \code * bool g_array_is_range = dash::is_range< * dash::Array @@ -245,12 +247,20 @@ struct is_range : dash::detail::_is_range_type { }; template < typename RangeType, typename Iterator, - typename Sentinel = Iterator > -class RangeBase { + typename Sentinel, + bool IsPatternIterator > +class RangeBase; + +template < + typename RangeType, + typename Iterator, + typename Sentinel > +class RangeBase { public: - typedef Iterator iterator; - typedef Sentinel sentinel; - typedef dash::default_index_t index_type; + typedef Iterator iterator; + typedef Sentinel sentinel; + typedef dash::default_index_t index_type; + typedef typename Iterator::pattern_type pattern_type; protected: RangeType & derived() { return static_cast(*this); @@ -260,6 +270,26 @@ class RangeBase { } }; +template < + typename RangeType, + typename Iterator, + typename Sentinel > +class RangeBase { +public: + typedef Iterator iterator; + typedef Sentinel sentinel; + typedef dash::default_index_t index_type; +//typedef internal::LocalPattern pattern_type; +protected: + RangeType & derived() { + return static_cast(*this); + } + const RangeType & derived() const { + return static_cast(*this); + } +}; + + /** * Specialization of \c dash::view_traits for IteratorRange. @@ -271,13 +301,17 @@ struct view_traits > { private: typedef IteratorRange RangeT; public: - typedef RangeT origin_type; typedef RangeT domain_type; + typedef RangeT origin_type; + typedef typename RangeT::pattern_type pattern_type; +//typedef typename IteratorT::pattern_type pattern_type; typedef RangeT image_type; typedef RangeT global_type; typedef typename RangeT::local_type local_type; typedef typename RangeT::index_type index_type; - typedef typename RangeT::index_set_type index_set_type; + typedef typename RangeT::size_type size_type; +//typedef typename RangeT::index_set_type index_set_type; + typedef dash::IndexSetIdentity index_set_type; /// Whether the view type is a projection (has less dimensions than the /// view's domain type). @@ -292,6 +326,8 @@ struct view_traits > { RangeT, typename RangeT::local_type >::value > is_local; + + typedef std::integral_constant rank; }; /** @@ -304,9 +340,17 @@ template < class IteratorRange : public RangeBase< IteratorRange, Iterator, - Sentinel > + Sentinel, + dash::has_type_pattern_type::value > { - typedef IteratorRange self_t; + typedef IteratorRange + self_t; + typedef RangeBase< + self_t, + Iterator, + Sentinel, + dash::has_type_pattern_type::value > + base_t; Iterator & _begin; Sentinel & _end; @@ -315,9 +359,15 @@ class IteratorRange typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; - typedef typename iterator::pattern_type pattern_type; - typedef dash::IndexSetIdentity index_set_type; + typedef dash::default_size_t size_type; +//typedef dash::IndexSetIdentity index_set_type; + typedef std::integral_constant rank; + typedef typename iterator::value_type value_type; + typedef typename base_t::pattern_type pattern_type; + + typedef std::integral_constant< + bool, std::is_pointer::value> is_local; typedef typename std::conditional< @@ -334,9 +384,10 @@ class IteratorRange typename sentinel::local_type >::type local_sentinel; - - typedef IteratorRange local_type; + typedef self_t domain_type; + typedef self_t global_type; + typedef IteratorRange local_type; public: template @@ -353,6 +404,8 @@ class IteratorRange constexpr iterator begin() const { return _begin; } constexpr iterator end() const { return _end; } + constexpr size_type size() const { return std::distance(_begin, _end); } + constexpr const local_type local() const { return local_type( _begin.local(), @@ -364,12 +417,43 @@ class IteratorRange return _begin.pattern(); } - constexpr index_set_type index_set() const { - return index_set_type(*this); - } +// constexpr index_set_type index_set() const { +// return index_set_type(*this); +// } }; +template < + typename IteratorT, + typename SentinelT > +struct view_traits > { +private: + typedef IteratorRange RangeT; +public: + typedef RangeT domain_type; + typedef RangeT origin_type; +//typedef typename RangeT::pattern_type pattern_type; + typedef RangeT image_type; + typedef RangeT global_type; + typedef typename RangeT::local_type local_type; + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; + typedef dash::IndexSetIdentity index_set_type; + + /// Whether the view type is a projection (has less dimensions than the + /// view's domain type). + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + /// Whether the view is the origin domain. + typedef std::integral_constant is_origin; + /// Whether the view / container type is a local view. + /// \note A container type is local if it is identical to its + /// \c local_type + typedef std::integral_constant is_local; + + typedef std::integral_constant rank; +}; + /** * Specialization of adapter template for range concept, wraps `begin` * and `end` pointers in range type. @@ -381,7 +465,9 @@ class IteratorRange : public RangeBase< IteratorRange, LocalIterator *, - LocalSentinel * > + LocalSentinel *, + false // iterator does not specify pattern + > { typedef IteratorRange self_t; @@ -389,16 +475,22 @@ class IteratorRange LocalSentinel * _end; public: - typedef LocalIterator * iterator; - typedef LocalSentinel * sentinel; - typedef dash::default_index_t index_type; - typedef dash::IndexSetIdentity index_set_type; - typedef LocalIterator value_type; + typedef LocalIterator * iterator; + typedef LocalSentinel * sentinel; + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; +//typedef typename internal::LocalPattern pattern_type; + typedef dash::IndexSetIdentity index_set_type; + typedef LocalIterator value_type; typedef iterator local_iterator; typedef sentinel local_sentinel; - typedef IteratorRange local_type; + typedef IteratorRange local_type; + typedef self_t global_type; + typedef self_t domain_type; + + typedef std::integral_constant is_local; public: template @@ -415,13 +507,15 @@ class IteratorRange constexpr iterator begin() const { return _begin; } constexpr iterator end() const { return _end; } + constexpr size_type size() const { return std::distance(_begin, _end); } + constexpr const local_type & local() const { return *this; } - constexpr index_set_type index_set() const { - return index_set_type(*this); - } +// constexpr index_set_type index_set() const { +// return index_set_type(*this); +// } }; /** diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 368d58ed9..44c63f1e8 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -4,6 +4,14 @@ #include #include +#include +#include +#include +#include + +#include + + #include #include @@ -439,7 +447,6 @@ dash::Future copy_async_impl( DASH_LOG_TRACE("dash::copy_async_impl [Future]()", " wait for", req_handles.size(), "async get request"); DASH_LOG_TRACE("dash::copy_async_impl [Future]", " flush:", req_handles); - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " _out:", _out); #ifdef DASH_ENABLE_TRACE_LOGGING for (auto gptr : req_handles) { DASH_LOG_TRACE("dash::copy_async_impl [Future]", " req_handle:", @@ -516,7 +523,7 @@ GlobOutputIt copy_impl( */ template < typename ValueType, - class GlobOutputIt > + class GlobOutputIt > dash::Future copy_async_impl( ValueType * in_first, ValueType * in_last, @@ -1022,109 +1029,136 @@ ValueType * copy( /** * Variant of \c dash::copy as asynchronous local-to-global copy operation. + * Output iterator type must specify dependent pattern type as + * \c GlobOutputIt::pattern_type. * * \ingroup DashAlgorithms */ template < typename ValueType, class GlobOutputIt > -dash::Future copy_async( +auto copy_async( ValueType * in_first, ValueType * in_last, GlobOutputIt out_first) + -> typename std::enable_if< + dash::has_type_pattern_type::value, + dash::Future + >::type { - auto fut = dash::internal::copy_async_impl(in_first, - in_last, - out_first); - return fut; + DASH_LOG_TRACE("dash::copy_async()", "blocking, local to global"); + // Return value, initialize with begin of output range, indicating no values + // have been copied: + GlobOutputIt out_last = out_first; + // Number of elements to copy in total: + auto num_elements = std::distance(in_first, in_last); + // Global iterator pointing at hypothetical end of output range: + GlobOutputIt out_h_last = out_first + num_elements; + + DASH_LOG_TRACE_VAR("dash::copy_async", num_elements); + + // Futures of asynchronous get requests, one per block: + auto futures = std::vector< dash::Future >(); + auto out_range = dash::make_range(out_first, out_h_last); + auto out_blocks = dash::blocks(out_range); + auto in_copy_it = in_first; + + DASH_LOG_TRACE("dash::copy_async", "number of blocks:", out_blocks.size()); + for (auto block : out_blocks) { + DASH_LOG_TRACE("dash::copy_async", "block size:", block.size()); + futures.push_back(static_cast>( + dash::internal::copy_async_impl( + in_copy_it, + in_copy_it + block.size(), + block.begin())) ); + in_copy_it += block.size(); + } + out_last += dash::distance(in_first, in_copy_it); + + dash::Future fut_result([=]() mutable { + auto _out = out_last; + DASH_LOG_TRACE("dash::copy_async [Future]()", + "wait for", futures.size(), "async copy requests"); + DASH_LOG_TRACE("dash::copy_async [Future]", " futures:", futures); + DASH_LOG_TRACE("dash::copy_async [Future]", " _out:", _out); + for (auto f : futures) { + f.wait(); + } + DASH_LOG_TRACE("dash::copy_async [Future] >", "async requests completed", + "futures:", futures, "_out:", _out); + return _out; + }); + DASH_LOG_TRACE("dash::copy_async >", "finished,", + "expected out_last:", out_last); + return fut_result; } /** - * Specialization of \c dash::copy as local-to-global blocking copy operation. + * Variant of \c dash::copy as asynchronous local-to-global copy operation. + * Output iterator type must specify dependent pattern type as + * \c GlobOutputIt::pattern_type. * * \ingroup DashAlgorithms */ template < typename ValueType, class GlobOutputIt > -GlobOutputIt copy( +auto copy_async( ValueType * in_first, ValueType * in_last, GlobOutputIt out_first) + -> typename std::enable_if< + !dash::has_type_pattern_type::value, + dash::Future + >::type +{ + DASH_LOG_TRACE("dash::copy_async()", + "blocking, local to global, restricted to single block"); + return dash::internal::copy_async_impl( + in_first, + in_last, + out_first); +} + +/** + * Specialization of \c dash::copy as local-to-global blocking copy operation. + * + * \ingroup DashAlgorithms + */ +template < + typename ValueType, + class GlobOutputIt > +GlobOutputIt copy( + const ValueType * in_first, + const ValueType * in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy()", "blocking, local to global"); - // Return value, initialize with begin of output range, indicating no values - // have been copied: + // Return value, initialize with begin of output range, indicating no + // values have been copied: GlobOutputIt out_last = out_first; // Number of elements to copy in total: auto num_elements = std::distance(in_first, in_last); - DASH_LOG_TRACE_VAR("dash::copy", num_elements); // Global iterator pointing at hypothetical end of output range: GlobOutputIt out_h_last = out_first + num_elements; + + DASH_LOG_TRACE_VAR("dash::copy", num_elements); DASH_LOG_TRACE_VAR("dash::copy", out_first.pos()); DASH_LOG_TRACE_VAR("dash::copy", out_h_last.pos()); - // Test if a subrange of global output range is local: - auto li_range_out = local_index_range(out_first, out_h_last); - DASH_LOG_TRACE_VAR("dash::copy", li_range_out.begin); - DASH_LOG_TRACE_VAR("dash::copy", li_range_out.end); - // Number of elements in the local subrange: - auto num_local_elem = li_range_out.end - li_range_out.begin; - // Check if part of the output range is local: - if (num_local_elem > 0) { - // Part of the output range is local - // Copy local input subrange to local output range directly: - auto pattern = out_first.pattern(); - DASH_LOG_TRACE("dash::copy", "resolving local subrange"); - DASH_LOG_TRACE_VAR("dash::copy", num_local_elem); - // Local index range to global output index range: - auto g_l_offset_begin = pattern.global(li_range_out.begin); - DASH_LOG_TRACE_VAR("dash::copy", g_l_offset_begin); - auto g_l_offset_end = pattern.global(li_range_out.end-1) - + 1; // pat.global(l_end) would be out of range - DASH_LOG_TRACE_VAR("dash::copy", g_l_offset_end); - // Offset of local subrange in output range - auto l_elem_offset = g_l_offset_begin - out_first.pos(); - DASH_LOG_TRACE_VAR("dash::copy",l_elem_offset); - // Convert local subrange of global output to native pointers: - ValueType * l_out_first = (out_first + l_elem_offset).local(); - DASH_LOG_TRACE_VAR("dash::copy", l_out_first); - ValueType * l_out_last = l_out_first + num_local_elem; - DASH_LOG_TRACE_VAR("dash::copy", l_out_last); - // ... [ ........ | ---- l ---- | ......... ] ... - // ^ ^ ^ ^ - // out_first l_out_first l_out_last out_last - out_last = out_first + num_local_elem; - // Assert that all elements in local range have been copied: - DASH_LOG_TRACE("dash::copy", "copying local subrange"); - DASH_LOG_TRACE_VAR("dash::copy", in_first); - DASH_ASSERT_RETURNS( - std::copy(in_first + l_elem_offset, - in_first + l_elem_offset + num_local_elem, - l_out_first), - l_out_last); - // Copy to remote elements preceding the local subrange: - if (g_l_offset_begin > out_first.pos()) { - DASH_LOG_TRACE("dash::copy", "copy to global preceding local subrange"); - out_last = dash::internal::copy_impl( - in_first, - in_first + l_elem_offset, - out_first); - } - // Copy to remote elements succeeding the local subrange: - if (g_l_offset_end < out_h_last.pos()) { - DASH_LOG_TRACE("dash::copy", "copy to global succeeding local subrange"); - out_last = dash::internal::copy_impl( - in_first + l_elem_offset + num_local_elem, - in_last, - out_first + num_local_elem); - } - } else { - // All elements in output range are remote - DASH_LOG_TRACE("dash::copy", "no local subrange"); - out_last = dash::internal::copy_impl( - in_first, - in_last, - out_first); + + auto out_range = dash::make_range(out_first, out_h_last); + auto out_blocks = dash::blocks(out_range); + auto in_copy_it = in_first; + + DASH_LOG_TRACE("dash::copy", "number of blocks:", out_blocks.size()); + for (auto block : out_blocks) { + DASH_LOG_TRACE("dash::copy", "block size:", block.size()); + out_last = static_cast( + dash::internal::copy_impl( + in_copy_it, + in_copy_it + block.size(), + block.begin())); + in_copy_it = in_first + dash::distance(out_first, out_last); } return out_last; } diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index 38a1c640c..2e9ed5ffa 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -105,7 +105,7 @@ class GlobIter self_const_t; public: - typedef std::integral_constant has_view; + typedef std::integral_constant has_view; public: // For ostream output diff --git a/dash/include/dash/pattern/CSRPattern.h b/dash/include/dash/pattern/CSRPattern.h index a516895a9..6ec6803bf 100644 --- a/dash/include/dash/pattern/CSRPattern.h +++ b/dash/include/dash/pattern/CSRPattern.h @@ -586,6 +586,7 @@ class CSRPattern<1, Arrangement, IndexType> { return std::array {{ _local_sizes[_team->myid()] }}; } + /** * The actual number of elements in this pattern that are local to the * given unit, by dimension. @@ -885,6 +886,14 @@ class CSRPattern<1, Arrangement, IndexType> return _blockspec; } + /** + * Cartesian arrangement of local pattern blocks. + */ + constexpr const BlockSpec_t local_blockspec() const noexcept + { + return BlockSpec_t { 1 }; + } + /** * Index of block at given global coordinates. * @@ -897,6 +906,25 @@ class CSRPattern<1, Arrangement, IndexType> return static_cast(unit_at(g_coords[0])); } + /** + * Unit and local block index at given global coordinates. + * + * \see DashPatternConcept + */ + local_index_t local_block_at( + /// Global coordinates of element + const std::array & g_coords) const + { + local_index_t l_pos; + + auto unit_id = unit_at(g_coords[0]); + // auto block_size = _local_sizes[unit_id]; + // index_type offset = _block_offsets[unit_id]; + l_pos.unit = _teamspec.at({ unit_id }); + l_pos.index = 0; + return l_pos; + } + /** * View spec (offset and extents) of block at global linear block index * in cartesian element space. diff --git a/dash/include/dash/pattern/internal/LocalPattern.h b/dash/include/dash/pattern/internal/LocalPattern.h new file mode 100644 index 000000000..4b99d12ca --- /dev/null +++ b/dash/include/dash/pattern/internal/LocalPattern.h @@ -0,0 +1,58 @@ +#ifndef DASH__PATTERN__INTERNAL__LOCAL_PATTERN_H__INCLUDED +#define DASH__PATTERN__INTERNAL__LOCAL_PATTERN_H__INCLUDED + +#include + +#include + + +namespace dash { +namespace internal { + +template< + dim_t NumDimensions, + MemArrange Arrangement = dash::ROW_MAJOR, + typename IndexType = dash::default_index_t > +class LocalPattern; + + + +template< + MemArrange Arrangement, + typename IndexType > +class LocalPattern<1, Arrangement, IndexType> { +private: + static const dim_t NumDimensions = 1; + +public: + static constexpr char const * PatternName = "LocalPattern"; + +public: + /// Satisfiable properties in pattern property category Partitioning: + typedef pattern_partitioning_properties< + // Block extents are constant for every dimension. + pattern_partitioning_tag::rectangular, + // Identical number of elements in every block. + pattern_partitioning_tag::balanced, + // Size of blocks may differ. + pattern_partitioning_tag::unbalanced + > partitioning_properties; + /// Satisfiable properties in pattern property category Mapping: + typedef pattern_mapping_properties< + // Number of blocks assigned to a unit may differ. + pattern_mapping_tag::unbalanced + > mapping_properties; + /// Satisfiable properties in pattern property category Layout: + typedef pattern_layout_properties< + // Local indices iterate over block boundaries. + pattern_layout_tag::canonical, + // Local element order corresponds to canonical linearization + // within entire local memory. + pattern_layout_tag::linear + > layout_properties; +}; + +} // namespace dash +} // namespace internal + +#endif // DASH__PATTERN__INTERNAL__LOCAL_PATTERN_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 3a6f55f3c..1eb27339d 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -19,6 +19,8 @@ #include #include +#include + namespace dash { @@ -51,6 +53,7 @@ struct view_traits > { typedef ViewBlockMod global_type; typedef typename DomainType::index_type index_type; + typedef typename view_traits::size_type size_type; typedef typename std::conditional< NDim == 1, dash::IndexSetSub, @@ -420,6 +423,7 @@ struct view_traits > { typedef ViewBlocksMod global_type; typedef typename DomainType::index_type index_type; + typedef typename view_traits::size_type size_type; typedef dash::IndexSetBlocks> index_set_type; diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 1ddd66542..61c85ef02 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -103,6 +103,10 @@ class ViewIterator constexpr explicit operator DomainIterator() const { return (_domain_it + _index_set[this->pos()]); } + + explicit operator DomainIterator() { + return (_domain_it + _index_set[this->pos()]); + } }; template < @@ -171,6 +175,14 @@ class ViewIterator inline value_type * local() { return (_domain_it + (_index_set[this->pos()])).local(); } + + constexpr explicit operator const value_type *() const { + return (_domain_it + (_index_set[this->pos()])).local(); + } + + explicit operator value_type *() { + return (_domain_it + (_index_set[this->pos()])).local(); + } }; template diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index fc0555981..cc5cc7d9b 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -96,7 +96,7 @@ namespace detail { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; + typedef std::integral_constant is_origin; typedef typename ViewT::index_type index_type; typedef typename ViewT::size_type size_type; diff --git a/dash/test/TestBase.h b/dash/test/TestBase.h index 8bc0bff78..849e09639 100644 --- a/dash/test/TestBase.h +++ b/dash/test/TestBase.h @@ -240,6 +240,30 @@ static bool expect_range_values_equal( return (end_a == it_a) && (end_b == it_b); } +template +static bool expect_range_values_equal( + const IteratorA & rng_a_begin, + const SentinelA & rng_a_end, + const IteratorB & rng_b_begin) { + auto it_a = rng_a_begin; + auto it_b = rng_b_begin; + const auto end_a = rng_a_end; + const auto end_b = rng_b_begin + dash::distance(it_a, end_a); + + const auto rng_a = dash::make_range(it_a, end_a); + const auto rng_b = dash::make_range(it_b, end_b); + + DASH_LOG_TRACE_VAR("TestBase.expect_range_values_equal", rng_a); + DASH_LOG_TRACE_VAR("TestBase.expect_range_values_equal", rng_b); + for (; it_a != end_a && it_b != end_b; ++it_a, ++it_b) { + if (static_cast(*it_a) != + static_cast(*it_b)) { + return false; + } + } + return (end_a == it_a) && (end_b == it_b); +} + class TestBase : public ::testing::Test { protected: diff --git a/dash/test/meta/RangeTest.cc b/dash/test/meta/RangeTest.cc index 5150a860a..cf9dce8be 100644 --- a/dash/test/meta/RangeTest.cc +++ b/dash/test/meta/RangeTest.cc @@ -92,5 +92,8 @@ TEST_F(RangeTest, RangeTraits) static_assert( dash::is_range::value == true, "dash::is_range::value not matched"); + static_assert( + dash::is_view::value == true, + "dash::is_view::value not matched"); } diff --git a/dash/test/view/ViewTest.cc b/dash/test/view/ViewTest.cc index 2fa55bfea..5dd67c151 100644 --- a/dash/test/view/ViewTest.cc +++ b/dash/test/view/ViewTest.cc @@ -6,6 +6,8 @@ #include #include +#include + #include #include @@ -571,7 +573,79 @@ TEST_F(ViewTest, ArrayCyclicPatternLocalSub) a.lbegin() + a.lsize() - 2, s_l_view.begin())); } +} + +TEST_F(ViewTest, ArrayCyclicPatternCopyLocalToGlobal) +{ + int elem_per_unit = 7; + int elem_additional = 2; + int array_size = dash::size() * elem_per_unit + elem_additional; + int num_local_elem = elem_per_unit + + ( dash::size() < elem_additional + ? elem_additional + : 0 ); + + dash::Array a(array_size, dash::CYCLIC); + dash::test::initialize_array(a); + + dash::Array a_pre(array_size, dash::CYCLIC); + dash::test::initialize_array(a_pre); + auto copy_num_elem = a.size() / 2; + auto copy_dest_begin_idx = a.size() / 4; + auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; + + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + "array:", range_str(a)); + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + "copy", copy_num_elem, + "[", copy_dest_begin_idx, "...", copy_dest_end_idx, "]"); + + std::vector buf(copy_num_elem); + std::iota(buf.begin(), buf.end(), 0.9999); + + if (dash::myid() == 0) { + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + // copy local buffer to global array + auto copy_end_it = dash::copy( + buf.data(), + buf.data() + copy_num_elem, + copy_begin_it); + EXPECT_EQ_U(copy_end_it, copy_begin_it + copy_num_elem); + } + a.barrier(); + + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + "array:", range_str(a)); + + auto eq_pred = + [](float el_a, + float el_b) { + return static_cast(el_a * 1000000) == + static_cast(el_b * 1000000); + }; + + // Elements in front of copied range: + EXPECT_TRUE_U( + std::equal( + a.begin(), + a.begin() + copy_dest_begin_idx, + a_pre.begin(), + eq_pred)); + // Elements in copied range: + EXPECT_TRUE_U( + std::equal( + a.begin() + copy_dest_begin_idx, + a.begin() + copy_dest_end_idx, + buf.begin(), + eq_pred)); + // Elements after copied range: + EXPECT_TRUE_U( + std::equal( + a.begin() + copy_dest_end_idx, + a.end(), + a_pre.begin() + copy_dest_end_idx, + eq_pred)); } TEST_F(ViewTest, ArrayBlockCyclicPatternLocalBlocks) @@ -600,7 +674,7 @@ TEST_F(ViewTest, ArrayBlockCyclicPatternLocalBlocks) int l_b_idx; int l_idx; - auto blocks_view = dash::blocks(a); + auto blocks_view = dash::blocks(a); if (dash::myid() == 0) { for (auto block : blocks_view) { DASH_LOG_DEBUG("ViewTest.ArrayBlockCyclicPatternLocalBlocks", "----", From f7aa958db62527bf908bf81f2990d48487363da2 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 23 May 2017 02:58:18 +0200 Subject: [PATCH 013/161] Added stream operators for unique_ptr, shared_ptr --- dash/include/dash/internal/StreamConversion.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dash/include/dash/internal/StreamConversion.h b/dash/include/dash/internal/StreamConversion.h index e65bcd621..88416f76f 100644 --- a/dash/include/dash/internal/StreamConversion.h +++ b/dash/include/dash/internal/StreamConversion.h @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -31,6 +32,30 @@ std::ostream & operator<<( dart_team_unit_t uid); +/** + * Write \c std::shared_ptr to output stream. + */ +template +std::ostream & operator<<( + std::ostream & os, + const std::shared_ptr & p) { + os << dash::typestr(p) + << "(" << p.get() << ")"; + return os; +} + +/** + * Write \c std::unique_ptr to output stream. + */ +template +std::ostream & operator<<( + std::ostream & os, + const std::unique_ptr & p) { + os << dash::typestr(p) + << "(" << p.get() << ")"; + return os; +} + /** * Write \c std::pair to output stream. */ From 9dbd69c766109c0f9205b5d95f2b0a7507fc9fd4 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 23 May 2017 03:20:39 +0200 Subject: [PATCH 014/161] View test: copy blockcyclic local to global --- dash/test/view/ViewTest.cc | 88 +++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 6 deletions(-) diff --git a/dash/test/view/ViewTest.cc b/dash/test/view/ViewTest.cc index 5dd67c151..c784221fa 100644 --- a/dash/test/view/ViewTest.cc +++ b/dash/test/view/ViewTest.cc @@ -545,10 +545,11 @@ TEST_F(ViewTest, ArrayCyclicPatternLocalSub) { int elem_per_unit = 7; int elem_additional = 2; - int array_size = dash::size() * elem_per_unit + elem_additional; + int array_size = dash::size() * elem_per_unit + + std::min(elem_additional, dash::size()); int num_local_elem = elem_per_unit + - ( dash::size() < elem_additional - ? elem_additional + ( dash::myid() < elem_additional + ? 1 : 0 ); dash::Array a(array_size, dash::CYCLIC); @@ -579,10 +580,11 @@ TEST_F(ViewTest, ArrayCyclicPatternCopyLocalToGlobal) { int elem_per_unit = 7; int elem_additional = 2; - int array_size = dash::size() * elem_per_unit + elem_additional; + int array_size = dash::size() * elem_per_unit + + std::min(elem_additional, dash::size()); int num_local_elem = elem_per_unit + - ( dash::size() < elem_additional - ? elem_additional + ( dash::myid() < elem_additional + ? 1 : 0 ); dash::Array a(array_size, dash::CYCLIC); @@ -648,6 +650,80 @@ TEST_F(ViewTest, ArrayCyclicPatternCopyLocalToGlobal) eq_pred)); } +TEST_F(ViewTest, ArrayBlockCyclicPatternCopyLocalToGlobal) +{ + int elem_per_unit = 7; + int elem_additional = 2; + int array_size = dash::size() * elem_per_unit + + std::min(elem_additional, dash::size()); + int num_local_elem = elem_per_unit + + ( dash::myid() < elem_additional + ? 1 + : 0 ); + + dash::Array a(array_size, dash::BLOCKCYCLIC(3)); + dash::test::initialize_array(a); + + dash::Array a_pre(array_size, dash::BLOCKCYCLIC(3)); + dash::test::initialize_array(a_pre); + + auto copy_num_elem = a.size() / 2; + auto copy_dest_begin_idx = a.size() / 4; + auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; + + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + "array:", range_str(a)); + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + "copy", copy_num_elem, + "[", copy_dest_begin_idx, "...", copy_dest_end_idx, "]"); + + std::vector buf(copy_num_elem); + std::iota(buf.begin(), buf.end(), 0.9999); + + if (dash::myid() == 0) { + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + // copy local buffer to global array + auto copy_end_it = dash::copy( + buf.data(), + buf.data() + copy_num_elem, + copy_begin_it); + EXPECT_EQ_U(copy_end_it, copy_begin_it + copy_num_elem); + } + a.barrier(); + + DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + "array:", range_str(a)); + + auto eq_pred = + [](float el_a, + float el_b) { + return static_cast(el_a * 1000000) == + static_cast(el_b * 1000000); + }; + + // Elements in front of copied range: + EXPECT_TRUE_U( + std::equal( + a.begin(), + a.begin() + copy_dest_begin_idx, + a_pre.begin(), + eq_pred)); + // Elements in copied range: + EXPECT_TRUE_U( + std::equal( + a.begin() + copy_dest_begin_idx, + a.begin() + copy_dest_end_idx, + buf.begin(), + eq_pred)); + // Elements after copied range: + EXPECT_TRUE_U( + std::equal( + a.begin() + copy_dest_end_idx, + a.end(), + a_pre.begin() + copy_dest_end_idx, + eq_pred)); +} + TEST_F(ViewTest, ArrayBlockCyclicPatternLocalBlocks) { int block_size = 5; From 5d31f8823fd5a904c3090add31b1feac6ce7f446 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 23 May 2017 03:47:11 +0200 Subject: [PATCH 015/161] Cleanup in dash::copy --- dash/include/dash/algorithm/Copy.h | 221 +++++++++++------------------ 1 file changed, 82 insertions(+), 139 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 44c63f1e8..3b11b3d48 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -22,11 +22,6 @@ #include -// #ifndef DASH__ALGORITHM__COPY__USE_WAIT -#define DASH__ALGORITHM__COPY__USE_FLUSH -// #define DASH__ALGORITHM__COPY__USE_WAIT -// #endif - namespace dash { #ifdef DOXYGEN @@ -36,7 +31,8 @@ namespace dash { * another range beginning at \c out_first. * * In terms of data distribution, source and destination ranges passed to - * \c dash::copy can be local (\c *ValueType) or global (\c GlobIter). + * \c dash::copy can be local (\c *ValueType) or global + * (\c GlobIter). * * For a non-blocking variant of \c dash::copy, see \c dash::copy_async. * @@ -71,7 +67,8 @@ OutputIt copy( * another range beginning at \c out_first. * * In terms of data distribution, source and destination ranges passed to - * \c dash::copy can be local (\c *ValueType) or global (\c GlobIter). + * \c dash::copy can be local (\c *ValueType) or global + * (\c GlobIter). * * For a blocking variant of \c dash::copy_async, see \c dash::copy. * @@ -118,12 +115,12 @@ namespace internal { template < typename ValueType, class GlobInputIt > -ValueType * copy_impl( +ValueType * copy_block( GlobInputIt in_first, GlobInputIt in_last, ValueType * out_first) { - DASH_LOG_TRACE("dash::copy_impl()", + DASH_LOG_TRACE("dash::copy_block()", "in_first:", in_first.pos(), "in_last:", in_last.pos(), "out_first:", out_first); @@ -132,10 +129,10 @@ ValueType * copy_impl( typedef typename decltype(pattern)::size_type size_type; size_type num_elem_total = dash::distance(in_first, in_last); if (num_elem_total <= 0) { - DASH_LOG_TRACE("dash::copy_impl", "input range empty"); + DASH_LOG_TRACE("dash::copy_block", "input range empty"); return out_first; } - DASH_LOG_TRACE("dash::copy_impl", + DASH_LOG_TRACE("dash::copy_block", "total elements:", num_elem_total, "expected out_last:", out_first + num_elem_total); // Input iterators could be relative to a view. Map first input iterator @@ -144,27 +141,27 @@ ValueType * copy_impl( // range. auto g_in_first = in_first.global(); auto g_in_last = g_in_first + num_elem_total; - DASH_LOG_TRACE("dash::copy_impl", + DASH_LOG_TRACE("dash::copy_block", "g_in_first:", g_in_first.pos(), "g_in_last:", g_in_last.pos()); auto unit_first = pattern.unit_at(g_in_first.pos()); - DASH_LOG_TRACE_VAR("dash::copy_impl", unit_first); + DASH_LOG_TRACE_VAR("dash::copy_block", unit_first); auto unit_last = pattern.unit_at(g_in_last.pos() - 1); - DASH_LOG_TRACE_VAR("dash::copy_impl", unit_last); + DASH_LOG_TRACE_VAR("dash::copy_block", unit_last); // MPI uses offset type int, do not copy more than INT_MAX bytes: size_type max_copy_elem = (std::numeric_limits::max() / sizeof(ValueType)); size_type num_elem_copied = 0; - DASH_LOG_TRACE_VAR("dash::copy_impl", max_copy_elem); + DASH_LOG_TRACE_VAR("dash::copy_block", max_copy_elem); if (num_elem_total > max_copy_elem) { - DASH_LOG_DEBUG("dash::copy_impl", + DASH_LOG_DEBUG("dash::copy_block", "cannot copy", num_elem_total, "elements", "in a single dart_get operation"); } if (unit_first == unit_last) { // Input range is located at a single remote unit: - DASH_LOG_TRACE("dash::copy_impl", "input range at single unit"); + DASH_LOG_TRACE("dash::copy_block", "input range at single unit"); while (num_elem_copied < num_elem_total) { // Number of elements left to copy: auto total_elem_left = num_elem_total - num_elem_copied; @@ -174,7 +171,7 @@ ValueType * copy_impl( if (num_copy_elem > total_elem_left) { num_copy_elem = total_elem_left; } - DASH_LOG_TRACE("dash::copy_impl", + DASH_LOG_TRACE("dash::copy_block", "copy max:", max_copy_elem, "get elements:", num_copy_elem, "total:", num_elem_total, @@ -194,7 +191,7 @@ ValueType * copy_impl( } } else { // Input range is spread over several remote units: - DASH_LOG_TRACE("dash::copy_impl", "input range spans multiple units"); + DASH_LOG_TRACE("dash::copy_block", "input range spans multiple units"); // // Copy elements from every unit: // @@ -221,7 +218,7 @@ ValueType * copy_impl( } DASH_ASSERT_GT(num_copy_elem, 0, "Number of element to copy is 0"); - DASH_LOG_TRACE("dash::copy_impl", + DASH_LOG_TRACE("dash::copy_block", "start g_idx:", cur_in_first.pos(), "->", "unit:", local_pos.unit, @@ -243,7 +240,7 @@ ValueType * copy_impl( ds.nelem, ds.dtype) != DART_OK) { - DASH_LOG_ERROR("dash::copy_impl", "dart_get failed"); + DASH_LOG_ERROR("dash::copy_block", "dart_get failed"); DASH_THROW( dash::exception::RuntimeError, "dart_get failed"); } @@ -252,7 +249,7 @@ ValueType * copy_impl( } ValueType * out_last = out_first + num_elem_copied; - DASH_LOG_TRACE_VAR("dash::copy_impl >", out_last); + DASH_LOG_TRACE_VAR("dash::copy_block >", out_last); return out_last; } @@ -263,12 +260,12 @@ ValueType * copy_impl( template < typename ValueType, class GlobInputIt > -dash::Future copy_async_impl( +dash::Future copy_block_async( GlobInputIt in_first, GlobInputIt in_last, ValueType * out_first) { - DASH_LOG_TRACE("dash::copy_async_impl()", + DASH_LOG_TRACE("dash::copy_block_async()", "in_first:", in_first.pos(), "in_last:", in_last.pos(), "out_first:", out_first); @@ -277,10 +274,10 @@ dash::Future copy_async_impl( typedef typename decltype(pattern)::size_type size_type; size_type num_elem_total = dash::distance(in_first, in_last); if (num_elem_total <= 0) { - DASH_LOG_TRACE("dash::copy_async_impl", "input range empty"); + DASH_LOG_TRACE("dash::copy_block_async", "input range empty"); return dash::Future([=]() { return out_first; }); } - DASH_LOG_TRACE("dash::copy_async_impl", + DASH_LOG_TRACE("dash::copy_block_async", "total elements:", num_elem_total, "expected out_last:", out_first + num_elem_total); // Input iterators could be relative to a view. Map first input iterator @@ -289,34 +286,30 @@ dash::Future copy_async_impl( // range. auto g_in_first = in_first.global(); auto g_in_last = g_in_first + num_elem_total; - DASH_LOG_TRACE("dash::copy_async_impl", + DASH_LOG_TRACE("dash::copy_block_async", "g_in_first:", g_in_first.pos(), "g_in_last:", g_in_last.pos()); auto unit_first = pattern.unit_at(g_in_first.pos()); - DASH_LOG_TRACE_VAR("dash::copy_async_impl", unit_first); + DASH_LOG_TRACE_VAR("dash::copy_block_async", unit_first); auto unit_last = pattern.unit_at(g_in_last.pos() - 1); - DASH_LOG_TRACE_VAR("dash::copy_async_impl", unit_last); + DASH_LOG_TRACE_VAR("dash::copy_block_async", unit_last); // Accessed global pointers to be flushed: -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - std::vector req_handles; -#else std::vector req_handles; -#endif // MPI uses offset type int, do not copy more than INT_MAX bytes: size_type max_copy_elem = (std::numeric_limits::max() / sizeof(ValueType)); size_type num_elem_copied = 0; - DASH_LOG_TRACE_VAR("dash::copy_async_impl", max_copy_elem); + DASH_LOG_TRACE_VAR("dash::copy_block_async", max_copy_elem); if (num_elem_total > max_copy_elem) { - DASH_LOG_DEBUG("dash::copy_async_impl", + DASH_LOG_DEBUG("dash::copy_block_async", "cannot copy", num_elem_total, "elements", "in a single dart_get operation"); } if (unit_first == unit_last) { // Input range is located at a single remote unit: - DASH_LOG_TRACE("dash::copy_async_impl", "input range at single unit"); + DASH_LOG_TRACE("dash::copy_block_async", "input range at single unit"); while (num_elem_copied < num_elem_total) { // Number of elements left to copy: auto total_elem_left = num_elem_total - num_elem_copied; @@ -326,7 +319,7 @@ dash::Future copy_async_impl( if (num_copy_elem > total_elem_left) { num_copy_elem = total_elem_left; } - DASH_LOG_TRACE("dash::copy_async_impl", + DASH_LOG_TRACE("dash::copy_block_async", "copy max:", max_copy_elem, "get elements:", num_copy_elem, "total:", num_elem_total, @@ -334,17 +327,6 @@ dash::Future copy_async_impl( "left:", total_elem_left); auto cur_in_first = g_in_first + num_elem_copied; auto cur_out_first = out_first + num_elem_copied; -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - dart_storage_t ds = dash::dart_storage(num_copy_elem); - DASH_ASSERT_RETURNS( - dart_get( - cur_out_first, - cur_in_first.dart_gptr(), - ds.nelem, - ds.dtype), - DART_OK); - req_handles.push_back(in_first.dart_gptr()); -#else dart_handle_t get_handle; dart_storage_t ds = dash::dart_storage(num_copy_elem); DASH_ASSERT_RETURNS( @@ -358,12 +340,12 @@ dash::Future copy_async_impl( if (get_handle != NULL) { req_handles.push_back(get_handle); } -#endif num_elem_copied += num_copy_elem; } } else { // Input range is spread over several remote units: - DASH_LOG_TRACE("dash::copy_async_impl", "input range spans multiple units"); + DASH_LOG_TRACE("dash::copy_block_async", + "input range spans multiple units"); // // Copy elements from every unit: // @@ -390,7 +372,7 @@ dash::Future copy_async_impl( } DASH_ASSERT_GT(num_copy_elem, 0, "Number of element to copy is 0"); - DASH_LOG_TRACE("dash::copy_async_impl", + DASH_LOG_TRACE("dash::copy_block_async", "start g_idx:", cur_in_first.pos(), "->", "unit:", local_pos.unit, @@ -405,20 +387,6 @@ dash::Future copy_async_impl( "left:", total_elem_left); auto src_gptr = cur_in_first.dart_gptr(); auto dest_ptr = out_first + num_elem_copied; -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - dart_storage_t ds = dash::dart_storage(num_copy_elem); - if (dart_get( - dest_ptr, - src_gptr, - ds.nelem, - ds.dtype) - != DART_OK) { - DASH_LOG_ERROR("dash::copy_async_impl", "dart_get failed"); - DASH_THROW( - dash::exception::RuntimeError, "dart_get failed"); - } - req_handles.push_back(src_gptr); -#else dart_handle_t get_handle; dart_storage_t ds = dash::dart_storage(num_copy_elem); DASH_ASSERT_RETURNS( @@ -432,50 +400,45 @@ dash::Future copy_async_impl( if (get_handle != NULL) { req_handles.push_back(get_handle); } -#endif num_elem_copied += num_copy_elem; } } #ifdef DASH_ENABLE_TRACE_LOGGING for (auto gptr : req_handles) { - DASH_LOG_TRACE("dash::copy_async_impl", " req_handle:", gptr); + DASH_LOG_TRACE("dash::copy_block_async", " req_handle:", gptr); } #endif dash::Future result([=]() mutable { // Wait for all get requests to complete: ValueType * _out = out_first + num_elem_copied; - DASH_LOG_TRACE("dash::copy_async_impl [Future]()", + DASH_LOG_TRACE("dash::copy_block_async [Future]()", " wait for", req_handles.size(), "async get request"); - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " flush:", req_handles); + DASH_LOG_TRACE("dash::copy_block_async [Future]", " flush:", + req_handles); #ifdef DASH_ENABLE_TRACE_LOGGING for (auto gptr : req_handles) { - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " req_handle:", + DASH_LOG_TRACE("dash::copy_block_async [Future]", " req_handle:", gptr); } #endif -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - for (auto gptr : req_handles) { - dart_flush_local_all(gptr); - } -#else if (req_handles.size() > 0) { if (dart_waitall_local(&req_handles[0], req_handles.size()) != DART_OK) { - DASH_LOG_ERROR("dash::copy_async_impl [Future]", + DASH_LOG_ERROR("dash::copy_block_async [Future]", " dart_waitall_local failed"); DASH_THROW( dash::exception::RuntimeError, - "dash::copy_async_impl [Future]: dart_waitall_local failed"); + "dash::copy_block_async [Future]: dart_waitall_local failed"); } } else { - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " No pending handles"); + DASH_LOG_TRACE("dash::copy_block_async [Future]", + " No pending handles"); } -#endif - DASH_LOG_TRACE("dash::copy_async_impl [Future] >", + DASH_LOG_TRACE("dash::copy_block_async [Future] >", " async requests completed, _out:", _out); return _out; }); - DASH_LOG_TRACE("dash::copy_async_impl >", " returning future"); + DASH_LOG_TRACE("dash::copy_block_async >", " returning future"); return result; } @@ -490,15 +453,17 @@ dash::Future copy_async_impl( template < typename ValueType, class GlobOutputIt > -GlobOutputIt copy_impl( +GlobOutputIt copy_block( ValueType * in_first, ValueType * in_last, GlobOutputIt out_first) { - DASH_LOG_TRACE("dash::copy_impl()", - "l_in_first:", in_first, - "l_in_last:", in_last, - "g_out_first:", out_first.pos()); + DASH_LOG_TRACE("dash::copy_block()", + "l_in_first:", in_first, + "l_in_last:", in_last, + "g_out_first.pos:", out_first.pos()); + DASH_LOG_TRACE("dash::copy_block", + "g_out_first:", out_first.dart_gptr()); auto num_elements = std::distance(in_first, in_last); dart_storage_t ds = dash::dart_storage(num_elements); @@ -511,7 +476,7 @@ GlobOutputIt copy_impl( DART_OK); auto out_last = out_first + num_elements; - DASH_LOG_TRACE("dash::copy_impl >", + DASH_LOG_TRACE("dash::copy_block >", "g_out_last:", out_last.dart_gptr()); return out_last; @@ -524,40 +489,22 @@ GlobOutputIt copy_impl( template < typename ValueType, class GlobOutputIt > -dash::Future copy_async_impl( +dash::Future copy_block_async( ValueType * in_first, ValueType * in_last, GlobOutputIt out_first) { - DASH_LOG_TRACE("dash::copy_async_impl()", + DASH_LOG_TRACE("dash::copy_block_async()", "l_in_first:", in_first, "l_in_last:", in_last, "g_out_first:", out_first.dart_gptr()); // Accessed global pointers to be flushed: -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - std::vector req_handles; -#else std::vector req_handles; -#endif auto num_copy_elem = std::distance(in_first, in_last); auto src_ptr = in_first; auto dest_gptr = out_first.dart_gptr(); -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - dart_storage_t ds = dash::dart_storage(num_copy_elem); - if (dart_put( - dest_gptr, - src_ptr, - ds.nelem, - ds.dtype) - != DART_OK) { - DASH_LOG_ERROR("dash::copy_async_impl", "dart_put failed"); - DASH_THROW( - dash::exception::RuntimeError, "dart_put failed"); - } - req_handles.push_back(dest_gptr); -#else dart_handle_t put_handle; dart_storage_t ds = dash::dart_storage(num_copy_elem); DASH_ASSERT_RETURNS( @@ -571,49 +518,44 @@ dash::Future copy_async_impl( if (put_handle != NULL) { req_handles.push_back(put_handle); } -#endif #ifdef DASH_ENABLE_TRACE_LOGGING for (auto gptr : req_handles) { - DASH_LOG_TRACE("dash::copy_async_impl", " req_handle:", gptr); + DASH_LOG_TRACE("dash::copy_block_async", " req_handle:", gptr); } #endif dash::Future result([=]() mutable { // Wait for all get requests to complete: GlobOutputIt _out = out_first + num_copy_elem; - DASH_LOG_TRACE("dash::copy_async_impl [Future]()", + DASH_LOG_TRACE("dash::copy_block_async [Future]()", " wait for", req_handles.size(), "async put request"); - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " flush:", req_handles); - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " _out:", _out); + DASH_LOG_TRACE("dash::copy_block_async [Future]", " flush:", + req_handles); + DASH_LOG_TRACE("dash::copy_block_async [Future]", " _out:", _out); #ifdef DASH_ENABLE_TRACE_LOGGING for (auto gptr : req_handles) { - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " req_handle:", + DASH_LOG_TRACE("dash::copy_block_async [Future]", " req_handle:", gptr); } #endif -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - for (auto gptr : req_handles) { - dart_flush_all(gptr); - } -#else if (req_handles.size() > 0) { if (dart_waitall(&req_handles[0], req_handles.size()) != DART_OK) { - DASH_LOG_ERROR("dash::copy_async_impl [Future]", + DASH_LOG_ERROR("dash::copy_block_async [Future]", " dart_waitall failed"); DASH_THROW( dash::exception::RuntimeError, - "dash::copy_async_impl [Future]: dart_waitall failed"); + "dash::copy_block_async [Future]: dart_waitall failed"); } } else { - DASH_LOG_TRACE("dash::copy_async_impl [Future]", " No pending handles"); + DASH_LOG_TRACE("dash::copy_block_async [Future]", + " No pending handles"); } -#endif - DASH_LOG_TRACE("dash::copy_async_impl [Future] >", + DASH_LOG_TRACE("dash::copy_block_async [Future] >", " async requests completed, _out:", _out); return _out; }); - DASH_LOG_TRACE("dash::copy_async_impl >", " returning future"); + DASH_LOG_TRACE("dash::copy_block_async >", " returning future"); return result; } @@ -652,8 +594,8 @@ dash::Future copy_async( return dash::Future([=]() { return out_first; }); } ValueType * dest_first = out_first; - // Return value, initialize with begin of output range, indicating no values - // have been copied: + // Return value, initialize with begin of output range, indicating noi + // values have been copied: ValueType * out_last = out_first; // Check if part of the input range is local: DASH_LOG_TRACE_VAR("dash::copy_async", in_first.dart_gptr()); @@ -665,9 +607,9 @@ dash::Future copy_async( // Total number of elements to be copied: auto total_copy_elem = in_last - in_first; - // Instead of testing in_first.local() and in_last.local(), this test for a - // local-only range only requires one call to in_first.local() which increases - // throughput by ~10% for local ranges. + // Instead of testing in_first.local() and in_last.local(), this test for + // a local-only range only requires one call to in_first.local() which + // increases throughput by ~10% for local ranges. if (num_local_elem == total_copy_elem) { // Entire input range is local: DASH_LOG_TRACE("dash::copy_async", "entire input range is local"); @@ -740,7 +682,7 @@ dash::Future copy_async( // ... [ --- copy --- | ... l ... | ........ ] // ^ ^ ^ ^ // in_first l_in_first l_in_last in_last - auto fut_prelocal = dash::internal::copy_async_impl(g_in_first, + auto fut_prelocal = dash::internal::copy_block_async(g_in_first, g_l_in_first, dest_first); futures.push_back(fut_prelocal); @@ -763,7 +705,7 @@ dash::Future copy_async( // ... [ ........ | ... l ... | --- copy --- ] // ^ ^ ^ ^ // in_first l_in_first l_in_last in_last - auto fut_postlocal = dash::internal::copy_async_impl(g_l_in_last, + auto fut_postlocal = dash::internal::copy_block_async(g_l_in_last, g_in_last, dest_first); futures.push_back(fut_postlocal); @@ -812,7 +754,7 @@ dash::Future copy_async( } else { DASH_LOG_TRACE("dash::copy_async", "no local subrange"); // All elements in input range are remote - auto fut_all = dash::internal::copy_async_impl(in_first, + auto fut_all = dash::internal::copy_block_async(in_first, in_last, dest_first); futures.push_back(fut_all); @@ -838,7 +780,8 @@ dash::Future copy_async( } /* - * Specialization of \c dash::copy as global-to-local blocking copy operation. + * Specialization of \c dash::copy as global-to-local blocking copy + * operation. * * \ingroup DashAlgorithms */ @@ -948,7 +891,7 @@ ValueType * copy( // ... [ --- copy --- | ... l ... | ........ ] // ^ ^ ^ ^ // in_first l_in_first l_in_last in_last - out_last = dash::internal::copy_impl(g_in_first, + out_last = dash::internal::copy_block(g_in_first, g_l_in_first, dest_first); // Advance output pointers: @@ -1006,14 +949,14 @@ ValueType * copy( // ... [ ........ | ... l ... | --- copy --- ] // ^ ^ ^ ^ // in_first l_in_first l_in_last in_last - out_last = dash::internal::copy_impl(g_l_in_last, + out_last = dash::internal::copy_block(g_l_in_last, g_in_last, dest_first); } } else { DASH_LOG_TRACE("dash::copy", "no local subrange"); // All elements in input range are remote - out_last = dash::internal::copy_impl(in_first, + out_last = dash::internal::copy_block(in_first, in_last, dest_first); } @@ -1067,7 +1010,7 @@ auto copy_async( for (auto block : out_blocks) { DASH_LOG_TRACE("dash::copy_async", "block size:", block.size()); futures.push_back(static_cast>( - dash::internal::copy_async_impl( + dash::internal::copy_block_async( in_copy_it, in_copy_it + block.size(), block.begin())) ); @@ -1114,7 +1057,7 @@ auto copy_async( { DASH_LOG_TRACE("dash::copy_async()", "blocking, local to global, restricted to single block"); - return dash::internal::copy_async_impl( + return dash::internal::copy_block_async( in_first, in_last, out_first); @@ -1154,7 +1097,7 @@ GlobOutputIt copy( for (auto block : out_blocks) { DASH_LOG_TRACE("dash::copy", "block size:", block.size()); out_last = static_cast( - dash::internal::copy_impl( + dash::internal::copy_block( in_copy_it, in_copy_it + block.size(), block.begin())); From 90595ea347f06baab5446ea5bc77af9a48376f2b Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 23 May 2017 06:36:49 +0200 Subject: [PATCH 016/161] Cleanup --- dash/include/dash/GlobPtr.h | 8 -------- dash/test/view/ViewTest.cc | 34 +++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/dash/include/dash/GlobPtr.h b/dash/include/dash/GlobPtr.h index a3a12f4d3..9035b2e43 100644 --- a/dash/include/dash/GlobPtr.h +++ b/dash/include/dash/GlobPtr.h @@ -79,14 +79,6 @@ class GlobPtr std::ostream & os, const GlobPtr & gptr); - template - friend dash::gptrdiff_t dash::distance( - const GlobPtr & gptr_begin, - const GlobPtr & gptr_end); - public: /// Convert GlobPtr to GlobPtr. template diff --git a/dash/test/view/ViewTest.cc b/dash/test/view/ViewTest.cc index c784221fa..dcc91bc06 100644 --- a/dash/test/view/ViewTest.cc +++ b/dash/test/view/ViewTest.cc @@ -671,27 +671,43 @@ TEST_F(ViewTest, ArrayBlockCyclicPatternCopyLocalToGlobal) auto copy_dest_begin_idx = a.size() / 4; auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; - DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + DASH_LOG_DEBUG("ViewTest.ArrayBlockCyclicPatternCopyLocalToGlobal", "array:", range_str(a)); - DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + DASH_LOG_DEBUG("ViewTest.ArrayBlockCyclicPatternCopyLocalToGlobal", "copy", copy_num_elem, "[", copy_dest_begin_idx, "...", copy_dest_end_idx, "]"); std::vector buf(copy_num_elem); std::iota(buf.begin(), buf.end(), 0.9999); + a.barrier(); + if (dash::myid() == 0) { - auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_end_it_exp = copy_begin_it + copy_num_elem; + auto dest_range = dash::make_range(copy_begin_it, + copy_end_it_exp); + + DASH_LOG_DEBUG_VAR("ViewTest.ArrayBlockCyclicPatternCopyLocalToGlobal", + copy_begin_it); + DASH_LOG_DEBUG_VAR("ViewTest.ArrayBlockCyclicPatternCopyLocalToGlobal", + copy_end_it_exp); + auto dest_blocks = dash::blocks(dest_range); + for (const auto & block : dest_blocks) { + DASH_LOG_DEBUG("ViewTest.ArrayBlockCyclicPatternCopyLocalToGlobal", + "copy dest block:", range_str(block)); + } + // copy local buffer to global array - auto copy_end_it = dash::copy( - buf.data(), - buf.data() + copy_num_elem, - copy_begin_it); - EXPECT_EQ_U(copy_end_it, copy_begin_it + copy_num_elem); + auto copy_end_it = dash::copy( + buf.data(), + buf.data() + copy_num_elem, + copy_begin_it); + EXPECT_EQ_U(copy_end_it_exp, copy_end_it); } a.barrier(); - DASH_LOG_DEBUG("ViewTest.ArrayCyclicPatternCopyLocalToGlobal", + DASH_LOG_DEBUG("ViewTest.ArrayBlockCyclicPatternCopyLocalToGlobal", "array:", range_str(a)); auto eq_pred = From 86ec45089287ff07be9548873b5c91e8dd6b1a09 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 23 May 2017 08:19:54 +0200 Subject: [PATCH 017/161] Updated CartesianTest --- dash/test/types/CartesianTest.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dash/test/types/CartesianTest.cc b/dash/test/types/CartesianTest.cc index 296fb4c57..f58029072 100644 --- a/dash/test/types/CartesianTest.cc +++ b/dash/test/types/CartesianTest.cc @@ -13,7 +13,8 @@ TEST_F(CartesianTest, DefaultConstructor) { // 1-dimensional: dash::CartesianIndexSpace<1> cartesian1d; EXPECT_EQ(cartesian1d.size(), 0); - EXPECT_EQ(cartesian1d.rank(), 1); + EXPECT_EQ(cartesian1d.rank(), 0); + EXPECT_EQ(decltype(cartesian1d)::ndim::value, 1); EXPECT_EQ(cartesian1d.extent(0), 0); #if defined(DASH_ENABLE_ASSERTIONS) dash::internal::logging::disable_log(); @@ -28,7 +29,8 @@ TEST_F(CartesianTest, DefaultConstructor) { // 4-dimensional: dash::CartesianIndexSpace<4> cartesian4d; EXPECT_EQ(cartesian4d.size(), 0); - EXPECT_EQ(cartesian4d.rank(), 4); + EXPECT_EQ(decltype(cartesian4d)::ndim::value, 4); + EXPECT_EQ(cartesian4d.rank(), 0); EXPECT_EQ(cartesian4d.extent(0), 0); EXPECT_EQ(cartesian4d.extent(1), 0); EXPECT_EQ(cartesian4d.extent(2), 0); @@ -137,8 +139,8 @@ TEST_F(CartesianTest, Conversion10Dim) { cartesianR(extents); dash::CartesianIndexSpace cartesianC(extents); - EXPECT_EQ(cartesianR.rank(), Dimensions); - EXPECT_EQ(cartesianC.rank(), Dimensions); + EXPECT_EQ(cartesianR.rank(), 8); + EXPECT_EQ(cartesianC.rank(), 8); EXPECT_EQ(cartesianR.size(), size); EXPECT_EQ(cartesianC.size(), size); for (int d = 0; d < Dimensions; ++d) { From 4e9519c92926335a70f3a48b69c8e6f4bd13089a Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 24 May 2017 22:06:03 +0200 Subject: [PATCH 018/161] Documenting the DASH Index Set concept --- dash/include/dash/View.h | 6 +-- dash/include/dash/view/IndexRange.h | 3 ++ dash/include/dash/view/IndexSet.h | 57 +++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index e7b0a845c..77d7c4f2f 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -18,12 +18,13 @@ * \see DashDimensionalConcept * \see DashRangeConcept * \see DashIteratorConcept + * \see DashIndexSetConcept * \see \c dash::view_traits * * \par Terminology * - * A \b View is a mapping between two index sets, from a \b Domain space to - * an \b Image space in the view's codomain. + * A \b View is a mapping from a \b Domain space to an \b Image space in the + * view's codomain defined by their underlying index sets. * Views can be chained such that the image obtained from the application of * a view expression can again act as the domain of other views. * In effect, a view expression can be understood as a composite function on @@ -65,7 +66,6 @@ * for (auto elem : matrix_rect) { * // ... * } - * * \endcode * * \} diff --git a/dash/include/dash/view/IndexRange.h b/dash/include/dash/view/IndexRange.h index 80553103c..8333fa68e 100644 --- a/dash/include/dash/view/IndexRange.h +++ b/dash/include/dash/view/IndexRange.h @@ -6,6 +6,7 @@ #include +#ifndef DOXYGEN namespace dash { @@ -52,4 +53,6 @@ class IndexRange<1, IndexType> } // namespace dash +#endif // DOXYGEN + #endif // DASH__VIEW__INDEX_RANGE_H__INCLUDED diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index f110d4faf..1c1f96633 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -21,6 +21,63 @@ #include +/** + * \defgroup DashIndexSetConcept Index Set Concept + * + * \ingroup DashNDimConcepts + * \{ + * \par Description + * + * An \c IndexSet specifies a injective, non-surjective map from a + * random-accessible sequence \f$ I = { i : (0...n) } \f$ to elements in + * another index set \$ F \$ (\em family or \em image set). + * More general, an index set is an enumeration of elements in a domain set. + * + * In the context of views and ranges, the function \c dash::index returns + * the index set of a view expression. + * Index sets establish a uniform, canonical interface to domains that do + * not exhibit range semantics such as non-contiguous, multi-dimensional + * and unordered element spaces. + * + * \see DashDimensionalConcept + * \see DashRangeConcept + * \see DashIteratorConcept + * \see DashViewConcept + * \see \c dash::view_traits + * + * + * \par Terminology + * + * + * \par Expressions + * + * For a index domain \f$ Id \f$, \f$ ia, ib \in Id \f$ mapped by an index + * set \f$ I \f$, the following operations and expressions are defined: + * + * Expression | Returns | Synopsis + * ----------------------- | ----------- | ----------------------------- + * sub(ia,ib, Id) | I | \f$ I := \f$ + * + * + * \par Examples + * + * \code + * // containers are view expressions: + * dash::Array array; + * + * a_idx_global = dash::index(array); + * // (0, 1, ..., n) -> (0, 1, ..., n] + * + * a_idx_sub = dash::sub({4, 14}, array); + * // (0, 1, ..., 9) -> (4, 5, ..., 14] + * + * a_idx_sub_loc = dash::local(a_idx_sub); + * // assuming array elements in global index range (7, 13] are not local: + * // (0, 1, 2, 3, 4) -> (4, 5, 6, 13, 14) + * \endcode + * + * \} + */ #ifndef DOXYGEN namespace dash { From 2d52c28b47853f6ac913af9856f71ef7e31e79c3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 25 May 2017 11:20:04 +0200 Subject: [PATCH 019/161] Fixing index set of dash::make_range --- .gitignore | 2 + dash/include/dash/GlobPtr.h | 8 -- dash/include/dash/Range.h | 49 +-------- dash/include/dash/algorithm/Copy.h | 17 ++- dash/include/dash/algorithm/LocalRange.h | 6 ++ dash/include/dash/iterator/GlobIter.h | 6 +- dash/include/dash/view/IndexSet.h | 10 +- dash/include/dash/view/MakeRange.h | 132 +++++++++++++++++++++++ dash/include/dash/view/ViewIterator.h | 10 +- dash/test/TestBase.h | 3 + dash/test/meta/RangeTest.cc | 16 +-- 11 files changed, 184 insertions(+), 75 deletions(-) create mode 100644 dash/include/dash/view/MakeRange.h diff --git a/.gitignore b/.gitignore index 2e326af81..8a22fc945 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ build.mic* build.min* build.nasty* build.cov* +build.gcc* +build.clang* build.analyze* build-ci* compile_commands.json diff --git a/dash/include/dash/GlobPtr.h b/dash/include/dash/GlobPtr.h index a3a12f4d3..9035b2e43 100644 --- a/dash/include/dash/GlobPtr.h +++ b/dash/include/dash/GlobPtr.h @@ -79,14 +79,6 @@ class GlobPtr std::ostream & os, const GlobPtr & gptr); - template - friend dash::gptrdiff_t dash::distance( - const GlobPtr & gptr_begin, - const GlobPtr & gptr_end); - public: /// Convert GlobPtr to GlobPtr. template diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index bb7c21741..f83f483a8 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -352,8 +352,8 @@ class IteratorRange dash::has_type_pattern_type::value > base_t; - Iterator & _begin; - Sentinel & _end; + Iterator _begin; + Sentinel _end; public: typedef Iterator iterator; @@ -396,7 +396,7 @@ class IteratorRange , _end(c.end()) { } - constexpr IteratorRange(iterator & begin, sentinel & end) + constexpr IteratorRange(const iterator & begin, const sentinel & end) : _begin(begin) , _end(end) { } @@ -481,6 +481,7 @@ class IteratorRange typedef dash::default_size_t size_type; //typedef typename internal::LocalPattern pattern_type; typedef dash::IndexSetIdentity index_set_type; + typedef LocalIterator value_type; typedef iterator local_iterator; @@ -518,48 +519,6 @@ class IteratorRange // } }; -/** - * Adapter utility function. - * Wraps `begin` and `end` const iterators in range type. - */ -template -constexpr dash::IteratorRange -make_range( - const Iterator & begin, - const Sentinel & end) { - return dash::IteratorRange( - begin, - end); -} - -/** - * Adapter utility function. - * Wraps `begin` and `end` pointers in range type. - */ -template -constexpr dash::IteratorRange -make_range( - Iterator * begin, - Sentinel * end) { - return dash::IteratorRange( - begin, - end); -} - -/** - * Adapter utility function. - * Wraps `begin` and `end` iterators in range type. - */ -template -dash::IteratorRange -make_range( - Iterator & begin, - Sentinel & end) { - return dash::IteratorRange( - begin, - end); -} - } // namespace dash #endif // DASH__RANGES_H__INCLUDED diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 3b11b3d48..b41157723 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -8,9 +8,7 @@ #include #include #include - -#include - +#include #include @@ -463,7 +461,7 @@ GlobOutputIt copy_block( "l_in_last:", in_last, "g_out_first.pos:", out_first.pos()); DASH_LOG_TRACE("dash::copy_block", - "g_out_first:", out_first.dart_gptr()); + "g_out_first:", out_first, out_first.dart_gptr()); auto num_elements = std::distance(in_first, in_last); dart_storage_t ds = dash::dart_storage(num_elements); @@ -1005,6 +1003,7 @@ auto copy_async( auto out_range = dash::make_range(out_first, out_h_last); auto out_blocks = dash::blocks(out_range); auto in_copy_it = in_first; + DASH_LOG_TRACE("dash::copy_async", "out range:", out_range); DASH_LOG_TRACE("dash::copy_async", "number of blocks:", out_blocks.size()); for (auto block : out_blocks) { @@ -1089,7 +1088,17 @@ GlobOutputIt copy( DASH_LOG_TRACE_VAR("dash::copy", out_first.pos()); DASH_LOG_TRACE_VAR("dash::copy", out_h_last.pos()); + // auto out_range = dash::sub( + // out_first.pos(), + // out_h_last.pos(), + // dash::make_range( + // out_first - out_first.pos(), + // out_h_last - out_first.pos())); auto out_range = dash::make_range(out_first, out_h_last); + + DASH_LOG_TRACE("dash::copy", "out value range:", out_range); + DASH_LOG_TRACE("dash::copy", "out index range:", dash::index(out_range)); + auto out_blocks = dash::blocks(out_range); auto in_copy_it = in_first; diff --git a/dash/include/dash/algorithm/LocalRange.h b/dash/include/dash/algorithm/LocalRange.h index cf00bafd1..7681ae31e 100644 --- a/dash/include/dash/algorithm/LocalRange.h +++ b/dash/include/dash/algorithm/LocalRange.h @@ -72,6 +72,8 @@ local_index_range( /** * Resolves the local index range between global iterators. * + * Precondition: \c GlobInputIter is a view iterator. + * * \b Example: * * Total range | 0 1 2 3 4 5 6 7 8 9 @@ -94,10 +96,14 @@ local_index_range( * \ingroup DashAlgorithms */ template +#ifndef DOXYGEN typename std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange >::type +#else + LocalIndexRange +#endif local_index_range( /// Iterator to the initial position in the global sequence const GlobInputIter & first, diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index 2e9ed5ffa..92af9b65d 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -197,12 +197,13 @@ class GlobIter * Copy constructor. */ template < + class T_, class P_, class GM_, class Ptr_, class Ref_ > constexpr GlobIter( - const GlobIter & other) + const GlobIter & other) : _globmem(other._globmem) , _pattern(other._pattern) , _idx (other._idx) @@ -215,12 +216,13 @@ class GlobIter * Move constructor. */ template < + class T_, class P_, class GM_, class Ptr_, class Ref_ > constexpr GlobIter( - GlobIter && other) + GlobIter && other) : _globmem(other._globmem) , _pattern(other._pattern) , _idx (other._idx) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 1c1f96633..0de8904e4 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -282,7 +282,7 @@ struct index_set_domain_bind_t { } // namespace detail /** - * \concept{DashRangeConcept} + * \concept{DashIndexSetConcept} */ template < class IndexSetType, @@ -584,7 +584,7 @@ global(const IndexSetIdentity & index_set) } /** - * \concept{DashRangeConcept} + * \concept{DashIndexSetConcept} */ template class IndexSetIdentity @@ -667,7 +667,7 @@ global(const IndexSetSub & index_set) } /** - * \concept{DashRangeConcept} + * \concept{DashIndexSetConcept} */ template < class DomainType, @@ -860,7 +860,7 @@ global(IndexSetLocal && index_set) -> } /** - * \concept{DashRangeConcept} + * \concept{DashIndexSetConcept} */ template class IndexSetLocal @@ -1147,7 +1147,7 @@ global(const IndexSetGlobal & index_set) { } /** - * \concept{DashRangeConcept} + * \concept{DashIndexSetConcept} */ template class IndexSetGlobal diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h new file mode 100644 index 000000000..029597221 --- /dev/null +++ b/dash/include/dash/view/MakeRange.h @@ -0,0 +1,132 @@ +#ifndef DASH__VIEW__MAKE_RANGE_H__INCLUDED +#define DASH__VIEW__MAKE_RANGE_H__INCLUDED + +#include +#include + + +namespace dash { + +#if 1 +/** + * Adapter utility function. + * Wraps `begin` and `end` pointers in range type. + */ +template < + class Iterator, + class Sentinel, + typename std::enable_if< std::is_pointer::value > * = nullptr > +constexpr dash::IteratorRange +make_range( + Iterator * const begin, + Sentinel * const end) { + return dash::IteratorRange( + begin, + end); +} +#endif + +#if 0 +/** + * Adapter utility function. + * Wraps `begin` and `end` pointers in range type. + */ +template +constexpr dash::IteratorRange +make_range( + Iterator * begin, + Sentinel * end) { + return dash::IteratorRange( + begin, + end); +} +#endif + +#if 0 +/** + * Adapter utility function. + * Wraps `begin` and `end` iterators in range type. + */ +template +dash::IteratorRange +make_range( + const Iterator & begin, + const Sentinel & end) { + return dash::IteratorRange(begin, end); +} + +/** + * Adapter utility function. + * Wraps `begin` and `end` iterators in range type. + */ +template +dash::IteratorRange< + typename std::decay::type, + typename std::decay::type > +make_range( + Iterator && begin, + Sentinel && end) { + return dash::IteratorRange< + typename std::decay::type, + typename std::decay::type + >(std::forward(begin), + std::forward(end)); +} +#endif + +#if 0 +/** + * Adapter utility function. + * Wraps `begin` and `end` iterators in range type. + */ +template < + class Iterator, + class Sentinel, + typename std::enable_if< !std::is_pointer::value > * = nullptr > +auto +make_range( + const Iterator & begin, + const Sentinel & end) + -> decltype(dash::sub( + begin.pos(), end.pos(), + dash::IteratorRange( + begin - begin.pos(), + end - begin.pos()))) { + return dash::sub(begin.pos(), end.pos(), + dash::IteratorRange( + begin - begin.pos(), + end - begin.pos())); +} +#endif + +#if 1 +/** + * Adapter utility function. + * Wraps `begin` and `end` iterators in range type. + */ +template < + class Iterator, + class Sentinel, + typename std::enable_if< !std::is_pointer::value > * = nullptr > +auto +make_range( + Iterator && begin, + Sentinel && end) + -> decltype(dash::sub(begin.pos(), end.pos(), + dash::IteratorRange< + typename std::decay::type, + typename std::decay::type + >((begin) - begin.pos(), + (end) - begin.pos()))) { + return dash::sub(begin.pos(), end.pos(), + dash::IteratorRange< + typename std::decay::type, + typename std::decay::type + >((begin) - begin.pos(), + (end) - begin.pos())); +} +#endif + +} // namespace dash + +#endif // DASH__VIEW__MAKE_RANGE_H__INCLUDED diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 61c85ef02..1bfc30ff6 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -43,8 +43,8 @@ class ViewIterator typedef typename base_t::value_type value_type; typedef typename IndexSetType::index_type index_type; private: - DomainIterator _domain_it; - IndexSetType _index_set; + typename std::decay::type _domain_it; + IndexSetType _index_set; public: constexpr ViewIterator() = delete; @@ -92,7 +92,11 @@ class ViewIterator return (_domain_it + (_index_set[this->pos()])).local(); } - constexpr dart_gptr_t dart_gptr() const { + dart_gptr_t dart_gptr() const { + DASH_LOG_DEBUG("ViewIterator", + "it.pos:", _domain_it.pos(), + "it.gpos:", _domain_it.gpos(), + "pos:", this->pos()); return (_domain_it + _index_set[this->pos()]).dart_gptr(); } diff --git a/dash/test/TestBase.h b/dash/test/TestBase.h index 849e09639..333c65600 100644 --- a/dash/test/TestBase.h +++ b/dash/test/TestBase.h @@ -11,7 +11,10 @@ #include #include + #include +#include + #include #include "TestGlobals.h" diff --git a/dash/test/meta/RangeTest.cc b/dash/test/meta/RangeTest.cc index cf9dce8be..88cadf51b 100644 --- a/dash/test/meta/RangeTest.cc +++ b/dash/test/meta/RangeTest.cc @@ -87,13 +87,13 @@ TEST_F(RangeTest, RangeTraits) dash::is_range::value == true, "dash::is_range>::value not matched"); - auto l_range = dash::make_range(array.local.begin(), - array.local.end()); - static_assert( - dash::is_range::value == true, - "dash::is_range::value not matched"); - static_assert( - dash::is_view::value == true, - "dash::is_view::value not matched"); +// auto l_range = dash::make_range(array.local.begin(), +// array.local.end()); +// static_assert( +// dash::is_range::value == true, +// "dash::is_range::value not matched"); +// static_assert( +// dash::is_view::value == true, +// "dash::is_view::value not matched"); } From a99d7105286fba384bf947d37bf5235611eb963b Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 25 May 2017 11:50:07 +0200 Subject: [PATCH 020/161] Minor --- dash/include/dash/View.h | 18 +++++++++++++++--- dash/include/dash/algorithm/Copy.h | 16 +++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index e7b0a845c..8189759a0 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -172,10 +172,22 @@ class IteratorViewOrigin template constexpr dash::IteratorViewOrigin -make_view(Iterator begin, Sentinel end) { +make_view(const Iterator & begin, const Sentinel & end) { return dash::IteratorViewOrigin( - std::move(begin), - std::move(end)); + (begin), + (end)); +} + +template +constexpr dash::IteratorViewOrigin< + typename std::decay::type, + typename std::decay::type > +make_view(Iterator && begin, Sentinel && end) { + return dash::IteratorViewOrigin< + typename std::decay::type, + typename std::decay::type + >(std::forward(begin), + std::forward(end)); } } // namespace dash diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 3b11b3d48..6e10e123c 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -4,9 +4,8 @@ #include #include +#include #include -#include -#include #include #include @@ -1064,7 +1063,8 @@ auto copy_async( } /** - * Specialization of \c dash::copy as local-to-global blocking copy operation. + * Specialization of \c dash::copy as local-to-global blocking copy + * operation. * * \ingroup DashAlgorithms */ @@ -1114,16 +1114,18 @@ GlobOutputIt copy( #ifdef DASH_EXPERIMENTAL /* - * Specialization of \c dash::copy as global-to-local blocking copy operation - * returning an allocated range. + * Specialization of \c dash::copy as global-to-local blocking copy + * operation returning an allocated range. * Allows for zero-copy operations if the copied range is local. * * Returns a future of a local range { begin, end }. * If the requested data range is in shared memory, the range returned * references the native pointers of the target range. * If the requested data range needed to be copied from remote memory, the - * range returned is the copied destination range such that begin = out_first - * and end = out_first + num_elem_copied. + * range returned is the copied destination range such that + * \c (begin = out_first). + * and + * \c (end = out_first + num_elem_copied.) */ template < typename ValueType, From 19b59399ad8751729fee08e59a2b45dd644ce3ee Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 25 May 2017 15:24:34 +0200 Subject: [PATCH 021/161] Fixing index set of dash::make_range --- dash/include/dash/Range.h | 33 +++++++++++++++++++------- dash/include/dash/algorithm/Copy.h | 11 ++++----- dash/include/dash/view/MakeRange.h | 34 +++++++++++++-------------- dash/include/dash/view/ViewIterator.h | 31 ++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index f83f483a8..cd47af4f8 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -49,6 +49,8 @@ #include #include +// #include + #include #include @@ -59,7 +61,6 @@ namespace dash { #ifndef DOXYGEN - // Related: boost::range // // https://github.com/boostorg/range/tree/develop/include/boost/range @@ -72,6 +73,9 @@ struct view_traits; template class IndexSetIdentity; +template +class IndexSetSub; + // Forward-declaration template class IteratorRange; @@ -303,15 +307,17 @@ struct view_traits > { public: typedef RangeT domain_type; typedef RangeT origin_type; - typedef typename RangeT::pattern_type pattern_type; -//typedef typename IteratorT::pattern_type pattern_type; +//typedef typename RangeT::pattern_type pattern_type; + typedef typename IteratorT::pattern_type pattern_type; typedef RangeT image_type; typedef RangeT global_type; typedef typename RangeT::local_type local_type; typedef typename RangeT::index_type index_type; typedef typename RangeT::size_type size_type; + + typedef dash::IndexSetSub index_set_type; //typedef typename RangeT::index_set_type index_set_type; - typedef dash::IndexSetIdentity index_set_type; +//typedef dash::IndexSetIdentity index_set_type; /// Whether the view type is a projection (has less dimensions than the /// view's domain type). @@ -361,6 +367,7 @@ class IteratorRange typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; //typedef dash::IndexSetIdentity index_set_type; + typedef dash::IndexSetSub index_set_type; typedef std::integral_constant rank; typedef typename iterator::value_type value_type; @@ -401,10 +408,18 @@ class IteratorRange , _end(end) { } - constexpr iterator begin() const { return _begin; } + constexpr IteratorRange(iterator && begin, sentinel && end) + : _begin(std::forward(begin)) + , _end(std::forward(end)) + { } + + constexpr iterator begin() const { return _begin - _begin.pos(); } constexpr iterator end() const { return _end; } - constexpr size_type size() const { return std::distance(_begin, _end); } + constexpr size_type size() const { + return _end.pos() - _begin().pos(); + // return std::distance(_begin, _end); + } constexpr const local_type local() const { return local_type( @@ -417,9 +432,9 @@ class IteratorRange return _begin.pattern(); } -// constexpr index_set_type index_set() const { -// return index_set_type(*this); -// } + constexpr index_set_type index_set() const { + return index_set_type(*this, _begin.pos(), _end.pos()); + } }; diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index b41157723..d06127fab 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -4,8 +4,11 @@ #include #include +#include + #include #include +#include #include #include #include @@ -1088,15 +1091,9 @@ GlobOutputIt copy( DASH_LOG_TRACE_VAR("dash::copy", out_first.pos()); DASH_LOG_TRACE_VAR("dash::copy", out_h_last.pos()); - // auto out_range = dash::sub( - // out_first.pos(), - // out_h_last.pos(), - // dash::make_range( - // out_first - out_first.pos(), - // out_h_last - out_first.pos())); auto out_range = dash::make_range(out_first, out_h_last); - DASH_LOG_TRACE("dash::copy", "out value range:", out_range); +// DASH_LOG_TRACE("dash::copy", "out value range:", out_range); DASH_LOG_TRACE("dash::copy", "out index range:", dash::index(out_range)); auto out_blocks = dash::blocks(out_range); diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index 029597221..a5d5bd25a 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -2,7 +2,7 @@ #define DASH__VIEW__MAKE_RANGE_H__INCLUDED #include -#include +// #include namespace dash { @@ -16,11 +16,11 @@ template < class Iterator, class Sentinel, typename std::enable_if< std::is_pointer::value > * = nullptr > -constexpr dash::IteratorRange +constexpr dash::IteratorRange make_range( Iterator * const begin, Sentinel * const end) { - return dash::IteratorRange( + return dash::IteratorRange( begin, end); } @@ -42,7 +42,7 @@ make_range( } #endif -#if 0 +#if 1 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -54,7 +54,9 @@ make_range( const Sentinel & end) { return dash::IteratorRange(begin, end); } +#endif +#if 1 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -85,21 +87,19 @@ template < typename std::enable_if< !std::is_pointer::value > * = nullptr > auto make_range( - const Iterator & begin, - const Sentinel & end) + Iterator begin, + Sentinel end) -> decltype(dash::sub( begin.pos(), end.pos(), - dash::IteratorRange( - begin - begin.pos(), - end - begin.pos()))) { + dash::IteratorRange( + begin -= begin.pos(), end))) { return dash::sub(begin.pos(), end.pos(), - dash::IteratorRange( - begin - begin.pos(), - end - begin.pos())); + dash::IteratorRange( + begin -= begin.pos(), end)); } #endif -#if 1 +#if 0 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -116,14 +116,14 @@ make_range( dash::IteratorRange< typename std::decay::type, typename std::decay::type - >((begin) - begin.pos(), - (end) - begin.pos()))) { + >((begin) -= begin.pos(), + (end) -= begin.pos()))) { return dash::sub(begin.pos(), end.pos(), dash::IteratorRange< typename std::decay::type, typename std::decay::type - >((begin) - begin.pos(), - (end) - begin.pos())); + >((begin) -= begin.pos(), + (end) -= begin.pos())); } #endif diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 1bfc30ff6..1ed2eff12 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -46,7 +46,10 @@ class ViewIterator typename std::decay::type _domain_it; IndexSetType _index_set; public: - constexpr ViewIterator() = delete; + constexpr ViewIterator() = delete; + + ViewIterator(self_t && other) = default; + self_t & operator=(self_t && other) = default; template ViewIterator( @@ -144,7 +147,31 @@ class ViewIterator DomainIterator * _domain_it; IndexSetType _index_set; public: - constexpr ViewIterator() = delete; + constexpr ViewIterator() = delete; + + ViewIterator(const self_t & other) + : base_t(other.pos()) + , _domain_it(other._domain_it) + , _index_set(other._index_set) + { } + + ViewIterator(self_t && other) + : base_t(other.pos()) + , _domain_it(other._domain_it) + , _index_set(other._index_set) + { } + + self_t & operator=(const self_t & other) { + base_t::operator=(other); + _domain_it = other._domain_it; + _index_set = other._index_set; + } + + self_t & operator=(self_t && other) { + base_t::operator=(other); + _domain_it = other._domain_it; + _index_set = other._index_set; + } template ViewIterator( From f0b18ccb80de2b75bf27089add055e129a411bf9 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 25 May 2017 17:30:01 +0200 Subject: [PATCH 022/161] Fixing index set of dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 136 +++++++++++++++++++++++ dash/include/dash/Range.h | 13 +-- dash/include/dash/view/IndexSet.h | 2 +- dash/include/dash/view/MakeRange.h | 48 ++++---- dash/include/dash/view/ViewIterator.h | 11 +- dash/include/dash/view/ViewMod1D.h | 2 +- 6 files changed, 173 insertions(+), 39 deletions(-) create mode 100644 dash/examples/ex.02.array-views/main.cpp diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp new file mode 100644 index 000000000..c52d6e5ce --- /dev/null +++ b/dash/examples/ex.02.array-views/main.cpp @@ -0,0 +1,136 @@ +#include + +using std::cout; +using std::cerr; +using std::clog; +using std::cin; +using std::endl; +using std::vector; + +using uint = unsigned int; + + +#define print(stream_expr) \ + do { \ + std::ostringstream ss; \ + ss << stream_expr; \ + cout << ss.str() << endl; \ + } while(0) + + +inline void sum(const uint nelts, + const dash::NArray &matIn, + const uint myid) { + uint lclRows = matIn.pattern().local_extents()[0]; + + uint const *mPtr; + uint localSum = 0; + + for (uint i = 0; i < lclRows; ++i) { + mPtr = matIn.local.row(i).lbegin(); + + for (uint j = 0; j < nelts; ++j) { + localSum += *(mPtr++); + } + } +} + +template +static std::string range_str( + const ValueRange & vrange) { + typedef typename ValueRange::value_type value_t; + std::ostringstream ss; + auto idx = dash::index(vrange); + int i = 0; + for (const auto & v : vrange) { + ss << std::setw(2) << *(dash::begin(idx) + i) << "|" + << std::fixed << std::setprecision(4) + << static_cast(v) << " "; + ++i; + } + return ss.str(); +} + +template +auto initialize_array(ArrayT & array) +-> typename std::enable_if< + std::is_floating_point::value, + void >::type +{ + auto block_size = array.pattern().blocksize(0); + for (auto li = 0; li != array.local.size(); ++li) { + auto block_lidx = li / block_size; + auto block_gidx = (block_lidx * dash::size()) + dash::myid().id; + auto gi = (block_gidx * block_size) + (li % block_size); + array.local[li] = // unit + (1.0000 * dash::myid().id) + + // local offset + (0.0001 * (li+1)) + + // global offset + (0.0100 * gi); + } + array.barrier(); +} + +int main(int argc, char *argv[]) +{ + dash::init(&argc, &argv); + + int elem_per_unit = 7; + int elem_additional = 2; + int array_size = dash::size() * elem_per_unit + + std::min(elem_additional, dash::size()); + int num_local_elem = elem_per_unit + + ( dash::myid() < elem_additional + ? 1 + : 0 ); + + dash::Array a(array_size, dash::BLOCKCYCLIC(3)); + initialize_array(a); + + dash::Array a_pre(array_size, dash::BLOCKCYCLIC(3)); + initialize_array(a_pre); + + auto copy_num_elem = a.size() / 2; + auto copy_dest_begin_idx = a.size() / 4; + auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; + + print("array: " << range_str(a)); + print("ncopy: " << copy_num_elem + << "(" << copy_dest_begin_idx + << "," << copy_dest_end_idx << "]"); + + std::vector buf(copy_num_elem); + std::iota(buf.begin(), buf.end(), 0.9999); + + a.barrier(); + + if (dash::myid() == 0) { + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_end_it_exp = copy_begin_it + copy_num_elem; + auto dest_range = dash::make_range(copy_begin_it, + copy_end_it_exp); + + print("copy begin: " << copy_begin_it); + print("copy end: " << copy_end_it_exp); + + // print("copy range: " << dash::make_range(copy_begin_it, + // copy_end_it_exp)); + + auto dest_blocks = dash::blocks(dest_range); + for (const auto & block : dest_blocks) { + print("copy to block:" << range_str(block)); + } + + // copy local buffer to global array + auto copy_end_it = dash::copy( + buf.data(), + buf.data() + copy_num_elem, + copy_begin_it); + } + a.barrier(); + + print("modified array: " << range_str(a)); + + dash::finalize(); +} diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index cd47af4f8..5dce44998 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -315,9 +315,9 @@ struct view_traits > { typedef typename RangeT::index_type index_type; typedef typename RangeT::size_type size_type; - typedef dash::IndexSetSub index_set_type; +//typedef dash::IndexSetSub index_set_type; //typedef typename RangeT::index_set_type index_set_type; -//typedef dash::IndexSetIdentity index_set_type; + typedef dash::IndexSetIdentity index_set_type; /// Whether the view type is a projection (has less dimensions than the /// view's domain type). @@ -366,8 +366,7 @@ class IteratorRange typedef Sentinel sentinel; typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; -//typedef dash::IndexSetIdentity index_set_type; - typedef dash::IndexSetSub index_set_type; +//typedef dash::IndexSetSub index_set_type; typedef std::integral_constant rank; typedef typename iterator::value_type value_type; @@ -432,9 +431,9 @@ class IteratorRange return _begin.pattern(); } - constexpr index_set_type index_set() const { - return index_set_type(*this, _begin.pos(), _end.pos()); - } +// constexpr index_set_type index_set() const { +// return index_set_type(*this, _begin.pos(), _end.pos()); +// } }; diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 0de8904e4..cd5553fac 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -31,7 +31,7 @@ * An \c IndexSet specifies a injective, non-surjective map from a * random-accessible sequence \f$ I = { i : (0...n) } \f$ to elements in * another index set \$ F \$ (\em family or \em image set). - * More general, an index set is an enumeration of elements in a domain set. + * More general, an index set is an enumeration of elements in a domain. * * In the context of views and ranges, the function \c dash::index returns * the index set of a view expression. diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index a5d5bd25a..f639522fc 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -2,7 +2,7 @@ #define DASH__VIEW__MAKE_RANGE_H__INCLUDED #include -// #include +#include namespace dash { @@ -43,6 +43,27 @@ make_range( #endif #if 1 +/** + * Adapter utility function. + * Wraps `begin` and `end` iterators in range type. + */ +template < + class Iterator, + class Sentinel, + typename std::enable_if< !std::is_pointer::value > * = nullptr > +auto +make_range( + const Iterator & begin, + const Sentinel & end) + -> decltype(dash::sub( + begin.pos(), end.pos(), + dash::IteratorRange( + begin - begin.pos(), end))) { + return dash::sub(begin.pos(), end.pos(), + dash::IteratorRange( + begin - begin.pos(), end)); +} +#else /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -54,9 +75,7 @@ make_range( const Sentinel & end) { return dash::IteratorRange(begin, end); } -#endif -#if 1 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -76,29 +95,6 @@ make_range( } #endif -#if 0 -/** - * Adapter utility function. - * Wraps `begin` and `end` iterators in range type. - */ -template < - class Iterator, - class Sentinel, - typename std::enable_if< !std::is_pointer::value > * = nullptr > -auto -make_range( - Iterator begin, - Sentinel end) - -> decltype(dash::sub( - begin.pos(), end.pos(), - dash::IteratorRange( - begin -= begin.pos(), end))) { - return dash::sub(begin.pos(), end.pos(), - dash::IteratorRange( - begin -= begin.pos(), end)); -} -#endif - #if 0 /** * Adapter utility function. diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 1ed2eff12..df2c497f1 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -25,7 +25,7 @@ class ViewIterator typename DomainIterator::difference_type, // difference type typename DomainIterator::pointer, // pointer typename DomainIterator::reference // reference -> { + > { typedef ViewIterator self_t; typedef dash::internal::IndexIteratorBase< ViewIterator, @@ -46,10 +46,13 @@ class ViewIterator typename std::decay::type _domain_it; IndexSetType _index_set; public: - constexpr ViewIterator() = delete; + constexpr ViewIterator() = delete; + + ViewIterator(self_t && other) = default; + self_t & operator=(self_t && other) = default; - ViewIterator(self_t && other) = default; - self_t & operator=(self_t && other) = default; + ViewIterator(const self_t & other) = default; + self_t & operator=(const self_t & other) = default; template ViewIterator( diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 2f82b2c8b..0154bfea4 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -47,7 +47,7 @@ class ViewSubMod typedef typename view_traits::size_type size_type; public: typedef dash::IndexSetSub index_set_type; - typedef ViewLocalMod local_type; + typedef dash::ViewLocalMod local_type; typedef self_t global_type; typedef std::integral_constant is_local; From 25c93b59a9fe1b8e3923cc9694d41f4a05c86a03 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 25 May 2017 18:57:23 +0200 Subject: [PATCH 023/161] Added ex.02.array-views --- dash/examples/ex.02.array-views/main.cpp | 14 +++++++++----- dash/include/dash/iterator/GlobIter.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index c52d6e5ce..0b5b1aae2 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -42,7 +42,7 @@ static std::string range_str( std::ostringstream ss; auto idx = dash::index(vrange); int i = 0; - for (const auto & v : vrange) { + for (auto v : vrange) { ss << std::setw(2) << *(dash::begin(idx) + i) << "|" << std::fixed << std::setprecision(4) << static_cast(v) << " "; @@ -111,15 +111,19 @@ int main(int argc, char *argv[]) auto dest_range = dash::make_range(copy_begin_it, copy_end_it_exp); - print("copy begin: " << copy_begin_it); - print("copy end: " << copy_end_it_exp); + + print("copy index range: " << dash::index(dest_range)); + print("copy num blocks: " << dash::blocks(dest_range).size()); + print("copy dom. begin: " << copy_begin_it - copy_begin_it.pos()); + print("copy begin: " << copy_begin_it); + print("copy end: " << copy_end_it_exp); // print("copy range: " << dash::make_range(copy_begin_it, // copy_end_it_exp)); auto dest_blocks = dash::blocks(dest_range); - for (const auto & block : dest_blocks) { - print("copy to block:" << range_str(block)); + for (auto block : dest_blocks) { + // print("copy to block:" << range_str(block)); } // copy local buffer to global array diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index 92af9b65d..e11c9f867 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -732,7 +732,7 @@ std::ostream & operator<<( { std::ostringstream ss; dash::GlobPtr ptr(*it._globmem, - it.dart_gptr()); + it.dart_gptr()); ss << "dash::GlobIter<" << typeid(ElementType).name() << ">(" << "idx:" << it._idx << ", " << "gptr:" << ptr << ")"; From 950e25a19370f3ebef9a7353eb9bb4f553a70ec1 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 26 May 2017 20:33:48 +0200 Subject: [PATCH 024/161] Fixing dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 44 ++++++++++++++++++------ dash/include/dash/Range.h | 20 +++++------ dash/include/dash/iterator/GlobIter.h | 35 +++++++++++++++---- dash/include/dash/view/MakeRange.h | 18 ++++++---- dash/include/dash/view/ViewIterator.h | 12 ++++++- 5 files changed, 95 insertions(+), 34 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 0b5b1aae2..b155e39cb 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -42,7 +42,7 @@ static std::string range_str( std::ostringstream ss; auto idx = dash::index(vrange); int i = 0; - for (auto v : vrange) { + for (const auto & v : vrange) { ss << std::setw(2) << *(dash::begin(idx) + i) << "|" << std::fixed << std::setprecision(4) << static_cast(v) << " "; @@ -111,15 +111,39 @@ int main(int argc, char *argv[]) auto dest_range = dash::make_range(copy_begin_it, copy_end_it_exp); - - print("copy index range: " << dash::index(dest_range)); - print("copy num blocks: " << dash::blocks(dest_range).size()); - print("copy dom. begin: " << copy_begin_it - copy_begin_it.pos()); - print("copy begin: " << copy_begin_it); - print("copy end: " << copy_end_it_exp); - - // print("copy range: " << dash::make_range(copy_begin_it, - // copy_end_it_exp)); + const auto & dest_range_idx = dash::index(dest_range); + const auto & dest_range_org = dash::origin(dest_range); + const auto & dest_range_pat = dest_range_idx.pattern(); + const auto & dest_range_idom = dash::domain( + dash::index(dash::blocks(dest_range))); + + print("dest first block: " << dest_range_pat.block_at( + dest_range_pat.coords( + dest_range_idom.first()) + )); + print("dest last block: " << dest_range_pat.block_at( + dest_range_pat.coords( + dest_range_idom.last()) + )); + + print("copy range type: " << dash::typestr(dest_range)); + print("copy range origin: " << dash::typestr(dest_range_org)); + print("copy range pattern: " << dash::typestr(dest_range_pat)); + print("copy range local: " << dash::view_traits< + decltype(dest_range) + >::is_local::value); + print("copy index domain: " << dash::index(dest_range)); + print("copy block dom.idx: " << dash::domain( + dash::index(dash::blocks(dest_range)) + )); + print("copy block indices: " << dash::index(dash::blocks(dest_range))); + print("copy num blocks: " << dash::blocks(dest_range).size()); + print("copy dom. begin: " << copy_begin_it - copy_begin_it.pos()); + print("copy begin: " << copy_begin_it); + print("copy end: " << copy_end_it_exp); + + print("copy range begin: " << dash::begin(dest_range)); + print("copy range: " << range_str(dest_range)); auto dest_blocks = dash::blocks(dest_range); for (auto block : dest_blocks) { diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 5dce44998..c70922e29 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -50,8 +50,7 @@ #include // #include - -#include +// #include #include @@ -358,15 +357,13 @@ class IteratorRange dash::has_type_pattern_type::value > base_t; - Iterator _begin; - Sentinel _end; - public: typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; //typedef dash::IndexSetSub index_set_type; +//typedef dash::IndexSetIdentity index_set_type; typedef std::integral_constant rank; typedef typename iterator::value_type value_type; @@ -395,6 +392,10 @@ class IteratorRange typedef self_t global_type; typedef IteratorRange local_type; +private: + typename std::decay::type _begin; + typename std::decay::type _end; + public: template constexpr explicit IteratorRange(Container && c) @@ -412,12 +413,11 @@ class IteratorRange , _end(std::forward(end)) { } - constexpr iterator begin() const { return _begin - _begin.pos(); } - constexpr iterator end() const { return _end; } + constexpr iterator begin() const { return _begin; } + constexpr sentinel end() const { return _end; } constexpr size_type size() const { - return _end.pos() - _begin().pos(); - // return std::distance(_begin, _end); + return std::distance(_begin, _end); } constexpr const local_type local() const { @@ -432,7 +432,7 @@ class IteratorRange } // constexpr index_set_type index_set() const { -// return index_set_type(*this, _begin.pos(), _end.pos()); +// return dash::index(dash::sub(*this, _begin_pos, _end.pos())); // } }; diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index e11c9f867..a78f19aa4 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -62,12 +62,12 @@ template< class PointerType = typename GlobMemType::pointer, class ReferenceType = GlobRef > class GlobIter -: public std::iterator< - std::random_access_iterator_tag, - ElementType, - typename PatternType::index_type, - PointerType, - ReferenceType > +// : public std::iterator< +// std::random_access_iterator_tag, +// ElementType, +// typename PatternType::index_type, +// PointerType, +// ReferenceType > { private: typedef GlobIter< @@ -81,6 +81,9 @@ class GlobIter typedef typename std::remove_const::type nonconst_value_type; public: + typedef typename std::random_access_iterator_tag iterator_category; + typedef typename PatternType::index_type difference_type; + typedef ElementType value_type; typedef ReferenceType reference; @@ -196,6 +199,11 @@ class GlobIter /** * Copy constructor. */ + constexpr GlobIter(const self_t & other) = default; + + /** + * Templated copy constructor. + */ template < class T_, class P_, @@ -215,6 +223,11 @@ class GlobIter /** * Move constructor. */ + constexpr GlobIter(self_t && other) = default; + + /** + * Templated move constructor. + */ template < class T_, class P_, @@ -234,6 +247,11 @@ class GlobIter /** * Assignment operator. */ + self_t & operator=(const self_t & other) = default; + + /** + * Templated assignment operator. + */ template < typename T_, class P_, @@ -255,6 +273,11 @@ class GlobIter /** * Move-assignment operator. */ + self_t & operator=(self_t && other) = default; + + /** + * Templated move-assignment operator. + */ template < typename T_, class P_, diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index f639522fc..991b2e6a0 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -42,7 +42,7 @@ make_range( } #endif -#if 1 +#if 0 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -58,10 +58,10 @@ make_range( -> decltype(dash::sub( begin.pos(), end.pos(), dash::IteratorRange( - begin - begin.pos(), end))) { + Iterator(begin - begin.pos()), end))) { return dash::sub(begin.pos(), end.pos(), dash::IteratorRange( - begin - begin.pos(), end)); + Iterator(begin - begin.pos()), end)); } #else /** @@ -76,6 +76,7 @@ make_range( return dash::IteratorRange(begin, end); } +#if 0 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -95,6 +96,8 @@ make_range( } #endif +#endif + #if 0 /** * Adapter utility function. @@ -112,14 +115,15 @@ make_range( dash::IteratorRange< typename std::decay::type, typename std::decay::type - >((begin) -= begin.pos(), - (end) -= begin.pos()))) { + >(Iterator( + std::forward(begin) - begin.pos()), + end))) { return dash::sub(begin.pos(), end.pos(), dash::IteratorRange< typename std::decay::type, typename std::decay::type - >((begin) -= begin.pos(), - (end) -= begin.pos())); + >(Iterator(std::forward(begin) - begin.pos()), + end)); } #endif diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index df2c497f1..acfd77c95 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -54,6 +54,7 @@ class ViewIterator ViewIterator(const self_t & other) = default; self_t & operator=(const self_t & other) = default; +#if 0 template ViewIterator( const DomainItType & domain_it, @@ -73,7 +74,16 @@ class ViewIterator , _domain_it(std::forward(domain_it)) , _index_set(index_set) { } - +#else + ViewIterator( + const DomainIterator & domain_it, + const IndexSetType & index_set, + index_type position) + : base_t(position) + , _domain_it(domain_it) + , _index_set(index_set) + { } +#endif ViewIterator( const self_t & other, index_type position) From 1bb8fb2b6a1b9e08ff6798acd01cd9957d84e18a Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 30 May 2017 07:27:25 +0200 Subject: [PATCH 025/161] Fixing dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 84 +++++++++++++++++++----- dash/include/dash/Range.h | 68 +++++++++---------- dash/include/dash/iterator/GlobIter.h | 6 +- dash/include/dash/view/IndexSet.h | 30 +++++---- dash/include/dash/view/MakeRange.h | 10 +-- dash/include/dash/view/ViewMod.h | 2 +- 6 files changed, 129 insertions(+), 71 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index b155e39cb..2d637d8d8 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -106,29 +106,78 @@ int main(int argc, char *argv[]) a.barrier(); if (dash::myid() == 0) { - auto copy_begin_it = a.begin() + copy_dest_begin_idx; - auto copy_end_it_exp = copy_begin_it + copy_num_elem; - auto dest_range = dash::make_range(copy_begin_it, - copy_end_it_exp); - - const auto & dest_range_idx = dash::index(dest_range); - const auto & dest_range_org = dash::origin(dest_range); - const auto & dest_range_pat = dest_range_idx.pattern(); - const auto & dest_range_idom = dash::domain( - dash::index(dash::blocks(dest_range))); + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_end_it_exp = copy_begin_it + copy_num_elem; + + // auto dest_range = dash::make_range(copy_begin_it, + // copy_end_it_exp); + auto dest_range = dash::sub(copy_begin_it.pos(), + copy_end_it_exp.pos(), + a); + const auto & dest_brange = dash::blocks(dest_range); + + const auto & dest_range_idx = dash::index(dest_range); + const auto & dest_range_org = dash::origin(dest_range); + const auto & dest_range_pat = dest_range_idx.pattern(); + const auto & dest_range_idom = dash::domain( + dash::index(dest_range)); + const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); + const auto & dest_brange_org = dash::origin(dest_brange); + const auto & dest_brange_pat = dest_brange_idx.pattern(); + const auto & dest_brange_idom = dash::domain( + dash::index(dest_brange)); + + auto dom_first_gidx = dest_range_idom.first(); + auto dom_last_gidx = dest_range_idom.last(); + + auto first_gidx = dest_range_idx.first(); + auto last_gidx = dest_range_idx.last(); + + print("copy idom range " << "(" << dom_first_gidx + << "," << last_gidx << ")"); + print("copy ridx range " << "(" << first_gidx + << "," << last_gidx << ")"); + + print("copy rg type: " << dash::typestr(dest_range)); + print("copy b.rg type: " << dash::typestr(dest_brange)); + print("copy rg origin: " << dash::typestr(dest_range_org)); + print("copy b.rg origin: " << dash::typestr(dest_brange_org)); + print("copy rg &origin: " << &(dest_range_org)); + print("copy b.rg &origin: " << &(dest_brange_org)); + + print("copy rg index: " << dash::typestr(dest_range_idx)); + print("copy b.rg index: " << dash::typestr(dest_brange_idx)); + print("copy rg &index: " << &(dest_range_idx)); + print("copy b.rg &index: " << &(dest_brange_idx)); + + print("copy rg pattern: " << dash::typestr(dest_range_pat)); + print("copy b.rg pattern: " << dash::typestr(dest_brange_pat)); + print("copy rg &pattern: " << &dest_range_pat); + print("copy b.rg &pattern: " << &dest_brange_pat); + print("copy rg pat.size: " << dest_range_pat.size()); + print("copy b.rg pat.size: " << dest_brange_pat.size()); print("dest first block: " << dest_range_pat.block_at( dest_range_pat.coords( - dest_range_idom.first()) + first_gidx) )); print("dest last block: " << dest_range_pat.block_at( dest_range_pat.coords( - dest_range_idom.last()) + last_gidx) + )); + + print("dest b.rg block0: " << dest_brange_pat.block_at( + dest_brange_pat.coords( + first_gidx) + )); + print("dest b.rg blockN: " << dest_brange_pat.block_at( + dest_brange_pat.coords( + last_gidx) )); - print("copy range type: " << dash::typestr(dest_range)); - print("copy range origin: " << dash::typestr(dest_range_org)); - print("copy range pattern: " << dash::typestr(dest_range_pat)); + print("copy range local: " << std::decay::type::view_domain_is_local); print("copy range local: " << dash::view_traits< decltype(dest_range) >::is_local::value); @@ -144,10 +193,10 @@ int main(int argc, char *argv[]) print("copy range begin: " << dash::begin(dest_range)); print("copy range: " << range_str(dest_range)); - +#if 1 auto dest_blocks = dash::blocks(dest_range); for (auto block : dest_blocks) { - // print("copy to block:" << range_str(block)); + print("copy to block:" << range_str(block)); } // copy local buffer to global array @@ -155,6 +204,7 @@ int main(int argc, char *argv[]) buf.data(), buf.data() + copy_num_elem, copy_begin_it); +#endif } a.barrier(); diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index c70922e29..adad238b2 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -49,9 +49,6 @@ #include #include -// #include -// #include - #include @@ -259,12 +256,20 @@ template < typename Iterator, typename Sentinel > class RangeBase { + typedef RangeBase self_t; public: typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; typedef typename Iterator::pattern_type pattern_type; + protected: + constexpr RangeBase() = default; + constexpr RangeBase(const self_t & other) = default; + constexpr RangeBase(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + RangeType & derived() { return static_cast(*this); } @@ -278,12 +283,20 @@ template < typename Iterator, typename Sentinel > class RangeBase { + typedef RangeBase self_t; public: typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; //typedef internal::LocalPattern pattern_type; + protected: + constexpr RangeBase() = default; + constexpr RangeBase(const self_t & other) = default; + constexpr RangeBase(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + RangeType & derived() { return static_cast(*this); } @@ -306,8 +319,7 @@ struct view_traits > { public: typedef RangeT domain_type; typedef RangeT origin_type; -//typedef typename RangeT::pattern_type pattern_type; - typedef typename IteratorT::pattern_type pattern_type; + typedef typename RangeT::pattern_type pattern_type; typedef RangeT image_type; typedef RangeT global_type; typedef typename RangeT::local_type local_type; @@ -324,13 +336,9 @@ struct view_traits > { typedef std::integral_constant is_view; /// Whether the view is the origin domain. typedef std::integral_constant is_origin; - /// Whether the view / container type is a local view. - /// \note A container type is local if it is identical to its - /// \c local_type - typedef std::integral_constant::value > is_local; + /// Whether the range is local view. + typedef std::integral_constant< + bool, std::is_pointer::value> is_local; typedef std::integral_constant rank; }; @@ -367,10 +375,7 @@ class IteratorRange typedef std::integral_constant rank; typedef typename iterator::value_type value_type; - typedef typename base_t::pattern_type pattern_type; - - typedef std::integral_constant< - bool, std::is_pointer::value> is_local; + typedef typename iterator::pattern_type pattern_type; typedef typename std::conditional< @@ -383,24 +388,23 @@ class IteratorRange typedef typename std::conditional< std::is_pointer::value, - iterator, + sentinel, typename sentinel::local_type >::type local_sentinel; - typedef self_t domain_type; typedef self_t global_type; typedef IteratorRange local_type; private: - typename std::decay::type _begin; - typename std::decay::type _end; + Iterator _begin; + Sentinel _end; public: template constexpr explicit IteratorRange(Container && c) - : _begin(c.begin()) - , _end(c.end()) + : _begin(std::forward(c).begin()) + , _end(std::forward(c).end()) { } constexpr IteratorRange(const iterator & begin, const sentinel & end) @@ -413,6 +417,12 @@ class IteratorRange , _end(std::forward(end)) { } + constexpr IteratorRange() = delete; + constexpr IteratorRange(const self_t & other) = default; + constexpr IteratorRange(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + constexpr iterator begin() const { return _begin; } constexpr sentinel end() const { return _end; } @@ -430,13 +440,8 @@ class IteratorRange constexpr const pattern_type & pattern() const { return _begin.pattern(); } - -// constexpr index_set_type index_set() const { -// return dash::index(dash::sub(*this, _begin_pos, _end.pos())); -// } }; - template < typename IteratorT, typename SentinelT > @@ -449,7 +454,7 @@ struct view_traits > { //typedef typename RangeT::pattern_type pattern_type; typedef RangeT image_type; typedef RangeT global_type; - typedef typename RangeT::local_type local_type; + typedef RangeT local_type; typedef typename RangeT::index_type index_type; typedef typename RangeT::size_type size_type; typedef dash::IndexSetIdentity index_set_type; @@ -483,7 +488,7 @@ class IteratorRange false // iterator does not specify pattern > { - typedef IteratorRange self_t; + typedef IteratorRange self_t; LocalIterator * _begin; LocalSentinel * _end; @@ -494,7 +499,6 @@ class IteratorRange typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; //typedef typename internal::LocalPattern pattern_type; - typedef dash::IndexSetIdentity index_set_type; typedef LocalIterator value_type; @@ -527,10 +531,6 @@ class IteratorRange constexpr const local_type & local() const { return *this; } - -// constexpr index_set_type index_set() const { -// return index_set_type(*this); -// } }; } // namespace dash diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index a78f19aa4..8d9bb7c1b 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -155,15 +155,15 @@ class GlobIter protected: /// Global memory used to dereference iterated values. - GlobMemType * _globmem; + GlobMemType * _globmem = nullptr; /// Pattern that specifies the iteration order (access pattern). - const PatternType * _pattern; + const PatternType * _pattern = nullptr; /// Current position of the iterator in global canonical index space. index_type _idx = 0; /// Maximum position allowed for this iterator. index_type _max_idx = 0; /// Unit id of the active unit - team_unit_t _myid; + team_unit_t _myid = DART_UNDEFINED_TEAM_UNIT_ID; /// Pointer to first element in local memory local_pointer _lbegin = nullptr; diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index cd5553fac..6a84d7955 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -179,8 +179,8 @@ class IndexSetIterator BaseStride >, index_type, int, std::nullptr_t, index_type > base_t; private: - const IndexSetType * const _index_set; - index_type _stride = BaseStride; + const IndexSetType * _index_set; + index_type _stride = BaseStride; public: constexpr IndexSetIterator() = delete; constexpr IndexSetIterator(self_t &&) = default; @@ -333,8 +333,8 @@ class IndexSetBase static constexpr std::size_t ndim() { return NDim; } protected: - domain_member_type _domain; - const pattern_type * _pattern; + domain_member_type _domain; + const pattern_type * _pattern = nullptr; constexpr const IndexSetType & derived() const { return static_cast(*this); @@ -342,12 +342,12 @@ class IndexSetBase constexpr explicit IndexSetBase(const DomainType & domain) : _domain(domain) - , _pattern(&dash::origin(domain).pattern()) + , _pattern(&dash::origin(_domain).pattern()) { } constexpr explicit IndexSetBase(DomainType && domain) : _domain(std::forward(domain)) - , _pattern(&dash::origin(view_domain()).pattern()) + , _pattern(&dash::origin(_domain).pattern()) { } typedef struct { @@ -405,10 +405,10 @@ class IndexSetBase } constexpr auto domain() const -// -> decltype(dash::index( -// std::declval() -// )) { - -> typename view_traits::index_set_type { + -> decltype(dash::index( + std::declval() + )) { +// -> typename view_traits::index_set_type { return dash::index(this->view_domain()); } @@ -1262,12 +1262,17 @@ class IndexSetBlocks typedef typename base_t::index_type index_type; typedef typename base_t::size_type size_type; + typedef typename base_t::view_origin_type view_origin_type; + typedef typename base_t::view_domain_type view_domain_type; + + typedef typename base_t::pattern_type pattern_type; + typedef self_t local_type; typedef IndexSetGlobal global_type; - typedef global_type preimage_type; typedef typename base_t::iterator iterator; - typedef typename base_t::pattern_type pattern_type; + + typedef global_type preimage_type; typedef dash::local_index_t local_index_type; typedef dash::global_index_t global_index_type; @@ -1279,6 +1284,7 @@ class IndexSetBlocks // the domain's pattern type. static constexpr std::size_t NBlocksDim = base_t::rank::value; + public: constexpr static bool view_domain_is_local = dash::view_traits::is_local::value; public: diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index 991b2e6a0..8cc907b56 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -42,7 +42,7 @@ make_range( } #endif -#if 0 +#if 1 /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -50,17 +50,19 @@ make_range( template < class Iterator, class Sentinel, - typename std::enable_if< !std::is_pointer::value > * = nullptr > + typename IteratorDT = typename std::decay::type, + typename SentinelDT = typename std::decay::type, + typename std::enable_if< !std::is_pointer::value > * = nullptr > auto make_range( const Iterator & begin, const Sentinel & end) -> decltype(dash::sub( begin.pos(), end.pos(), - dash::IteratorRange( + dash::IteratorRange( Iterator(begin - begin.pos()), end))) { return dash::sub(begin.pos(), end.pos(), - dash::IteratorRange( + dash::IteratorRange( Iterator(begin - begin.pos()), end)); } #else diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 7903bfabb..53ead7f5e 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -621,7 +621,7 @@ class ViewSubMod index_type begin, index_type end) : base_t(std::forward(domain)) - , _index_set(this->domain(), begin, end) + , _index_set(std::forward(domain), begin, end) { } constexpr ViewSubMod( From f275c067e62af42646b843e9d827bfbfd30f100d Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 30 May 2017 07:47:08 +0200 Subject: [PATCH 026/161] Fixing dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 17 ++++++++----- dash/include/dash/view/IndexSet.h | 4 +-- dash/include/dash/view/MakeRange.h | 18 +++++++------ dash/include/dash/view/ViewIterator.h | 32 ++++++++---------------- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 2d637d8d8..3b43c421a 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -109,11 +109,11 @@ int main(int argc, char *argv[]) auto copy_begin_it = a.begin() + copy_dest_begin_idx; auto copy_end_it_exp = copy_begin_it + copy_num_elem; - // auto dest_range = dash::make_range(copy_begin_it, - // copy_end_it_exp); - auto dest_range = dash::sub(copy_begin_it.pos(), - copy_end_it_exp.pos(), - a); + auto dest_range = dash::make_range(copy_begin_it, + copy_end_it_exp); + // auto dest_range = dash::sub(copy_begin_it.pos(), + // copy_end_it_exp.pos(), + // a); const auto & dest_brange = dash::blocks(dest_range); const auto & dest_range_idx = dash::index(dest_range); @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) const auto & dest_range_pat = dest_range_idx.pattern(); const auto & dest_range_idom = dash::domain( dash::index(dest_range)); - const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); + const auto & dest_brange_idx = dash::index(dest_brange); const auto & dest_brange_org = dash::origin(dest_brange); const auto & dest_brange_pat = dest_brange_idx.pattern(); const auto & dest_brange_idom = dash::domain( @@ -133,10 +133,15 @@ int main(int argc, char *argv[]) auto first_gidx = dest_range_idx.first(); auto last_gidx = dest_range_idx.last(); + auto first_bidx = dest_brange_idx.first(); + auto last_bidx = dest_brange_idx.last(); + print("copy idom range " << "(" << dom_first_gidx << "," << last_gidx << ")"); print("copy ridx range " << "(" << first_gidx << "," << last_gidx << ")"); + print("copy bidx range " << "(" << first_bidx + << "," << last_bidx << ")"); print("copy rg type: " << dash::typestr(dest_range)); print("copy b.rg type: " << dash::typestr(dest_brange)); diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 6a84d7955..cb5be5799 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -342,12 +342,12 @@ class IndexSetBase constexpr explicit IndexSetBase(const DomainType & domain) : _domain(domain) - , _pattern(&dash::origin(_domain).pattern()) + , _pattern(&dash::origin(domain).pattern()) { } constexpr explicit IndexSetBase(DomainType && domain) : _domain(std::forward(domain)) - , _pattern(&dash::origin(_domain).pattern()) + , _pattern(&dash::origin(domain).pattern()) { } typedef struct { diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index 8cc907b56..02629493b 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -57,13 +57,17 @@ auto make_range( const Iterator & begin, const Sentinel & end) - -> decltype(dash::sub( - begin.pos(), end.pos(), - dash::IteratorRange( - Iterator(begin - begin.pos()), end))) { - return dash::sub(begin.pos(), end.pos(), - dash::IteratorRange( - Iterator(begin - begin.pos()), end)); + -> decltype( + dash::sub(begin.pos(), + end.pos(), + dash::IteratorRange( + begin - begin.pos(), + begin + (begin.pattern().size() - begin.pos())))) { + return dash::sub(begin.pos(), + end.pos(), + dash::IteratorRange( + begin - begin.pos(), + begin + (begin.pattern().size() - begin.pos()))); } #else /** diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index acfd77c95..ce0624868 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -43,8 +43,8 @@ class ViewIterator typedef typename base_t::value_type value_type; typedef typename IndexSetType::index_type index_type; private: - typename std::decay::type _domain_it; - IndexSetType _index_set; + DomainIterator _domain_it; + IndexSetType _index_set; public: constexpr ViewIterator() = delete; @@ -54,7 +54,6 @@ class ViewIterator ViewIterator(const self_t & other) = default; self_t & operator=(const self_t & other) = default; -#if 0 template ViewIterator( const DomainItType & domain_it, @@ -74,16 +73,7 @@ class ViewIterator , _domain_it(std::forward(domain_it)) , _index_set(index_set) { } -#else - ViewIterator( - const DomainIterator & domain_it, - const IndexSetType & index_set, - index_type position) - : base_t(position) - , _domain_it(domain_it) - , _index_set(index_set) - { } -#endif + ViewIterator( const self_t & other, index_type position) @@ -108,11 +98,11 @@ class ViewIterator return (_domain_it + (_index_set[this->pos()])).local(); } - dart_gptr_t dart_gptr() const { - DASH_LOG_DEBUG("ViewIterator", - "it.pos:", _domain_it.pos(), - "it.gpos:", _domain_it.gpos(), - "pos:", this->pos()); + constexpr dart_gptr_t dart_gptr() const { +// DASH_LOG_DEBUG("ViewIterator", +// "it.pos:", _domain_it.pos(), +// "it.gpos:", _domain_it.gpos(), +// "pos:", this->pos()); return (_domain_it + _index_set[this->pos()]).dart_gptr(); } @@ -124,9 +114,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()]); +// } }; template < From 81f089d06206e4eb7d9aa99ad42aa7f52a601e65 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 30 May 2017 09:01:15 +0200 Subject: [PATCH 027/161] Fixed type definition traits macro --- dash/examples/ex.02.array-views/main.cpp | 37 ++++++++++++++++++++++-- dash/include/dash/Meta.h | 3 +- dash/include/dash/Range.h | 23 ++++++++------- dash/include/dash/view/IndexSet.h | 2 +- dash/include/dash/view/ViewBlocksMod.h | 9 ++++-- 5 files changed, 57 insertions(+), 17 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 3b43c421a..865212617 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -121,11 +121,14 @@ int main(int argc, char *argv[]) const auto & dest_range_pat = dest_range_idx.pattern(); const auto & dest_range_idom = dash::domain( dash::index(dest_range)); + // Works: const auto & dest_brange_idx = dash::index(dest_brange); - const auto & dest_brange_org = dash::origin(dest_brange); + // Fails: +// const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); + const auto & dest_brange_org = dash::origin(dash::blocks(dest_range)); const auto & dest_brange_pat = dest_brange_idx.pattern(); const auto & dest_brange_idom = dash::domain( - dash::index(dest_brange)); + dash::index(dash::blocks(dest_range))); auto dom_first_gidx = dest_range_idom.first(); auto dom_last_gidx = dest_range_idom.last(); @@ -136,6 +139,26 @@ int main(int argc, char *argv[]) auto first_bidx = dest_brange_idx.first(); auto last_bidx = dest_brange_idx.last(); + print("make_range is range: " << dash::is_range< + decltype(dest_range) + >::value); + print("blocks(range) is range: " << dash::is_range< + decltype(dest_brange) + >::value); + print("d(blocks(rg)) is range: " << dash::is_range< + decltype(dash::domain(dest_brange)) + >::value); + + print("make_range is view: " << dash::is_view< + decltype(dest_range) + >::value); + print("blocks(range) is view: " << dash::is_view< + decltype(dest_brange) + >::value); + print("d(make_range) is view: " << dash::is_view< + decltype(dash::domain(dest_range)) + >::value); + print("copy idom range " << "(" << dom_first_gidx << "," << last_gidx << ")"); print("copy ridx range " << "(" << first_gidx @@ -145,6 +168,14 @@ int main(int argc, char *argv[]) print("copy rg type: " << dash::typestr(dest_range)); print("copy b.rg type: " << dash::typestr(dest_brange)); + + print("copy rg domain: " << dash::typestr(dest_range_idom)); + print("copy b.rg domain: " << dash::typestr(dest_brange_idom)); + print("copy rg &domain: " << &(dest_range_idom)); + print("copy b.rg &domain: " << &(dest_brange_idom)); + print("copy rg domain.sz " << dest_range_idom.size()); + print("copy b.rg domain.sz " << dest_brange_idom.size()); + print("copy rg origin: " << dash::typestr(dest_range_org)); print("copy b.rg origin: " << dash::typestr(dest_brange_org)); print("copy rg &origin: " << &(dest_range_org)); @@ -154,6 +185,8 @@ int main(int argc, char *argv[]) print("copy b.rg index: " << dash::typestr(dest_brange_idx)); print("copy rg &index: " << &(dest_range_idx)); print("copy b.rg &index: " << &(dest_brange_idx)); + print("copy rg index.siz " << (dest_range_idx.size())); + print("copy b.rg index.siz " << (dest_brange_idx.size())); print("copy rg pattern: " << dash::typestr(dest_range_pat)); print("copy b.rg pattern: " << dash::typestr(dest_brange_pat)); diff --git a/dash/include/dash/Meta.h b/dash/include/dash/Meta.h index 9929ab224..65110d59b 100644 --- a/dash/include/dash/Meta.h +++ b/dash/include/dash/Meta.h @@ -13,12 +13,13 @@ template \ struct has_type_##DepType { \ private: \ + typedef typename std::decay::type DT; \ typedef char yes; \ typedef struct { char array[2]; } no; \ template static yes test(typename C:: DepType *); \ template static no test(...); \ public: \ - static constexpr bool value = sizeof(test(0)) == sizeof(yes); \ + static constexpr bool value = sizeof(test
(0)) == sizeof(yes); \ }; #endif // DOXYGEN diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index adad238b2..a4bcdcd53 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -122,10 +122,7 @@ struct _is_range_type typedef char yes; typedef long no; - typedef typename std::remove_reference< - typename std::remove_const::type - >::type - ValueT; + typedef typename std::decay::type ValueT; #ifdef __TODO__ private: @@ -133,7 +130,7 @@ struct _is_range_type template static yes has_dash_begin( decltype( dash::begin( - std::move(std::declval()) + std::move(std::declval()) ) ) * ); template static no has_dash_begin(...); @@ -142,7 +139,7 @@ struct _is_range_type template static yes has_dash_end( decltype( dash::end( - std::move(std::declval()) + std::move(std::declval()) ) ) * ); template static no has_dash_end(...); @@ -242,7 +239,10 @@ struct _is_range_type * \endcode */ template -struct is_range : dash::detail::_is_range_type { }; +struct is_range : dash::detail::_is_range_type< + typename std::decay::type + > +{ }; template < typename RangeType, @@ -261,7 +261,7 @@ class RangeBase { typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; - typedef typename Iterator::pattern_type pattern_type; +//typedef typename Iterator::pattern_type pattern_type; protected: constexpr RangeBase() = default; @@ -397,8 +397,8 @@ class IteratorRange typedef IteratorRange local_type; private: - Iterator _begin; - Sentinel _end; + Iterator _begin; + Sentinel _end; public: template @@ -426,6 +426,9 @@ class IteratorRange constexpr iterator begin() const { return _begin; } constexpr sentinel end() const { return _end; } + iterator begin() { return _begin; } + sentinel end() { return _end; } + constexpr size_type size() const { return std::distance(_begin, _end); } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index cb5be5799..e546ca910 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1378,7 +1378,7 @@ class IndexSetBlocks } constexpr index_type size() const { - return _size; // calc_size(); + return calc_size(); } private: diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 1eb27339d..c82b9b294 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -525,8 +525,11 @@ class ViewBlocksMod }; public: - typedef block_iterator iterator; - typedef block_iterator const_iterator; + typedef block_iterator iterator; + typedef block_iterator const_iterator; + + using reference = typename iterator::reference; + using const_reference = typename const_iterator::reference; public: constexpr ViewBlocksMod() = delete; @@ -551,7 +554,7 @@ class ViewBlocksMod constexpr explicit ViewBlocksMod( domain_type && domain) : base_t(std::forward(domain)) - , _index_set(this->domain()) + , _index_set(std::forward(domain)) { } // ---- extents --------------------------------------------------------- From bd91cd4ead801a81b0bf95438a686845ff794ae1 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 30 May 2017 09:59:25 +0200 Subject: [PATCH 028/161] Fixed pointer ranges --- dash/include/dash/Range.h | 32 ++++++++++++++++++--------- dash/include/dash/view/MakeRange.h | 4 ++-- dash/include/dash/view/ViewIterator.h | 2 +- dash/test/meta/RangeTest.cc | 16 +++++++------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index a4bcdcd53..21b4b30bb 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -397,24 +397,28 @@ class IteratorRange typedef IteratorRange local_type; private: - Iterator _begin; - Sentinel _end; + Iterator _begin; + Sentinel _end; + const pattern_type * _pattern; public: template constexpr explicit IteratorRange(Container && c) : _begin(std::forward(c).begin()) , _end(std::forward(c).end()) + , _pattern(&c.pattern()) { } constexpr IteratorRange(const iterator & begin, const sentinel & end) : _begin(begin) , _end(end) + , _pattern(&begin.pattern()) { } constexpr IteratorRange(iterator && begin, sentinel && end) : _begin(std::forward(begin)) , _end(std::forward(end)) + , _pattern(&begin.pattern()) { } constexpr IteratorRange() = delete; @@ -441,7 +445,7 @@ class IteratorRange } constexpr const pattern_type & pattern() const { - return _begin.pattern(); + return *_pattern; // _begin.pattern(); } }; @@ -499,6 +503,9 @@ class IteratorRange public: typedef LocalIterator * iterator; typedef LocalSentinel * sentinel; + typedef const LocalIterator * const_iterator; + typedef const LocalSentinel * const_sentinel; + typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; //typedef typename internal::LocalPattern pattern_type; @@ -510,24 +517,27 @@ class IteratorRange typedef IteratorRange local_type; typedef self_t global_type; - typedef self_t domain_type; +//typedef self_t domain_type; typedef std::integral_constant is_local; public: - template - constexpr explicit IteratorRange(Container && c) - : _begin(c.begin()) - , _end(c.end()) - { } +// template +// constexpr explicit IteratorRange(Container && c) +// : _begin(c.begin()) +// , _end(c.end()) +// { } constexpr IteratorRange(iterator & begin, sentinel & end) : _begin(begin) , _end(end) { } - constexpr iterator begin() const { return _begin; } - constexpr iterator end() const { return _end; } + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } constexpr size_type size() const { return std::distance(_begin, _end); } diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index 02629493b..808285140 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -18,8 +18,8 @@ template < typename std::enable_if< std::is_pointer::value > * = nullptr > constexpr dash::IteratorRange make_range( - Iterator * const begin, - Sentinel * const end) { + Iterator * begin, + Sentinel * end) { return dash::IteratorRange( begin, end); diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index ce0624868..9c478de8e 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -130,7 +130,7 @@ class ViewIterator DomainIterator *, DomainIterator & > { - typedef ViewIterator self_t; + typedef ViewIterator self_t; typedef dash::internal::IndexIteratorBase< ViewIterator, DomainIterator, diff --git a/dash/test/meta/RangeTest.cc b/dash/test/meta/RangeTest.cc index 88cadf51b..f5c83fd40 100644 --- a/dash/test/meta/RangeTest.cc +++ b/dash/test/meta/RangeTest.cc @@ -87,13 +87,13 @@ TEST_F(RangeTest, RangeTraits) dash::is_range::value == true, "dash::is_range>::value not matched"); -// auto l_range = dash::make_range(array.local.begin(), -// array.local.end()); -// static_assert( -// dash::is_range::value == true, -// "dash::is_range::value not matched"); -// static_assert( -// dash::is_view::value == true, -// "dash::is_view::value not matched"); + auto l_range = dash::make_range(array.local.begin(), + array.local.end()); + static_assert( + dash::is_range::value == true, + "dash::is_range::value not matched"); + static_assert( + dash::is_view::value == false, + "dash::is_view::value not matched"); } From c880aabf27a5d25902d1bf538d39c62c9d2390c3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 30 May 2017 10:07:38 +0200 Subject: [PATCH 029/161] Fixing dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 2 ++ dash/include/dash/Range.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 865212617..ea28bea94 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -180,6 +180,8 @@ int main(int argc, char *argv[]) print("copy b.rg origin: " << dash::typestr(dest_brange_org)); print("copy rg &origin: " << &(dest_range_org)); print("copy b.rg &origin: " << &(dest_brange_org)); + print("copy rg orig.p.sz " << dest_range_org.pattern().size()); + print("copy b.rg orig.p.sz " << dest_brange_org.pattern().size()); print("copy rg index: " << dash::typestr(dest_range_idx)); print("copy b.rg index: " << dash::typestr(dest_brange_idx)); diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 21b4b30bb..11e04b406 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -445,7 +445,7 @@ class IteratorRange } constexpr const pattern_type & pattern() const { - return *_pattern; // _begin.pattern(); + return _begin.pattern(); } }; From 12ad36b66fa111a0b4f318d0e13b1446bb6780eb Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 30 May 2017 11:20:35 +0200 Subject: [PATCH 030/161] Fixing dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 10 ++++++++-- dash/include/dash/Range.h | 6 +++--- dash/include/dash/view/IndexSet.h | 17 +++++++++++++++-- dash/include/dash/view/ViewBlocksMod.h | 18 ++++++++++-------- dash/include/dash/view/ViewMod1D.h | 7 ++++--- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index ea28bea94..fda9052a5 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -122,9 +122,9 @@ int main(int argc, char *argv[]) const auto & dest_range_idom = dash::domain( dash::index(dest_range)); // Works: - const auto & dest_brange_idx = dash::index(dest_brange); +// const auto & dest_brange_idx = dash::index(dest_brange); // Fails: -// const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); + const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); const auto & dest_brange_org = dash::origin(dash::blocks(dest_range)); const auto & dest_brange_pat = dest_brange_idx.pattern(); const auto & dest_brange_idom = dash::domain( @@ -166,6 +166,10 @@ int main(int argc, char *argv[]) print("copy bidx range " << "(" << first_bidx << "," << last_bidx << ")"); + print("array &pattern: " << &a.pattern()); + print("begin+1 &pattern: " << &(dash::index( + dash::sub(2, 8, a)).pattern())); + print("copy rg type: " << dash::typestr(dest_range)); print("copy b.rg type: " << dash::typestr(dest_brange)); @@ -180,6 +184,8 @@ int main(int argc, char *argv[]) print("copy b.rg origin: " << dash::typestr(dest_brange_org)); print("copy rg &origin: " << &(dest_range_org)); print("copy b.rg &origin: " << &(dest_brange_org)); + print("copy rg &orig.pat " << &dest_range_org.pattern()); + print("copy b.rg &orig.pat " << &dest_brange_org.pattern()); print("copy rg orig.p.sz " << dest_range_org.pattern().size()); print("copy b.rg orig.p.sz " << dest_brange_org.pattern().size()); diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 11e04b406..9de37ab01 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -319,7 +319,7 @@ struct view_traits > { public: typedef RangeT domain_type; typedef RangeT origin_type; - typedef typename RangeT::pattern_type pattern_type; + typedef typename IteratorT::pattern_type pattern_type; typedef RangeT image_type; typedef RangeT global_type; typedef typename RangeT::local_type local_type; @@ -399,7 +399,7 @@ class IteratorRange private: Iterator _begin; Sentinel _end; - const pattern_type * _pattern; + const pattern_type * _pattern; public: template @@ -445,7 +445,7 @@ class IteratorRange } constexpr const pattern_type & pattern() const { - return _begin.pattern(); + return *_pattern; // _begin.pattern(); } }; diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index e546ca910..9286d4946 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -217,6 +217,19 @@ class IndexSetIterator } // namespace detail +template < + class ContainerType, + class ContainerDecayType = typename std::decay::type > +constexpr auto +index(ContainerType && c) +-> typename std::enable_if < + !dash::view_traits::is_view::value, + IndexSetIdentity + >::type { + return IndexSetIdentity( + std::forward(c)); +} + template < class ContainerType, class ContainerDecayType = typename std::decay::type > @@ -224,7 +237,7 @@ constexpr auto index(const ContainerType & c) -> typename std::enable_if < !dash::view_traits::is_view::value, - const IndexSetIdentity + IndexSetIdentity >::type { return IndexSetIdentity(c); } @@ -409,7 +422,7 @@ class IndexSetBase std::declval() )) { // -> typename view_traits::index_set_type { - return dash::index(this->view_domain()); + return dash::index(_domain); } constexpr const pattern_type & pattern() const { diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index c82b9b294..403ee7ed2 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -422,9 +422,10 @@ struct view_traits > { typedef typename domain_type::local_type local_type; typedef ViewBlocksMod global_type; - typedef typename DomainType::index_type index_type; + typedef typename view_traits::index_type index_type; typedef typename view_traits::size_type size_type; - typedef dash::IndexSetBlocks> +//typedef dash::IndexSetBlocks> + typedef dash::IndexSetBlocks index_set_type; typedef std::integral_constant is_projection; @@ -443,9 +444,9 @@ class ViewBlocksMod : public ViewModBase< ViewBlocksMod, DomainType, NDim > { private: typedef ViewBlocksMod self_t; + typedef ViewBlocksMod const_self_t; typedef ViewModBase, DomainType, NDim> base_t; - typedef ViewBlocksMod const_self_t; public: typedef DomainType domain_type; typedef typename base_t::origin_type origin_type; @@ -512,7 +513,8 @@ class ViewBlocksMod ViewBlocksModType && blocks_view, index_type position) : iterator_base_t(position) - , _blocks_view_domain(std::forward(blocks_view)) + , _blocks_view_domain( + dash::domain(std::forward(blocks_view))) { } constexpr block_type dereference(index_type idx) const { @@ -532,10 +534,10 @@ class ViewBlocksMod using const_reference = typename const_iterator::reference; public: + ~ViewBlocksMod() = default; constexpr ViewBlocksMod() = delete; constexpr ViewBlocksMod(const self_t &) = default; constexpr ViewBlocksMod(self_t &&) = default; - ~ViewBlocksMod() = default; self_t & operator=(self_t &&) = default; self_t & operator=(const self_t &) = default; @@ -611,10 +613,10 @@ class ViewBlocksMod return iterator(*this, _index_set.last() + 1); } - constexpr block_type operator[](int offset) const { - return *iterator(*this, _index_set[offset]); + constexpr const_reference operator[](int offset) const { + return *const_iterator(*this, _index_set[offset]); } - block_type operator[](int offset) { + reference operator[](int offset) { return *iterator(*this, _index_set[offset]); } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 0154bfea4..581d7a114 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -73,12 +73,13 @@ class ViewSubMod self_t & operator=(self_t &&) = default; self_t & operator=(const self_t &) = default; + template constexpr ViewSubMod( - domain_type && domain, + DomainT_ && domain, index_type begin, index_type end) - : base_t(std::forward(domain)) - , _index_set(this->domain(), begin, end) + : base_t(std::forward(domain)) + , _index_set(std::forward(domain), begin, end) { } constexpr ViewSubMod( From 368de777a6c37b3123f20bed8cd9ad2d2f0df961 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 01:49:36 +0200 Subject: [PATCH 031/161] Fixed dash::make_range --- dash/examples/ex.02.array-views/main.cpp | 29 ++++++------- dash/include/dash/Range.h | 18 ++++---- dash/include/dash/View.h | 40 ++++++++++++++---- dash/include/dash/algorithm/Copy.h | 2 +- dash/include/dash/view/IndexSet.h | 52 +++++++++++++++--------- dash/include/dash/view/Origin.h | 6 +-- dash/include/dash/view/Sub.h | 26 +----------- dash/include/dash/view/ViewBlocksMod.h | 16 +++----- dash/include/dash/view/ViewMod.h | 4 +- dash/include/dash/view/ViewMod1D.h | 17 ++++---- dash/include/dash/view/ViewTraits.h | 6 +-- 11 files changed, 110 insertions(+), 106 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index fda9052a5..601348cac 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) // auto dest_range = dash::sub(copy_begin_it.pos(), // copy_end_it_exp.pos(), // a); - const auto & dest_brange = dash::blocks(dest_range); + auto dest_brange = dash::blocks(dest_range); const auto & dest_range_idx = dash::index(dest_range); const auto & dest_range_org = dash::origin(dest_range); @@ -122,9 +122,9 @@ int main(int argc, char *argv[]) const auto & dest_range_idom = dash::domain( dash::index(dest_range)); // Works: -// const auto & dest_brange_idx = dash::index(dest_brange); +// auto dest_brange_idx = dash::index(dest_brange); // Fails: - const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); + auto dest_brange_idx = dash::index(dash::blocks(dest_range)); const auto & dest_brange_org = dash::origin(dash::blocks(dest_range)); const auto & dest_brange_pat = dest_brange_idx.pattern(); const auto & dest_brange_idom = dash::domain( @@ -184,10 +184,12 @@ int main(int argc, char *argv[]) print("copy b.rg origin: " << dash::typestr(dest_brange_org)); print("copy rg &origin: " << &(dest_range_org)); print("copy b.rg &origin: " << &(dest_brange_org)); - print("copy rg &orig.pat " << &dest_range_org.pattern()); - print("copy b.rg &orig.pat " << &dest_brange_org.pattern()); + print("copy rg &orig.pat " << &(dest_range_org.pattern())); + print("copy b.rg &orig.pat " << &(dest_brange_org.pattern())); print("copy rg orig.p.sz " << dest_range_org.pattern().size()); print("copy b.rg orig.p.sz " << dest_brange_org.pattern().size()); + print("copy rg &orig.idx " << &(dash::index(dest_range_org).pattern())); + print("copy b.rg &orig.idx " << &(dash::index(dest_brange_org).pattern())); print("copy rg index: " << dash::typestr(dest_range_idx)); print("copy b.rg index: " << dash::typestr(dest_brange_idx)); @@ -231,17 +233,16 @@ int main(int argc, char *argv[]) print("copy block dom.idx: " << dash::domain( dash::index(dash::blocks(dest_range)) )); - print("copy block indices: " << dash::index(dash::blocks(dest_range))); - print("copy num blocks: " << dash::blocks(dest_range).size()); - print("copy dom. begin: " << copy_begin_it - copy_begin_it.pos()); - print("copy begin: " << copy_begin_it); - print("copy end: " << copy_end_it_exp); - - print("copy range begin: " << dash::begin(dest_range)); - print("copy range: " << range_str(dest_range)); + print("copy block indices: " << dash::index(dest_brange)); + print("copy num blocks: " << dest_brange.size()); + print("copy begin: " << dash::begin(dest_range)); + print("copy end: " << dash::end(dest_range)); + +// print("copy range begin: " << dash::begin(dest_range)); +// print("copy range: " << range_str(dest_range)); #if 1 auto dest_blocks = dash::blocks(dest_range); - for (auto block : dest_blocks) { + for (const auto & block : dest_blocks) { print("copy to block:" << range_str(block)); } diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 9de37ab01..3c102707b 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -261,7 +261,7 @@ class RangeBase { typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; -//typedef typename Iterator::pattern_type pattern_type; + typedef typename Iterator::pattern_type pattern_type; protected: constexpr RangeBase() = default; @@ -335,7 +335,7 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; + typedef std::integral_constant is_origin; /// Whether the range is local view. typedef std::integral_constant< bool, std::is_pointer::value> is_local; @@ -399,26 +399,22 @@ class IteratorRange private: Iterator _begin; Sentinel _end; - const pattern_type * _pattern; public: template constexpr explicit IteratorRange(Container && c) : _begin(std::forward(c).begin()) , _end(std::forward(c).end()) - , _pattern(&c.pattern()) { } constexpr IteratorRange(const iterator & begin, const sentinel & end) : _begin(begin) , _end(end) - , _pattern(&begin.pattern()) { } constexpr IteratorRange(iterator && begin, sentinel && end) - : _begin(std::forward(begin)) - , _end(std::forward(end)) - , _pattern(&begin.pattern()) + : _begin(std::move(begin)) + , _end(std::move(end)) { } constexpr IteratorRange() = delete; @@ -445,7 +441,7 @@ class IteratorRange } constexpr const pattern_type & pattern() const { - return *_pattern; // _begin.pattern(); + return _begin.pattern(); // *_pattern; } }; @@ -471,7 +467,7 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; + typedef std::integral_constant is_origin; /// Whether the view / container type is a local view. /// \note A container type is local if it is identical to its /// \c local_type @@ -528,7 +524,7 @@ class IteratorRange // , _end(c.end()) // { } - constexpr IteratorRange(iterator & begin, sentinel & end) + constexpr IteratorRange(iterator begin, sentinel end) : _begin(begin) , _end(end) { } diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index 97210ae2c..caa62b0ff 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -111,17 +111,22 @@ template < class Iterator, class Sentinel > struct view_traits > { - typedef IteratorViewOrigin domain_type; - typedef IteratorViewOrigin origin_type; + typedef IteratorRange domain_type; + typedef IteratorRange origin_type; typedef IteratorViewOrigin image_type; // Uses container::local_type directly, e.g. dash::LocalArrayRef: - // typedef typename dash::view_traits::local_type local_type; + typedef typename dash::view_traits::local_type local_type; + typedef typename dash::view_traits::global_type global_type; // Uses ViewLocalMod wrapper on domain, e.g. ViewLocalMod: - typedef ViewLocalMod local_type; - typedef ViewGlobalMod global_type; +//typedef ViewLocalMod local_type; +//typedef ViewGlobalMod global_type; typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef typename Iterator::pattern_type pattern_type; + typedef dash::IndexSetIdentity< IteratorViewOrigin > index_set_type; @@ -129,6 +134,8 @@ struct view_traits > { typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant is_local; + + typedef std::integral_constant rank; }; template < @@ -140,6 +147,7 @@ class IteratorViewOrigin { public: typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; private: typedef IteratorViewOrigin self_t; typedef IteratorRange base_t; @@ -152,10 +160,21 @@ class IteratorViewOrigin typedef typename view_traits::global_type global_type; typedef typename Iterator::pattern_type pattern_type; + + typedef dash::IndexSetIdentity< + IteratorRange > index_set_type; + + typedef std::integral_constant rank; + +private: + index_set_type _index_set; + public: constexpr IteratorViewOrigin(Iterator begin, Iterator end) - : base_t(std::move(begin), std::move(end)) { - } +//: base_t(std::move(begin), std::move(end)) { + : base_t(begin, end) + , _index_set(*this) + { } constexpr const pattern_type & pattern() const { return this->begin().pattern(); @@ -167,6 +186,9 @@ class IteratorViewOrigin return local_type(*this); } + constexpr const index_set_type & index_set() const { + return _index_set; + } }; @@ -186,8 +208,8 @@ make_view(Iterator && begin, Sentinel && end) { return dash::IteratorViewOrigin< typename std::decay::type, typename std::decay::type - >(std::forward(begin), - std::forward(end)); + >(std::forward(begin), + std::forward(end)); } } // namespace dash diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 05a81b65b..69fc4c04b 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1098,7 +1098,7 @@ GlobOutputIt copy( auto out_range = dash::make_range(out_first, out_h_last); // DASH_LOG_TRACE("dash::copy", "out value range:", out_range); - DASH_LOG_TRACE("dash::copy", "out index range:", dash::index(out_range)); +// DASH_LOG_TRACE("dash::copy", "out index range:", dash::index(out_range)); auto out_blocks = dash::blocks(out_range); auto in_copy_it = in_first; diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 9286d4946..e24f5701b 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -139,9 +139,9 @@ constexpr auto index(DomainType && v) -> typename std::enable_if< dash::view_traits::is_view::value, - decltype(std::forward(v).index_set()) + typename std::decay::type >::type { - return std::forward(v).index_set(); + return v.index_set(); } template < @@ -283,12 +283,16 @@ global( namespace detail { +// !!! HERE !!! template struct index_set_domain_bind_t { typedef typename - std::conditional< dash::is_view::value, - DomainT, - const DomainT & >::type + std::conditional< + !dash::view_traits< + typename std::decay::type + >::is_origin::value, + DomainT, + const DomainT & >::type type; }; @@ -355,12 +359,12 @@ class IndexSetBase constexpr explicit IndexSetBase(const DomainType & domain) : _domain(domain) - , _pattern(&dash::origin(domain).pattern()) + , _pattern(&dash::origin(_domain).pattern()) { } constexpr explicit IndexSetBase(DomainType && domain) - : _domain(std::forward(domain)) - , _pattern(&dash::origin(domain).pattern()) + : _domain(std::move(domain)) + , _pattern(&dash::origin(_domain).pattern()) { } typedef struct { @@ -418,10 +422,10 @@ class IndexSetBase } constexpr auto domain() const - -> decltype(dash::index( - std::declval() - )) { -// -> typename view_traits::index_set_type { +// -> decltype(dash::index( +// std::declval() +// )) { + -> typename view_traits::index_set_type { return dash::index(_domain); } @@ -618,12 +622,14 @@ class IndexSetIdentity self_t & operator=(const self_t &) = default; public: typedef typename DomainType::index_type index_type; + public: constexpr explicit IndexSetIdentity(const DomainType & view) : base_t(view) { } + constexpr explicit IndexSetIdentity(DomainType && view) - : base_t(std::forward(view)) + : base_t(std::move(view)) { } constexpr index_type rel(index_type image_index) const { @@ -735,7 +741,7 @@ class IndexSetSub DomainType && view, index_type begin_idx, index_type end_idx) - : base_t(std::forward(view)) + : base_t(std::move(view)) , _domain_begin_idx(begin_idx) , _domain_end_idx(end_idx) { } @@ -923,7 +929,7 @@ class IndexSetLocal * Constructor, creates index set for given view. */ constexpr explicit IndexSetLocal(DomainType && view) - : base_t(std::forward(view)) + : base_t(std::move(view)) , _size(calc_size()) { } @@ -1150,7 +1156,7 @@ constexpr auto local(IndexSetGlobal && index_set) -> decltype(index_set.local()) { // Note: Not a universal reference, index_set has partially defined type - return index_set.local(); + return std::move(index_set).local(); } template @@ -1209,7 +1215,7 @@ class IndexSetGlobal * Constructor, creates index set for given view. */ constexpr explicit IndexSetGlobal(DomainType && view) - : base_t(std::forward(view)) + : base_t(std::move(view)) { } constexpr auto local() const noexcept @@ -1321,7 +1327,7 @@ class IndexSetBlocks * Constructor, creates index set for given view. */ constexpr explicit IndexSetBlocks(DomainType && view) - : base_t(std::forward(view)) + : base_t(std::move(view)) , _size(calc_size()) { } @@ -1391,7 +1397,7 @@ class IndexSetBlocks } constexpr index_type size() const { - return calc_size(); + return _size; // calc_size(); } private: @@ -1478,6 +1484,14 @@ class IndexSetBlock , _size(calc_size()) { } + constexpr explicit IndexSetBlock( + DomainType && view, + index_type block_idx) + : base_t(std::move(view)) + , _block_idx(block_idx) + , _size(calc_size()) + { } + constexpr iterator begin() const { return iterator(*this, 0); } diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index 9b69a2835..2f8b5cb64 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -26,10 +26,10 @@ origin(ViewT & view); template typename std::enable_if< - dash::view_traits::is_origin::value, - ContainerT & + !dash::view_traits::type>::is_view::value, + ContainerT >::type -origin(ContainerT & container) { +origin(ContainerT && container) { return container; } diff --git a/dash/include/dash/view/Sub.h b/dash/include/dash/view/Sub.h index 8c9960f80..0c042f47c 100644 --- a/dash/include/dash/view/Sub.h +++ b/dash/include/dash/view/Sub.h @@ -13,6 +13,7 @@ namespace dash { // View Modifiers (not coupled with origin memory / index space): // ------------------------------------------------------------------------- +#if 0 /** * Sub-section, view dimensions maintain domain dimensions. * @@ -43,6 +44,7 @@ sub(const IndexRangeT & range) { return sub(dash::begin(range), dash::end(range)); } +#endif #if 0 /** @@ -64,30 +66,6 @@ sub( // View Proxies (coupled with origin memory / index space): // ------------------------------------------------------------------------- -template < - dim_t SubDim = 0, - class DomainT, - class OffsetFirstT, - class OffsetFinalT, - typename DomainValueT = typename std::decay::type > -constexpr -ViewSubMod< - DomainValueT, - SubDim, - dash::view_traits::rank::value > -sub( - OffsetFirstT begin, - OffsetFinalT end, - const DomainT & domain) { - return ViewSubMod< - DomainValueT, - SubDim, - dash::view_traits::rank::value - >(domain, - begin, - end); -} - template < dim_t SubDim = 0, class DomainT, diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 403ee7ed2..c58f3aef8 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -156,7 +156,7 @@ class ViewBlockMod constexpr ViewBlockMod( domain_type && domain, index_type block_idx) - : base_t(std::forward(domain)) + : base_t(std::move(domain)) , _index_set(this->domain(), block_idx) { } @@ -290,7 +290,7 @@ class ViewBlockMod constexpr ViewBlockMod( domain_type && domain, index_type block_idx) - : base_t(std::forward(domain)) + : base_t(std::move(domain)) , _index_set(this->domain(), block_first_gidx(this->domain(), block_idx), block_final_gidx(this->domain(), block_idx)) @@ -396,12 +396,6 @@ class ViewBlockMod // ViewBlocksMod // ------------------------------------------------------------------------ -template -constexpr ViewBlocksMod -blocks(const ViewType & domain) { - return ViewBlocksMod(domain); -} - template < class ViewType, class ViewValueT @@ -514,7 +508,7 @@ class ViewBlocksMod index_type position) : iterator_base_t(position) , _blocks_view_domain( - dash::domain(std::forward(blocks_view))) + dash::domain(std::move(blocks_view))) { } constexpr block_type dereference(index_type idx) const { @@ -555,8 +549,8 @@ class ViewBlocksMod */ constexpr explicit ViewBlocksMod( domain_type && domain) - : base_t(std::forward(domain)) - , _index_set(std::forward(domain)) + : base_t(std::move(domain)) + , _index_set(std::move(domain)) { } // ---- extents --------------------------------------------------------- diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 53ead7f5e..46a07e391 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -620,8 +620,8 @@ class ViewSubMod domain_type && domain, index_type begin, index_type end) - : base_t(std::forward(domain)) - , _index_set(std::forward(domain), begin, end) + : base_t(std::move(domain)) + , _index_set(this->domain(), begin, end) { } constexpr ViewSubMod( diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 581d7a114..586c8ee2a 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -73,19 +73,18 @@ class ViewSubMod self_t & operator=(self_t &&) = default; self_t & operator=(const self_t &) = default; - template constexpr ViewSubMod( - DomainT_ && domain, + DomainType && domain, index_type begin, index_type end) - : base_t(std::forward(domain)) - , _index_set(std::forward(domain), begin, end) + : base_t(std::move(domain)) + , _index_set(this->domain(), begin, end) { } constexpr ViewSubMod( - const domain_type & domain, - index_type begin, - index_type end) + const domain_type & domain, + index_type begin, + index_type end) : base_t(domain) , _index_set(domain, begin, end) { } @@ -214,7 +213,7 @@ class ViewLocalMod */ constexpr explicit ViewLocalMod( domain_type && domain) - : base_t(std::forward(domain)) + : base_t(std::move(domain)) , _index_set(this->domain()) { } @@ -336,7 +335,7 @@ class ViewGlobalMod */ constexpr explicit ViewGlobalMod( domain_type && domain) - : base_t(std::forward(domain)) + : base_t(std::move(domain)) , _index_set(this->domain()) { } diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index cc5cc7d9b..d9c5dff5c 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -172,9 +172,9 @@ namespace detail { template struct view_traits : detail::_view_traits< - ViewableType, - dash::is_view::value, - dash::is_range::value > { + typename std::decay::type, + dash::is_view< typename std::decay::type>::value, + dash::is_range::type>::value > { }; #endif // DOXYGEN From f9ee3b109dc34d410ecc4c82b3ff1355294daed7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 02:01:42 +0200 Subject: [PATCH 032/161] Cleanup ex.02.array-views (local-to-global copy) --- dash/examples/ex.02.array-views/main.cpp | 134 +++-------------------- 1 file changed, 13 insertions(+), 121 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 601348cac..17dbc808e 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -10,10 +10,10 @@ using std::vector; using uint = unsigned int; -#define print(stream_expr) \ +#define print(stream_expr__) \ do { \ std::ostringstream ss; \ - ss << stream_expr; \ + ss << stream_expr__; \ cout << ss.str() << endl; \ } while(0) @@ -88,32 +88,26 @@ int main(int argc, char *argv[]) dash::Array a(array_size, dash::BLOCKCYCLIC(3)); initialize_array(a); - dash::Array a_pre(array_size, dash::BLOCKCYCLIC(3)); - initialize_array(a_pre); - auto copy_num_elem = a.size() / 2; auto copy_dest_begin_idx = a.size() / 4; auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; - print("array: " << range_str(a)); - print("ncopy: " << copy_num_elem - << "(" << copy_dest_begin_idx - << "," << copy_dest_end_idx << "]"); - std::vector buf(copy_num_elem); std::iota(buf.begin(), buf.end(), 0.9999); a.barrier(); if (dash::myid() == 0) { + print("array: " << range_str(a)); + print("copy target index range: " + << "[" << copy_dest_begin_idx + << "," << copy_dest_end_idx << ")"); + auto copy_begin_it = a.begin() + copy_dest_begin_idx; auto copy_end_it_exp = copy_begin_it + copy_num_elem; auto dest_range = dash::make_range(copy_begin_it, copy_end_it_exp); - // auto dest_range = dash::sub(copy_begin_it.pos(), - // copy_end_it_exp.pos(), - // a); auto dest_brange = dash::blocks(dest_range); const auto & dest_range_idx = dash::index(dest_range); @@ -121,10 +115,7 @@ int main(int argc, char *argv[]) const auto & dest_range_pat = dest_range_idx.pattern(); const auto & dest_range_idom = dash::domain( dash::index(dest_range)); - // Works: -// auto dest_brange_idx = dash::index(dest_brange); - // Fails: - auto dest_brange_idx = dash::index(dash::blocks(dest_range)); + const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); const auto & dest_brange_org = dash::origin(dash::blocks(dest_range)); const auto & dest_brange_pat = dest_brange_idx.pattern(); const auto & dest_brange_idom = dash::domain( @@ -139,111 +130,13 @@ int main(int argc, char *argv[]) auto first_bidx = dest_brange_idx.first(); auto last_bidx = dest_brange_idx.last(); - print("make_range is range: " << dash::is_range< - decltype(dest_range) - >::value); - print("blocks(range) is range: " << dash::is_range< - decltype(dest_brange) - >::value); - print("d(blocks(rg)) is range: " << dash::is_range< - decltype(dash::domain(dest_brange)) - >::value); - - print("make_range is view: " << dash::is_view< - decltype(dest_range) - >::value); - print("blocks(range) is view: " << dash::is_view< - decltype(dest_brange) - >::value); - print("d(make_range) is view: " << dash::is_view< - decltype(dash::domain(dest_range)) - >::value); - - print("copy idom range " << "(" << dom_first_gidx - << "," << last_gidx << ")"); - print("copy ridx range " << "(" << first_gidx - << "," << last_gidx << ")"); - print("copy bidx range " << "(" << first_bidx - << "," << last_bidx << ")"); - - print("array &pattern: " << &a.pattern()); - print("begin+1 &pattern: " << &(dash::index( - dash::sub(2, 8, a)).pattern())); - - print("copy rg type: " << dash::typestr(dest_range)); - print("copy b.rg type: " << dash::typestr(dest_brange)); - - print("copy rg domain: " << dash::typestr(dest_range_idom)); - print("copy b.rg domain: " << dash::typestr(dest_brange_idom)); - print("copy rg &domain: " << &(dest_range_idom)); - print("copy b.rg &domain: " << &(dest_brange_idom)); - print("copy rg domain.sz " << dest_range_idom.size()); - print("copy b.rg domain.sz " << dest_brange_idom.size()); - - print("copy rg origin: " << dash::typestr(dest_range_org)); - print("copy b.rg origin: " << dash::typestr(dest_brange_org)); - print("copy rg &origin: " << &(dest_range_org)); - print("copy b.rg &origin: " << &(dest_brange_org)); - print("copy rg &orig.pat " << &(dest_range_org.pattern())); - print("copy b.rg &orig.pat " << &(dest_brange_org.pattern())); - print("copy rg orig.p.sz " << dest_range_org.pattern().size()); - print("copy b.rg orig.p.sz " << dest_brange_org.pattern().size()); - print("copy rg &orig.idx " << &(dash::index(dest_range_org).pattern())); - print("copy b.rg &orig.idx " << &(dash::index(dest_brange_org).pattern())); - - print("copy rg index: " << dash::typestr(dest_range_idx)); - print("copy b.rg index: " << dash::typestr(dest_brange_idx)); - print("copy rg &index: " << &(dest_range_idx)); - print("copy b.rg &index: " << &(dest_brange_idx)); - print("copy rg index.siz " << (dest_range_idx.size())); - print("copy b.rg index.siz " << (dest_brange_idx.size())); - - print("copy rg pattern: " << dash::typestr(dest_range_pat)); - print("copy b.rg pattern: " << dash::typestr(dest_brange_pat)); - print("copy rg &pattern: " << &dest_range_pat); - print("copy b.rg &pattern: " << &dest_brange_pat); - print("copy rg pat.size: " << dest_range_pat.size()); - print("copy b.rg pat.size: " << dest_brange_pat.size()); - - print("dest first block: " << dest_range_pat.block_at( - dest_range_pat.coords( - first_gidx) - )); - print("dest last block: " << dest_range_pat.block_at( - dest_range_pat.coords( - last_gidx) - )); - - print("dest b.rg block0: " << dest_brange_pat.block_at( - dest_brange_pat.coords( - first_gidx) - )); - print("dest b.rg blockN: " << dest_brange_pat.block_at( - dest_brange_pat.coords( - last_gidx) - )); - - print("copy range local: " << std::decay::type::view_domain_is_local); - print("copy range local: " << dash::view_traits< - decltype(dest_range) - >::is_local::value); - print("copy index domain: " << dash::index(dest_range)); - print("copy block dom.idx: " << dash::domain( - dash::index(dash::blocks(dest_range)) - )); - print("copy block indices: " << dash::index(dest_brange)); - print("copy num blocks: " << dest_brange.size()); - print("copy begin: " << dash::begin(dest_range)); - print("copy end: " << dash::end(dest_range)); + print("target index set: " << dash::index(dest_range)); + print("target block set: " << dash::index(dest_brange)); + print("copy target range: " << range_str(dest_range)); -// print("copy range begin: " << dash::begin(dest_range)); -// print("copy range: " << range_str(dest_range)); -#if 1 - auto dest_blocks = dash::blocks(dest_range); + auto dest_blocks = dash::blocks(dest_range); for (const auto & block : dest_blocks) { - print("copy to block:" << range_str(block)); + print("copy to block: " << range_str(block)); } // copy local buffer to global array @@ -251,7 +144,6 @@ int main(int argc, char *argv[]) buf.data(), buf.data() + copy_num_elem, copy_begin_it); -#endif } a.barrier(); From 6ae01cf06d20239bc997966705b51e2841ba5c20 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 02:09:32 +0200 Subject: [PATCH 033/161] Cleanup in ex.02.array-views --- dash/examples/ex.02.array-views/main.cpp | 63 +++++------------------- dash/include/dash/view/IndexSet.h | 1 - 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 17dbc808e..ee8e5718f 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -7,8 +7,6 @@ using std::cin; using std::endl; using std::vector; -using uint = unsigned int; - #define print(stream_expr__) \ do { \ @@ -18,23 +16,6 @@ using uint = unsigned int; } while(0) -inline void sum(const uint nelts, - const dash::NArray &matIn, - const uint myid) { - uint lclRows = matIn.pattern().local_extents()[0]; - - uint const *mPtr; - uint localSum = 0; - - for (uint i = 0; i < lclRows; ++i) { - mPtr = matIn.local.row(i).lbegin(); - - for (uint j = 0; j < nelts; ++j) { - localSum += *(mPtr++); - } - } -} - template static std::string range_str( const ValueRange & vrange) { @@ -65,9 +46,9 @@ auto initialize_array(ArrayT & array) array.local[li] = // unit (1.0000 * dash::myid().id) + // local offset - (0.0001 * (li+1)) + + (0.0100 * (li+1)) + // global offset - (0.0100 * gi); + (0.0001 * gi); } array.barrier(); } @@ -80,10 +61,6 @@ int main(int argc, char *argv[]) int elem_additional = 2; int array_size = dash::size() * elem_per_unit + std::min(elem_additional, dash::size()); - int num_local_elem = elem_per_unit + - ( dash::myid() < elem_additional - ? 1 - : 0 ); dash::Array a(array_size, dash::BLOCKCYCLIC(3)); initialize_array(a); @@ -103,38 +80,19 @@ int main(int argc, char *argv[]) << "[" << copy_dest_begin_idx << "," << copy_dest_end_idx << ")"); - auto copy_begin_it = a.begin() + copy_dest_begin_idx; - auto copy_end_it_exp = copy_begin_it + copy_num_elem; - - auto dest_range = dash::make_range(copy_begin_it, - copy_end_it_exp); - auto dest_brange = dash::blocks(dest_range); - - const auto & dest_range_idx = dash::index(dest_range); - const auto & dest_range_org = dash::origin(dest_range); - const auto & dest_range_pat = dest_range_idx.pattern(); - const auto & dest_range_idom = dash::domain( - dash::index(dest_range)); - const auto & dest_brange_idx = dash::index(dash::blocks(dest_range)); - const auto & dest_brange_org = dash::origin(dash::blocks(dest_range)); - const auto & dest_brange_pat = dest_brange_idx.pattern(); - const auto & dest_brange_idom = dash::domain( - dash::index(dash::blocks(dest_range))); + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_end_it_exp = copy_begin_it + copy_num_elem; - auto dom_first_gidx = dest_range_idom.first(); - auto dom_last_gidx = dest_range_idom.last(); - - auto first_gidx = dest_range_idx.first(); - auto last_gidx = dest_range_idx.last(); - - auto first_bidx = dest_brange_idx.first(); - auto last_bidx = dest_brange_idx.last(); + auto dest_range = dash::make_range(copy_begin_it, + copy_end_it_exp); + auto dest_blocks = dash::blocks(dest_range); + // Printing temporaries from view expressions instead of + // named values for testing: print("target index set: " << dash::index(dest_range)); - print("target block set: " << dash::index(dest_brange)); + print("target block set: " << dash::index(dash::blocks(dest_range))); print("copy target range: " << range_str(dest_range)); - auto dest_blocks = dash::blocks(dest_range); for (const auto & block : dest_blocks) { print("copy to block: " << range_str(block)); } @@ -151,3 +109,4 @@ int main(int argc, char *argv[]) dash::finalize(); } + diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index e24f5701b..61b00ba1c 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -283,7 +283,6 @@ global( namespace detail { -// !!! HERE !!! template struct index_set_domain_bind_t { typedef typename From e1f7a72d2344cb7cecd9b5438055d61a77be9db2 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 02:13:56 +0200 Subject: [PATCH 034/161] Update LocalPattern.h --- dash/include/dash/pattern/internal/LocalPattern.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/include/dash/pattern/internal/LocalPattern.h b/dash/include/dash/pattern/internal/LocalPattern.h index 4b99d12ca..4d91a0eff 100644 --- a/dash/include/dash/pattern/internal/LocalPattern.h +++ b/dash/include/dash/pattern/internal/LocalPattern.h @@ -52,7 +52,7 @@ class LocalPattern<1, Arrangement, IndexType> { > layout_properties; }; -} // namespace dash } // namespace internal +} // namespace dash #endif // DASH__PATTERN__INTERNAL__LOCAL_PATTERN_H__INCLUDED From c1a92192d3c39044da6917c5ac9ca2f8c7c52a65 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 06:18:35 +0200 Subject: [PATCH 035/161] Added multidimensional block phase views --- dash/include/dash/Range.h | 8 -- dash/include/dash/View.h | 1 - dash/include/dash/algorithm/Copy.h | 3 - dash/include/dash/pattern/PatternProperties.h | 18 +-- dash/include/dash/pattern/SeqTilePattern.h | 4 +- dash/include/dash/view/IndexSet.h | 117 ++++++++++++------ dash/include/dash/view/ViewBlocksMod.h | 45 ++++++- dash/test/view/NViewTest.cc | 57 ++++++--- 8 files changed, 171 insertions(+), 82 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 3c102707b..555405583 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -288,7 +288,6 @@ class RangeBase { typedef Iterator iterator; typedef Sentinel sentinel; typedef dash::default_index_t index_type; -//typedef internal::LocalPattern pattern_type; protected: constexpr RangeBase() = default; @@ -326,8 +325,6 @@ struct view_traits > { typedef typename RangeT::index_type index_type; typedef typename RangeT::size_type size_type; -//typedef dash::IndexSetSub index_set_type; -//typedef typename RangeT::index_set_type index_set_type; typedef dash::IndexSetIdentity index_set_type; /// Whether the view type is a projection (has less dimensions than the @@ -370,8 +367,6 @@ class IteratorRange typedef Sentinel sentinel; typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; -//typedef dash::IndexSetSub index_set_type; -//typedef dash::IndexSetIdentity index_set_type; typedef std::integral_constant rank; typedef typename iterator::value_type value_type; @@ -454,7 +449,6 @@ struct view_traits > { public: typedef RangeT domain_type; typedef RangeT origin_type; -//typedef typename RangeT::pattern_type pattern_type; typedef RangeT image_type; typedef RangeT global_type; typedef RangeT local_type; @@ -504,7 +498,6 @@ class IteratorRange typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; -//typedef typename internal::LocalPattern pattern_type; typedef LocalIterator value_type; @@ -513,7 +506,6 @@ class IteratorRange typedef IteratorRange local_type; typedef self_t global_type; -//typedef self_t domain_type; typedef std::integral_constant is_local; diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index caa62b0ff..9de131490 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -171,7 +171,6 @@ class IteratorViewOrigin public: constexpr IteratorViewOrigin(Iterator begin, Iterator end) -//: base_t(std::move(begin), std::move(end)) { : base_t(begin, end) , _index_set(*this) { } diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 69fc4c04b..3fe9b5d50 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1097,9 +1097,6 @@ GlobOutputIt copy( auto out_range = dash::make_range(out_first, out_h_last); -// DASH_LOG_TRACE("dash::copy", "out value range:", out_range); -// DASH_LOG_TRACE("dash::copy", "out index range:", dash::index(out_range)); - auto out_blocks = dash::blocks(out_range); auto in_copy_it = in_first; diff --git a/dash/include/dash/pattern/PatternProperties.h b/dash/include/dash/pattern/PatternProperties.h index 44e704e42..65d64b881 100644 --- a/dash/include/dash/pattern/PatternProperties.h +++ b/dash/include/dash/pattern/PatternProperties.h @@ -776,26 +776,30 @@ struct pattern_layout_traits template struct pattern_traits { - typedef typename PatternType::index_type + typedef typename std::decay::type pattern_type; + + typedef typename pattern_type::index_type index_type; - typedef typename PatternType::size_type + typedef typename pattern_type::size_type size_type; - typedef typename dash::pattern_partitioning_traits::type + typedef typename dash::pattern_partitioning_traits::type partitioning; - typedef typename dash::pattern_mapping_traits::type + typedef typename dash::pattern_mapping_traits::type mapping; - typedef typename dash::pattern_layout_traits::type + typedef typename dash::pattern_layout_traits::type layout; typedef typename std::decay< - decltype(std::declval().blockspec()) + decltype(std::declval().blockspec()) >::type blockspec_type; typedef typename std::decay< - decltype(std::declval().local_blockspec()) + decltype(std::declval().local_blockspec()) >::type local_blockspec_type; + + typedef std::integral_constant ndim; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/dash/include/dash/pattern/SeqTilePattern.h b/dash/include/dash/pattern/SeqTilePattern.h index c111d2564..d6246ef8f 100644 --- a/dash/include/dash/pattern/SeqTilePattern.h +++ b/dash/include/dash/pattern/SeqTilePattern.h @@ -937,8 +937,8 @@ class SeqTilePattern } /** - * Global coordinates to global position in the pattern's block-wise iteration - * order. + * Global coordinates to global position in the pattern's block-wise + * iteration order. * * NOTE: * Expects extent[d] to be a multiple of blocksize[d] * nunits[d] diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 61b00ba1c..37191e533 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1274,8 +1274,16 @@ class IndexSetBlocks >::blockspec_type::ndim::value > { + typedef + typename dash::pattern_traits< + typename dash::view_traits< + typename std::decay::type + >::pattern_type + >::blockspec_type::ndim + blocks_ndim; + typedef IndexSetBlocks self_t; - typedef IndexSetBase base_t; + typedef IndexSetBase base_t; public: typedef typename base_t::index_type index_type; typedef typename base_t::size_type size_type; @@ -1300,7 +1308,7 @@ class IndexSetBlocks // Rank of blocks index set should depend on blockspec dimensions of // the domain's pattern type. - static constexpr std::size_t NBlocksDim = base_t::rank::value; + static constexpr std::size_t NBlocksDim = blocks_ndim::value; public: constexpr static bool view_domain_is_local @@ -1442,12 +1450,28 @@ template class IndexSetBlock : public IndexSetBase< IndexSetBlock, - DomainType > + DomainType, + // Number of dimensions in the domain pattern's block spec: + dash::pattern_traits< + typename dash::view_traits< + typename std::decay::type + >::pattern_type + >::ndim::value + > { + typedef + typename dash::pattern_traits< + typename dash::view_traits< + typename std::decay::type + >::pattern_type + >::ndim + pattern_ndim; + typedef IndexSetBlock self_t; - typedef IndexSetBase base_t; + typedef IndexSetBase base_t; public: typedef typename DomainType::index_type index_type; + typedef typename DomainType::size_type size_type; typedef self_t local_type; typedef IndexSetGlobal global_type; @@ -1463,7 +1487,7 @@ class IndexSetBlock index_type _block_idx; index_type _size; - constexpr static dim_t NDim = 1; + constexpr static dim_t NBlockDim = pattern_ndim::value; constexpr static bool view_domain_is_local = dash::view_traits::is_local::value; public: @@ -1480,7 +1504,7 @@ class IndexSetBlock index_type block_idx) : base_t(view) , _block_idx(block_idx) - , _size(calc_size()) + , _size(calc_size(block_idx)) { } constexpr explicit IndexSetBlock( @@ -1488,9 +1512,31 @@ class IndexSetBlock index_type block_idx) : base_t(std::move(view)) , _block_idx(block_idx) - , _size(calc_size()) + , _size(calc_size(block_idx)) { } + // ---- extents --------------------------------------------------------- + + constexpr std::array + extents() const { + return ( this->is_local() + ? this->pattern().local_block(_block_idx).extents() + : this->pattern().block(_block_idx).extents() + ); + } + + // ---- offsets --------------------------------------------------------- + + constexpr std::array + offsets() const { + return ( this->is_local() + ? this->pattern().local_block(_block_idx).offsets() + : this->pattern().block(_block_idx).offsets() + ); + } + + // ---- access ---------------------------------------------------------- + constexpr iterator begin() const { return iterator(*this, 0); } @@ -1500,20 +1546,22 @@ class IndexSetBlock } constexpr index_type rel(index_type block_phase) const { - return block_phase + - ( view_domain_is_local - ? ( // index of block at last index in domain - this->pattern().local_block_at( - this->pattern().coords( - // local offset to global offset: - this->pattern().global( - *(this->domain().begin()) - ) - ) - ).index ) - : ( // index of block at first index in domain - this->pattern().block_at( - {{ *(this->domain().begin()) }} + return ( view_domain_is_local + ? ( // translate block phase to local index: + this->pattern().local_at( + // global coords + this->pattern().coords(block_phase), + // viewspec + this->pattern().local_block(_block_idx) + ) ) + : ( // translate block phase to global index: + this->pattern().global_at( + // global coords + dash::CartesianIndexSpace( + this->pattern().block(_block_idx).extents() + ).coords(block_phase), + // viewspec + this->pattern().block(_block_idx) ) ) ); } @@ -1533,31 +1581,20 @@ class IndexSetBlock } private: - constexpr index_type calc_size() const { + constexpr index_type calc_size(index_type block_idx) const { return ( view_domain_is_local - ? ( // index of block at last index in domain - this->pattern().local_block_at( - {{ *( this->domain().begin() - + (this->domain().size() - 1) ) }} - ).index - - // index of block at first index in domain - this->pattern().local_block_at( - {{ *( this->domain().begin() ) }} - ).index + 1 ) - : ( // index of block at last index in domain - this->pattern().block_at( - {{ *( this->domain().begin() - + (this->domain().size() - 1) ) }} - ) - - // index of block at first index in domain - this->pattern().block_at( - {{ *(this->domain().begin()) }} - ) + 1 ) + ? ( // viewspec of local block referenced by this view: + this->pattern().local_block(block_idx).size() + ) + : ( // viewspec of block referenced by this view: + this->pattern().block(block_idx).size() + ) ); } }; // class IndexSetBlock } // namespace dash + #endif // DOXYGEN #endif // DASH__VIEW__INDEX_SET_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index c58f3aef8..e30e91164 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -90,6 +90,7 @@ class ViewBlockMod public: typedef DomainType domain_type; typedef typename view_traits::index_type index_type; + typedef typename view_traits::size_type size_type; typedef typename base_t::origin_type origin_type; public: typedef dash::IndexSetBlock index_set_type; @@ -161,6 +162,42 @@ class ViewBlockMod block_idx) { } + // ---- extents --------------------------------------------------------- + + constexpr std::array extents() const { + return _index_set.extents(); + } + + template + constexpr size_type extent() const { + return _index_set.template extent(); + } + + constexpr size_type extent(dim_t shape_dim) const { + return _index_set.extent(shape_dim); + } + + // ---- offsets --------------------------------------------------------- + + template + constexpr index_type offset() const { + return _index_set.template offset(); + } + + constexpr std::array offsets() const { + return _index_set.offsets(); + } + + constexpr index_type offset(dim_t shape_dim) const { + return _index_set.offset(shape_dim); + } + + // ---- size ------------------------------------------------------------ + + constexpr size_type size() const { + return index_set().size(); + } + constexpr const_iterator begin() const { return const_iterator(dash::origin(*this).begin(), _index_set, 0); @@ -550,7 +587,7 @@ class ViewBlocksMod constexpr explicit ViewBlocksMod( domain_type && domain) : base_t(std::move(domain)) - , _index_set(std::move(domain)) + , _index_set(this->domain()) { } // ---- extents --------------------------------------------------------- @@ -607,10 +644,10 @@ class ViewBlocksMod return iterator(*this, _index_set.last() + 1); } - constexpr const_reference operator[](int offset) const { - return *const_iterator(*this, _index_set[offset]); + constexpr block_type operator[](int offset) const { + return *iterator(*this, _index_set[offset]); } - reference operator[](int offset) { + block_type operator[](int offset) { return *iterator(*this, _index_set[offset]); } diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 527bfe1e3..2161b4dc4 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -47,7 +47,9 @@ namespace test { std::ostringstream row_ss; for (int c = 0; c < view_ncols; ++c) { int offset = r * view_ncols + c; - row_ss << std::fixed << std::setw(2) + row_ss << std::fixed << std::setw(3) + << offset << ":" + << std::fixed << std::setw(2) << nindex[offset] << ":" << std::fixed << std::setprecision(3) @@ -258,14 +260,15 @@ TEST_F(NViewTest, MatrixBlocked1DimSingle) dash::test::print_nview("nview_rows_g", nview_rows_g); auto exp_nview_rows_g = dash::test::region_values( - mat, {{ 1,0 }, { 2,mat.extent(1) }} ); + mat, {{ 1,0 }, { 2,mat.extent(1) }} + ); - EXPECT_TRUE_U( + EXPECT_TRUE( dash::test::expect_range_values_equal( exp_nview_rows_g, nview_rows_g)); - EXPECT_EQ_U(2, nview_rows_g.extent<0>()); - EXPECT_EQ_U(mat.extent(1), nview_rows_g.extent<1>()); + EXPECT_EQ(2, nview_rows_g.extent<0>()); + EXPECT_EQ(mat.extent(1), nview_rows_g.extent<1>()); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimSingle", "sub<1>(2,7, mat) ->", @@ -835,7 +838,7 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) 1); team_spec.balance_extents(); - auto pattern = dash::SeqTilePattern<2>( + auto pattern = dash::TilePattern<2>( dash::SizeSpec<2>( nrows, ncols), @@ -929,18 +932,31 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", nview_blocks.extents()); - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", - nview_blocks[0].size()); - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", - nview_blocks[0].offsets()); - DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlockCyclic2DSub", - nview_blocks[0].extents()); - int bi = 0; for (const auto & block : nview_blocks) { - DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSingle", - "block", bi, ":", "extents:", block.extents(), - range_str(block)); + DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", + "block", bi, ":", + "offsets:", block.offsets(), + "extents:", block.extents()); + + dash::test::print_nview(" block row", block); + + const auto & block_idx = dash::index(block); + const auto & pat_block = mat.pattern().block(bi); + + for (int bphase = 0; bphase < pat_block.size(); ++bphase) { + int bphase_row = bphase / pat_block.extents()[1]; + int bphase_col = bphase % pat_block.extents()[1]; + auto pat_g_index = mat.pattern().global_at({ + bphase_row + pat_block.offsets()[0], + bphase_col + pat_block.offsets()[1] + }); + EXPECT_EQ(pat_g_index, block_idx[bphase]); + } + + EXPECT_EQ(pat_block.size(), block.size()); + EXPECT_EQ(pat_block.offsets(), block.offsets()); + EXPECT_EQ(pat_block.extents(), block.extents()); bi++; } } @@ -951,8 +967,14 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) 0, mat.extents()[0], mat)); + typedef typename dash::pattern_traits::mapping + pat_mapping_traits; + bool pat_traits_shifted = pat_mapping_traits::shifted || + pat_mapping_traits::diagonal; + + EXPECT_EQ_U(pat_traits_shifted, index(mat_local).is_shifted()); + EXPECT_TRUE_U(index(mat_local).is_strided()); - EXPECT_TRUE_U(index(mat_local).is_shifted()); EXPECT_TRUE_U(index(mat_local).is_sub()); EXPECT_FALSE_U(index(dash::domain(mat_local)).is_sub()); @@ -965,3 +987,4 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) dash::test::print_nview("mat_local", mat_local); } + From c170d7c396853ab437efc2b5c2115a65434412c5 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 06:36:56 +0200 Subject: [PATCH 036/161] Minor fix in NView test --- dash/examples/ex.02.array-views/main.cpp | 2 +- dash/test/view/NViewTest.cc | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index ee8e5718f..349974474 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { dash::init(&argc, &argv); - int elem_per_unit = 7; + int elem_per_unit = 5; int elem_additional = 2; int array_size = dash::size() * elem_per_unit + std::min(elem_additional, dash::size()); diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 2161b4dc4..e82aa95c5 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -962,6 +962,9 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) } mat.barrier(); + // TODO: multi-dimensional strided local views not supported yet, + // for example when using dash::SeqTilePattern in this test. + auto mat_local = dash::local( dash::sub<0>( 0, mat.extents()[0], @@ -974,8 +977,8 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) EXPECT_EQ_U(pat_traits_shifted, index(mat_local).is_shifted()); - EXPECT_TRUE_U(index(mat_local).is_strided()); - EXPECT_TRUE_U(index(mat_local).is_sub()); + EXPECT_TRUE_U(index(mat_local).is_strided() || dash::size() < 2); + EXPECT_TRUE_U(index(mat_local).is_sub() || dash::size() < 2); EXPECT_FALSE_U(index(dash::domain(mat_local)).is_sub()); EXPECT_EQ_U(mat.pattern().local_size(), mat_local.size()); From 63da3cd64ed5a014c7f36b9a7364f688e35e5e6d Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 22:26:47 +0200 Subject: [PATCH 037/161] Defining iterator ranges as model of View concept --- dash/examples/ex.05.transform/Makefile | 1 + dash/examples/ex.05.transform/main.cpp | 62 ++++ dash/include/dash/Range.h | 324 ------------------- dash/include/dash/View.h | 96 +----- dash/include/dash/algorithm/Copy.h | 170 +++++----- dash/include/dash/algorithm/Transform.h | 4 +- dash/include/dash/view/MakeRange.h | 407 +++++++++++++++++++----- doc/config/Doxyfile.codedocs | 3 +- doc/config/Doxyfile.in | 3 +- 9 files changed, 477 insertions(+), 593 deletions(-) create mode 100644 dash/examples/ex.05.transform/Makefile create mode 100644 dash/examples/ex.05.transform/main.cpp diff --git a/dash/examples/ex.05.transform/Makefile b/dash/examples/ex.05.transform/Makefile new file mode 100644 index 000000000..f3c00dab1 --- /dev/null +++ b/dash/examples/ex.05.transform/Makefile @@ -0,0 +1 @@ +include ../Makefile_cpp \ No newline at end of file diff --git a/dash/examples/ex.05.transform/main.cpp b/dash/examples/ex.05.transform/main.cpp new file mode 100644 index 000000000..9f930fa18 --- /dev/null +++ b/dash/examples/ex.05.transform/main.cpp @@ -0,0 +1,62 @@ +#include + +#include +#include + +using std::cout; +using std::cerr; +using std::endl; +using std::setw; +using std::setprecision; + +// ========================================================================== +// Type definitions +// ========================================================================== + +typedef double + ElementType; +typedef dash::default_index_t + IndexType; + +typedef dash::LoadBalancePattern<1> + PatternType; + +typedef dash::Array + ArrayType; + + +int main(int argc, char **argv) +{ + static const int NELEM = 100; + + dash::init(&argc, &argv); + + dash::util::TeamLocality tloc(dash::Team::All()); + PatternType pattern( + dash::SizeSpec<1>(NELEM), + tloc); + + ArrayType arr_a(pattern); + ArrayType arr_b(pattern); + ArrayType arr_c(pattern); + + for (size_t li = 0; li < arr_a.lsize(); li++) { + arr_a.local[li] = 1 + ((42 * (li + 1)) % 1024); + arr_b.local[li] = 1 + ((42 * (li + 1)) % 1024); + } + + dash::barrier(); + + auto min_git = dash::transform(arr_a.begin(), arr_a.end(), + arr_b.begin(), + arr_c.begin(), + dash::plus()); + + DASH_LOG_DEBUG("perform_test", "Waiting for completion of all units"); + dash::barrier(); + + dash::finalize(); + + return 0; +} + diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 555405583..ee0be5dfe 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -83,7 +83,6 @@ class IteratorRange; #endif - /** * \concept{DashRangeConcept} */ @@ -124,39 +123,6 @@ struct _is_range_type typedef typename std::decay::type ValueT; -#ifdef __TODO__ -private: - // Test if dash::begin(x) is valid expression: - template static yes has_dash_begin( - decltype( - dash::begin( - std::move(std::declval()) - ) - ) * ); - template static no has_dash_begin(...); - - // Test if dash::end(x) is valid expression: - template static yes has_dash_end( - decltype( - dash::end( - std::move(std::declval()) - ) - ) * ); - template static no has_dash_end(...); - -public: - enum { value = ( - sizeof(has_dash_begin(static_cast(nullptr))) == sizeof(yes) - && sizeof(has_dash_end(static_cast(nullptr))) == sizeof(yes) - ) }; - - //template()) - // )) > - //static yes has_dash_begin(C *); -#endif // Test if x.begin() is valid expression and type x::iterator is // defined: template @@ -244,296 +210,6 @@ struct is_range : dash::detail::_is_range_type< > { }; -template < - typename RangeType, - typename Iterator, - typename Sentinel, - bool IsPatternIterator > -class RangeBase; - -template < - typename RangeType, - typename Iterator, - typename Sentinel > -class RangeBase { - typedef RangeBase self_t; -public: - typedef Iterator iterator; - typedef Sentinel sentinel; - typedef dash::default_index_t index_type; - typedef typename Iterator::pattern_type pattern_type; - -protected: - constexpr RangeBase() = default; - constexpr RangeBase(const self_t & other) = default; - constexpr RangeBase(self_t && other) = default; - self_t & operator=(const self_t & other) = default; - self_t & operator=(self_t && other) = default; - - RangeType & derived() { - return static_cast(*this); - } - const RangeType & derived() const { - return static_cast(*this); - } -}; - -template < - typename RangeType, - typename Iterator, - typename Sentinel > -class RangeBase { - typedef RangeBase self_t; -public: - typedef Iterator iterator; - typedef Sentinel sentinel; - typedef dash::default_index_t index_type; - -protected: - constexpr RangeBase() = default; - constexpr RangeBase(const self_t & other) = default; - constexpr RangeBase(self_t && other) = default; - self_t & operator=(const self_t & other) = default; - self_t & operator=(self_t && other) = default; - - RangeType & derived() { - return static_cast(*this); - } - const RangeType & derived() const { - return static_cast(*this); - } -}; - - - -/** - * Specialization of \c dash::view_traits for IteratorRange. - */ -template < - typename IteratorT, - typename SentinelT > -struct view_traits > { -private: - typedef IteratorRange RangeT; -public: - typedef RangeT domain_type; - typedef RangeT origin_type; - typedef typename IteratorT::pattern_type pattern_type; - typedef RangeT image_type; - typedef RangeT global_type; - typedef typename RangeT::local_type local_type; - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; - - typedef dash::IndexSetIdentity index_set_type; - - /// Whether the view type is a projection (has less dimensions than the - /// view's domain type). - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; - /// Whether the range is local view. - typedef std::integral_constant< - bool, std::is_pointer::value> is_local; - - typedef std::integral_constant rank; -}; - -/** - * Adapter template for range concept, wraps `begin` and `end` iterators - * in range type. - */ -template < - typename Iterator, - typename Sentinel > -class IteratorRange -: public RangeBase< IteratorRange, - Iterator, - Sentinel, - dash::has_type_pattern_type::value > -{ - typedef IteratorRange - self_t; - typedef RangeBase< - self_t, - Iterator, - Sentinel, - dash::has_type_pattern_type::value > - base_t; - -public: - typedef Iterator iterator; - typedef Sentinel sentinel; - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; - typedef std::integral_constant rank; - - typedef typename iterator::value_type value_type; - typedef typename iterator::pattern_type pattern_type; - - typedef typename - std::conditional< - std::is_pointer::value, - iterator, - typename iterator::local_type - >::type - local_iterator; - - typedef typename - std::conditional< - std::is_pointer::value, - sentinel, - typename sentinel::local_type - >::type - local_sentinel; - - typedef self_t global_type; - typedef IteratorRange local_type; - -private: - Iterator _begin; - Sentinel _end; - -public: - template - constexpr explicit IteratorRange(Container && c) - : _begin(std::forward(c).begin()) - , _end(std::forward(c).end()) - { } - - constexpr IteratorRange(const iterator & begin, const sentinel & end) - : _begin(begin) - , _end(end) - { } - - constexpr IteratorRange(iterator && begin, sentinel && end) - : _begin(std::move(begin)) - , _end(std::move(end)) - { } - - constexpr IteratorRange() = delete; - constexpr IteratorRange(const self_t & other) = default; - constexpr IteratorRange(self_t && other) = default; - self_t & operator=(const self_t & other) = default; - self_t & operator=(self_t && other) = default; - - constexpr iterator begin() const { return _begin; } - constexpr sentinel end() const { return _end; } - - iterator begin() { return _begin; } - sentinel end() { return _end; } - - constexpr size_type size() const { - return std::distance(_begin, _end); - } - - constexpr const local_type local() const { - return local_type( - _begin.local(), - _end.local() - ); - } - - constexpr const pattern_type & pattern() const { - return _begin.pattern(); // *_pattern; - } -}; - -template < - typename IteratorT, - typename SentinelT > -struct view_traits > { -private: - typedef IteratorRange RangeT; -public: - typedef RangeT domain_type; - typedef RangeT origin_type; - typedef RangeT image_type; - typedef RangeT global_type; - typedef RangeT local_type; - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; - typedef dash::IndexSetIdentity index_set_type; - - /// Whether the view type is a projection (has less dimensions than the - /// view's domain type). - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; - /// Whether the view / container type is a local view. - /// \note A container type is local if it is identical to its - /// \c local_type - typedef std::integral_constant is_local; - - typedef std::integral_constant rank; -}; - -/** - * Specialization of adapter template for range concept, wraps `begin` - * and `end` pointers in range type. - */ -template < - typename LocalIterator, - typename LocalSentinel > -class IteratorRange -: public RangeBase< - IteratorRange, - LocalIterator *, - LocalSentinel *, - false // iterator does not specify pattern - > -{ - typedef IteratorRange self_t; - - LocalIterator * _begin; - LocalSentinel * _end; - -public: - typedef LocalIterator * iterator; - typedef LocalSentinel * sentinel; - typedef const LocalIterator * const_iterator; - typedef const LocalSentinel * const_sentinel; - - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; - - typedef LocalIterator value_type; - - typedef iterator local_iterator; - typedef sentinel local_sentinel; - - typedef IteratorRange local_type; - typedef self_t global_type; - - typedef std::integral_constant is_local; - -public: -// template -// constexpr explicit IteratorRange(Container && c) -// : _begin(c.begin()) -// , _end(c.end()) -// { } - - constexpr IteratorRange(iterator begin, sentinel end) - : _begin(begin) - , _end(end) - { } - - constexpr const_iterator begin() const { return _begin; } - constexpr const_sentinel end() const { return _end; } - - iterator begin() { return _begin; } - sentinel end() { return _end; } - - constexpr size_type size() const { return std::distance(_begin, _end); } - - constexpr const local_type & local() const { - return *this; - } -}; - } // namespace dash #endif // DASH__RANGES_H__INCLUDED diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index 9de131490..106fed172 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -97,99 +97,13 @@ #include #include -#include +//#include namespace dash { -template < - class Iterator, - class Sentinel > -class IteratorViewOrigin; - -template < - class Iterator, - class Sentinel > -struct view_traits > { - typedef IteratorRange domain_type; - typedef IteratorRange origin_type; - typedef IteratorViewOrigin image_type; - - // Uses container::local_type directly, e.g. dash::LocalArrayRef: - typedef typename dash::view_traits::local_type local_type; - typedef typename dash::view_traits::global_type global_type; - // Uses ViewLocalMod wrapper on domain, e.g. ViewLocalMod: -//typedef ViewLocalMod local_type; -//typedef ViewGlobalMod global_type; - - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; - - typedef typename Iterator::pattern_type pattern_type; - - typedef dash::IndexSetIdentity< - IteratorViewOrigin > index_set_type; - - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; - - typedef std::integral_constant rank; -}; - -template < - class Iterator, - class Sentinel -> -class IteratorViewOrigin -: public dash::IteratorRange -{ -public: - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; -private: - typedef IteratorViewOrigin self_t; - typedef IteratorRange base_t; -public: - typedef self_t domain_type; - typedef self_t origin_type; - typedef self_t image_type; - // Alternative: IteratorLocalView - typedef typename view_traits::local_type local_type; - typedef typename view_traits::global_type global_type; - - typedef typename Iterator::pattern_type pattern_type; - - typedef dash::IndexSetIdentity< - IteratorRange > index_set_type; - - typedef std::integral_constant rank; - -private: - index_set_type _index_set; - -public: - constexpr IteratorViewOrigin(Iterator begin, Iterator end) - : base_t(begin, end) - , _index_set(*this) - { } - - constexpr const pattern_type & pattern() const { - return this->begin().pattern(); - } - - constexpr local_type local() const { - // for local_type: IteratorLocalView - // return local_type(this->begin(), this->end()); - return local_type(*this); - } - - constexpr const index_set_type & index_set() const { - return _index_set; - } -}; +#if 0 template constexpr dash::IteratorViewOrigin @@ -207,10 +121,12 @@ make_view(Iterator && begin, Sentinel && end) { return dash::IteratorViewOrigin< typename std::decay::type, typename std::decay::type - >(std::forward(begin), - std::forward(end)); + >(std::move(begin), + std::move(end)); } +#endif + } // namespace dash diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 847737a61..907822ddd 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -61,9 +61,9 @@ template < class InputIt, class OutputIt > OutputIt copy( - InputIt in_first, - InputIt in_last, - OutputIt out_first); + const InputIt in_first, + const InputIt in_last, + OutputIt out_first); /** * Asynchronous variant of \c dash::copy. @@ -100,9 +100,9 @@ template < typename ValueType, class GlobInputIt > dash::Future copy_async( - InputIt in_first, - InputIt in_last, - OutputIt out_first); + const InputIt in_first, + const InputIt in_last, + OutputIt out_first); #else // DOXYGEN @@ -117,12 +117,12 @@ namespace internal { * optimization for local subrange. */ template < - typename ValueType, + class ValueType, class GlobInputIt > ValueType * copy_block( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { DASH_LOG_TRACE("dash::copy_block()", "in_first:", in_first.pos(), @@ -262,12 +262,12 @@ ValueType * copy_block( * optimization for local subrange. */ template < - typename ValueType, + class ValueType, class GlobInputIt > dash::Future copy_block_async( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { DASH_LOG_TRACE("dash::copy_block_async()", "in_first:", in_first.pos(), @@ -455,12 +455,12 @@ dash::Future copy_block_async( * optimization for local subrange. */ template < - typename ValueType, + class ValueType, class GlobOutputIt > GlobOutputIt copy_block( - ValueType * in_first, - ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy_block()", "l_in_first:", in_first, @@ -491,12 +491,12 @@ GlobOutputIt copy_block( * optimization for local subrange. */ template < - typename ValueType, - class GlobOutputIt > + class ValueType, + class GlobOutputIt > dash::Future copy_block_async( - ValueType * in_first, - ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy_block_async()", "l_in_first:", in_first, @@ -578,12 +578,12 @@ dash::Future copy_block_async( * \ingroup DashAlgorithms */ template < - typename ValueType, - class GlobInputIt > + class ValueType, + class GlobInputIt > dash::Future copy_async( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { const auto & team = in_first.team(); dash::util::UnitLocality uloc(team, team.myid()); @@ -790,12 +790,12 @@ dash::Future copy_async( * \ingroup DashAlgorithms */ template < - typename ValueType, - class GlobInputIt > + class ValueType, + class GlobInputIt > ValueType * copy( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { const auto & team = in_first.team(); dash::util::UnitLocality uloc(team, team.myid()); @@ -982,12 +982,12 @@ ValueType * copy( * \ingroup DashAlgorithms */ template < - typename ValueType, + class ValueType, class GlobOutputIt > auto copy_async( - ValueType * in_first, - ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) -> typename std::enable_if< dash::has_type_pattern_type::value, dash::Future @@ -1003,13 +1003,11 @@ auto copy_async( GlobOutputIt out_h_last = out_first + num_elements; DASH_LOG_TRACE_VAR("dash::copy_async", num_elements); - // Futures of asynchronous get requests, one per block: auto futures = std::vector< dash::Future >(); auto out_range = dash::make_range(out_first, out_h_last); auto out_blocks = dash::blocks(out_range); auto in_copy_it = in_first; - DASH_LOG_TRACE("dash::copy_async", "out range:", out_range); DASH_LOG_TRACE("dash::copy_async", "number of blocks:", out_blocks.size()); for (auto block : out_blocks) { @@ -1049,12 +1047,12 @@ auto copy_async( * \ingroup DashAlgorithms */ template < - typename ValueType, + class ValueType, class GlobOutputIt > auto copy_async( - ValueType * in_first, - ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) -> typename std::enable_if< !dash::has_type_pattern_type::value, dash::Future @@ -1075,12 +1073,12 @@ auto copy_async( * \ingroup DashAlgorithms */ template < - typename ValueType, + class ValueType, class GlobOutputIt > GlobOutputIt copy( - const ValueType * in_first, - const ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy()", "blocking, local to global"); // Return value, initialize with begin of output range, indicating no @@ -1113,6 +1111,42 @@ GlobOutputIt copy( return out_last; } +/** + * Specialization of \c dash::copy as global-to-global blocking copy + * operation. + * + * \ingroup DashAlgorithms + */ +template < + class GlobInputIt, + class GlobOutputIt > +GlobOutputIt copy( + GlobInputIt in_first, + GlobInputIt in_last, + GlobOutputIt out_first) +{ + DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); + + DASH_LOG_TRACE_VAR("dash::copy()", in_first); + DASH_LOG_TRACE_VAR("dash::copy()", in_last); + DASH_LOG_TRACE_VAR("dash::copy()", out_first); + + auto num_elements = dash::distance(in_first, in_last); + auto out_h_last = out_first + num_elements; + + // in/out ranges in global domain: + auto out_g_range = dash::make_range(out_first, out_h_last); + auto in_g_range = dash::make_range(in_first, in_last); + // local view on in/out ranges: + auto out_l_range = dash::local(out_g_range); + auto in_l_range = dash::local(in_g_range); + // copy local to global range: + auto out_l_end = dash::copy(dash::begin(in_l_range), + dash::end(in_l_range), + dash::begin(out_l_range)); + + return out_first + num_elements; +} // ========================================================================= @@ -1165,64 +1199,6 @@ copy_async( } #endif -/** - * Specialization of \c dash::copy as global-to-global blocking copy - * operation. - * - * \ingroup DashAlgorithms - */ -template < - class GlobInputIt, - class GlobOutputIt > -GlobOutputIt copy( - GlobInputIt in_first, - GlobInputIt in_last, - GlobOutputIt out_first) -{ - DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); - - DASH_LOG_TRACE_VAR("dash::copy()", in_first); - DASH_LOG_TRACE_VAR("dash::copy()", in_last); - DASH_LOG_TRACE_VAR("dash::copy()", out_first); - - auto num_elements = dash::distance(in_first, in_last); - auto li_range_in = local_index_range(in_first, in_last); - auto num_local_elem = li_range_in.end - li_range_in.begin; - DASH_LOG_TRACE_VAR("dash::copy()", num_elements); - DASH_LOG_TRACE_VAR("dash::copy()", num_local_elem); - - - // copy our local portion into the global output range - if (num_local_elem > 0) { - auto pattern = in_first.pattern(); - // the distance from the first local element to the in_first iterator - auto in_offset = pattern.global(li_range_in.begin) - - in_first.global().gpos(); - - // the first local element - auto local_in_first = in_first + in_offset; - // the last local element - auto local_in_last = in_first + (num_local_elem + in_offset - 1); - auto local_out_first = out_first + in_offset; - - DASH_LOG_TRACE("Copying from range \n [", - pattern.global(li_range_in.begin), ", ", - pattern.global(li_range_in.end - 1), "] \n [", local_in_first, - "] to \n ", local_out_first, " (global offset ", in_offset, ") "); - - dash::copy( - local_in_first.local(), - // pointer one past the last element - local_in_last.local() + 1, - local_out_first); - } - // TODO: - // - Implement adapter for local-to-global dash::copy here - // - Return if global input range has no local sub-range - - return (out_first + num_elements); -} - #endif // DOXYGEN } // namespace dash diff --git a/dash/include/dash/algorithm/Transform.h b/dash/include/dash/algorithm/Transform.h index f5364557c..e692a9810 100644 --- a/dash/include/dash/algorithm/Transform.h +++ b/dash/include/dash/algorithm/Transform.h @@ -212,7 +212,7 @@ GlobOutputIt transform( * */ template< - typename ValueType, + class ValueType, class InputAIt, class InputBIt, class OutputIt, @@ -283,7 +283,7 @@ OutputIt transform_local( * */ template< - typename ValueType, + class ValueType, class InputIt, class GlobInputIt, class GlobOutputIt, diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index 808285140..db08fbba0 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -2,36 +2,337 @@ #define DASH__VIEW__MAKE_RANGE_H__INCLUDED #include +#include + #include + namespace dash { -#if 1 +template < + class Iterator, + class Sentinel > +class IteratorRangeOrigin; + +template < + class Iterator, + class Sentinel > +struct view_traits > { + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; + + typedef typename dash::view_traits::local_type local_type; + typedef typename dash::view_traits::global_type global_type; + + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef typename Iterator::pattern_type pattern_type; + + typedef dash::IndexSetIdentity< + IteratorRangeOrigin > index_set_type; + + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; + + typedef std::integral_constant rank; +}; + +template < + class Iterator, + class Sentinel +> +class IteratorRangeOrigin +{ + typedef IteratorRangeOrigin self_t; +public: + typedef Iterator iterator; + typedef Iterator const_iterator; + typedef Sentinel sentinel; + typedef Sentinel const_sentinel; + + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; + + typedef typename iterator::value_type value_type; + + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef typename iterator::pattern_type pattern_type; + + typedef ViewLocalMod local_type; + typedef ViewGlobalMod global_type; + + typedef std::integral_constant rank; + + typedef typename + std::conditional< + std::is_pointer::value, + iterator, + typename iterator::local_type + >::type + local_iterator; + + typedef typename + std::conditional< + std::is_pointer::value, + sentinel, + typename sentinel::local_type + >::type + local_sentinel; + + +private: + Iterator _begin; + Sentinel _end; + +public: + constexpr IteratorRangeOrigin(const iterator & begin, const sentinel & end) + : _begin(begin) + , _end(end) + { } + + constexpr IteratorRangeOrigin(iterator && begin, sentinel && end) + : _begin(std::move(begin)) + , _end(std::move(end)) + { } + + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } + + constexpr size_type size() const { return std::distance(_begin, _end); } + + constexpr const pattern_type & pattern() const { + return this->begin().pattern(); + } + + constexpr local_type local() const { + // for local_type: IteratorLocalView + // return local_type(this->begin(), this->end()); + return local_type(*this); + } +}; + /** - * Adapter utility function. - * Wraps `begin` and `end` pointers in range type. + * Specialization of \c dash::view_traits for IteratorRange. */ template < - class Iterator, - class Sentinel, - typename std::enable_if< std::is_pointer::value > * = nullptr > -constexpr dash::IteratorRange -make_range( - Iterator * begin, - Sentinel * end) { - return dash::IteratorRange( - begin, - end); -} -#endif + typename IteratorT, + typename SentinelT > +struct view_traits > { +private: + typedef IteratorRange RangeT; +public: + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + + typedef typename IteratorT::pattern_type pattern_type; + + typedef RangeT image_type; + typedef RangeT global_type; + typedef typename RangeT::local_type local_type; + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; + + typedef dash::IndexSetSub index_set_type; + + /// Whether the view type is a projection (has less dimensions than the + /// view's domain type). + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + /// Whether the view is the origin domain. + typedef std::integral_constant is_origin; + /// Whether the range is local view. + typedef std::integral_constant< + bool, std::is_pointer::value> is_local; + + typedef std::integral_constant rank; +}; + +/** + * Adapter template for range concept, wraps `begin` and `end` iterators + * in range type. + */ +template < + typename Iterator, + typename Sentinel > +class IteratorRange +: public ViewModBase< + IteratorRange>, + IteratorRangeOrigin, + 1 > +{ + typedef IteratorRange self_t; + typedef ViewModBase< + IteratorRange>, + IteratorRangeOrigin, + 1 > base_t; +public: + typedef Iterator iterator; + typedef Sentinel sentinel; + + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef self_t image_type; + + typedef self_t global_type; + typedef ViewLocalMod local_type; + + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef typename iterator::value_type value_type; + typedef typename iterator::pattern_type pattern_type; + + typedef dash::IndexSetSub index_set_type; + + typedef std::integral_constant rank; + + typedef typename + std::conditional< + std::is_pointer::value, + iterator, + typename iterator::local_type + >::type + local_iterator; + + typedef typename + std::conditional< + std::is_pointer::value, + sentinel, + typename sentinel::local_type + >::type + local_sentinel; + +private: + index_set_type _index_set; + +public: + constexpr IteratorRange(const iterator & begin, const sentinel & end) + : base_t(domain_type(begin, end)) + , _index_set(this->domain(), begin.pos(), end.pos()) + { } + + constexpr IteratorRange(iterator && begin, sentinel && end) + : base_t(domain_type(std::move(begin), std::move(end))) + , _index_set(this->domain(), begin.pos(), end.pos()) + { } + + constexpr IteratorRange() = delete; + constexpr IteratorRange(const self_t & other) = default; + constexpr IteratorRange(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + + constexpr const index_set_type & index_set() const { + return _index_set; + } + + constexpr local_type local() const { + return local_type(*this); + } +}; #if 0 +template < + typename IteratorT, + typename SentinelT > +struct view_traits > { +private: + typedef IteratorRange RangeT; +public: + typedef RangeT domain_type; + typedef RangeT origin_type; + typedef RangeT image_type; + typedef RangeT global_type; + typedef RangeT local_type; + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; + typedef dash::IndexSetIdentity index_set_type; + + /// Whether the view type is a projection (has less dimensions than the + /// view's domain type). + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + /// Whether the view is the origin domain. + typedef std::integral_constant is_origin; + /// Whether the view / container type is a local view. + /// \note A container type is local if it is identical to its + /// \c local_type + typedef std::integral_constant is_local; + + typedef std::integral_constant rank; +}; + +/** + * Specialization of adapter template for range concept, wraps `begin` + * and `end` pointers in range type. + */ +template < + typename LocalIterator, + typename LocalSentinel > +class IteratorRange +{ + typedef IteratorRange self_t; + + LocalIterator * _begin; + LocalSentinel * _end; + +public: + typedef LocalIterator * iterator; + typedef LocalSentinel * sentinel; + typedef const LocalIterator * const_iterator; + typedef const LocalSentinel * const_sentinel; + + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef LocalIterator value_type; + + typedef iterator local_iterator; + typedef sentinel local_sentinel; + + typedef IteratorRange local_type; + typedef self_t global_type; + + typedef std::integral_constant is_local; + +public: + constexpr IteratorRange(iterator begin, sentinel end) + : _begin(begin) + , _end(end) + { } + + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } + + constexpr size_type size() const { return std::distance(_begin, _end); } + + constexpr const local_type & local() const { + return *this; + } +}; + /** * Adapter utility function. * Wraps `begin` and `end` pointers in range type. */ -template +template < + class Iterator, + class Sentinel, + typename std::enable_if< std::is_pointer::value > * = nullptr > constexpr dash::IteratorRange make_range( Iterator * begin, @@ -43,6 +344,18 @@ make_range( #endif #if 1 +template +constexpr dash::IteratorRange< + typename std::decay::type, + typename std::decay::type > +make_range(Iterator && begin, Sentinel && end) { + return dash::IteratorRange< + typename std::decay::type, + typename std::decay::type + >(std::forward(begin), + std::forward(end)); +} +#else /** * Adapter utility function. * Wraps `begin` and `end` iterators in range type. @@ -69,68 +382,6 @@ make_range( begin - begin.pos(), begin + (begin.pattern().size() - begin.pos()))); } -#else -/** - * Adapter utility function. - * Wraps `begin` and `end` iterators in range type. - */ -template -dash::IteratorRange -make_range( - const Iterator & begin, - const Sentinel & end) { - return dash::IteratorRange(begin, end); -} - -#if 0 -/** - * Adapter utility function. - * Wraps `begin` and `end` iterators in range type. - */ -template -dash::IteratorRange< - typename std::decay::type, - typename std::decay::type > -make_range( - Iterator && begin, - Sentinel && end) { - return dash::IteratorRange< - typename std::decay::type, - typename std::decay::type - >(std::forward(begin), - std::forward(end)); -} -#endif - -#endif - -#if 0 -/** - * Adapter utility function. - * Wraps `begin` and `end` iterators in range type. - */ -template < - class Iterator, - class Sentinel, - typename std::enable_if< !std::is_pointer::value > * = nullptr > -auto -make_range( - Iterator && begin, - Sentinel && end) - -> decltype(dash::sub(begin.pos(), end.pos(), - dash::IteratorRange< - typename std::decay::type, - typename std::decay::type - >(Iterator( - std::forward(begin) - begin.pos()), - end))) { - return dash::sub(begin.pos(), end.pos(), - dash::IteratorRange< - typename std::decay::type, - typename std::decay::type - >(Iterator(std::forward(begin) - begin.pos()), - end)); -} #endif } // namespace dash diff --git a/doc/config/Doxyfile.codedocs b/doc/config/Doxyfile.codedocs index 8b59bd8bf..ab40ddb86 100644 --- a/doc/config/Doxyfile.codedocs +++ b/doc/config/Doxyfile.codedocs @@ -50,7 +50,7 @@ MARKDOWN_SUPPORT = YES DISTRIBUTE_GROUP_DOC = YES SUBGROUPING = YES SOURCE_BROWSER = YES -INLINE_SOURCES = YES +INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES @@ -148,3 +148,4 @@ UML_LOOK = NO TEMPLATE_RELATIONS = NO INTERACTIVE_SVG = NO +USE_MATHJAX = YES diff --git a/doc/config/Doxyfile.in b/doc/config/Doxyfile.in index 589d83817..4d42e34d5 100644 --- a/doc/config/Doxyfile.in +++ b/doc/config/Doxyfile.in @@ -41,7 +41,7 @@ MARKDOWN_SUPPORT = YES DISTRIBUTE_GROUP_DOC = YES SUBGROUPING = YES SOURCE_BROWSER = YES -INLINE_SOURCES = YES +INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES @@ -155,3 +155,4 @@ LATEX_HIDE_INDICES = NO LATEX_SOURCE_CODE = NO LATEX_BIB_STYLE = plain +USE_MATHJAX = YES From 9d0258938873dccf7050a7e4864afc3528e5b453 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 31 May 2017 23:27:54 +0200 Subject: [PATCH 038/161] Defined iterator ranges as model of View concept --- dash/include/dash/View.h | 34 +----- dash/include/dash/view/MakeRange.h | 160 ++++++++++++++++++------- dash/include/dash/view/ViewBlocksMod.h | 2 + dash/include/dash/view/ViewMod.h | 6 +- 4 files changed, 124 insertions(+), 78 deletions(-) diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index 106fed172..ff9f2c62e 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -81,6 +81,7 @@ #include #include #include +#include #include #include @@ -97,37 +98,4 @@ #include #include -//#include - - -namespace dash { - - -#if 0 - -template -constexpr dash::IteratorViewOrigin -make_view(const Iterator & begin, const Sentinel & end) { - return dash::IteratorViewOrigin( - (begin), - (end)); -} - -template -constexpr dash::IteratorViewOrigin< - typename std::decay::type, - typename std::decay::type > -make_view(Iterator && begin, Sentinel && end) { - return dash::IteratorViewOrigin< - typename std::decay::type, - typename std::decay::type - >(std::move(begin), - std::move(end)); -} - -#endif - -} // namespace dash - - #endif // DASH__VIEW_H__INCLUDED diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index db08fbba0..b8d57d1ea 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -4,7 +4,10 @@ #include #include -#include +// #include +// #include +// #include +#include @@ -23,23 +26,22 @@ struct view_traits > { typedef IteratorRangeOrigin origin_type; typedef IteratorRangeOrigin image_type; - typedef typename dash::view_traits::local_type local_type; - typedef typename dash::view_traits::global_type global_type; + typedef typename Iterator::pattern_type pattern_type; + typedef std::integral_constant rank; + + typedef domain_type local_type; + typedef domain_type global_type; typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef typename Iterator::pattern_type pattern_type; - typedef dash::IndexSetIdentity< IteratorRangeOrigin > index_set_type; typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; typedef std::integral_constant is_local; - - typedef std::integral_constant rank; }; template < @@ -66,10 +68,10 @@ class IteratorRangeOrigin typedef typename iterator::pattern_type pattern_type; - typedef ViewLocalMod local_type; - typedef ViewGlobalMod global_type; + typedef self_t local_type; + typedef self_t global_type; - typedef std::integral_constant rank; + typedef std::integral_constant rank; typedef typename std::conditional< @@ -128,22 +130,25 @@ class IteratorRangeOrigin template < typename IteratorT, typename SentinelT > -struct view_traits > { +struct view_traits > { private: - typedef IteratorRange RangeT; + typedef IteratorRange RangeT; public: - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef RangeT image_type; - typedef typename IteratorT::pattern_type pattern_type; + typedef typename IteratorT::pattern_type pattern_type; - typedef RangeT image_type; - typedef RangeT global_type; - typedef typename RangeT::local_type local_type; - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; + typedef std::integral_constant rank; + + typedef RangeT global_type; + typedef ViewLocalMod local_type; + + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; - typedef dash::IndexSetSub index_set_type; + typedef dash::IndexSetSub index_set_type; /// Whether the view type is a projection (has less dimensions than the /// view's domain type). @@ -154,8 +159,6 @@ struct view_traits > { /// Whether the range is local view. typedef std::integral_constant< bool, std::is_pointer::value> is_local; - - typedef std::integral_constant rank; }; /** @@ -171,31 +174,36 @@ class IteratorRange IteratorRangeOrigin, 1 > { - typedef IteratorRange self_t; + typedef IteratorRange self_t; typedef ViewModBase< IteratorRange>, IteratorRangeOrigin, - 1 > base_t; + 1 > base_t; public: - typedef Iterator iterator; - typedef Sentinel sentinel; + typedef Iterator iterator; + typedef Iterator const_iterator; + typedef Sentinel sentinel; + typedef Sentinel const_sentinel; - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef self_t image_type; + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef self_t image_type; - typedef self_t global_type; - typedef ViewLocalMod local_type; + typedef typename iterator::value_type value_type; + typedef typename iterator::pattern_type pattern_type; - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; + typedef std::integral_constant rank; - typedef typename iterator::value_type value_type; - typedef typename iterator::pattern_type pattern_type; + typedef self_t global_type; + typedef ViewLocalMod local_type; - typedef dash::IndexSetSub index_set_type; + typedef std::integral_constant< + bool, std::is_pointer::value> is_local; - typedef std::integral_constant rank; + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef dash::IndexSetSub index_set_type; typedef typename std::conditional< @@ -213,17 +221,21 @@ class IteratorRange >::type local_sentinel; + using reference = typename iterator::reference; + using const_reference = typename iterator::const_reference; + private: - index_set_type _index_set; + static const dim_t NDim = rank::value; + index_set_type _index_set; public: constexpr IteratorRange(const iterator & begin, const sentinel & end) - : base_t(domain_type(begin, end)) + : base_t(domain_type(begin - begin.pos(), end)) , _index_set(this->domain(), begin.pos(), end.pos()) { } constexpr IteratorRange(iterator && begin, sentinel && end) - : base_t(domain_type(std::move(begin), std::move(end))) + : base_t(domain_type(std::move(begin) - begin.pos(), std::move(end))) , _index_set(this->domain(), begin.pos(), end.pos()) { } @@ -233,6 +245,68 @@ class IteratorRange self_t & operator=(const self_t & other) = default; self_t & operator=(self_t && other) = default; + // ---- extents --------------------------------------------------------- + + constexpr std::array extents() const { + return _index_set.extents(); + } + + template + constexpr size_type extent() const { + return _index_set.template extent(); + } + + constexpr size_type extent(dim_t shape_dim) const { + return _index_set.extent(shape_dim); + } + + // ---- offsets --------------------------------------------------------- + + template + constexpr index_type offset() const { + return _index_set.template offset(); + } + + constexpr std::array offsets() const { + return _index_set.offsets(); + } + + constexpr index_type offset(dim_t shape_dim) const { + return _index_set.offset(shape_dim); + } + + // ---- size ------------------------------------------------------------ + + constexpr size_type size(dim_t sub_dim = 0) const { + return _index_set.size(sub_dim); + } + + // ---- access ---------------------------------------------------------- + + constexpr const_iterator begin() const { + return dash::domain(*this).begin() + _index_set[0]; + } + + iterator begin() { + return dash::domain(*this).begin() + _index_set[0]; + } + + constexpr const_iterator end() const { + return dash::domain(*this).end(); + } + + iterator end() { + return dash::domain(*this).end(); + } + + constexpr const_reference operator[](int offset) const { + return *(dash::domain(*this).begin() + _index_set[offset]); + } + + reference operator[](int offset) { + return *(dash::domain(*this).begin() + _index_set[offset]); + } + constexpr const index_set_type & index_set() const { return _index_set; } diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index e30e91164..f6e595ea0 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -19,6 +19,8 @@ #include #include +#include + #include diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 46a07e391..f27c782c3 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -163,8 +163,10 @@ class ViewModBase typedef DomainType domain_type; typedef typename std::conditional< - // try is_copyable, is_moveable - view_traits::is_origin::value, + // try is_copyable, is_moveable + ( view_traits::is_origin::value + // && !view_traits::is_view::value + ), const domain_type &, domain_type >::type From d90ee3803e2567679f84dc914c966896a6f24086 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 07:01:23 +0200 Subject: [PATCH 039/161] Adding local views for iterator ranges --- dash/include/dash/Range.h | 173 +++++-- dash/include/dash/View.h | 2 +- dash/include/dash/algorithm/Copy.h | 2 +- dash/include/dash/internal/StreamConversion.h | 93 ---- dash/include/dash/view/Apply.h | 3 - dash/include/dash/view/Domain.h | 19 +- dash/include/dash/view/IndexSet.h | 11 +- dash/include/dash/view/Local.h | 1 - dash/include/dash/view/MakeRange.h | 331 ++----------- dash/include/dash/view/Origin.h | 2 +- dash/include/dash/view/ViewBlocksMod.h | 5 +- dash/include/dash/view/ViewIterator.h | 4 - dash/include/dash/view/ViewMod.h | 132 +++++- dash/include/dash/view/ViewMod1D.h | 444 +++++++++++++++++- dash/include/dash/view/ViewOrigin.h | 7 +- dash/include/dash/view/ViewTraits.h | 15 +- dash/test/TestBase.h | 1 + 17 files changed, 772 insertions(+), 473 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index ee0be5dfe..f4bd5cd4f 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -46,70 +46,76 @@ */ +// Related: boost::range +// +// https://github.com/boostorg/range/tree/develop/include/boost/range +// + + #include #include +#include + #include +#include namespace dash { - -#ifndef DOXYGEN - -// Related: boost::range -// -// https://github.com/boostorg/range/tree/develop/include/boost/range -// +// ----------------------------------------------------------------------- +// Forward-declarations template struct view_traits; -// Forward-declaration -template +template +class IndexSetBase; + +template class IndexSetIdentity; +template +class IndexSetLocal; + +template +class IndexSetGlobal; + template class IndexSetSub; -// Forward-declaration -template +template class IteratorRange; -// Forward-declaration +template +class IteratorRangeOrigin; + template -class IteratorRange; +class IteratorRangeOrigin; -#endif +template < + class ViewModType, + class DomainType, + dim_t NDim > +class ViewModBase; +template < + class DomainType, + dim_t NDim > +class ViewLocalMod; -/** - * \concept{DashRangeConcept} - */ -template -constexpr auto begin(RangeType && range) - -> decltype(std::forward(range).begin()) { - return std::forward(range).begin(); -} +template < + class DomainType, + dim_t SubDim, + dim_t NDim > +class ViewSubMod; -/** - * \concept{DashRangeConcept} - */ -template -constexpr auto end(RangeType && range) - -> decltype(std::forward(range).end()) { - return std::forward(range).end(); -} +template < + class DomainType, + dim_t NDim > +class ViewGlobalMod; -/** - * \concept{DashRangeConcept} - */ -template -constexpr auto -size(RangeType && r) - -> decltype(std::forward(r).size()) { - return std::forward(r).size(); -} +// ----------------------------------------------------------------------- namespace detail { @@ -210,6 +216,95 @@ struct is_range : dash::detail::_is_range_type< > { }; +#if 0 + +template < + class RangeOrigin, + typename std::enable_if< + view_traits::is_local::value + > * = 0> +struct view_traits > +{ +private: + typedef IteratorRange RangeT; +public: + typedef RangeT domain_type; + typedef RangeT origin_type; + typedef RangeT image_type; + typedef RangeT global_type; + typedef RangeT local_type; + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; + typedef dash::IndexSetIdentity index_set_type; + + /// Whether the view type is a projection (has less dimensions than the + /// view's domain type). + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + /// Whether the view is the origin domain. + typedef std::integral_constant is_origin; + /// Whether the view / container type is a local view. + /// \note A container type is local if it is identical to its + /// \c local_type + typedef std::integral_constant is_local; + + typedef std::integral_constant rank; +}; + +/** + * Specialization of adapter template for range concept, wraps `begin` + * and `end` pointers in range type. + */ +template < + typename LocalIterator, + typename LocalSentinel > +class IteratorRange +{ + typedef IteratorRange self_t; + + LocalIterator * _begin; + LocalSentinel * _end; + +public: + typedef LocalIterator * iterator; + typedef LocalSentinel * sentinel; + typedef const LocalIterator * const_iterator; + typedef const LocalSentinel * const_sentinel; + + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef LocalIterator value_type; + + typedef iterator local_iterator; + typedef sentinel local_sentinel; + + typedef IteratorRange local_type; + typedef self_t global_type; + + typedef std::integral_constant is_local; + +public: + constexpr IteratorRange(iterator begin, sentinel end) + : _begin(begin) + , _end(end) + { } + + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } + + constexpr size_type size() const { return std::distance(_begin, _end); } + + constexpr const local_type & local() const { + return *this; + } +}; + +#endif + } // namespace dash #endif // DASH__RANGES_H__INCLUDED diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index ff9f2c62e..b940376ee 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -81,7 +81,7 @@ #include #include #include -#include +// #include #include #include diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 907822ddd..63b996775 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -795,7 +795,7 @@ template < ValueType * copy( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { const auto & team = in_first.team(); dash::util::UnitLocality uloc(team, team.myid()); diff --git a/dash/include/dash/internal/StreamConversion.h b/dash/include/dash/internal/StreamConversion.h index 88416f76f..245f0888c 100644 --- a/dash/include/dash/internal/StreamConversion.h +++ b/dash/include/dash/internal/StreamConversion.h @@ -7,8 +7,6 @@ #include -#include - #include #include #include @@ -111,97 +109,6 @@ std::ostream & operator<<( return o; } -/** - * Write range of random access iterators to output stream. - */ -template < - class Range, - class RangeDType = typename std::decay::type -> -auto operator<<( - std::ostream & o, - Range && range) - -> typename std::enable_if< - ( - // type is range: - dash::is_range::value && - // type is not std::string or derivative: - !std::is_same::value && - !std::is_base_of::value && - // range iterator type is random access: - std::is_same< - std::random_access_iterator_tag, - typename std::iterator_traits< - typename std::decay< - decltype(dash::begin(std::forward(range))) - >::type - >::iterator_category - >::value - ), - std::ostream & - >::type -{ - typedef typename std::iterator_traits::value_type - value_t; - - auto && rng = std::forward(range); - - std::ostringstream ss; - int pos = 0; - ss << dash::typestr(*dash::begin(rng)) - << " { "; - for (auto it = dash::begin(rng); it != dash::end(rng); ++it, ++pos) { - ss << static_cast(*it) << " "; - } - ss << "}"; - return operator<<(o, ss.str()); -} - -/** - * Write range of non-random access iterators to output stream. - */ -template < - class Range, - class RangeDType = typename std::decay::type -> -auto operator<<( - std::ostream & o, - Range && range) - -> typename std::enable_if< - ( - // type is range: - dash::is_range::value && - // type is not std::string or derivative: - !std::is_same::value && - !std::is_base_of::value && - // range iterator type is not random access: - !std::is_same< - std::random_access_iterator_tag, - typename std::iterator_traits< - typename std::decay< - decltype(dash::begin(std::forward(range))) - >::type - >::iterator_category - >::value - ), - std::ostream & - >::type -{ - typedef typename std::iterator_traits::value_type - value_t; - - auto && rng = std::forward(range); - - std::ostringstream ss; - ss << dash::typestr(*dash::begin(rng)) - << " { "; - for (auto it = dash::begin(rng); it != dash::end(rng); ++it) { - ss << static_cast(*it) << " "; - } - ss << "}"; - return operator<<(o, ss.str()); -} - } // namespace dash #endif // DASH__INTERNAL__STREAM_CONVERSION_H_ diff --git a/dash/include/dash/view/Apply.h b/dash/include/dash/view/Apply.h index a3f6db5cb..f940e9339 100644 --- a/dash/include/dash/view/Apply.h +++ b/dash/include/dash/view/Apply.h @@ -2,9 +2,6 @@ #define DASH__VIEW__APPLY_H__INCLUDED #include -#include - -#include namespace dash { diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index cb790a8c3..f99f5bfdb 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -2,12 +2,25 @@ #define DASH__VIEW__DOMAIN_H__INCLUDED #include -#include +#include -#include +namespace dash { +namespace detail { + /** + * Definition of type trait \c dash::detail::has_type_domain_type + * with static member \c value indicating whether type \c T provides + * dependent type \c domain_type. + */ + DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_type); +} -namespace dash { + +// ----------------------------------------------------------------------- +// Forward-declarations + +template +struct view_traits; // ------------------------------------------------------------------------ // dash::domain(View) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 37191e533..3cedc542e 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1,6 +1,8 @@ #ifndef DASH__VIEW__INDEX_SET_H__INCLUDED #define DASH__VIEW__INDEX_SET_H__INCLUDED +#include + #include #include #include @@ -11,8 +13,6 @@ #include -#include - #include #include #include @@ -126,6 +126,11 @@ class IndexSetGlobal; template class IndexSetSub; +template +class IndexSetBlocks; + +template +class IndexSetBlock; // ----------------------------------------------------------------------- @@ -315,7 +320,7 @@ class IndexSetBase view_origin_type; typedef DomainValueT view_domain_type; - typedef typename DomainValueT::local_type + typedef typename dash::view_traits::local_type view_local_type; typedef typename dash::view_traits::global_type view_global_type; diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index c58aeb0a6..dc833213b 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -2,7 +2,6 @@ #define DASH__VIEW__LOCAL_H__INCLUDED #include -#include #include diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h index b8d57d1ea..1a8cda691 100644 --- a/dash/include/dash/view/MakeRange.h +++ b/dash/include/dash/view/MakeRange.h @@ -6,315 +6,36 @@ // #include // #include -// #include -#include +// #include +#include namespace dash { -template < - class Iterator, - class Sentinel > -class IteratorRangeOrigin; - -template < - class Iterator, - class Sentinel > -struct view_traits > { - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeOrigin image_type; - - typedef typename Iterator::pattern_type pattern_type; - typedef std::integral_constant rank; - - typedef domain_type local_type; - typedef domain_type global_type; - - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; - - typedef dash::IndexSetIdentity< - IteratorRangeOrigin > index_set_type; - - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; -}; - -template < - class Iterator, - class Sentinel -> -class IteratorRangeOrigin -{ - typedef IteratorRangeOrigin self_t; -public: - typedef Iterator iterator; - typedef Iterator const_iterator; - typedef Sentinel sentinel; - typedef Sentinel const_sentinel; - - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeOrigin image_type; - - typedef typename iterator::value_type value_type; - - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; - - typedef typename iterator::pattern_type pattern_type; - - typedef self_t local_type; - typedef self_t global_type; - - typedef std::integral_constant rank; - - typedef typename - std::conditional< - std::is_pointer::value, - iterator, - typename iterator::local_type - >::type - local_iterator; - - typedef typename - std::conditional< - std::is_pointer::value, - sentinel, - typename sentinel::local_type - >::type - local_sentinel; - - -private: - Iterator _begin; - Sentinel _end; - -public: - constexpr IteratorRangeOrigin(const iterator & begin, const sentinel & end) - : _begin(begin) - , _end(end) - { } - - constexpr IteratorRangeOrigin(iterator && begin, sentinel && end) - : _begin(std::move(begin)) - , _end(std::move(end)) - { } - - constexpr const_iterator begin() const { return _begin; } - constexpr const_sentinel end() const { return _end; } - - iterator begin() { return _begin; } - sentinel end() { return _end; } - - constexpr size_type size() const { return std::distance(_begin, _end); } - - constexpr const pattern_type & pattern() const { - return this->begin().pattern(); - } - - constexpr local_type local() const { - // for local_type: IteratorLocalView - // return local_type(this->begin(), this->end()); - return local_type(*this); - } -}; - -/** - * Specialization of \c dash::view_traits for IteratorRange. - */ -template < - typename IteratorT, - typename SentinelT > -struct view_traits > { -private: - typedef IteratorRange RangeT; -public: - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef RangeT image_type; - - typedef typename IteratorT::pattern_type pattern_type; - - typedef std::integral_constant rank; - - typedef RangeT global_type; - typedef ViewLocalMod local_type; - - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; - - typedef dash::IndexSetSub index_set_type; - - /// Whether the view type is a projection (has less dimensions than the - /// view's domain type). - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; - /// Whether the range is local view. - typedef std::integral_constant< - bool, std::is_pointer::value> is_local; -}; - -/** - * Adapter template for range concept, wraps `begin` and `end` iterators - * in range type. - */ -template < - typename Iterator, - typename Sentinel > -class IteratorRange -: public ViewModBase< - IteratorRange>, - IteratorRangeOrigin, - 1 > -{ - typedef IteratorRange self_t; - typedef ViewModBase< - IteratorRange>, - IteratorRangeOrigin, - 1 > base_t; -public: - typedef Iterator iterator; - typedef Iterator const_iterator; - typedef Sentinel sentinel; - typedef Sentinel const_sentinel; - - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef self_t image_type; - - typedef typename iterator::value_type value_type; - typedef typename iterator::pattern_type pattern_type; - - typedef std::integral_constant rank; - - typedef self_t global_type; - typedef ViewLocalMod local_type; - - typedef std::integral_constant< - bool, std::is_pointer::value> is_local; - - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; - - typedef dash::IndexSetSub index_set_type; - - typedef typename - std::conditional< - std::is_pointer::value, - iterator, - typename iterator::local_type - >::type - local_iterator; - - typedef typename - std::conditional< - std::is_pointer::value, - sentinel, - typename sentinel::local_type - >::type - local_sentinel; - - using reference = typename iterator::reference; - using const_reference = typename iterator::const_reference; - -private: - static const dim_t NDim = rank::value; - index_set_type _index_set; - -public: - constexpr IteratorRange(const iterator & begin, const sentinel & end) - : base_t(domain_type(begin - begin.pos(), end)) - , _index_set(this->domain(), begin.pos(), end.pos()) - { } - - constexpr IteratorRange(iterator && begin, sentinel && end) - : base_t(domain_type(std::move(begin) - begin.pos(), std::move(end))) - , _index_set(this->domain(), begin.pos(), end.pos()) - { } - - constexpr IteratorRange() = delete; - constexpr IteratorRange(const self_t & other) = default; - constexpr IteratorRange(self_t && other) = default; - self_t & operator=(const self_t & other) = default; - self_t & operator=(self_t && other) = default; - - // ---- extents --------------------------------------------------------- - - constexpr std::array extents() const { - return _index_set.extents(); - } - - template - constexpr size_type extent() const { - return _index_set.template extent(); - } +#ifndef DOXYGEN - constexpr size_type extent(dim_t shape_dim) const { - return _index_set.extent(shape_dim); - } - - // ---- offsets --------------------------------------------------------- - - template - constexpr index_type offset() const { - return _index_set.template offset(); - } - - constexpr std::array offsets() const { - return _index_set.offsets(); - } - - constexpr index_type offset(dim_t shape_dim) const { - return _index_set.offset(shape_dim); - } - - // ---- size ------------------------------------------------------------ - - constexpr size_type size(dim_t sub_dim = 0) const { - return _index_set.size(sub_dim); - } - - // ---- access ---------------------------------------------------------- - - constexpr const_iterator begin() const { - return dash::domain(*this).begin() + _index_set[0]; - } - - iterator begin() { - return dash::domain(*this).begin() + _index_set[0]; - } +// Related: boost::range +// +// https://github.com/boostorg/range/tree/develop/include/boost/range +// - constexpr const_iterator end() const { - return dash::domain(*this).end(); - } +template +struct view_traits; - iterator end() { - return dash::domain(*this).end(); - } +// Forward-declaration +template +class IndexSetIdentity; - constexpr const_reference operator[](int offset) const { - return *(dash::domain(*this).begin() + _index_set[offset]); - } +template +class IndexSetSub; - reference operator[](int offset) { - return *(dash::domain(*this).begin() + _index_set[offset]); - } +// Forward-declaration +template +class IteratorRange; - constexpr const index_set_type & index_set() const { - return _index_set; - } +#endif - constexpr local_type local() const { - return local_type(*this); - } -}; #if 0 template < @@ -418,6 +139,7 @@ make_range( #endif #if 1 +/* template constexpr dash::IteratorRange< typename std::decay::type, @@ -429,6 +151,21 @@ make_range(Iterator && begin, Sentinel && end) { >(std::forward(begin), std::forward(end)); } + +template +constexpr dash::IteratorRange< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type > > +make_range(Iterator && begin, Sentinel && end) { + return dash::IteratorRange< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type > + >(std::forward(begin), + std::forward(end)); +} +*/ #else /** * Adapter utility function. diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index 2f8b5cb64..8232d2654 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -30,7 +30,7 @@ typename std::enable_if< ContainerT >::type origin(ContainerT && container) { - return container; + return std::forward(container); } template diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index f6e595ea0..985bc090d 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -452,12 +452,11 @@ struct view_traits > { typedef typename view_traits::origin_type origin_type; typedef typename view_traits::pattern_type pattern_type; typedef ViewBlocksMod image_type; - typedef typename domain_type::local_type local_type; + typedef typename view_traits::local_type local_type; typedef ViewBlocksMod global_type; typedef typename view_traits::index_type index_type; typedef typename view_traits::size_type size_type; -//typedef dash::IndexSetBlocks> typedef dash::IndexSetBlocks index_set_type; @@ -487,7 +486,7 @@ class ViewBlocksMod typedef typename view_traits::size_type size_type; private: typedef ViewBlockMod block_type; - typedef typename domain_type::local_type domain_local_type; + typedef typename view_traits::local_type domain_local_type; public: typedef dash::IndexSetBlocks index_set_type; typedef self_t global_type; diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 9c478de8e..da3f17adf 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -99,10 +99,6 @@ class ViewIterator } constexpr dart_gptr_t dart_gptr() const { -// DASH_LOG_DEBUG("ViewIterator", -// "it.pos:", _domain_it.pos(), -// "it.gpos:", _domain_it.gpos(), -// "pos:", this->pos()); return (_domain_it + _index_set[this->pos()]).dart_gptr(); } diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index f27c782c3..a45840cb6 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -2,7 +2,6 @@ #define DASH__VIEW__VIEW_MOD_H__INCLUDED #include -#include #include #include @@ -146,6 +145,125 @@ class ViewGlobalMod; #endif // DOXYGEN +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto begin(RangeType && range) + -> decltype(std::forward(range).begin()) { + return std::forward(range).begin(); +} + +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto end(RangeType && range) + -> decltype(std::forward(range).end()) { + return std::forward(range).end(); +} + +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto +size(RangeType && r) + -> decltype(std::forward(r).size()) { + return std::forward(r).size(); +} + +/** + * Write range of random access iterators to output stream. + */ +template < + class Range, + class RangeDType = typename std::decay::type +> +auto operator<<( + std::ostream & o, + Range && range) + -> typename std::enable_if< + ( + // type is range: + dash::is_range::value && + // type is not std::string or derivative: + !std::is_same::value && + !std::is_base_of::value && + // range iterator type is random access: + std::is_same< + std::random_access_iterator_tag, + typename std::iterator_traits< + typename std::decay< + decltype(dash::begin(std::forward(range))) + >::type + >::iterator_category + >::value + ), + std::ostream & + >::type +{ + typedef typename std::iterator_traits::value_type + value_t; + + auto && rng = std::forward(range); + + std::ostringstream ss; + int pos = 0; + ss << dash::typestr(*dash::begin(rng)) + << " { "; + for (auto it = dash::begin(rng); it != dash::end(rng); ++it, ++pos) { + ss << static_cast(*it) << " "; + } + ss << "}"; + return operator<<(o, ss.str()); +} + +/** + * Write range of non-random access iterators to output stream. + */ +template < + class Range, + class RangeDType = typename std::decay::type +> +auto operator<<( + std::ostream & o, + Range && range) + -> typename std::enable_if< + ( + // type is range: + dash::is_range::value && + // type is not std::string or derivative: + !std::is_same::value && + !std::is_base_of::value && + // range iterator type is not random access: + !std::is_same< + std::random_access_iterator_tag, + typename std::iterator_traits< + typename std::decay< + decltype(dash::begin(std::forward(range))) + >::type + >::iterator_category + >::value + ), + std::ostream & + >::type +{ + typedef typename std::iterator_traits::value_type + value_t; + + auto && rng = std::forward(range); + + std::ostringstream ss; + ss << dash::typestr(*dash::begin(rng)) + << " { "; + for (auto it = dash::begin(rng); it != dash::end(rng); ++it) { + ss << static_cast(*it) << " "; + } + ss << "}"; + return operator<<(o, ss.str()); +} + // ------------------------------------------------------------------------ @@ -165,7 +283,7 @@ class ViewModBase typedef typename std::conditional< // try is_copyable, is_moveable ( view_traits::is_origin::value - // && !view_traits::is_view::value + && !view_traits::is_view::value ), const domain_type &, domain_type @@ -231,7 +349,7 @@ class ViewModBase * Constructor, creates a view on a given domain. */ constexpr explicit ViewModBase(domain_type && domain) - : _domain(std::forward(domain)) + : _domain(std::move(domain)) { } /** @@ -319,7 +437,7 @@ struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; typedef typename view_traits::pattern_type pattern_type; - typedef typename domain_type::local_type image_type; + typedef typename view_traits::local_type image_type; typedef ViewLocalMod local_type; typedef domain_type global_type; @@ -350,9 +468,9 @@ class ViewLocalMod typedef typename view_traits::index_type index_type; typedef typename view_traits::size_type size_type; private: - typedef ViewLocalMod self_t; + typedef ViewLocalMod self_t; typedef ViewModBase< - ViewLocalMod, DomainType, NDim > base_t; + ViewLocalMod, DomainType, NDim > base_t; public: typedef dash::IndexSetLocal index_set_type; typedef self_t local_type; @@ -418,7 +536,7 @@ class ViewLocalMod */ constexpr explicit ViewLocalMod( domain_type && domain) - : base_t(std::forward(domain)) + : base_t(std::move(domain)) , _index_set(this->domain()) { } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 586c8ee2a..a8f14b97e 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -2,7 +2,6 @@ #define DASH__VIEW__VIEW_MOD_1D_H__INCLUDED #include -#include #include #include @@ -18,9 +17,36 @@ #include #include +#include namespace dash { + +template +class IndexSetBase; + +template +class IndexSetIdentity; + +template +class IndexSetLocal; + +template +class IndexSetGlobal; + +template +class IndexSetSub; + +template +class IteratorRange; + +template +class IteratorRangeOrigin; + +template +class IteratorRangeOrigin; + + #ifndef DOXYGEN // ------------------------------------------------------------------------ @@ -33,7 +59,8 @@ template < class ViewSubMod : public ViewModBase< ViewSubMod, - DomainType > + DomainType, + 1 > { public: typedef DomainType domain_type; @@ -139,6 +166,23 @@ class ViewSubMod // ViewLocalMod // ------------------------------------------------------------------------ +#if 0 // HERE !!! +template +constexpr ViewLocalMod, 1> +local(const IteratorRange & ir) { + return ViewLocalMod, 1>(ir); +} + +template < + class Iterator, + class Sentinel > +constexpr ViewLocalMod, 1> +local(const IteratorRangeOrigin & ir) { + return ViewLocalMod, 1>(ir); +} +#endif + + template < class DomainType > class ViewLocalMod @@ -148,7 +192,7 @@ class ViewLocalMod public: typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; - typedef typename domain_type::local_type image_type; + typedef typename view_traits::local_type image_type; typedef typename domain_type::index_type index_type; typedef typename domain_type::size_type size_type; private: @@ -294,7 +338,6 @@ class ViewLocalMod } }; // class ViewLocalMod - // ------------------------------------------------------------------------ // ViewGlobalMod // ------------------------------------------------------------------------ @@ -396,6 +439,399 @@ class ViewGlobalMod } }; // class ViewGlobalMod + + +// ------------------------------------------------------------------------ +// Iterator Range Origin +// ------------------------------------------------------------------------ + +template < + class Iterator, + class Sentinel > +class IteratorRangeOrigin; + +template < + class Iterator, + class Sentinel > +struct view_traits > { +private: + typedef IteratorRangeOrigin RangeT; +public: + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; + + typedef typename Iterator::pattern_type pattern_type; + typedef std::integral_constant rank; + + typedef ViewLocalMod< + IteratorRangeOrigin, 1> local_type; + typedef RangeT global_type; + + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef dash::IndexSetIdentity< + IteratorRangeOrigin > index_set_type; + + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant< + bool, std::is_pointer::value > is_local; +}; + + +template < + class Iterator, + class Sentinel > +class IteratorRangeOrigin +{ + typedef IteratorRangeOrigin self_t; +public: + typedef Iterator iterator; + typedef Iterator const_iterator; + typedef Sentinel sentinel; + typedef Sentinel const_sentinel; + + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; + + typedef typename iterator::value_type value_type; + + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef typename iterator::pattern_type pattern_type; + + typedef std::integral_constant rank; + + typedef std::integral_constant::value> + is_local; + + typedef ViewIterator< + typename std::conditional< + std::is_pointer::value, + iterator, + typename iterator::local_type + >::type, + IndexSetLocal > + local_iterator; + + typedef ViewIterator< + typename std::conditional< + std::is_pointer::value, + sentinel, + typename sentinel::local_type + >::type, + IndexSetLocal > + local_sentinel; + + typedef self_t global_type; + typedef IteratorRangeOrigin local_type; +//typedef ViewLocalMod local_type; + +private: + iterator _begin; + sentinel _end; + +public: + constexpr IteratorRangeOrigin(const iterator & begin, const sentinel & end) + : _begin(begin) + , _end(end) + { } + + constexpr IteratorRangeOrigin(iterator && begin, sentinel && end) + : _begin(std::move(begin)) + , _end(std::move(end)) + { } + + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } + + constexpr size_type size() const { return std::distance(_begin, _end); } + + constexpr const pattern_type & pattern() const { + return this->begin().pattern(); + } + + constexpr local_type local() const { + // for local_type: IteratorLocalView + return local_type(_begin.local(), _end.local()); + //return local_type(*this); + } +}; + + +template < + typename LocalIterator, + typename LocalSentinel > +class IteratorRangeOrigin +{ + typedef IteratorRangeOrigin self_t; + + LocalIterator * _begin; + LocalSentinel * _end; + +public: + typedef LocalIterator * iterator; + typedef LocalSentinel * sentinel; + typedef const LocalIterator * const_iterator; + typedef const LocalSentinel * const_sentinel; + + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef LocalIterator value_type; + +//typedef ViewLocalMod local_type; + typedef self_t global_type; + + typedef std::integral_constant is_local; + +public: + constexpr IteratorRangeOrigin(iterator begin, sentinel end) + : _begin(begin) + , _end(end) + { } + + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } + + constexpr size_type size() const { return std::distance(_begin, _end); } + +// constexpr const local_type & local() const { +// return *this; +// } +}; + + +// ------------------------------------------------------------------------ +// Iterator Range +// ------------------------------------------------------------------------ + +/** + * Specialization of \c dash::view_traits for IteratorRange. + */ +template +struct view_traits > { +private: + typedef IteratorRange RangeT; +public: + typedef RangeOrigin domain_type; + typedef RangeOrigin origin_type; + typedef RangeT image_type; + + typedef typename RangeOrigin::pattern_type pattern_type; + + typedef std::integral_constant rank; + + typedef RangeT global_type; + typedef ViewLocalMod local_type; + + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; + + typedef dash::IndexSetSub index_set_type; + + /// Whether the view type is a projection (has less dimensions than the + /// view's domain type). + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + /// Whether the view is the origin domain. + typedef std::integral_constant is_origin; + /// Whether the range is local view. + typedef typename view_traits::is_local is_local; +}; + +/** + * Adapter template for range concept, wraps `begin` and `end` iterators + * in range type. + */ +template +class IteratorRange +: public ViewModBase< + IteratorRange, + RangeOrigin, + 1 > +{ + typedef IteratorRange self_t; + typedef ViewModBase< + IteratorRange, + RangeOrigin, + 1 > base_t; +public: + typedef typename RangeOrigin::iterator iterator; + typedef typename RangeOrigin::const_iterator const_iterator; + typedef typename RangeOrigin::sentinel sentinel; + typedef typename RangeOrigin::const_sentinel const_sentinel; + + typedef RangeOrigin domain_type; + typedef RangeOrigin origin_type; + typedef self_t image_type; + + typedef typename domain_type::value_type value_type; + typedef typename domain_type::pattern_type pattern_type; + + typedef std::integral_constant rank; + + typedef self_t global_type; + typedef ViewLocalMod local_type; + + typedef std::integral_constant< + bool, std::is_pointer::value> is_local; + + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef dash::IndexSetSub index_set_type; + + typedef typename + std::conditional< + std::is_pointer::value, + iterator, + typename iterator::local_type + >::type + local_iterator; + + typedef typename + std::conditional< + std::is_pointer::value, + sentinel, + typename sentinel::local_type + >::type + local_sentinel; + + using reference = typename iterator::reference; + using const_reference = typename iterator::const_reference; + +private: + static const dim_t NDim = rank::value; + index_set_type _index_set; + +public: + constexpr IteratorRange(const iterator & begin, const sentinel & end) + : base_t(domain_type( + // 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()) )) + // Convert iterator positions to sub-range index set: + , _index_set(this->domain(), begin.pos(), end.pos()) + { } + + constexpr IteratorRange(iterator && begin, sentinel && end) + : base_t(domain_type( + // 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()) )) + // Convert iterator positions to sub-range index set: + , _index_set(this->domain(), begin.pos(), end.pos()) + { } + + constexpr IteratorRange() = delete; + constexpr IteratorRange(const self_t & other) = default; + constexpr IteratorRange(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + + // ---- extents --------------------------------------------------------- + + constexpr std::array extents() const { + return _index_set.extents(); + } + + template + constexpr size_type extent() const { + return _index_set.template extent(); + } + + constexpr size_type extent(dim_t shape_dim) const { + return _index_set.extent(shape_dim); + } + + // ---- offsets --------------------------------------------------------- + + template + constexpr index_type offset() const { + return _index_set.template offset(); + } + + constexpr std::array offsets() const { + return _index_set.offsets(); + } + + constexpr index_type offset(dim_t shape_dim) const { + return _index_set.offset(shape_dim); + } + + // ---- size ------------------------------------------------------------ + + constexpr size_type size(dim_t sub_dim = 0) const { + return _index_set.size(sub_dim); + } + + // ---- access ---------------------------------------------------------- + + constexpr const_iterator begin() const { + return dash::domain(*this).begin() + _index_set[0]; + } + + iterator begin() { + return dash::domain(*this).begin() + _index_set[0]; + } + + constexpr const_iterator end() const { + return dash::domain(*this).end(); + } + + iterator end() { + return dash::domain(*this).end(); + } + + constexpr const_reference operator[](int offset) const { + return *(dash::domain(*this).begin() + _index_set[offset]); + } + + reference operator[](int offset) { + return *(dash::domain(*this).begin() + _index_set[offset]); + } + + constexpr const index_set_type & index_set() const { + return _index_set; + } + + constexpr local_type local() const { + return local_type(*this); + } +}; + +// ------------------------------------------------------------------------ +// dash::make_range +// ------------------------------------------------------------------------ + +template +constexpr dash::IteratorRange< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type > > +make_range(Iterator && begin, Sentinel && end) { + return dash::IteratorRange< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type > + >(std::forward(begin), + std::forward(end)); +} + #endif // DOXYGEN } // namespace dash diff --git a/dash/include/dash/view/ViewOrigin.h b/dash/include/dash/view/ViewOrigin.h index a20a452c0..195d17346 100644 --- a/dash/include/dash/view/ViewOrigin.h +++ b/dash/include/dash/view/ViewOrigin.h @@ -1,14 +1,13 @@ #ifndef DASH__VIEW__VIEW_ORIGIN_H__INCLUDED #define DASH__VIEW__VIEW_ORIGIN_H__INCLUDED +#include +#include + #include #include #include -#include -#include -#include - namespace dash { diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index d9c5dff5c..b32b9f326 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -53,12 +53,6 @@ template class IndexSetIdentity; namespace detail { - /** - * Definition of type trait \c dash::detail::has_type_domain_type - * with static member \c value indicating whether type \c T provides - * dependent type \c domain_type. - */ - DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_type); DASH__META__DEFINE_TRAIT__HAS_TYPE(index_set_type); } @@ -111,7 +105,8 @@ namespace detail { dash::is_range::value >::is_local::value > is_local; - typedef typename ViewT::local_type local_type; +// typedef typename ViewT::local_type local_type; + typedef typename view_traits::local_type local_type; typedef typename ViewT::global_type global_type; typedef typename std::conditional::local_type local_type; typedef typename ContainerT::index_type index_type; typedef typename ContainerT::size_type size_type; typedef typename dash::IndexSetIdentity index_set_type; @@ -156,7 +152,8 @@ namespace detail { /// \c local_type typedef std::integral_constant::value > is_local; typedef std::integral_constant #include +#include #include From d5a7b721fbeb474e4ed5d861e97323e3b63818c6 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 10:58:24 +0200 Subject: [PATCH 040/161] Adding local views for iterator ranges --- dash/include/dash/Range.h | 165 +++------------------- dash/include/dash/view/IndexSet.h | 17 ++- dash/include/dash/view/Origin.h | 4 +- dash/include/dash/view/ViewIterator.h | 5 + dash/include/dash/view/ViewMod.h | 37 +---- dash/include/dash/view/ViewMod1D.h | 194 ++++++++++++++++++++++---- dash/include/dash/view/ViewTraits.h | 4 +- 7 files changed, 214 insertions(+), 212 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index f4bd5cd4f..f8a0bf301 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -55,69 +55,11 @@ #include #include -#include - #include -#include namespace dash { -// ----------------------------------------------------------------------- -// Forward-declarations - -template -struct view_traits; - -template -class IndexSetBase; - -template -class IndexSetIdentity; - -template -class IndexSetLocal; - -template -class IndexSetGlobal; - -template -class IndexSetSub; - -template -class IteratorRange; - -template -class IteratorRangeOrigin; - -template -class IteratorRangeOrigin; - -template < - class ViewModType, - class DomainType, - dim_t NDim > -class ViewModBase; - -template < - class DomainType, - dim_t NDim > -class ViewLocalMod; - -template < - class DomainType, - dim_t SubDim, - dim_t NDim > -class ViewSubMod; - -template < - class DomainType, - dim_t NDim > -class ViewGlobalMod; - -// ----------------------------------------------------------------------- - - namespace detail { template @@ -216,94 +158,33 @@ struct is_range : dash::detail::_is_range_type< > { }; -#if 0 - -template < - class RangeOrigin, - typename std::enable_if< - view_traits::is_local::value - > * = 0> -struct view_traits > -{ -private: - typedef IteratorRange RangeT; -public: - typedef RangeT domain_type; - typedef RangeT origin_type; - typedef RangeT image_type; - typedef RangeT global_type; - typedef RangeT local_type; - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; - typedef dash::IndexSetIdentity index_set_type; - - /// Whether the view type is a projection (has less dimensions than the - /// view's domain type). - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; - /// Whether the view / container type is a local view. - /// \note A container type is local if it is identical to its - /// \c local_type - typedef std::integral_constant is_local; - - typedef std::integral_constant rank; -}; - /** - * Specialization of adapter template for range concept, wraps `begin` - * and `end` pointers in range type. + * \concept{DashRangeConcept} */ -template < - typename LocalIterator, - typename LocalSentinel > -class IteratorRange -{ - typedef IteratorRange self_t; - - LocalIterator * _begin; - LocalSentinel * _end; - -public: - typedef LocalIterator * iterator; - typedef LocalSentinel * sentinel; - typedef const LocalIterator * const_iterator; - typedef const LocalSentinel * const_sentinel; - - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; - - typedef LocalIterator value_type; - - typedef iterator local_iterator; - typedef sentinel local_sentinel; - - typedef IteratorRange local_type; - typedef self_t global_type; - - typedef std::integral_constant is_local; - -public: - constexpr IteratorRange(iterator begin, sentinel end) - : _begin(begin) - , _end(end) - { } - - constexpr const_iterator begin() const { return _begin; } - constexpr const_sentinel end() const { return _end; } - - iterator begin() { return _begin; } - sentinel end() { return _end; } +template +constexpr auto begin(RangeType && range) + -> decltype(std::forward(range).begin()) { + return std::forward(range).begin(); +} - constexpr size_type size() const { return std::distance(_begin, _end); } - - constexpr const local_type & local() const { - return *this; - } -}; +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto end(RangeType && range) + -> decltype(std::forward(range).end()) { + return std::forward(range).end(); +} -#endif +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto +size(RangeType && r) + -> decltype(std::forward(r).size()) { + return std::forward(r).size(); +} } // namespace dash diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 3cedc542e..597100c9c 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -2,6 +2,7 @@ #define DASH__VIEW__INDEX_SET_H__INCLUDED #include +#include #include #include @@ -228,6 +229,7 @@ template < constexpr auto index(ContainerType && c) -> typename std::enable_if < + dash::view_traits::is_origin::value || !dash::view_traits::is_view::value, IndexSetIdentity >::type { @@ -241,6 +243,7 @@ template < constexpr auto index(const ContainerType & c) -> typename std::enable_if < + dash::view_traits::is_origin::value || !dash::view_traits::is_view::value, IndexSetIdentity >::type { @@ -292,12 +295,14 @@ template struct index_set_domain_bind_t { typedef typename std::conditional< - !dash::view_traits< + dash::view_traits< typename std::decay::type - >::is_origin::value, - DomainT, - const DomainT & >::type - type; + >::is_origin::value && + !std::is_copy_constructible::value, + const DomainT &, + DomainT + >::type + type; }; } // namespace detail @@ -345,7 +350,7 @@ class IndexSetBase typedef index_type value_type; - typedef typename detail::index_set_domain_bind_t::type + typedef typename detail::index_set_domain_bind_t::type domain_member_type; typedef std::integral_constant diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index 8232d2654..b1e139b58 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -26,7 +26,8 @@ origin(ViewT & view); template typename std::enable_if< - !dash::view_traits::type>::is_view::value, + view_traits::type>::is_origin::value || + !view_traits::type>::is_view::value, ContainerT >::type origin(ContainerT && container) { @@ -38,6 +39,7 @@ constexpr auto origin(const ViewT & view) -> typename std::enable_if< ( dash::view_traits::is_view::value && + !dash::view_traits::is_origin::value && !dash::view_traits::is_local::value ), const typename dash::view_traits::origin_type & >::type { diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index da3f17adf..9be908699 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -42,6 +42,7 @@ class ViewIterator typedef typename base_t::reference reference; typedef typename base_t::value_type value_type; typedef typename IndexSetType::index_type index_type; + typedef typename DomainIterator::pattern_type pattern_type; private: DomainIterator _domain_it; IndexSetType _index_set; @@ -113,6 +114,10 @@ class ViewIterator // explicit operator DomainIterator() { // return (_domain_it + _index_set[this->pos()]); // } + + constexpr const pattern_type & pattern() const { + return _domain_it.pattern(); + } }; template < diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index a45840cb6..3575343a7 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -145,34 +146,6 @@ class ViewGlobalMod; #endif // DOXYGEN -/** - * \concept{DashRangeConcept} - */ -template -constexpr auto begin(RangeType && range) - -> decltype(std::forward(range).begin()) { - return std::forward(range).begin(); -} - -/** - * \concept{DashRangeConcept} - */ -template -constexpr auto end(RangeType && range) - -> decltype(std::forward(range).end()) { - return std::forward(range).end(); -} - -/** - * \concept{DashRangeConcept} - */ -template -constexpr auto -size(RangeType && r) - -> decltype(std::forward(r).size()) { - return std::forward(r).size(); -} - /** * Write range of random access iterators to output stream. */ @@ -280,10 +253,10 @@ class ViewModBase public: typedef DomainType domain_type; - typedef typename std::conditional< - // try is_copyable, is_moveable - ( view_traits::is_origin::value - && !view_traits::is_view::value + typedef typename std::conditional<( + view_traits::is_origin::value && + !view_traits::is_view::value && + !std::is_copy_constructible::value ), const domain_type &, domain_type diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index a8f14b97e..e5469686f 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -442,52 +442,59 @@ class ViewGlobalMod // ------------------------------------------------------------------------ -// Iterator Range Origin +// Iterator Range Local Origin // ------------------------------------------------------------------------ template < class Iterator, class Sentinel > -class IteratorRangeOrigin; +class IteratorRangeLocalOrigin; template < class Iterator, class Sentinel > -struct view_traits > { +struct view_traits > { private: - typedef IteratorRangeOrigin RangeT; + typedef IteratorRangeLocalOrigin RangeT; public: typedef IteratorRangeOrigin domain_type; typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeOrigin image_type; + typedef RangeT image_type; typedef typename Iterator::pattern_type pattern_type; typedef std::integral_constant rank; - typedef ViewLocalMod< - IteratorRangeOrigin, 1> local_type; - typedef RangeT global_type; + typedef RangeT local_type; + typedef IteratorRangeOrigin global_type; typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef dash::IndexSetIdentity< - IteratorRangeOrigin > index_set_type; + typedef dash::IndexSetLocal index_set_type; typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant< - bool, std::is_pointer::value > is_local; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; }; - template < class Iterator, class Sentinel > -class IteratorRangeOrigin +class IteratorRangeLocalOrigin +: public ViewModBase< + IteratorRangeLocalOrigin, + IteratorRangeOrigin, + IteratorRangeOrigin::rank::value > { - typedef IteratorRangeOrigin self_t; + // Do not depend on DomainType (IndexRangeOrigin) and use Iterator, + // Sentinel in template parameters to decouple cyclic type dependency. + + typedef IteratorRangeLocalOrigin self_t; + typedef ViewModBase< + IteratorRangeLocalOrigin, + IteratorRangeOrigin, + IteratorRangeOrigin::rank::value > base_t; public: typedef Iterator iterator; typedef Iterator const_iterator; @@ -496,7 +503,7 @@ class IteratorRangeOrigin typedef IteratorRangeOrigin domain_type; typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeOrigin image_type; + typedef IteratorRangeLocalOrigin image_type; typedef typename iterator::value_type value_type; @@ -505,11 +512,12 @@ class IteratorRangeOrigin typedef typename iterator::pattern_type pattern_type; + typedef IndexSetLocal index_set_type; + typedef std::integral_constant rank; typedef std::integral_constant::value> is_local; - typedef ViewIterator< typename std::conditional< std::is_pointer::value, @@ -528,9 +536,132 @@ class IteratorRangeOrigin IndexSetLocal > local_sentinel; + typedef IteratorRangeOrigin global_type; + typedef self_t local_type; + +private: + index_set_type _index_set; + +public: + constexpr IteratorRangeLocalOrigin( + const IteratorRangeOrigin & range_origin) + : base_t(range_origin) + , _index_set(this->domain()) + { } + + constexpr local_iterator begin() const { + return local_iterator( + dash::begin( + this->domain()), + _index_set, 0); + } + + local_iterator begin() { + return local_iterator( + dash::begin( + this->domain()), + _index_set, 0); + } + + constexpr local_sentinel end() const { + return local_iterator( + dash::begin( + this->domain()), + _index_set, _index_set.size()); + } + + local_sentinel end() { + return local_iterator( + dash::begin( + this->domain()), + _index_set, _index_set.size()); + } + + constexpr size_type size() const { return _index_set.size(); } + + constexpr const pattern_type & pattern() const { + return this->begin().pattern(); + } + + constexpr const local_type & local() const { + return *this; + } + + local_type & local() { + return *this; + } +}; + +// ------------------------------------------------------------------------ +// Iterator Range Origin +// ------------------------------------------------------------------------ + +template < + class Iterator, + class Sentinel > +class IteratorRangeOrigin; + +template < + class Iterator, + class Sentinel > +struct view_traits > { +private: + typedef IteratorRangeOrigin RangeT; +public: + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; + + typedef typename Iterator::pattern_type pattern_type; + typedef std::integral_constant rank; + + typedef IteratorRangeLocalOrigin local_type; + typedef RangeT global_type; + + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef dash::IndexSetIdentity< + IteratorRangeOrigin > index_set_type; + + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant< + bool, std::is_pointer::value > is_local; +}; + + +template < + class Iterator, + class Sentinel > +class IteratorRangeOrigin +{ + typedef IteratorRangeOrigin self_t; +public: + typedef Iterator iterator; + typedef Iterator const_iterator; + typedef Sentinel sentinel; + typedef Sentinel const_sentinel; + + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; + + typedef typename iterator::value_type value_type; + + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef typename iterator::pattern_type pattern_type; + + typedef std::integral_constant rank; + + typedef std::integral_constant::value> + is_local; + typedef self_t global_type; - typedef IteratorRangeOrigin local_type; -//typedef ViewLocalMod local_type; + typedef IteratorRangeLocalOrigin local_type; private: iterator _begin; @@ -547,6 +678,12 @@ class IteratorRangeOrigin , _end(std::move(end)) { } + constexpr IteratorRangeOrigin() = delete; + constexpr IteratorRangeOrigin(const self_t & other) = default; + constexpr IteratorRangeOrigin(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + constexpr const_iterator begin() const { return _begin; } constexpr const_sentinel end() const { return _end; } @@ -560,9 +697,7 @@ class IteratorRangeOrigin } constexpr local_type local() const { - // for local_type: IteratorLocalView - return local_type(_begin.local(), _end.local()); - //return local_type(*this); + return local_type(*this); } }; @@ -588,7 +723,6 @@ class IteratorRangeOrigin typedef LocalIterator value_type; -//typedef ViewLocalMod local_type; typedef self_t global_type; typedef std::integral_constant is_local; @@ -599,6 +733,12 @@ class IteratorRangeOrigin , _end(end) { } + constexpr IteratorRangeOrigin() = delete; + constexpr IteratorRangeOrigin(const self_t & other) = default; + constexpr IteratorRangeOrigin(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + constexpr const_iterator begin() const { return _begin; } constexpr const_sentinel end() const { return _end; } @@ -606,10 +746,6 @@ class IteratorRangeOrigin sentinel end() { return _end; } constexpr size_type size() const { return std::distance(_begin, _end); } - -// constexpr const local_type & local() const { -// return *this; -// } }; diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index b32b9f326..6ea5e0933 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -133,8 +133,8 @@ namespace detail { typedef ContainerT domain_type; typedef ContainerT image_type; typedef ContainerT global_type; - //typedef typename ContainerT::local_type local_type; - typedef typename view_traits::local_type local_type; + typedef typename ContainerT::local_type local_type; + //typedef typename view_traits::local_type local_type; typedef typename ContainerT::index_type index_type; typedef typename ContainerT::size_type size_type; typedef typename dash::IndexSetIdentity index_set_type; From e2a15128ac00b78cd595e11ccb1c1410f504e615 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 12:18:30 +0200 Subject: [PATCH 041/161] Adding local views for iterator ranges --- dash/include/dash/view/ViewMod1D.h | 64 +++++++++++++++++++++++----- dash/test/algorithm/CopyTest.cc | 4 +- dash/test/algorithm/TransformTest.cc | 1 + 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index e5469686f..d9d53872f 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -614,6 +614,7 @@ struct view_traits > { typedef typename Iterator::pattern_type pattern_type; typedef std::integral_constant rank; +//typedef std::integral_constant rank; typedef IteratorRangeLocalOrigin local_type; typedef RangeT global_type; @@ -702,21 +703,60 @@ class IteratorRangeOrigin }; + +template < + class LocalIterator, + class LocalSentinel, + class IndexSet > +struct view_traits< + IteratorRangeOrigin< + ViewIterator, + ViewIterator + > > { +private: + typedef ViewIterator iterator; + typedef ViewIterator sentinel; + + typedef IteratorRangeOrigin RangeT; +public: + typedef RangeT domain_type; + typedef RangeT origin_type; + typedef RangeT image_type; + + typedef std::integral_constant rank; + + typedef RangeT local_type; +//typedef IteratorRangeLocalOrigin global_type; + + typedef typename iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef dash::IndexSetIdentity< + IteratorRangeOrigin > index_set_type; + + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; +}; + template < typename LocalIterator, - typename LocalSentinel > -class IteratorRangeOrigin + typename LocalSentinel, + typename IndexSet > +class IteratorRangeOrigin< + ViewIterator, + ViewIterator > { - typedef IteratorRangeOrigin self_t; - - LocalIterator * _begin; - LocalSentinel * _end; + typedef IteratorRangeOrigin< + ViewIterator, + ViewIterator > self_t; public: - typedef LocalIterator * iterator; - typedef LocalSentinel * sentinel; - typedef const LocalIterator * const_iterator; - typedef const LocalSentinel * const_sentinel; + typedef ViewIterator iterator; + typedef ViewIterator sentinel; + typedef ViewIterator const_iterator; + typedef ViewIterator const_sentinel; typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; @@ -727,6 +767,10 @@ class IteratorRangeOrigin typedef std::integral_constant is_local; +private: + iterator _begin; + sentinel _end; + public: constexpr IteratorRangeOrigin(iterator begin, sentinel end) : _begin(begin) diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 3b00107eb..191bdca5f 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -806,7 +806,7 @@ TEST_F(CopyTest, AsyncGlobalToLocalBlock) } } - +#if 0 TEST_F(CopyTest, GlobalToGlobal) { using value_t = int; @@ -851,8 +851,8 @@ TEST_F(CopyTest, GlobalToGlobal) } } ); - } +#endif #if 0 // TODO diff --git a/dash/test/algorithm/TransformTest.cc b/dash/test/algorithm/TransformTest.cc index 85370ec0c..f9f094065 100644 --- a/dash/test/algorithm/TransformTest.cc +++ b/dash/test/algorithm/TransformTest.cc @@ -261,3 +261,4 @@ TEST_F(TransformTest, LocalIteratorInput) global_v.barrier(); } + From 3877796ab71159b9c79a08f93ada17f7aecc1e21 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 13:39:13 +0200 Subject: [PATCH 042/161] Adding local views for iterator ranges --- dash/include/dash/view/ViewIterator.h | 1 + dash/include/dash/view/ViewMod1D.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 9be908699..c7226699f 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -147,6 +147,7 @@ class ViewIterator typedef DomainIterator & reference; typedef DomainIterator value_type; typedef std::ptrdiff_t index_type; + typedef self_t local_type; private: DomainIterator * _domain_it; IndexSetType _index_set; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index d9d53872f..56afd731e 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -656,14 +656,14 @@ class IteratorRangeOrigin typedef typename iterator::pattern_type pattern_type; - typedef std::integral_constant rank; - typedef std::integral_constant::value> is_local; typedef self_t global_type; typedef IteratorRangeLocalOrigin local_type; + typedef std::integral_constant rank; + private: iterator _begin; sentinel _end; @@ -767,6 +767,8 @@ class IteratorRangeOrigin< typedef std::integral_constant is_local; + typedef std::integral_constant rank; + private: iterator _begin; sentinel _end; @@ -858,14 +860,16 @@ class IteratorRange typedef self_t image_type; typedef typename domain_type::value_type value_type; - typedef typename domain_type::pattern_type pattern_type; - typedef std::integral_constant rank; +//typedef typename domain_type::pattern_type pattern_type; +//typedef std::integral_constant rank; + typedef std::integral_constant rank; typedef self_t global_type; typedef ViewLocalMod local_type; typedef std::integral_constant< + // !!! HERE !!! should test for ViewIterator bool, std::is_pointer::value> is_local; typedef dash::default_index_t index_type; From 9b5a7907e3dc9a90e869235907f68fc9c3808889 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 16:19:49 +0200 Subject: [PATCH 043/161] Redefining dash::transform with views/ranges --- dash/include/dash/Types.h | 77 +++++++++++++++---------- dash/include/dash/algorithm/Transform.h | 61 ++++++-------------- dash/include/dash/view/ViewMod1D.h | 17 ++++-- 3 files changed, 74 insertions(+), 81 deletions(-) diff --git a/dash/include/dash/Types.h b/dash/include/dash/Types.h index be0511854..9258650be 100644 --- a/dash/include/dash/Types.h +++ b/dash/include/dash/Types.h @@ -84,81 +84,76 @@ struct Extent { ::std::array sizes; }; -#ifdef DOXYGEN - -/** - * Type trait for mapping to DART data types. - */ -template -struct dart_datatype { - static constexpr const dart_datatype_t value; -}; -/** - * Type trait for mapping to punned DART data type for reduce operations. - */ -template -struct dart_punned_datatype { - static constexpr const dart_datatype_t value; -}; - -#else +namespace internal { template -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_UNDEFINED; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_BYTE; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_BYTE; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_SHORT; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_SHORT; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_INT; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_UINT; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_FLOAT; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_LONG; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_ULONG; }; template<> -struct dart_datatype { +struct dart_datatype_ { static constexpr const dart_datatype_t value = DART_TYPE_DOUBLE; }; +} // namespace internal + +/** + * Type trait for mapping to DART data types. + */ +template +struct dart_datatype +: public dash::internal::dart_datatype_< + typename std::remove_const< + typename std::remove_reference::type + >::type > { +}; namespace internal { @@ -189,16 +184,34 @@ struct dart_pun_datatype_size<8> } // namespace internal +#ifdef DOXYGEN + +/** + * Type trait for mapping to punned DART data type for reduce operations. + */ +template +struct dart_punned_datatype { + static constexpr const dart_datatype_t value; +}; + +#else + template struct dart_punned_datatype { +private: + typedef typename std::remove_const< + typename std::remove_reference::type + >::type + TDec; +public: static constexpr const dart_datatype_t value = std::conditional< // only use type punning if T is not a DART // data type: - dash::dart_datatype::value + dash::dart_datatype::value == DART_TYPE_UNDEFINED, - internal::dart_pun_datatype_size, - dash::dart_datatype + internal::dart_pun_datatype_size, + dash::dart_datatype >::type::value; }; diff --git a/dash/include/dash/algorithm/Transform.h b/dash/include/dash/algorithm/Transform.h index e692a9810..36f0bba47 100644 --- a/dash/include/dash/algorithm/Transform.h +++ b/dash/include/dash/algorithm/Transform.h @@ -296,65 +296,40 @@ GlobOutputIt transform( BinaryOperation binary_op) { DASH_LOG_DEBUG("dash::transform(af, al, bf, outf, binop)"); - auto &pattern = out_first.pattern(); // Outut range different from rhs input range is not supported yet - ValueType* in_first = &(*in_a_first); - ValueType* in_last = &(*in_a_last); - // Number of elements in local range: - size_t num_local_elements = std::distance(in_first, in_last); - auto out_last = out_first + num_local_elements; - if (out_last.gpos() > pattern.size()) { - DASH_THROW(dash::exception::OutOfRange, - "Too many input elements in dash::transform"); - } + ValueType * in_first = &(*in_a_first); + ValueType * in_last = &(*in_a_last); + std::vector in_range; if (in_b_first == out_first) { // Output range is rhs input range: C += A // Input is (in_a_first, in_a_last). } else { // Output range different from rhs input range: C = A+B // Input is (in_a_first, in_a_last) + (in_b_first, in_b_last): - dash::copy( + std::transform( + in_a_first, in_a_last, in_b_first, - in_b_first + std::distance(in_a_first, in_a_last), - out_first); + std::back_inserter(in_range), + binary_op); + in_first = in_range.data(); + in_last = in_first + in_range.size(); } dash::util::Trace trace("transform"); + // Resolve local range from global range: + // Number of elements in local range: + size_t num_local_elements = std::distance(in_first, in_last); // Global iterator to dart_gptr_t: dart_gptr_t dest_gptr = out_first.dart_gptr(); // Send accumulate message: - auto &team = pattern.team(); - size_t towrite = num_local_elements; - auto out_it = out_first; - auto in_it = in_first; - while (towrite > 0) { - auto lpos = out_it.lpos(); - size_t lsize = pattern.local_size(lpos.unit); - size_t num_values = std::min(lsize - lpos.index, towrite); - dart_gptr_t dest_gptr = out_it.dart_gptr(); - // use non-blocking transform and wait for all at the end - dash::internal::transform_impl( + trace.enter_state("transform_blocking"); + dash::internal::transform_blocking_impl( dest_gptr, - in_it, - num_values, + in_first, + num_local_elements, binary_op.dart_operation()); - out_it += num_values; - in_it += num_values; - towrite -= num_values; - } - -// out_first.team().barrier(); - dart_flush_all(out_first.dart_gptr()); - - -// trace.enter_state("transform_blocking"); -// dash::internal::transform_blocking_impl( -// dest_gptr, -// in_first, -// num_local_elements, -// binary_op.dart_operation()); -// trace.exit_state("transform_blocking"); + trace.exit_state("transform_blocking"); // The position past the last element transformed in global element space // cannot be resolved from the size of the local range if the local range // spans over more than one block. Otherwise, the difference of two global @@ -370,7 +345,7 @@ GlobOutputIt transform( // For ranges over block borders, we would have to resolve the global // position past the last element transformed from the iterator's pattern // (see dash::PatternIterator). - return out_it; + return out_first + num_local_elements; } /** diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 56afd731e..cd4ae2c35 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -198,7 +198,7 @@ class ViewLocalMod private: typedef ViewLocalMod self_t; typedef ViewModBase< - ViewLocalMod, DomainType, 1 > base_t; + ViewLocalMod, DomainType > base_t; public: typedef dash::IndexSetLocal index_set_type; typedef self_t local_type; @@ -614,10 +614,9 @@ struct view_traits > { typedef typename Iterator::pattern_type pattern_type; typedef std::integral_constant rank; -//typedef std::integral_constant rank; - typedef IteratorRangeLocalOrigin local_type; typedef RangeT global_type; + typedef IteratorRangeLocalOrigin local_type; typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; @@ -626,7 +625,7 @@ struct view_traits > { IteratorRangeOrigin > index_set_type; typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; + typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant< bool, std::is_pointer::value > is_local; @@ -704,6 +703,10 @@ class IteratorRangeOrigin +// ------------------------------------------------------------------------ +// Iterator Range Origin (local pointers) +// ------------------------------------------------------------------------ + template < class LocalIterator, class LocalSentinel, @@ -725,8 +728,8 @@ struct view_traits< typedef std::integral_constant rank; + typedef RangeT global_type; typedef RangeT local_type; -//typedef IteratorRangeLocalOrigin global_type; typedef typename iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; @@ -735,7 +738,7 @@ struct view_traits< IteratorRangeOrigin > index_set_type; typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; + typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant is_local; }; @@ -765,6 +768,8 @@ class IteratorRangeOrigin< typedef self_t global_type; + typedef typename IndexSet::pattern_type pattern_type; + typedef std::integral_constant is_local; typedef std::integral_constant rank; From 876f55eabf59d149c635eec9f628061a29cb9826 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 16:43:05 +0200 Subject: [PATCH 044/161] Extended ex.02.array-copy --- dash/examples/ex.02.array-copy/main.cpp | 39 ++++++++++++++++--------- dash/include/dash/algorithm/Copy.h | 6 ++-- dash/test/algorithm/CopyTest.cc | 2 -- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index b95c8552c..61b4f93a5 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -1,6 +1,8 @@ /* * \example ex.02.array-copy\main.cpp - * Example illustrating the use of \c dash::copy with a local array as destination. + * + * Example illustrating the use of \c dash::copy with a local array + * as destination. */ #include @@ -54,35 +56,44 @@ int main(int argc, char* argv[]) cout << "Array size: " << array.size() << endl; } + // ---------------------------------------------------------------------- + // global-to-local copy: + // ---------------------------------------------------------------------- + // destination array int * local_array = new int[num_elems_copy]; -#ifdef DASH_ENABLE_IPM - MPI_Pcontrol(0, "on"); // turn monitoring on - MPI_Pcontrol(0, "clear"); // clear all performance data -#endif - - // each unit copies from the global array into it's own local array - // note: each unit has the same data in it's local array at the end dash::copy(array.begin() + start_index, array.begin() + start_index + num_elems_copy, local_array); -#ifdef DASH_ENABLE_IPM - MPI_Pcontrol(0, "off"); // turn monitoring off -#endif - std::ostringstream ss; ss << "Local copy at unit " << myid << ": "; for(size_t i = 0; i < num_elems_copy; ++i) { ss << local_array[i] << " "; } - ss << endl; + ss << endl; cout << ss.str(); + delete[] local_array; + + array.barrier(); + + // ---------------------------------------------------------------------- + // global-to-global copy: + // ---------------------------------------------------------------------- + + dash::Array src_array(num_elems_total / 2); + + std::fill(array.lbegin(), array.lend(), (myid + 1) * 10); + array.barrier(); + + dash::copy(src_array.begin(), + src_array.end(), + array.begin() + (array.size() / 4)); + array.barrier(); - delete[] local_array; dash::finalize(); diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 63b996775..59aca47f1 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1121,9 +1121,9 @@ template < class GlobInputIt, class GlobOutputIt > GlobOutputIt copy( - GlobInputIt in_first, - GlobInputIt in_last, - GlobOutputIt out_first) + GlobInputIt in_first, + GlobInputIt in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 191bdca5f..7882a2942 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -806,7 +806,6 @@ TEST_F(CopyTest, AsyncGlobalToLocalBlock) } } -#if 0 TEST_F(CopyTest, GlobalToGlobal) { using value_t = int; @@ -852,7 +851,6 @@ TEST_F(CopyTest, GlobalToGlobal) } ); } -#endif #if 0 // TODO From 911851f9d5c44355ed225902127d4830bd7a60c6 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 16:56:32 +0200 Subject: [PATCH 045/161] Extended ex.02.array-copy --- dash/include/dash/algorithm/Copy.h | 6 +++--- dash/include/dash/view/ViewMod1D.h | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 59aca47f1..09da89131 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1141,9 +1141,9 @@ GlobOutputIt copy( auto out_l_range = dash::local(out_g_range); auto in_l_range = dash::local(in_g_range); // copy local to global range: - auto out_l_end = dash::copy(dash::begin(in_l_range), - dash::end(in_l_range), - dash::begin(out_l_range)); + 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; } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index cd4ae2c35..785600da7 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -516,8 +516,7 @@ class IteratorRangeLocalOrigin typedef std::integral_constant rank; - typedef std::integral_constant::value> - is_local; + typedef std::integral_constant is_local; typedef ViewIterator< typename std::conditional< std::is_pointer::value, @@ -627,8 +626,7 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; typedef std::integral_constant is_origin; - typedef std::integral_constant< - bool, std::is_pointer::value > is_local; + typedef std::integral_constant is_local; }; @@ -655,8 +653,7 @@ class IteratorRangeOrigin typedef typename iterator::pattern_type pattern_type; - typedef std::integral_constant::value> - is_local; + typedef std::integral_constant is_local; typedef self_t global_type; typedef IteratorRangeLocalOrigin local_type; @@ -874,8 +871,9 @@ class IteratorRange typedef ViewLocalMod local_type; typedef std::integral_constant< - // !!! HERE !!! should test for ViewIterator - bool, std::is_pointer::value> is_local; + // !!! HERE !!! should test for ViewIterator + //bool, std::is_pointer::value> is_local; + bool, view_traits::is_local::value> is_local; typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; From d87c51dcdd7172e5e25bf842bdecb6b61859de88 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 1 Jun 2017 17:41:45 +0200 Subject: [PATCH 046/161] Extended ex.02.array-copy --- dash/include/dash/algorithm/Copy.h | 15 +++++++-------- dash/include/dash/view/ViewMod1D.h | 28 +++++++++++++--------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 09da89131..5ea4ef41c 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1135,16 +1135,15 @@ GlobOutputIt copy( auto out_h_last = out_first + num_elements; // in/out ranges in global domain: - auto out_g_range = dash::make_range(out_first, out_h_last); - auto in_g_range = dash::make_range(in_first, in_last); + auto out_g_range = dash::make_range(out_first, out_h_last); + const auto & in_g_range = dash::make_range(in_first, in_last); // local view on in/out ranges: - auto out_l_range = dash::local(out_g_range); - auto in_l_range = dash::local(in_g_range); + auto out_l_range = dash::local(out_g_range); + const auto & in_l_range = dash::local(in_g_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)); - + 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; } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 785600da7..9ae585791 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -518,20 +518,12 @@ class IteratorRangeLocalOrigin typedef std::integral_constant is_local; typedef ViewIterator< - typename std::conditional< - std::is_pointer::value, - iterator, - typename iterator::local_type - >::type, + typename iterator::local_type, IndexSetLocal > local_iterator; typedef ViewIterator< - typename std::conditional< - std::is_pointer::value, - sentinel, - typename sentinel::local_type - >::type, + typename sentinel::local_type, IndexSetLocal > local_sentinel; @@ -551,28 +543,34 @@ class IteratorRangeLocalOrigin constexpr local_iterator begin() const { return local_iterator( dash::begin( - this->domain()), + dash::local( + this->domain())), _index_set, 0); } local_iterator begin() { return local_iterator( dash::begin( - this->domain()), + dash::local( + const_cast( + dash::domain(*this)))), _index_set, 0); } constexpr local_sentinel end() const { return local_iterator( dash::begin( - this->domain()), + dash::local( + this->domain())), _index_set, _index_set.size()); } local_sentinel end() { return local_iterator( dash::begin( - this->domain()), + dash::local( + const_cast( + dash::domain(*this)))), _index_set, _index_set.size()); } @@ -624,7 +622,7 @@ struct view_traits > { IteratorRangeOrigin > index_set_type; typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; + typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant is_local; }; From 7e15ff78d9163ae441580ceed2c75425e47f3516 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 2 Jun 2017 22:02:28 +0200 Subject: [PATCH 047/161] Cleanup in view headers --- dash/include/dash/algorithm/Copy.h | 133 ++++--- dash/include/dash/view/Domain.h | 9 +- dash/include/dash/view/IndexRange.h | 21 +- dash/include/dash/view/IndexSet.h | 2 +- dash/include/dash/view/Local.h | 21 +- dash/include/dash/view/MakeRange.h | 200 ----------- dash/include/dash/view/ViewBlocksMod.h | 42 ++- dash/include/dash/view/ViewMod.h | 45 +-- dash/include/dash/view/ViewMod1D.h | 467 +++++++++++++------------ dash/test/TestBase.h | 1 - 10 files changed, 405 insertions(+), 536 deletions(-) delete mode 100644 dash/include/dash/view/MakeRange.h diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 5ea4ef41c..048dfd4ba 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -14,7 +14,6 @@ #include #include #include -#include #include @@ -91,8 +90,8 @@ OutputIt copy( * \endcode * * \returns An instance of \c dash::Future providing the output range end - * iterator that is created on completion of the asynchronous copy - * operation. + * iterator that is created on completion of the asynchronous + * copy operation. * * \ingroup DashAlgorithms */ @@ -108,9 +107,9 @@ dash::Future copy_async( namespace internal { -// ========================================================================= +// ======================================================================= // Global to Local -// ========================================================================= +// ======================================================================= /** * Blocking implementation of \c dash::copy (global to local) without @@ -141,8 +140,8 @@ ValueType * copy_block( "expected out_last:", out_first + num_elem_total); // Input iterators could be relative to a view. Map first input iterator // to global index range and use it to resolve last input iterator. - // Do not use in_last.global() as this would span over the relative input - // range. + // Do not use in_last.global() as this would span over the relative + // input range. auto g_in_first = in_first.global(); auto g_in_last = g_in_first + num_elem_total; DASH_LOG_TRACE("dash::copy_block", @@ -195,7 +194,8 @@ ValueType * copy_block( } } else { // Input range is spread over several remote units: - DASH_LOG_TRACE("dash::copy_block", "input range spans multiple units"); + DASH_LOG_TRACE("dash::copy_block", + "input range spans multiple units"); // // Copy elements from every unit: // @@ -286,8 +286,8 @@ dash::Future copy_block_async( "expected out_last:", out_first + num_elem_total); // Input iterators could be relative to a view. Map first input iterator // to global index range and use it to resolve last input iterator. - // Do not use in_last.global() as this would span over the relative input - // range. + // Do not use in_last.global() as this would span over the relative + // input range. auto g_in_first = in_first.global(); auto g_in_last = g_in_first + num_elem_total; DASH_LOG_TRACE("dash::copy_block_async", @@ -313,7 +313,8 @@ dash::Future copy_block_async( } if (unit_first == unit_last) { // Input range is located at a single remote unit: - DASH_LOG_TRACE("dash::copy_block_async", "input range at single unit"); + DASH_LOG_TRACE("dash::copy_block_async", + "input range at single unit"); while (num_elem_copied < num_elem_total) { // Number of elements left to copy: auto total_elem_left = num_elem_total - num_elem_copied; @@ -446,9 +447,9 @@ dash::Future copy_block_async( return result; } -// ========================================================================= +// ======================================================================= // Local to Global -// ========================================================================= +// ======================================================================= /** * Blocking implementation of \c dash::copy (local to global) without @@ -568,12 +569,13 @@ dash::Future copy_block_async( -// ========================================================================= +// ======================================================================= // Global to Local, Distributed Range -// ========================================================================= +// ======================================================================= /** - * Variant of \c dash::copy as asynchronous global-to-local copy operation. + * Variant of \c dash::copy as asynchronous global-to-local copy + * operation. * * \ingroup DashAlgorithms */ @@ -611,9 +613,9 @@ dash::Future copy_async( // Total number of elements to be copied: auto total_copy_elem = in_last - in_first; - // Instead of testing in_first.local() and in_last.local(), this test for - // a local-only range only requires one call to in_first.local() which - // increases throughput by ~10% for local ranges. + // Instead of testing in_first.local() and in_last.local(), this test + // for a local-only range only requires one call to in_first.local() + // which increases throughput by ~10% for local ranges. if (num_local_elem == total_copy_elem) { // Entire input range is local: DASH_LOG_TRACE("dash::copy_async", "entire input range is local"); @@ -647,8 +649,8 @@ dash::Future copy_async( auto futures = std::vector< dash::Future >(); // Check if global input range is partially local: if (num_local_elem > 0) { - // Part of the input range is local, copy local input subrange to local - // output range directly. + // Part of the input range is local, copy local input subrange to + // local output range directly. auto pattern = in_first.pattern(); // Map input iterators to global index domain: auto g_in_first = in_first.global(); @@ -659,21 +661,27 @@ dash::Future copy_async( // Global index of local range begin index: auto g_l_offset_begin = pattern.global(li_range_in.begin); // Global index of local range end index: - auto g_l_offset_end = pattern.global(li_range_in.end-1) - + 1; // pat.global(l_end) would be out of range + // + // NOTE: definition as pat.global(l_end-1)+1 as + // pat.global(l_end) would be out of range + auto g_l_offset_end = pattern.global(li_range_in.end-1) + 1; DASH_LOG_TRACE("dash::copy_async", "global index range of local subrange:", "begin:", g_l_offset_begin, "end:", g_l_offset_end); // Global position of input start iterator: auto g_offset_begin = g_in_first.pos(); // Convert local subrange to global iterators: - auto g_l_in_first = g_in_first + (g_l_offset_begin - g_offset_begin); - auto g_l_in_last = g_in_first + (g_l_offset_end - g_offset_begin); - DASH_LOG_TRACE("dash::copy_async", "global it. range of local subrange:", - "begin:", g_l_in_first.pos(), "end:", g_l_in_last.pos()); + auto g_l_in_first = g_in_first + + (g_l_offset_begin - g_offset_begin); + auto g_l_in_last = g_in_first + + (g_l_offset_end - g_offset_begin); + DASH_LOG_TRACE("dash::copy_async", + "global it. range of local subrange:", + "begin:", g_l_in_first.pos(), + "end:", g_l_in_last.pos()); DASH_LOG_TRACE_VAR("dash::copy_async", g_l_in_last.pos()); // - // ----------------------------------------------------------------------- + // ------------------------------------------------------------------- // Copy remote elements preceding the local subrange: // auto num_prelocal_elem = g_l_in_first.pos() - g_in_first.pos(); @@ -695,7 +703,7 @@ dash::Future copy_async( dest_first = out_last; } // - // ----------------------------------------------------------------------- + // ------------------------------------------------------------------- // Copy remote elements succeeding the local subrange: // auto num_postlocal_elem = in_last.pos() - g_l_offset_end; @@ -716,7 +724,7 @@ dash::Future copy_async( out_last += num_postlocal_elem; } // - // ----------------------------------------------------------------------- + // ------------------------------------------------------------------- // Copy local subrange: // // Convert local subrange of global input to native pointers: @@ -774,7 +782,8 @@ dash::Future copy_async( for (auto f : futures) { f.wait(); } - DASH_LOG_TRACE("dash::copy_async [Future] >", "async requests completed", + DASH_LOG_TRACE("dash::copy_async [Future] >", + "async requests completed", "futures:", futures, "_out:", _out); return _out; }); @@ -820,9 +829,9 @@ ValueType * copy( // Total number of elements to be copied: auto total_copy_elem = in_last - in_first; - // Instead of testing in_first.local() and in_last.local(), this test for - // a local-only range only requires one call to in_first.local() which - // increases throughput by ~10% for local ranges. + // Instead of testing in_first.local() and in_last.local(), this test + // for a local-only range only requires one call to in_first.local() + // which increases throughput by ~10% for local ranges. if (num_local_elem == total_copy_elem) { // Entire input range is local: DASH_LOG_TRACE("dash::copy", "entire input range is local"); @@ -851,8 +860,8 @@ ValueType * copy( "in_first.is_local:", in_first.is_local()); // Check if global input range is partially local: if (num_local_elem > 0) { - // Part of the input range is local, copy local input subrange to local - // output range directly. + // Part of the input range is local, copy local input subrange to + // local output range directly. auto pattern = in_first.pattern(); // Map input iterators to global index domain: auto g_in_first = in_first.global(); @@ -863,8 +872,10 @@ ValueType * copy( // Global index of local range begin index: auto g_l_offset_begin = pattern.global(li_range_in.begin); // Global index of local range end index: - auto g_l_offset_end = pattern.global(li_range_in.end-1) - + 1; // pat.global(l_end) would be out of range + // + // NOTE: definition as pat.global(l_end-1)+1 as + // pat.global(l_end) would be out of range + auto g_l_offset_end = pattern.global(li_range_in.end-1) + 1; DASH_LOG_TRACE("dash::copy", "global index range of local subrange:", "begin:", g_l_offset_begin, "end:", g_l_offset_end); @@ -872,10 +883,13 @@ ValueType * copy( // Global position of input start iterator: auto g_offset_begin = g_in_first.pos(); // Convert local subrange to global iterators: - auto g_l_in_first = g_in_first + (g_l_offset_begin - g_offset_begin); - auto g_l_in_last = g_in_first + (g_l_offset_end - g_offset_begin); + auto g_l_in_first = g_in_first + + (g_l_offset_begin - g_offset_begin); + auto g_l_in_last = g_in_first + + (g_l_offset_end - g_offset_begin); DASH_LOG_TRACE("dash::copy", "global it. range of local subrange:", - "begin:", g_l_in_first.pos(), "end:", g_l_in_last.pos()); + "begin:", g_l_in_first.pos(), + "end:", g_l_in_last.pos()); DASH_LOG_TRACE_VAR("dash::copy", g_l_in_last.pos()); auto num_prelocal_elem = g_l_in_first.pos() - g_in_first.pos(); @@ -884,7 +898,7 @@ ValueType * copy( DASH_LOG_TRACE_VAR("dash::copy", num_postlocal_elem); // - // ----------------------------------------------------------------------- + // ------------------------------------------------------------------- // Copy remote elements preceding the local subrange: // if (num_prelocal_elem > 0) { @@ -902,7 +916,7 @@ ValueType * copy( dest_first = out_last; } // - // ----------------------------------------------------------------------- + // ------------------------------------------------------------------- // Copy local subrange: // // Convert local subrange of global input to native pointers: @@ -935,14 +949,15 @@ ValueType * copy( } // Assert that all elements in local range have been copied: DASH_ASSERT_EQ(out_last, dest_first + num_local_elem, - "Expected to copy " << num_local_elem << " local elements " + "Expected to copy " << num_local_elem << + " local elements " "but copied " << (out_last - dest_first)); DASH_LOG_TRACE("dash::copy", "finished local copy of", (out_last - dest_first), "elements"); // Advance output pointers: dest_first = out_last; // - // ----------------------------------------------------------------------- + // ------------------------------------------------------------------- // Copy remote elements succeeding the local subrange: // if (num_postlocal_elem > 0) { @@ -970,12 +985,13 @@ ValueType * copy( } -// ========================================================================= +// ====================================================================== // Local to Global, Distributed Range -// ========================================================================= +// ====================================================================== /** - * Variant of \c dash::copy as asynchronous local-to-global copy operation. + * Variant of \c dash::copy as asynchronous local-to-global copy + * operation. * Output iterator type must specify dependent pattern type as * \c GlobOutputIt::pattern_type. * @@ -994,8 +1010,8 @@ auto copy_async( >::type { DASH_LOG_TRACE("dash::copy_async()", "blocking, local to global"); - // Return value, initialize with begin of output range, indicating no values - // have been copied: + // Return value, initialize with begin of output range, indicating no + // values have been copied: GlobOutputIt out_last = out_first; // Number of elements to copy in total: auto num_elements = std::distance(in_first, in_last); @@ -1009,7 +1025,8 @@ auto copy_async( auto out_blocks = dash::blocks(out_range); auto in_copy_it = in_first; - DASH_LOG_TRACE("dash::copy_async", "number of blocks:", out_blocks.size()); + DASH_LOG_TRACE("dash::copy_async", + "number of blocks:", out_blocks.size()); for (auto block : out_blocks) { DASH_LOG_TRACE("dash::copy_async", "block size:", block.size()); futures.push_back(static_cast>( @@ -1030,7 +1047,8 @@ auto copy_async( for (auto f : futures) { f.wait(); } - DASH_LOG_TRACE("dash::copy_async [Future] >", "async requests completed", + DASH_LOG_TRACE("dash::copy_async [Future] >", + "async requests completed", "futures:", futures, "_out:", _out); return _out; }); @@ -1040,7 +1058,8 @@ auto copy_async( } /** - * Variant of \c dash::copy as asynchronous local-to-global copy operation. + * Variant of \c dash::copy as asynchronous local-to-global copy + * operation. * Output iterator type must specify dependent pattern type as * \c GlobOutputIt::pattern_type. * @@ -1148,9 +1167,9 @@ GlobOutputIt copy( } -// ========================================================================= +// ====================================================================== // Other Specializations -// ========================================================================= +// ====================================================================== #ifdef DASH_EXPERIMENTAL /* @@ -1161,8 +1180,8 @@ GlobOutputIt copy( * Returns a future of a local range { begin, end }. * If the requested data range is in shared memory, the range returned * references the native pointers of the target range. - * If the requested data range needed to be copied from remote memory, the - * range returned is the copied destination range such that + * If the requested data range needed to be copied from remote memory, + * the range returned is the copied destination range such that * \c (begin = out_first). * and * \c (end = out_first + num_elem_copied.) diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index f99f5bfdb..0795f5928 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -35,11 +35,10 @@ template < constexpr auto domain(ViewT && view) -> typename std::enable_if< - // dash::view_traits::is_view::value, dash::detail::has_type_domain_type::value, - decltype(std::forward(view).domain()) + typename std::decay::type >::type { - return std::forward(view).domain(); + return std::move(view).domain(); } template @@ -47,10 +46,8 @@ constexpr auto domain(const ViewT & view) -> typename std::enable_if< dash::detail::has_type_domain_type::value, - // dash::view_traits::is_view::value, decltype(view.domain()) // const typename dash::view_traits::domain_type & - // const typename ViewT::domain_type & >::type { return view.domain(); } @@ -66,7 +63,6 @@ template < class ContainerT, typename ContainerValueT = typename std::decay::type > constexpr typename std::enable_if< -//!dash::view_traits::is_view::value, !dash::detail::has_type_domain_type::value, ContainerT & >::type @@ -82,7 +78,6 @@ template < class ContainerT, typename ContainerValueT = typename std::decay::type > constexpr typename std::enable_if< -//!dash::view_traits::is_view::value, !dash::detail::has_type_domain_type::value, const ContainerT & >::type diff --git a/dash/include/dash/view/IndexRange.h b/dash/include/dash/view/IndexRange.h index 8333fa68e..365fb8ee6 100644 --- a/dash/include/dash/view/IndexRange.h +++ b/dash/include/dash/view/IndexRange.h @@ -10,35 +10,36 @@ namespace dash { -// N-dimensional index range +/** + * Multidimensional index range. + */ template < dim_t NDim, typename IndexType > -class IndexRange -{ +class IndexRange { typedef IndexRange self_t; // One-dimensional index range in every dimension: std::array< IndexRange<1, IndexType>, NDim > _ranges; -public: + public: template constexpr self_t sub(IndexType first, IndexType last) const { return self_t(*this); // _ranges[SDim].sub(first, last) } }; -// Specialization for one-dimensional index range -template < - typename IndexType > -class IndexRange<1, IndexType> -{ +/** + * Specialization for one-dimensional index range + */ +template +class IndexRange<1, IndexType> { typedef IndexRange<1, IndexType> self_t; IndexType _first; IndexType _last; -public: + public: constexpr IndexRange(IndexType first, IndexType last) : _first(first) , _last(last) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 597100c9c..75cd700e4 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -147,7 +147,7 @@ index(DomainType && v) dash::view_traits::is_view::value, typename std::decay::type >::type { - return v.index_set(); + return std::move(v).index_set(); } template < diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index dc833213b..4106048f1 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -56,15 +56,30 @@ template < = typename std::decay::type > constexpr typename std::enable_if< - ( !dash::view_traits::is_view::value && - !dash::view_traits::is_local::value && - dash::view_traits::is_origin::value ), + ( !dash::view_traits::is_local::value && + !std::is_member_function_pointer< + decltype(&ContainerDecayType::local)>::value ), const typename ContainerType::local_type & >::type local(const ContainerType & c) { return c.local; } +template < + class ContainerType, + typename ContainerDecayType + = typename std::decay::type > +constexpr +typename std::enable_if< + ( !dash::view_traits::is_local::value && + std::is_member_function_pointer< + decltype(&ContainerDecayType::local)>::value ), + decltype(std::declval.local()) +>::type +local(const ContainerType & c) { + return c.local(); +} + #if 0 /** * \concept{DashViewConcept} diff --git a/dash/include/dash/view/MakeRange.h b/dash/include/dash/view/MakeRange.h deleted file mode 100644 index 1a8cda691..000000000 --- a/dash/include/dash/view/MakeRange.h +++ /dev/null @@ -1,200 +0,0 @@ -#ifndef DASH__VIEW__MAKE_RANGE_H__INCLUDED -#define DASH__VIEW__MAKE_RANGE_H__INCLUDED - -#include -#include - -// #include -// #include -// #include -#include - - - -namespace dash { - -#ifndef DOXYGEN - -// Related: boost::range -// -// https://github.com/boostorg/range/tree/develop/include/boost/range -// - -template -struct view_traits; - -// Forward-declaration -template -class IndexSetIdentity; - -template -class IndexSetSub; - -// Forward-declaration -template -class IteratorRange; - -#endif - - -#if 0 -template < - typename IteratorT, - typename SentinelT > -struct view_traits > { -private: - typedef IteratorRange RangeT; -public: - typedef RangeT domain_type; - typedef RangeT origin_type; - typedef RangeT image_type; - typedef RangeT global_type; - typedef RangeT local_type; - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; - typedef dash::IndexSetIdentity index_set_type; - - /// Whether the view type is a projection (has less dimensions than the - /// view's domain type). - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; - /// Whether the view / container type is a local view. - /// \note A container type is local if it is identical to its - /// \c local_type - typedef std::integral_constant is_local; - - typedef std::integral_constant rank; -}; - -/** - * Specialization of adapter template for range concept, wraps `begin` - * and `end` pointers in range type. - */ -template < - typename LocalIterator, - typename LocalSentinel > -class IteratorRange -{ - typedef IteratorRange self_t; - - LocalIterator * _begin; - LocalSentinel * _end; - -public: - typedef LocalIterator * iterator; - typedef LocalSentinel * sentinel; - typedef const LocalIterator * const_iterator; - typedef const LocalSentinel * const_sentinel; - - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; - - typedef LocalIterator value_type; - - typedef iterator local_iterator; - typedef sentinel local_sentinel; - - typedef IteratorRange local_type; - typedef self_t global_type; - - typedef std::integral_constant is_local; - -public: - constexpr IteratorRange(iterator begin, sentinel end) - : _begin(begin) - , _end(end) - { } - - constexpr const_iterator begin() const { return _begin; } - constexpr const_sentinel end() const { return _end; } - - iterator begin() { return _begin; } - sentinel end() { return _end; } - - constexpr size_type size() const { return std::distance(_begin, _end); } - - constexpr const local_type & local() const { - return *this; - } -}; - -/** - * Adapter utility function. - * Wraps `begin` and `end` pointers in range type. - */ -template < - class Iterator, - class Sentinel, - typename std::enable_if< std::is_pointer::value > * = nullptr > -constexpr dash::IteratorRange -make_range( - Iterator * begin, - Sentinel * end) { - return dash::IteratorRange( - begin, - end); -} -#endif - -#if 1 -/* -template -constexpr dash::IteratorRange< - typename std::decay::type, - typename std::decay::type > -make_range(Iterator && begin, Sentinel && end) { - return dash::IteratorRange< - typename std::decay::type, - typename std::decay::type - >(std::forward(begin), - std::forward(end)); -} - -template -constexpr dash::IteratorRange< - dash::IteratorRangeOrigin< - typename std::decay::type, - typename std::decay::type > > -make_range(Iterator && begin, Sentinel && end) { - return dash::IteratorRange< - dash::IteratorRangeOrigin< - typename std::decay::type, - typename std::decay::type > - >(std::forward(begin), - std::forward(end)); -} -*/ -#else -/** - * Adapter utility function. - * Wraps `begin` and `end` iterators in range type. - */ -template < - class Iterator, - class Sentinel, - typename IteratorDT = typename std::decay::type, - typename SentinelDT = typename std::decay::type, - typename std::enable_if< !std::is_pointer::value > * = nullptr > -auto -make_range( - const Iterator & begin, - const Sentinel & end) - -> decltype( - dash::sub(begin.pos(), - end.pos(), - dash::IteratorRange( - begin - begin.pos(), - begin + (begin.pattern().size() - begin.pos())))) { - return dash::sub(begin.pos(), - end.pos(), - dash::IteratorRange( - begin - begin.pos(), - begin + (begin.pattern().size() - begin.pos()))); -} -#endif - -} // namespace dash - -#endif // DASH__VIEW__MAKE_RANGE_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 985bc090d..f3de74fae 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -19,8 +19,6 @@ #include #include -#include - #include @@ -34,8 +32,8 @@ namespace dash { // template < class DomainType, - dim_t NDim = dash::view_traits< - typename std::decay::type>::rank::value > + dim_t NDim = dash::view_traits< + typename std::decay::type>::rank::value > class ViewBlocksMod; @@ -104,14 +102,16 @@ class ViewBlockMod typedef decltype( dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + origin_type>::type >() )) origin_iterator; typedef decltype( dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + const origin_type>::type >() )) const_origin_iterator; @@ -123,14 +123,16 @@ class ViewBlockMod typedef decltype(*dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + origin_type>::type >() )) reference; typedef decltype(*dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + const origin_type>::type >() )) const_reference; @@ -246,8 +248,8 @@ class ViewBlockMod template < class DomainType > class ViewBlockMod -// Actually just an adapter for block_idx -> sub(begin_idx, end_idx), -// should sublass +// One-dimensional blocks are actually just an adapter for +// block_idx -> sub(begin_idx, end_idx), could be defined by sublassing // // public ViewSubMod // @@ -273,14 +275,16 @@ class ViewBlockMod typedef decltype( dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + origin_type>::type >() )) origin_iterator; typedef decltype( dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + const origin_type>::type >() )) const_origin_iterator; @@ -292,14 +296,16 @@ class ViewBlockMod typedef decltype(*dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + origin_type>::type >() )) reference; typedef decltype(*dash::begin( std::declval< - typename std::add_lvalue_reference::type + typename std::add_lvalue_reference< + const origin_type>::type >() )) const_reference; @@ -381,8 +387,8 @@ class ViewBlockMod // If domain is local, block_idx refers to local block range // so use pattern().local_block(block_idx) // - // TODO: Currently values passed as `block_idx` are global block indices - // even if domain is local + // TODO: Currently values passed as `block_idx` are global block + // indices, even if domain is local return std::max( ( // block viewspec (extents, offsets) ( false && @@ -406,8 +412,8 @@ class ViewBlockMod // If domain is local, block_idx refers to local block range // so use pattern().local_block(block_idx) // - // TODO: Currently values passed as `block_idx` are global block indices - // even if domain is local + // TODO: Currently values passed as `block_idx` are global block + // indices, even if domain is local return std::min( dash::index(vdomain).last() + 1, ( // block viewspec (extents, offsets) diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 3575343a7..4f14b7c50 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -197,8 +197,7 @@ auto operator<<( */ template < class Range, - class RangeDType = typename std::decay::type -> + class RangeDType = typename std::decay::type > auto operator<<( std::ostream & o, Range && range) @@ -222,7 +221,9 @@ auto operator<<( std::ostream & >::type { - typedef typename std::iterator_traits::value_type + typedef typename std::iterator_traits< + decltype(range.begin()) + >::value_type value_t; auto && rng = std::forward(range); @@ -250,8 +251,8 @@ template < class ViewModBase { typedef ViewModBase self_t; -public: - typedef DomainType domain_type; + public: + typedef DomainType domain_type; typedef typename std::conditional<( view_traits::is_origin::value && @@ -308,7 +309,7 @@ class ViewModBase static constexpr dim_t ndim() { return NDim; } -protected: + protected: domain_member_type _domain; ViewModType & derived() { @@ -335,7 +336,7 @@ class ViewModBase constexpr ViewModBase() = delete; ~ViewModBase() = default; -public: + public: constexpr ViewModBase(const self_t &) = default; constexpr ViewModBase(self_t &&) = default; self_t & operator=(const self_t &) = default; @@ -418,10 +419,10 @@ struct view_traits > { typedef typename view_traits::size_type size_type; typedef dash::IndexSetLocal index_set_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; typedef std::integral_constant rank; }; @@ -434,17 +435,17 @@ class ViewLocalMod ViewLocalMod, DomainType, NDim > { -public: + public: typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; typedef typename domain_type::local_type image_type; typedef typename view_traits::index_type index_type; typedef typename view_traits::size_type size_type; -private: + private: typedef ViewLocalMod self_t; typedef ViewModBase< ViewLocalMod, DomainType, NDim > base_t; -public: + public: typedef dash::IndexSetLocal index_set_type; typedef self_t local_type; typedef typename domain_type::global_type global_type; @@ -456,7 +457,8 @@ class ViewLocalMod dash::begin( dash::local(dash::origin( std::declval< - typename std::add_lvalue_reference::type >() + typename std::add_lvalue_reference< + domain_type>::type >() )))) origin_iterator; @@ -465,7 +467,8 @@ class ViewLocalMod dash::begin( dash::local(dash::origin( std::declval< - typename std::add_lvalue_reference::type >() + typename std::add_lvalue_reference< + const domain_type>::type >() )))) const_origin_iterator; @@ -481,7 +484,8 @@ class ViewLocalMod *(dash::begin( dash::local(dash::origin( std::declval< - typename std::add_lvalue_reference::type >() + typename std::add_lvalue_reference< + domain_type>::type >() ))))) reference; @@ -490,13 +494,14 @@ class ViewLocalMod *(dash::begin( dash::local(dash::origin( std::declval< - typename std::add_lvalue_reference::type >() + typename std::add_lvalue_reference< + const domain_type>::type >() ))))) const_reference; -private: + private: index_set_type _index_set; -public: + public: constexpr ViewLocalMod() = delete; constexpr ViewLocalMod(self_t &&) = default; constexpr ViewLocalMod(const self_t &) = default; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 9ae585791..772a4dc4f 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -49,35 +49,34 @@ class IteratorRangeOrigin; #ifndef DOXYGEN -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- // ViewSubMod -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- template < class DomainType, dim_t SubDim > class ViewSubMod : public ViewModBase< - ViewSubMod, - DomainType, - 1 > -{ + ViewSubMod, DomainType, 1 + > { public: - typedef DomainType domain_type; + typedef DomainType domain_type; private: - typedef ViewSubMod self_t; - typedef ViewModBase< ViewSubMod, domain_type > base_t; + typedef ViewSubMod self_t; + typedef ViewModBase< + ViewSubMod, domain_type > base_t; public: - typedef typename base_t::origin_type origin_type; + typedef typename base_t::origin_type origin_type; - typedef typename view_traits::index_type index_type; - typedef typename view_traits::size_type size_type; + typedef typename view_traits::index_type index_type; + typedef typename view_traits::size_type size_type; public: - typedef dash::IndexSetSub index_set_type; - typedef dash::ViewLocalMod local_type; - typedef self_t global_type; + typedef dash::IndexSetSub index_set_type; + typedef dash::ViewLocalMod local_type; + typedef self_t global_type; - typedef std::integral_constant is_local; + typedef std::integral_constant is_local; typedef ViewIterator< typename base_t::origin_iterator, index_set_type > @@ -162,9 +161,9 @@ class ViewSubMod }; // class ViewSubMod -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- // ViewLocalMod -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- #if 0 // HERE !!! template @@ -190,21 +189,21 @@ class ViewLocalMod ViewLocalMod, DomainType > { public: - typedef DomainType domain_type; - typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::local_type image_type; - typedef typename domain_type::index_type index_type; - typedef typename domain_type::size_type size_type; + typedef DomainType domain_type; + typedef typename view_traits::origin_type origin_type; + typedef typename view_traits::local_type image_type; + typedef typename domain_type::index_type index_type; + typedef typename domain_type::size_type size_type; private: - typedef ViewLocalMod self_t; + typedef ViewLocalMod self_t; typedef ViewModBase< - ViewLocalMod, DomainType > base_t; + ViewLocalMod, DomainType > base_t; public: - typedef dash::IndexSetLocal index_set_type; - typedef self_t local_type; - typedef typename domain_type::global_type global_type; + typedef dash::IndexSetLocal index_set_type; + typedef self_t local_type; + typedef typename domain_type::global_type global_type; - typedef std::integral_constant is_local; + typedef std::integral_constant is_local; typedef decltype( @@ -220,7 +219,8 @@ class ViewLocalMod dash::begin( dash::local(dash::origin( std::declval< - typename std::add_lvalue_reference::type >() + typename std::add_lvalue_reference< + const domain_type>::type >() )))) const_iterator; @@ -238,7 +238,8 @@ class ViewLocalMod *(dash::begin( dash::local(dash::origin( std::declval< - typename std::add_lvalue_reference::type >() + typename std::add_lvalue_reference< + const domain_type>::type >() ))))) const_reference; @@ -338,30 +339,30 @@ class ViewLocalMod } }; // class ViewLocalMod -// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------- // ViewGlobalMod -// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------- template < class DomainType > class ViewGlobalMod : public ViewModBase< ViewGlobalMod, DomainType > { public: - typedef DomainType domain_type; + typedef DomainType domain_type; private: - typedef ViewGlobalMod self_t; - typedef ViewModBase< ViewLocalMod, DomainType > base_t; + typedef ViewGlobalMod self_t; + typedef ViewModBase< ViewLocalMod, DomainType > base_t; public: - typedef typename base_t::origin_type origin_type; - typedef typename domain_type::global_type image_type; - typedef typename view_traits::index_type index_type; - typedef typename view_traits::size_type size_type; + typedef typename base_t::origin_type origin_type; + typedef typename domain_type::global_type image_type; + typedef typename view_traits::index_type index_type; + typedef typename view_traits::size_type size_type; public: - typedef dash::IndexSetGlobal< DomainType > index_set_type; - typedef self_t global_type; - typedef typename domain_type::local_type local_type; + typedef dash::IndexSetGlobal< DomainType > index_set_type; + typedef self_t global_type; + typedef typename domain_type::local_type local_type; - typedef std::integral_constant is_local; + typedef std::integral_constant is_local; private: index_set_type _index_set; @@ -441,9 +442,9 @@ class ViewGlobalMod -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- // Iterator Range Local Origin -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- template < class Iterator, @@ -454,28 +455,28 @@ template < class Iterator, class Sentinel > struct view_traits > { -private: - typedef IteratorRangeLocalOrigin RangeT; -public: - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef RangeT image_type; + private: + typedef IteratorRangeLocalOrigin RangeT; + public: + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef RangeT image_type; - typedef typename Iterator::pattern_type pattern_type; - typedef std::integral_constant rank; + typedef typename Iterator::pattern_type pattern_type; + typedef std::integral_constant rank; - typedef RangeT local_type; - typedef IteratorRangeOrigin global_type; + typedef RangeT local_type; + typedef IteratorRangeOrigin global_type; - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; - typedef dash::IndexSetLocal index_set_type; + typedef dash::IndexSetLocal index_set_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; }; template < @@ -490,33 +491,33 @@ class IteratorRangeLocalOrigin // Do not depend on DomainType (IndexRangeOrigin) and use Iterator, // Sentinel in template parameters to decouple cyclic type dependency. - typedef IteratorRangeLocalOrigin self_t; + typedef IteratorRangeLocalOrigin self_t; typedef ViewModBase< IteratorRangeLocalOrigin, IteratorRangeOrigin, - IteratorRangeOrigin::rank::value > base_t; -public: - typedef Iterator iterator; - typedef Iterator const_iterator; - typedef Sentinel sentinel; - typedef Sentinel const_sentinel; + IteratorRangeOrigin::rank::value > base_t; + public: + typedef Iterator iterator; + typedef Iterator const_iterator; + typedef Sentinel sentinel; + typedef Sentinel const_sentinel; - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeLocalOrigin image_type; + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeLocalOrigin image_type; - typedef typename iterator::value_type value_type; + typedef typename iterator::value_type value_type; - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; - typedef typename iterator::pattern_type pattern_type; + typedef typename iterator::pattern_type pattern_type; - typedef IndexSetLocal index_set_type; + typedef IndexSetLocal index_set_type; - typedef std::integral_constant rank; + typedef std::integral_constant rank; - typedef std::integral_constant is_local; + typedef std::integral_constant is_local; typedef ViewIterator< typename iterator::local_type, IndexSetLocal > @@ -527,14 +528,14 @@ class IteratorRangeLocalOrigin IndexSetLocal > local_sentinel; - typedef IteratorRangeOrigin global_type; - typedef self_t local_type; + typedef IteratorRangeOrigin global_type; + typedef self_t local_type; -private: + private: index_set_type _index_set; -public: - constexpr IteratorRangeLocalOrigin( + public: + constexpr explicit IteratorRangeLocalOrigin( const IteratorRangeOrigin & range_origin) : base_t(range_origin) , _index_set(this->domain()) @@ -580,6 +581,10 @@ class IteratorRangeLocalOrigin return this->begin().pattern(); } + constexpr const index_set_type & index_set() const { + return _index_set; + } + constexpr const local_type & local() const { return *this; } @@ -587,11 +592,19 @@ class IteratorRangeLocalOrigin local_type & local() { return *this; } + + constexpr const global_type & global() const { + return this->domain(); + } + + global_type & global() { + return this->domain(); + } }; -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- // Iterator Range Origin -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- template < class Iterator, @@ -602,29 +615,29 @@ template < class Iterator, class Sentinel > struct view_traits > { -private: - typedef IteratorRangeOrigin RangeT; -public: - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeOrigin image_type; + private: + typedef IteratorRangeOrigin RangeT; + public: + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; - typedef typename Iterator::pattern_type pattern_type; - typedef std::integral_constant rank; + typedef typename Iterator::pattern_type pattern_type; + typedef std::integral_constant rank; - typedef RangeT global_type; - typedef IteratorRangeLocalOrigin local_type; + typedef RangeT global_type; + typedef IteratorRangeLocalOrigin local_type; - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; typedef dash::IndexSetIdentity< - IteratorRangeOrigin > index_set_type; + IteratorRangeOrigin > index_set_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; }; @@ -633,37 +646,39 @@ template < class Sentinel > class IteratorRangeOrigin { - typedef IteratorRangeOrigin self_t; -public: - typedef Iterator iterator; - typedef Iterator const_iterator; - typedef Sentinel sentinel; - typedef Sentinel const_sentinel; + typedef IteratorRangeOrigin self_t; + public: + typedef Iterator iterator; + typedef Iterator const_iterator; + typedef Sentinel sentinel; + typedef Sentinel const_sentinel; - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeOrigin image_type; + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeOrigin image_type; - typedef typename iterator::value_type value_type; + typedef typename iterator::value_type value_type; - typedef typename Iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; + typedef typename Iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; - typedef typename iterator::pattern_type pattern_type; + typedef typename iterator::pattern_type pattern_type; - typedef std::integral_constant is_local; + typedef std::integral_constant is_local; - typedef self_t global_type; - typedef IteratorRangeLocalOrigin local_type; + typedef self_t global_type; + typedef IteratorRangeLocalOrigin local_type; - typedef std::integral_constant rank; + typedef std::integral_constant rank; -private: + private: iterator _begin; sentinel _end; -public: - constexpr IteratorRangeOrigin(const iterator & begin, const sentinel & end) + public: + constexpr IteratorRangeOrigin( + const iterator & begin, + const sentinel & end) : _begin(begin) , _end(end) { } @@ -685,22 +700,32 @@ class IteratorRangeOrigin iterator begin() { return _begin; } sentinel end() { return _end; } - constexpr size_type size() const { return std::distance(_begin, _end); } + constexpr size_type size() const noexcept { + return std::distance(_begin, _end); + } - constexpr const pattern_type & pattern() const { + constexpr const pattern_type & pattern() const noexcept { return this->begin().pattern(); } - constexpr local_type local() const { + constexpr local_type local() const noexcept { return local_type(*this); } + + constexpr const self_t & global() const { + return *this; + } + + self_t & global() { + return *this; + } }; -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- // Iterator Range Origin (local pointers) -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- template < class LocalIterator, @@ -711,31 +736,31 @@ struct view_traits< ViewIterator, ViewIterator > > { -private: - typedef ViewIterator iterator; - typedef ViewIterator sentinel; + private: + typedef ViewIterator iterator; + typedef ViewIterator sentinel; - typedef IteratorRangeOrigin RangeT; -public: - typedef RangeT domain_type; - typedef RangeT origin_type; - typedef RangeT image_type; + typedef IteratorRangeOrigin RangeT; + public: + typedef RangeT domain_type; + typedef RangeT origin_type; + typedef RangeT image_type; - typedef std::integral_constant rank; + typedef std::integral_constant rank; - typedef RangeT global_type; - typedef RangeT local_type; + typedef RangeT global_type; + typedef RangeT local_type; - typedef typename iterator::index_type index_type; - typedef typename std::make_unsigned::type size_type; + typedef typename iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; typedef dash::IndexSetIdentity< - IteratorRangeOrigin > index_set_type; + IteratorRangeOrigin > index_set_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; }; template < @@ -748,32 +773,33 @@ class IteratorRangeOrigin< { typedef IteratorRangeOrigin< ViewIterator, - ViewIterator > self_t; + ViewIterator > + self_t; -public: - typedef ViewIterator iterator; - typedef ViewIterator sentinel; - typedef ViewIterator const_iterator; - typedef ViewIterator const_sentinel; + public: + typedef ViewIterator iterator; + typedef ViewIterator sentinel; + typedef ViewIterator const_iterator; + typedef ViewIterator const_sentinel; - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; - typedef LocalIterator value_type; + typedef LocalIterator value_type; - typedef self_t global_type; + typedef self_t global_type; - typedef typename IndexSet::pattern_type pattern_type; + typedef typename IndexSet::pattern_type pattern_type; - typedef std::integral_constant is_local; + typedef std::integral_constant is_local; - typedef std::integral_constant rank; + typedef std::integral_constant rank; -private: + private: iterator _begin; sentinel _end; -public: + public: constexpr IteratorRangeOrigin(iterator begin, sentinel end) : _begin(begin) , _end(end) @@ -791,46 +817,44 @@ class IteratorRangeOrigin< iterator begin() { return _begin; } sentinel end() { return _end; } - constexpr size_type size() const { return std::distance(_begin, _end); } + constexpr size_type size() const { + return std::distance(_begin, _end); + } }; -// ------------------------------------------------------------------------ +// ---------------------------------------------------------------------- // Iterator Range -// ------------------------------------------------------------------------ +// ---------------------------------------------------------------------- /** * Specialization of \c dash::view_traits for IteratorRange. */ template struct view_traits > { -private: - typedef IteratorRange RangeT; -public: - typedef RangeOrigin domain_type; - typedef RangeOrigin origin_type; - typedef RangeT image_type; + private: + typedef IteratorRange RangeT; + public: + typedef RangeOrigin domain_type; + typedef RangeOrigin origin_type; + typedef RangeT image_type; - typedef typename RangeOrigin::pattern_type pattern_type; + typedef typename RangeOrigin::pattern_type pattern_type; - typedef std::integral_constant rank; + typedef std::integral_constant rank; - typedef RangeT global_type; - typedef ViewLocalMod local_type; + typedef RangeT global_type; + typedef ViewLocalMod local_type; - typedef typename RangeT::index_type index_type; - typedef typename RangeT::size_type size_type; + typedef typename RangeT::index_type index_type; + typedef typename RangeT::size_type size_type; - typedef dash::IndexSetSub index_set_type; + typedef dash::IndexSetSub index_set_type; - /// Whether the view type is a projection (has less dimensions than the - /// view's domain type). - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - /// Whether the view is the origin domain. - typedef std::integral_constant is_origin; - /// Whether the range is local view. - typedef typename view_traits::is_local is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef typename view_traits::is_local is_local; }; /** @@ -844,39 +868,36 @@ class IteratorRange RangeOrigin, 1 > { - typedef IteratorRange self_t; - typedef ViewModBase< - IteratorRange, - RangeOrigin, - 1 > base_t; -public: - typedef typename RangeOrigin::iterator iterator; - typedef typename RangeOrigin::const_iterator const_iterator; - typedef typename RangeOrigin::sentinel sentinel; - typedef typename RangeOrigin::const_sentinel const_sentinel; + typedef IteratorRange + self_t; + typedef ViewModBase, RangeOrigin, 1 > + base_t; + public: + typedef typename RangeOrigin::iterator iterator; + typedef typename RangeOrigin::const_iterator const_iterator; + typedef typename RangeOrigin::sentinel sentinel; + typedef typename RangeOrigin::const_sentinel const_sentinel; - typedef RangeOrigin domain_type; - typedef RangeOrigin origin_type; - typedef self_t image_type; + typedef RangeOrigin domain_type; + typedef RangeOrigin origin_type; + typedef self_t image_type; - typedef typename domain_type::value_type value_type; + typedef typename domain_type::value_type value_type; -//typedef typename domain_type::pattern_type pattern_type; -//typedef std::integral_constant rank; - typedef std::integral_constant rank; +//typedef typename domain_type::pattern_type pattern_type; +//typedef std::integral_constant rank; + typedef std::integral_constant rank; - typedef self_t global_type; - typedef ViewLocalMod local_type; + typedef self_t global_type; + typedef ViewLocalMod local_type; typedef std::integral_constant< - // !!! HERE !!! should test for ViewIterator - //bool, std::is_pointer::value> is_local; - bool, view_traits::is_local::value> is_local; + bool, view_traits::is_local::value> is_local; - typedef dash::default_index_t index_type; - typedef dash::default_size_t size_type; + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; - typedef dash::IndexSetSub index_set_type; + typedef dash::IndexSetSub index_set_type; typedef typename std::conditional< @@ -897,11 +918,11 @@ class IteratorRange using reference = typename iterator::reference; using const_reference = typename iterator::const_reference; -private: + private: static const dim_t NDim = rank::value; index_set_type _index_set; -public: + public: constexpr IteratorRange(const iterator & begin, const sentinel & end) : base_t(domain_type( // Move begin iterator first position of its iteration scope: @@ -928,7 +949,7 @@ class IteratorRange self_t & operator=(const self_t & other) = default; self_t & operator=(self_t && other) = default; - // ---- extents --------------------------------------------------------- + // ---- extents ------------------------------------------------------- constexpr std::array extents() const { return _index_set.extents(); @@ -943,7 +964,7 @@ class IteratorRange return _index_set.extent(shape_dim); } - // ---- offsets --------------------------------------------------------- + // ---- offsets ------------------------------------------------------- template constexpr index_type offset() const { @@ -958,13 +979,13 @@ class IteratorRange return _index_set.offset(shape_dim); } - // ---- size ------------------------------------------------------------ + // ---- size ---------------------------------------------------------- constexpr size_type size(dim_t sub_dim = 0) const { return _index_set.size(sub_dim); } - // ---- access ---------------------------------------------------------- + // ---- access -------------------------------------------------------- constexpr const_iterator begin() const { return dash::domain(*this).begin() + _index_set[0]; @@ -997,11 +1018,19 @@ class IteratorRange constexpr local_type local() const { return local_type(*this); } + + constexpr const self_t & global() const { + return *this; + } + + self_t & global() { + return *this; + } }; -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- // dash::make_range -// ------------------------------------------------------------------------ +// ----------------------------------------------------------------------- template constexpr dash::IteratorRange< diff --git a/dash/test/TestBase.h b/dash/test/TestBase.h index 1a429ad7b..7044a2adf 100644 --- a/dash/test/TestBase.h +++ b/dash/test/TestBase.h @@ -13,7 +13,6 @@ #include #include -#include #include #include From f12b797b1d311aedde431d2df5557707fa0d61d8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 2 Jun 2017 23:23:26 +0200 Subject: [PATCH 048/161] Iterator range adapter types --- dash/include/dash/algorithm/Copy.h | 14 +++---- dash/include/dash/view/IndexSet.h | 3 +- dash/include/dash/view/Local.h | 32 ++++++++++++++- dash/include/dash/view/ViewIterator.h | 19 ++++++++- dash/include/dash/view/ViewMod1D.h | 59 +++++++++++++++++---------- 5 files changed, 95 insertions(+), 32 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 048dfd4ba..3c28d391f 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1154,15 +1154,15 @@ GlobOutputIt copy( auto out_h_last = out_first + num_elements; // in/out ranges in global domain: - auto out_g_range = dash::make_range(out_first, out_h_last); - const auto & in_g_range = dash::make_range(in_first, in_last); + auto out_g_range = dash::make_range(out_first, out_h_last); + auto in_g_range = dash::make_range(in_first, in_last); // local view on in/out ranges: - auto out_l_range = dash::local(out_g_range); - const auto & in_l_range = dash::local(in_g_range); + auto out_l_range = dash::local(out_g_range); + auto in_l_range = dash::local(in_g_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)); + 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; } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 75cd700e4..ea4b88701 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -456,7 +456,8 @@ class IndexSetBase constexpr bool is_strided() const noexcept { return ( - ( this->pattern().blockspec().size() > this->pattern().team().size() ) + ( this->pattern().blockspec().size() > + this->pattern().team().size() ) || ( this->pattern().ndim() > 1 && this->domain().extent(1) < ( this->domain().is_local() diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index 4106048f1..7a46444a8 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -65,6 +65,21 @@ local(const ContainerType & c) { return c.local; } +template < + class ContainerType, + typename ContainerDecayType + = typename std::decay::type > +constexpr +typename std::enable_if< + ( !dash::view_traits::is_local::value && + !std::is_member_function_pointer< + decltype(&ContainerDecayType::local)>::value ), + typename ContainerType::local_type & +>::type +local(ContainerType & c) { + return c.local; +} + template < class ContainerType, typename ContainerDecayType @@ -74,12 +89,27 @@ typename std::enable_if< ( !dash::view_traits::is_local::value && std::is_member_function_pointer< decltype(&ContainerDecayType::local)>::value ), - decltype(std::declval.local()) + decltype(std::declval().local()) >::type local(const ContainerType & c) { return c.local(); } +template < + class ContainerType, + typename ContainerDecayType + = typename std::decay::type > +constexpr +typename std::enable_if< + ( !dash::view_traits::is_local::value && + std::is_member_function_pointer< + decltype(&ContainerDecayType::local)>::value ), + decltype(std::declval().local()) +>::type +local(ContainerType & c) { + return c.local(); +} + #if 0 /** * \concept{DashViewConcept} diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index c7226699f..4240b8010 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -178,18 +178,29 @@ class ViewIterator _index_set = other._index_set; } - template + template ViewIterator( DomainItType * domain_it, - const IndexSetType & index_set, + const IndexSetO & index_set, index_type position) : base_t(position) , _domain_it(domain_it) , _index_set(index_set) { } + template ViewIterator( const self_t & other, + const IndexSetO & index_set, + index_type position) + : base_t(position) + , _domain_it(other._domain_it) + , _index_set(index_set) + { } + + template + ViewIterator( + const ViewIteratorO & other, index_type position) : base_t(position) , _domain_it(other._domain_it) @@ -219,6 +230,10 @@ class ViewIterator explicit operator value_type *() { return (_domain_it + (_index_set[this->pos()])).local(); } + + constexpr explicit operator DomainIterator() const { + return (_domain_it + _index_set[this->pos()]); + } }; template diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 772a4dc4f..c3ef7f423 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -155,9 +155,21 @@ class ViewSubMod return _index_set; } - constexpr local_type local() const { + constexpr const local_type local() const { return local_type(*this); } + + local_type local() { + return local_type(*this); + } + + constexpr const self_t & global() const { + return *this; + } + + self_t & global() { + return *this; + } }; // class ViewSubMod @@ -518,14 +530,15 @@ class IteratorRangeLocalOrigin typedef std::integral_constant rank; typedef std::integral_constant is_local; + typedef ViewIterator< typename iterator::local_type, - IndexSetLocal > + index_set_type > local_iterator; typedef ViewIterator< typename sentinel::local_type, - IndexSetLocal > + index_set_type > local_sentinel; typedef IteratorRangeOrigin global_type; @@ -544,34 +557,30 @@ class IteratorRangeLocalOrigin constexpr local_iterator begin() const { return local_iterator( dash::begin( - dash::local( - this->domain())), + this->domain()), _index_set, 0); } local_iterator begin() { return local_iterator( dash::begin( - dash::local( - const_cast( - dash::domain(*this)))), + const_cast( + this->domain())), _index_set, 0); } constexpr local_sentinel end() const { return local_iterator( dash::begin( - dash::local( - this->domain())), + this->domain()), _index_set, _index_set.size()); } local_sentinel end() { return local_iterator( dash::begin( - dash::local( - const_cast( - dash::domain(*this)))), + const_cast( + this->domain())), _index_set, _index_set.size()); } @@ -708,7 +717,7 @@ class IteratorRangeOrigin return this->begin().pattern(); } - constexpr local_type local() const noexcept { + constexpr const local_type local() const noexcept { return local_type(*this); } @@ -851,10 +860,13 @@ struct view_traits > { typedef dash::IndexSetSub index_set_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef typename view_traits::is_local is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; +//typedef typename view_traits< +// typename std::decay::type +// >::is_local is_local; + typedef std::integral_constant is_local; }; /** @@ -891,8 +903,9 @@ class IteratorRange typedef self_t global_type; typedef ViewLocalMod local_type; - typedef std::integral_constant< - bool, view_traits::is_local::value> is_local; + typedef typename view_traits< + typename std::decay::type + >::is_local is_local; typedef dash::default_index_t index_type; typedef dash::default_size_t size_type; @@ -1015,7 +1028,11 @@ class IteratorRange return _index_set; } - constexpr local_type local() const { + constexpr const local_type local() const { + return local_type(*this); + } + + local_type local() { return local_type(*this); } From 83327b4a75251fabfe724ef8c3a14c2b67239fd8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 3 Jun 2017 02:24:17 +0200 Subject: [PATCH 049/161] Iterator range adapter types --- dash/include/dash/View.h | 2 - dash/include/dash/view/ViewMod1D.h | 99 ++++++++++++++++-------------- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index b940376ee..edfe34ffc 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -71,7 +71,6 @@ * \} */ -#include #include #include #include @@ -81,7 +80,6 @@ #include #include #include -// #include #include #include diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index c3ef7f423..f30cb3e05 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -492,38 +492,38 @@ struct view_traits > { }; template < - class Iterator, + class OriginIter, class Sentinel > class IteratorRangeLocalOrigin : public ViewModBase< - IteratorRangeLocalOrigin, - IteratorRangeOrigin, - IteratorRangeOrigin::rank::value > + IteratorRangeLocalOrigin, + IteratorRangeOrigin, + IteratorRangeOrigin::rank::value > { - // Do not depend on DomainType (IndexRangeOrigin) and use Iterator, - // Sentinel in template parameters to decouple cyclic type dependency. + // Do not depend on DomainType (IndexRangeOrigin): + // Use OriginIter, OriginSntl in template parameters to decouple + // cyclic type dependency. + typedef OriginIter g_origin_iterator; + typedef OriginIter const_g_origin_iterator; - typedef IteratorRangeLocalOrigin self_t; + typedef IteratorRangeLocalOrigin self_t; + public: + typedef IteratorRangeOrigin domain_type; + typedef IteratorRangeOrigin origin_type; + typedef IteratorRangeLocalOrigin image_type; + private: typedef ViewModBase< - IteratorRangeLocalOrigin, - IteratorRangeOrigin, - IteratorRangeOrigin::rank::value > base_t; + self_t, + domain_type, + domain_type::rank::value > base_t; public: - typedef Iterator iterator; - typedef Iterator const_iterator; - typedef Sentinel sentinel; - typedef Sentinel const_sentinel; - typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef IteratorRangeLocalOrigin image_type; - - typedef typename iterator::value_type value_type; + typedef typename g_origin_iterator::value_type value_type; - typedef typename Iterator::index_type index_type; + typedef typename g_origin_iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef typename iterator::pattern_type pattern_type; + typedef typename g_origin_iterator::pattern_type pattern_type; typedef IndexSetLocal index_set_type; @@ -531,17 +531,20 @@ class IteratorRangeLocalOrigin typedef std::integral_constant is_local; - typedef ViewIterator< - typename iterator::local_type, - index_set_type > - local_iterator; + typedef typename g_origin_iterator::local_type + origin_iterator; + + typedef typename g_origin_iterator::local_type + const_origin_iterator; typedef ViewIterator< - typename sentinel::local_type, - index_set_type > - local_sentinel; + origin_iterator, index_set_type > + iterator; + typedef ViewIterator< + const_origin_iterator, index_set_type > + const_iterator; - typedef IteratorRangeOrigin global_type; + typedef IteratorRangeOrigin global_type; typedef self_t local_type; private: @@ -549,38 +552,42 @@ class IteratorRangeLocalOrigin public: constexpr explicit IteratorRangeLocalOrigin( - const IteratorRangeOrigin & range_origin) + const IteratorRangeOrigin & range_origin) : base_t(range_origin) , _index_set(this->domain()) { } - constexpr local_iterator begin() const { - return local_iterator( + constexpr const_iterator begin() const { + return const_iterator( dash::begin( - this->domain()), - _index_set, 0); + dash::local( + dash::origin(*this) )), + _index_set, 0); } - local_iterator begin() { - return local_iterator( + iterator begin() { + return iterator( dash::begin( - const_cast( - this->domain())), + dash::local( + const_cast( + dash::origin(*this)) )), _index_set, 0); } - constexpr local_sentinel end() const { - return local_iterator( + constexpr const_iterator end() const { + return const_iterator( dash::begin( - this->domain()), - _index_set, _index_set.size()); + dash::local( + dash::origin(*this) )), + _index_set, _index_set.size()); } - local_sentinel end() { - return local_iterator( + iterator end() { + return iterator( dash::begin( - const_cast( - this->domain())), + dash::local( + const_cast( + dash::origin(*this)) )), _index_set, _index_set.size()); } From 15c9f5df724d7371f9d8fbc8820e78981ef5fed3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 3 Jun 2017 03:18:41 +0200 Subject: [PATCH 050/161] Iterator range adapter types --- dash/examples/ex.02.array-copy/main.cpp | 7 +-- dash/include/dash/view/ViewMod1D.h | 77 +++++++++++++++++-------- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 61b4f93a5..717d99fb3 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef DASH_ENABLE_IPM #include @@ -61,11 +62,11 @@ int main(int argc, char* argv[]) // ---------------------------------------------------------------------- // destination array - int * local_array = new int[num_elems_copy]; + std::vector local_array(num_elems_copy); dash::copy(array.begin() + start_index, array.begin() + start_index + num_elems_copy, - local_array); + local_array.data()); std::ostringstream ss; ss << "Local copy at unit " << myid << ": "; @@ -75,8 +76,6 @@ int main(int argc, char* argv[]) ss << endl; cout << ss.str(); - delete[] local_array; - array.barrier(); // ---------------------------------------------------------------------- diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index f30cb3e05..ad276dcb9 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -177,23 +177,6 @@ class ViewSubMod // ViewLocalMod // ----------------------------------------------------------------------- -#if 0 // HERE !!! -template -constexpr ViewLocalMod, 1> -local(const IteratorRange & ir) { - return ViewLocalMod, 1>(ir); -} - -template < - class Iterator, - class Sentinel > -constexpr ViewLocalMod, 1> -local(const IteratorRangeOrigin & ir) { - return ViewLocalMod, 1>(ir); -} -#endif - - template < class DomainType > class ViewLocalMod @@ -351,6 +334,7 @@ class ViewLocalMod } }; // class ViewLocalMod + // ------------------------------------------------------------------------- // ViewGlobalMod // ------------------------------------------------------------------------- @@ -454,14 +438,47 @@ class ViewGlobalMod +// ======================================================================= +// +// Iterator Range Interface +// +// ======================================================================= + +template < + class Iterator, + class Sentinel > +class IteratorRangeLocalOrigin; + +template < + class Iterator, + class Sentinel > +class IteratorRangeOrigin; + +template +class IteratorRange; + // ----------------------------------------------------------------------- // Iterator Range Local Origin +// +// Concept adapter for iterator range +// +// local(range(Container.iter, +// Container.iter) +// = +// range(Container.local.iter, +// Container.local.iter) +// +// to semantics of Container.local type. +// // ----------------------------------------------------------------------- template < class Iterator, class Sentinel > -class IteratorRangeLocalOrigin; +constexpr IteratorRangeLocalOrigin +local(const IteratorRangeOrigin & ir) { + return IteratorRangeLocalOrigin(ir); +} template < class Iterator, @@ -517,7 +534,6 @@ class IteratorRangeLocalOrigin domain_type, domain_type::rank::value > base_t; public: - typedef typename g_origin_iterator::value_type value_type; typedef typename g_origin_iterator::index_type index_type; @@ -620,13 +636,15 @@ class IteratorRangeLocalOrigin // ----------------------------------------------------------------------- // Iterator Range Origin +// +// Concept adapter for iterator range +// +// range(Container.iter, Container.iter) +// +// to semantics of type Container. +// // ----------------------------------------------------------------------- -template < - class Iterator, - class Sentinel > -class IteratorRangeOrigin; - template < class Iterator, class Sentinel > @@ -741,6 +759,17 @@ class IteratorRangeOrigin // ----------------------------------------------------------------------- // Iterator Range Origin (local pointers) +// +// Concept adapter for iterator range +// +// local(range(Container.iter, +// Container.iter) +// = +// range(Container.local.iter, +// Container.local.iter) +// +// to semantics of Container.local type. +// // ----------------------------------------------------------------------- template < From e3b0aa1a8d440e75078933a492a8cf30cf53b996 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 3 Jun 2017 03:42:05 +0200 Subject: [PATCH 051/161] Range ostream operators --- dash/examples/ex.02.array-copy/main.cpp | 2 +- dash/include/dash/algorithm/Copy.h | 19 +++- dash/include/dash/internal/StreamConversion.h | 94 +++++++++++++++++++ dash/include/dash/view/ViewMod.h | 94 ------------------- dash/include/dash/view/ViewMod1D.h | 2 - 5 files changed, 113 insertions(+), 98 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 717d99fb3..7480d01ae 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) dash::Array src_array(num_elems_total / 2); - std::fill(array.lbegin(), array.lend(), (myid + 1) * 10); + std::fill(src_array.lbegin(), src_array.lend(), (myid + 1) * 10); array.barrier(); dash::copy(src_array.begin(), diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 3c28d391f..7cda2dd47 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1148,17 +1148,34 @@ GlobOutputIt copy( DASH_LOG_TRACE_VAR("dash::copy()", in_first); DASH_LOG_TRACE_VAR("dash::copy()", in_last); - DASH_LOG_TRACE_VAR("dash::copy()", out_first); auto num_elements = dash::distance(in_first, in_last); + DASH_LOG_TRACE_VAR("dash::copy()", num_elements); + DASH_LOG_TRACE_VAR("dash::copy()", out_first); + auto out_h_last = out_first + num_elements; + DASH_LOG_TRACE_VAR("dash::copy()", out_h_last); // in/out ranges in global domain: auto out_g_range = dash::make_range(out_first, out_h_last); + DASH_LOG_TRACE_VAR("dash::copy()", out_g_range); + auto in_g_range = dash::make_range(in_first, in_last); + DASH_LOG_TRACE_VAR("dash::copy()", in_g_range); + // local view on in/out ranges: auto out_l_range = dash::local(out_g_range); + DASH_LOG_TRACE("dash::copy()", "local(range(out_i, out_e)):", + dash::typestr(out_l_range)); + DASH_LOG_TRACE("dash::copy()", "local(range(out_i, out_e)):", + out_l_range); + auto in_l_range = dash::local(in_g_range); + DASH_LOG_TRACE("dash::copy()", "local(range(in_i, in_e)):", + dash::typestr(in_l_range)); + DASH_LOG_TRACE("dash::copy()", "local(range(in_i, in_e)):", + in_l_range); + // copy local to global range: auto out_l_end = std::copy(dash::begin(in_l_range), dash::end(in_l_range), diff --git a/dash/include/dash/internal/StreamConversion.h b/dash/include/dash/internal/StreamConversion.h index 245f0888c..bf39d5ee5 100644 --- a/dash/include/dash/internal/StreamConversion.h +++ b/dash/include/dash/internal/StreamConversion.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -109,6 +110,99 @@ std::ostream & operator<<( return o; } +/** + * Write range of random access iterators to output stream. + */ +template < + class Range, + class RangeDType = typename std::decay::type +> +auto operator<<( + std::ostream & o, + Range && range) + -> typename std::enable_if< + ( + // type is range: + dash::is_range::value && + // type is not std::string or derivative: + !std::is_same::value && + !std::is_base_of::value && + // range iterator type is random access: + std::is_same< + std::random_access_iterator_tag, + typename std::iterator_traits< + typename std::decay< + decltype(dash::begin(std::forward(range))) + >::type + >::iterator_category + >::value + ), + std::ostream & + >::type +{ + typedef typename std::iterator_traits::value_type + value_t; + + auto && rng = std::forward(range); + + std::ostringstream ss; + int pos = 0; + ss << dash::typestr(*dash::begin(rng)) + << " { "; + for (auto it = dash::begin(rng); it != dash::end(rng); ++it, ++pos) { + ss << static_cast(*it) << " "; + } + ss << "}"; + return operator<<(o, ss.str()); +} + +/** + * Write range of non-random access iterators to output stream. + */ +template < + class Range, + class RangeDType = typename std::decay::type > +auto operator<<( + std::ostream & o, + Range && range) + -> typename std::enable_if< + ( + // type is range: + dash::is_range::value && + // type is not std::string or derivative: + !std::is_same::value && + !std::is_base_of::value && + // range iterator type is not random access: + !std::is_same< + std::random_access_iterator_tag, + typename std::iterator_traits< + typename std::decay< + decltype(dash::begin(std::forward(range))) + >::type + >::iterator_category + >::value + ), + std::ostream & + >::type +{ + typedef typename std::iterator_traits< + decltype(range.begin()) + >::value_type + value_t; + + auto && rng = std::forward(range); + + std::ostringstream ss; + ss << dash::typestr(*dash::begin(rng)) + << " { "; + for (auto it = dash::begin(rng); it != dash::end(rng); ++it) { + ss << static_cast(*it) << " "; + } + ss << "}"; + return operator<<(o, ss.str()); +} + + } // namespace dash #endif // DASH__INTERNAL__STREAM_CONVERSION_H_ diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 4f14b7c50..b3c6e03c9 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -146,100 +146,6 @@ class ViewGlobalMod; #endif // DOXYGEN -/** - * Write range of random access iterators to output stream. - */ -template < - class Range, - class RangeDType = typename std::decay::type -> -auto operator<<( - std::ostream & o, - Range && range) - -> typename std::enable_if< - ( - // type is range: - dash::is_range::value && - // type is not std::string or derivative: - !std::is_same::value && - !std::is_base_of::value && - // range iterator type is random access: - std::is_same< - std::random_access_iterator_tag, - typename std::iterator_traits< - typename std::decay< - decltype(dash::begin(std::forward(range))) - >::type - >::iterator_category - >::value - ), - std::ostream & - >::type -{ - typedef typename std::iterator_traits::value_type - value_t; - - auto && rng = std::forward(range); - - std::ostringstream ss; - int pos = 0; - ss << dash::typestr(*dash::begin(rng)) - << " { "; - for (auto it = dash::begin(rng); it != dash::end(rng); ++it, ++pos) { - ss << static_cast(*it) << " "; - } - ss << "}"; - return operator<<(o, ss.str()); -} - -/** - * Write range of non-random access iterators to output stream. - */ -template < - class Range, - class RangeDType = typename std::decay::type > -auto operator<<( - std::ostream & o, - Range && range) - -> typename std::enable_if< - ( - // type is range: - dash::is_range::value && - // type is not std::string or derivative: - !std::is_same::value && - !std::is_base_of::value && - // range iterator type is not random access: - !std::is_same< - std::random_access_iterator_tag, - typename std::iterator_traits< - typename std::decay< - decltype(dash::begin(std::forward(range))) - >::type - >::iterator_category - >::value - ), - std::ostream & - >::type -{ - typedef typename std::iterator_traits< - decltype(range.begin()) - >::value_type - value_t; - - auto && rng = std::forward(range); - - std::ostringstream ss; - ss << dash::typestr(*dash::begin(rng)) - << " { "; - for (auto it = dash::begin(rng); it != dash::end(rng); ++it) { - ss << static_cast(*it) << " "; - } - ss << "}"; - return operator<<(o, ss.str()); -} - - - // ------------------------------------------------------------------------ // ViewModBase // ------------------------------------------------------------------------ diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index ad276dcb9..17b2c685d 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -755,8 +755,6 @@ class IteratorRangeOrigin } }; - - // ----------------------------------------------------------------------- // Iterator Range Origin (local pointers) // From 05d77c180b912204468a5fd9bd565ad09a6006c3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 3 Jun 2017 07:59:30 +0200 Subject: [PATCH 052/161] Decouple concepts IndexSet and Pattern --- dash/include/dash/Iterator.h | 19 ++ dash/include/dash/view/Local.h | 16 - dash/include/dash/view/PatternIndexSet.h | 370 +++++++++++++++++++++++ dash/include/dash/view/ViewMod1D.h | 122 ++++++-- 4 files changed, 493 insertions(+), 34 deletions(-) create mode 100644 dash/include/dash/view/PatternIndexSet.h diff --git a/dash/include/dash/Iterator.h b/dash/include/dash/Iterator.h index ec1ced14b..6bdd2f82c 100644 --- a/dash/include/dash/Iterator.h +++ b/dash/include/dash/Iterator.h @@ -58,6 +58,25 @@ namespace detail { DASH__META__DEFINE_TRAIT__HAS_TYPE(const_pointer); } + +template +struct iterator_traits +: public std::iterator_traits { + private: + using iterator = typename std::decay::type; + using is_local = typename std::integral_constant::value + >; + +}; + +template +struct iterator_traits +: public std::iterator_traits { + using is_local = typename std::integral_constant; +}; + + /** * * \concept{DashIteratorConcept} diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index 7a46444a8..095a0ac75 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -34,22 +34,6 @@ local(ViewType & v) return v; } -#if 0 -template < - class ContainerLocalType, - typename ContainerLocalDecayType - = typename std::decay::type > -constexpr -typename std::enable_if< - ( dash::view_traits::is_origin::value && - dash::view_traits::is_local::value ), - ContainerLocalType & ->::type -local(ContainerLocalType & cl) { - return cl; -} -#endif - template < class ContainerType, typename ContainerDecayType diff --git a/dash/include/dash/view/PatternIndexSet.h b/dash/include/dash/view/PatternIndexSet.h new file mode 100644 index 000000000..532ab50d4 --- /dev/null +++ b/dash/include/dash/view/PatternIndexSet.h @@ -0,0 +1,370 @@ +#ifndef DASH__VIEW__PATTERN_INDEX_SET_H__INCLUDED +#define DASH__VIEW__PATTERN_INDEX_SET_H__INCLUDED + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include + +#include + + +#ifndef DOXYGEN +namespace dash { + + +// Forward-declarations + +template +class IndexSetBase; + +template +class PatternIndexSetBase; + +template +class IndexSetIdentity; + +template +class IndexSetLocal; + +template +class IndexSetGlobal; + +template +class IndexSetSub; + +template +class IndexSetBlocks; + +template +class IndexSetBlock; + + +#if 0 +template < + class IndexSetType, + class DomainType, + std::size_t NDim = DomainType::rank::value > +class IndexSetBase +{ + typedef IndexSetBase self_t; + + typedef typename std::decay::type DomainValueT; + + public: + typedef typename dash::view_traits::origin_type + view_origin_type; + typedef DomainValueT + view_domain_type; + typedef typename dash::view_traits::local_type + view_local_type; + typedef typename dash::view_traits::global_type + view_global_type; + + typedef typename view_traits::index_set_type + domain_type; + typedef typename dash::view_traits::index_set_type + local_type; + typedef typename dash::view_traits::index_set_type + global_type; + + typedef detail::IndexSetIterator + iterator; + typedef detail::IndexSetIterator + const_iterator; + typedef typename DomainType::size_type + size_type; + typedef typename DomainType::index_type + index_type; + typedef index_type + value_type; + + typedef typename detail::index_set_domain_bind_t::type + domain_member_type; + + typedef std::integral_constant + rank; + + static constexpr std::size_t ndim() { return NDim; } + + protected: + domain_member_type _domain; + + constexpr const IndexSetType & derived() const { + return static_cast(*this); + } + + constexpr explicit IndexSetBase(const DomainType & domain) + : _domain(domain) + { } + + constexpr explicit IndexSetBase(DomainType && domain) + : _domain(std::move(domain)) + { } + + typedef struct { + index_type begin; + index_type end; + } index_range_t; + + static constexpr index_range_t index_range_intersect( + const index_range_t & a, + const index_range_t & b) noexcept { + return index_range_t { + std::max(a.begin, b.begin), + std::min(a.end, b.end) + }; + } + static constexpr index_type index_range_size( + const index_range_t & irng) noexcept { + return irng.end - irng.begin; + } + + ~IndexSetBase() = default; + public: + constexpr IndexSetBase() = delete; + constexpr IndexSetBase(self_t &&) = default; + constexpr IndexSetBase(const self_t &) = default; + self_t & operator=(self_t &&) = default; + self_t & operator=(const self_t &) = default; + + constexpr const DomainType & view_domain() const & { + return _domain; + } + + constexpr DomainType view_domain() const && { + return _domain; + } + + constexpr auto domain() const +// -> decltype(dash::index( +// std::declval() +// )) { + -> typename view_traits::index_set_type { + return dash::index(_domain); + } + + constexpr const local_type local() const { + return dash::index(dash::local(_domain)); + } + + constexpr const global_type global() const { + return dash::index(dash::global(_domain)); + } + + constexpr bool is_local() const noexcept { + return dash::view_traits::is_local::value; + } + + constexpr bool is_strided() const noexcept { + return false; + } + + constexpr bool is_sub() const noexcept { + return ( + derived().size() < this->extents().size() + ); + } + + constexpr bool is_shifted() const noexcept { + return false; + } + + // ---- extents --------------------------------------------------------- + + constexpr std::array + extents() const { + return derived().extents(); + } + + template + constexpr size_type extent() const { + return derived().extents()[ShapeDim]; + } + + constexpr size_type extent(std::size_t shape_dim) const { + return derived().extents()[shape_dim]; + } + + // ---- offsets --------------------------------------------------------- + + constexpr std::array + offsets() const { + return std::array { }; + } + + template + constexpr index_type offset() const { + return derived().offsets()[ShapeDim]; + } + + constexpr index_type offset(std::size_t shape_dim) const { + return derived().offsets()[shape_dim]; + } + + // ---- access ---------------------------------------------------------- + + constexpr index_type rel(index_type image_index) const { + return image_index; + } + + constexpr index_type rel( + const std::array & coords) const { + return -1; + } + + constexpr index_type operator[](index_type image_index) const { + return domain()[derived().rel(image_index)]; + } + + constexpr index_type operator[]( + const std::array & coords) const { + return domain()[derived().rel(coords)]; + } + + constexpr const_iterator begin() const { + return iterator(derived(), 0); + } + + constexpr const_iterator end() const { + return iterator(derived(), derived().size()); + } + + constexpr index_type first() const { + return derived()[0]; + } + + constexpr index_type last() const { + return derived()[ derived().size() - 1 ]; + } + + /* + * dash::index(r(10..100)).step(2)[8] -> 26 + * dash::index(r(10..100)).step(-5)[4] -> 80 + */ + constexpr const_iterator step(index_type stride) const { + return ( + stride > 0 + ? iterator(derived(), 0, stride) + : iterator(derived(), derived().size(), stride) + ); + } +}; +#endif + +/** + * \concept{DashIndexSetConcept} + */ +template < + class IndexSetType, + class DomainType, + class PatternType, + std::size_t NDim = PatternType::ndim() > +class PatternIndexSetBase +: public IndexSetBase< + PatternIndexSetBase< + IndexSetType, DomainType, PatternType, NDim >, + DomainType, NDim > +{ + typedef PatternIndexSetBase< + IndexSetType, DomainType, PatternType, NDim> + self_t; + typedef IndexSetBase< + IndexSetType, DomainType, NDim> + base_t; + + typedef typename std::decay::type DomainValueT; + + using typename base_t::index_range_t; + using typename base_t::size_type; + using typename base_t::index_type; + + public: + typedef PatternType pattern_type; + + private: + const pattern_type * _pattern; + + protected: + template + static constexpr index_range_t index_range_g2l( + const PatternT_ & pat, + const index_range_t & grng) noexcept { + return index_range_t { + pat.local_coords({{ grng.begin }})[0], + pat.local_coords({{ grng.end }})[0] + }; + } + + template + static constexpr index_range_t index_range_l2g( + const PatternT_ & pat, + const index_range_t & lrng) noexcept { + return index_range_t { + pat.global(lrng.begin), + pat.global(lrng.end) + }; + } + + public: + constexpr explicit PatternIndexSetBase(const DomainType & domain) + : base_t(domain) + , _pattern(&dash::origin(this->domain()).pattern()) + { } + + constexpr explicit PatternIndexSetBase(DomainType && domain) + : base_t(std::move(domain)) + , _pattern(&dash::origin(this->domain()).pattern()) + { } + + constexpr const pattern_type & pattern() const { + return *_pattern; + } + + constexpr bool is_strided() const noexcept { + return ( + ( this->pattern().blockspec().size() > + this->pattern().team().size() ) + || + ( this->pattern().ndim() > 1 && + this->domain().extent(1) < ( this->domain().is_local() + ? this->pattern().local_extents()[1] + : this->pattern().extents()[1] )) + ); + } + + constexpr bool is_shifted() const noexcept { + typedef typename dash::pattern_mapping_traits::type + pat_mapping_traits; + return pat_mapping_traits::shifted || + pat_mapping_traits::diagonal; + } + + // ---- extents --------------------------------------------------------- + + constexpr std::array + extents() const { + return this->pattern().extents(); + } +}; +#endif + +} // namespace dash + +#endif // DOXYGEN + +#endif // DASH__VIEW__PATTERN_INDEX_SET_H__INCLUDED diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 17b2c685d..790d03a97 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -770,6 +770,7 @@ class IteratorRangeOrigin // // ----------------------------------------------------------------------- +#if 0 template < class LocalIterator, class LocalSentinel, @@ -864,7 +865,98 @@ class IteratorRangeOrigin< return std::distance(_begin, _end); } }; +#else +template < + class LocalIterator, + class LocalSentinel > +struct view_traits< + IteratorRangeOrigin< + LocalIterator *, + LocalSentinel *> + > { + private: + typedef typename std::decay::type iterator; + typedef typename std::decay::type sentinel; + + typedef IteratorRangeOrigin RangeT; + public: + typedef RangeT domain_type; + typedef RangeT origin_type; + typedef RangeT image_type; + + typedef std::integral_constant rank; + + typedef RangeT global_type; + typedef RangeT local_type; + + typedef typename std::ptrdiff_t index_type; + typedef typename std::make_unsigned::type size_type; + + typedef dash::IndexSetIdentity< + IteratorRangeOrigin > index_set_type; + + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; +}; + +template < + typename LocalIterator, + typename LocalSentinel > +class IteratorRangeOrigin< + LocalIterator *, + LocalSentinel * > +{ + typedef IteratorRangeOrigin< + LocalIterator *, + LocalSentinel * > + self_t; + + public: + typedef typename std::decay< LocalIterator *>::type iterator; + typedef typename std::decay::type const_iterator; + typedef typename std::decay< LocalSentinel *>::type sentinel; + typedef typename std::decay::type const_sentinel; + typedef dash::default_index_t index_type; + typedef dash::default_size_t size_type; + + typedef typename std::decay::type value_type; + + typedef self_t global_type; + + typedef std::integral_constant is_local; + + typedef std::integral_constant rank; + + private: + iterator _begin; + sentinel _end; + + public: + constexpr IteratorRangeOrigin(iterator begin, sentinel end) + : _begin(begin) + , _end(end) + { } + + constexpr IteratorRangeOrigin() = delete; + constexpr IteratorRangeOrigin(const self_t & other) = default; + constexpr IteratorRangeOrigin(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + + constexpr const_iterator begin() const { return _begin; } + constexpr const_sentinel end() const { return _end; } + + iterator begin() { return _begin; } + sentinel end() { return _end; } + + constexpr size_type size() const { + return std::distance(_begin, _end); + } +}; +#endif // ---------------------------------------------------------------------- // Iterator Range @@ -946,24 +1038,18 @@ class IteratorRange typedef dash::IndexSetSub index_set_type; - typedef typename - std::conditional< - std::is_pointer::value, - iterator, - typename iterator::local_type - >::type - local_iterator; - - typedef typename - std::conditional< - std::is_pointer::value, - sentinel, - typename sentinel::local_type - >::type - local_sentinel; - - using reference = typename iterator::reference; - using const_reference = typename iterator::const_reference; +// typedef typename +// std::conditional< +// dash::iterator_traits::is_local::value, +// iterator, +// typename iterator::local_type +// >::type +// local_iterator; + + using reference = + typename std::iterator_traits< iterator>::reference; + using const_reference = + typename std::iterator_traits::reference; private: static const dim_t NDim = rank::value; From 5fce765256c0d24d04b41930065abbded9247d91 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 3 Jun 2017 08:30:36 +0200 Subject: [PATCH 053/161] extending ex.02.array-copy --- dash/examples/ex.02.array-copy/main.cpp | 69 ++++++++++++++++++++----- dash/include/dash/algorithm/Copy.h | 12 +++-- dash/include/dash/view/IndexSet.h | 20 +++++++ 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 7480d01ae..727ee32e8 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -21,6 +21,44 @@ using std::cout; using std::endl; +template +auto initialize_array(ArrayT & array) +-> typename std::enable_if< + std::is_floating_point::value, + void >::type +{ + auto block_size = array.pattern().blocksize(0); + for (auto li = 0; li != array.local.size(); ++li) { + auto block_lidx = li / block_size; + auto block_gidx = (block_lidx * dash::size()) + dash::myid().id; + auto gi = (block_gidx * block_size) + (li % block_size); + array.local[li] = // unit + (1.0000 * dash::myid().id) + + // local offset + (0.0100 * (li+1)) + + // global offset + (0.0001 * gi); + } + array.barrier(); +} + +template +static std::string range_str( + const ValueRange & vrange) { + typedef typename ValueRange::value_type value_t; + std::ostringstream ss; + auto idx = dash::index(vrange); + int i = 0; + for (const auto & v : vrange) { + ss << std::setw(2) << *(dash::begin(idx) + i) << "|" + << std::fixed << std::setprecision(4) + << static_cast(v) << " "; + ++i; + } + return ss.str(); +} + + int main(int argc, char* argv[]) { dash::init(&argc, &argv); @@ -29,16 +67,16 @@ int main(int argc, char* argv[]) size_t num_units = dash::Team::All().size(); size_t num_elems_unit = (argc > 1) ? static_cast(atoi(argv[1])) - : 20; + : 6; + size_t num_elems_total = num_elems_unit * num_units; size_t start_index = (argc > 2) ? static_cast(atoi(argv[2])) - : 10; + : num_elems_total / 4; size_t num_elems_copy = (argc > 3) ? static_cast(atoi(argv[3])) - : 20; - size_t num_elems_total = num_elems_unit * num_units; + : num_elems_total / 2; - dash::Array array(num_elems_total); + dash::Array array(num_elems_total); if (myid == 0) { cout << endl @@ -47,27 +85,30 @@ int main(int argc, char* argv[]) << "Elements to copy: " << num_elems_copy << endl; } - // fill the local part of the global array each unit is holding with - // it's DASH ID (\c dash::myid). - std::fill(array.lbegin(), array.lend(), myid); - - array.barrier(); + initialize_array(array); if (myid == 0) { cout << "Array size: " << array.size() << endl; + cout << range_str(array) << endl; } // ---------------------------------------------------------------------- // global-to-local copy: // ---------------------------------------------------------------------- + if (myid == 0) { + cout << "=== Global to Local =================================" << endl; + } + // destination array - std::vector local_array(num_elems_copy); + std::vector local_array(num_elems_copy); dash::copy(array.begin() + start_index, array.begin() + start_index + num_elems_copy, local_array.data()); + array.barrier(); + std::ostringstream ss; ss << "Local copy at unit " << myid << ": "; for(size_t i = 0; i < num_elems_copy; ++i) { @@ -82,7 +123,11 @@ int main(int argc, char* argv[]) // global-to-global copy: // ---------------------------------------------------------------------- - dash::Array src_array(num_elems_total / 2); + if (myid == 0) { + cout << "=== Global to Global ================================" << endl; + } + + dash::Array src_array(num_elems_total / 2); std::fill(src_array.lbegin(), src_array.lend(), (myid + 1) * 10); array.barrier(); diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 7cda2dd47..5c1ae9454 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1158,22 +1158,26 @@ GlobOutputIt copy( // in/out ranges in global domain: auto out_g_range = dash::make_range(out_first, out_h_last); + DASH_LOG_TRACE("dash::copy()", "range(out_gi, out_ge):", + dash::typestr(out_g_range)); DASH_LOG_TRACE_VAR("dash::copy()", out_g_range); auto in_g_range = dash::make_range(in_first, in_last); + DASH_LOG_TRACE("dash::copy()", "range(in_gi, in_ge):", + dash::typestr(in_g_range)); DASH_LOG_TRACE_VAR("dash::copy()", in_g_range); // local view on in/out ranges: auto out_l_range = dash::local(out_g_range); - DASH_LOG_TRACE("dash::copy()", "local(range(out_i, out_e)):", + DASH_LOG_TRACE("dash::copy()", "local(range(out_gi, out_ge)):", dash::typestr(out_l_range)); - DASH_LOG_TRACE("dash::copy()", "local(range(out_i, out_e)):", + DASH_LOG_TRACE("dash::copy()", "local(range(out_gi, out_ge)):", out_l_range); auto in_l_range = dash::local(in_g_range); - DASH_LOG_TRACE("dash::copy()", "local(range(in_i, in_e)):", + DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", dash::typestr(in_l_range)); - DASH_LOG_TRACE("dash::copy()", "local(range(in_i, in_e)):", + DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", in_l_range); // copy local to global range: diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index ea4b88701..19d956b65 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -50,6 +50,26 @@ * \par Terminology * * + * \par Types + * + * \code + * template < + * class IndexSetT, + * class DomainT, + * dim_t NDim = view_traits::rank::value > + * class IndexSetBase; + * \endcode + * + * Generic adapter base class with default implementation for models of the + * \c IndexSet concept. + * + * Type | Synopsis + * ------------------- | -------------------------------------------------- + * IndexSetT | Specific index set, CRTP type + * DomainT | Indexed data domain, model of the \c View concept + * NDim | Number of dimensions in the index set + * + * * \par Expressions * * For a index domain \f$ Id \f$, \f$ ia, ib \in Id \f$ mapped by an index From 85c19ce48c933e49b755d88ad04d2324781d4923 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 00:49:02 +0200 Subject: [PATCH 054/161] Fixed compiler errors --- dash/include/dash/view/Domain.h | 4 ++-- dash/test/meta/RangeTest.cc | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index 0795f5928..74402a318 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -36,9 +36,9 @@ constexpr auto domain(ViewT && view) -> typename std::enable_if< dash::detail::has_type_domain_type::value, - typename std::decay::type + decltype(view.domain()) >::type { - return std::move(view).domain(); + return view.domain(); } template diff --git a/dash/test/meta/RangeTest.cc b/dash/test/meta/RangeTest.cc index f5c83fd40..a77594d87 100644 --- a/dash/test/meta/RangeTest.cc +++ b/dash/test/meta/RangeTest.cc @@ -87,13 +87,13 @@ TEST_F(RangeTest, RangeTraits) dash::is_range::value == true, "dash::is_range>::value not matched"); - auto l_range = dash::make_range(array.local.begin(), - array.local.end()); - static_assert( - dash::is_range::value == true, - "dash::is_range::value not matched"); - static_assert( - dash::is_view::value == false, - "dash::is_view::value not matched"); +// auto l_range = dash::make_range(array.local.begin(), +// array.local.end()); +// static_assert( +// dash::is_range::value == true, +// "dash::is_range::value not matched"); +// static_assert( +// dash::is_view::value == false, +// "dash::is_view::value not matched"); } From 088fff6be8eaa23c2c71a1fb30a0293f55af38a3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 07:32:10 +0200 Subject: [PATCH 055/161] Removed view_traits::pattern_type --- dash/include/dash/view/IndexSet.h | 101 ++++++++++++++--------- dash/include/dash/view/PatternIndexSet.h | 48 +++++++++-- dash/include/dash/view/ViewBlocksMod.h | 4 +- dash/include/dash/view/ViewMod.h | 4 +- dash/include/dash/view/ViewMod1D.h | 20 ++--- dash/include/dash/view/ViewTraits.h | 22 ++--- 6 files changed, 122 insertions(+), 77 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 19d956b65..1bdd6769c 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -352,8 +352,6 @@ class IndexSetBase typedef typename view_traits::index_set_type domain_type; - typedef typename view_traits::pattern_type - pattern_type; typedef typename dash::view_traits::index_set_type local_type; typedef typename dash::view_traits::index_set_type @@ -376,11 +374,14 @@ class IndexSetBase typedef std::integral_constant rank; + typedef typename view_origin_type::pattern_type + pattern_type; + static constexpr std::size_t ndim() { return NDim; } protected: - domain_member_type _domain; - const pattern_type * _pattern = nullptr; + domain_member_type _domain; + const pattern_type * _pattern = nullptr; constexpr const IndexSetType & derived() const { return static_cast(*this); @@ -409,6 +410,7 @@ class IndexSetBase std::min(a.end, b.end) }; } + static constexpr index_type index_range_size( const index_range_t & irng) noexcept { return irng.end - irng.begin; @@ -441,6 +443,10 @@ class IndexSetBase constexpr IndexSetBase(const self_t &) = default; self_t & operator=(self_t &&) = default; self_t & operator=(const self_t &) = default; + + constexpr const pattern_type & pattern() const { + return *_pattern; + } constexpr const DomainType & view_domain() const & { return _domain; @@ -458,10 +464,6 @@ class IndexSetBase return dash::index(_domain); } - constexpr const pattern_type & pattern() const { - return *_pattern; - } - constexpr const local_type local() const { return dash::index(dash::local(_domain)); } @@ -474,6 +476,12 @@ class IndexSetBase return dash::view_traits::is_local::value; } + constexpr bool is_sub() const noexcept { + return ( + derived().size() < this->extents().size() + ); + } + constexpr bool is_strided() const noexcept { return ( ( this->pattern().blockspec().size() > @@ -486,12 +494,6 @@ class IndexSetBase ); } - constexpr bool is_sub() const noexcept { - return ( - derived().size() < this->pattern().size() - ); - } - constexpr bool is_shifted() const noexcept { typedef typename dash::pattern_mapping_traits::type pat_mapping_traits; @@ -503,7 +505,7 @@ class IndexSetBase constexpr std::array extents() const { - return pattern().extents(); + return derived().extents(); } template @@ -580,6 +582,7 @@ class IndexSetBase } }; + // ----------------------------------------------------------------------- // IndexSetIdentity // ----------------------------------------------------------------------- @@ -733,7 +736,6 @@ class IndexSetSub typedef typename base_t::size_type size_type; typedef typename base_t::view_origin_type view_origin_type; typedef typename base_t::view_domain_type view_domain_type; - typedef typename base_t::pattern_type pattern_type; typedef typename base_t::local_type local_type; typedef typename base_t::global_type global_type; typedef typename base_t::iterator iterator; @@ -915,10 +917,16 @@ template class IndexSetLocal : public IndexSetBase< IndexSetLocal, - DomainType > + DomainType + > { - typedef IndexSetLocal self_t; - typedef IndexSetBase base_t; + typedef IndexSetLocal + self_t; + typedef IndexSetBase< + self_t, + DomainType + > + base_t; constexpr static bool view_domain_is_local = dash::view_traits::is_local::value; @@ -1202,10 +1210,16 @@ template class IndexSetGlobal : public IndexSetBase< IndexSetGlobal, - DomainType > + DomainType + > { - typedef IndexSetGlobal self_t; - typedef IndexSetBase base_t; + typedef IndexSetGlobal + self_t; + typedef IndexSetBase< + self_t, + DomainType + > + base_t; constexpr static bool view_domain_is_local = dash::view_traits::is_local::value; @@ -1297,24 +1311,25 @@ class IndexSetBlocks : public IndexSetBase< IndexSetBlocks, DomainType, - // Number of dimensions in the domain pattern's block spec: dash::pattern_traits< - typename dash::view_traits< - typename std::decay::type - >::pattern_type + typename view_traits::origin_type::pattern_type >::blockspec_type::ndim::value > { typedef typename dash::pattern_traits< - typename dash::view_traits< - typename std::decay::type - >::pattern_type + typename view_traits::origin_type::pattern_type >::blockspec_type::ndim blocks_ndim; - typedef IndexSetBlocks self_t; - typedef IndexSetBase base_t; + typedef IndexSetBlocks + self_t; + typedef IndexSetBase< + self_t, + DomainType, + blocks_ndim::value + > + base_t; public: typedef typename base_t::index_type index_type; typedef typename base_t::size_type size_type; @@ -1322,7 +1337,8 @@ class IndexSetBlocks typedef typename base_t::view_origin_type view_origin_type; typedef typename base_t::view_domain_type view_domain_type; - typedef typename base_t::pattern_type pattern_type; + typedef typename view_traits::origin_type::pattern_type + pattern_type; typedef self_t local_type; typedef IndexSetGlobal global_type; @@ -1482,24 +1498,27 @@ class IndexSetBlock : public IndexSetBase< IndexSetBlock, DomainType, - // Number of dimensions in the domain pattern's block spec: dash::pattern_traits< - typename dash::view_traits< - typename std::decay::type - >::pattern_type + typename view_traits::origin_type::pattern_type >::ndim::value > { typedef typename dash::pattern_traits< - typename dash::view_traits< - typename std::decay::type - >::pattern_type + typename view_traits::origin_type::pattern_type >::ndim pattern_ndim; - typedef IndexSetBlock self_t; - typedef IndexSetBase base_t; + typedef IndexSetBlock + self_t; + typedef IndexSetBase< + self_t, + DomainType, + dash::pattern_traits< + typename view_traits::origin_type::pattern_type + >::ndim::value + > + base_t; public: typedef typename DomainType::index_type index_type; typedef typename DomainType::size_type size_type; diff --git a/dash/include/dash/view/PatternIndexSet.h b/dash/include/dash/view/PatternIndexSet.h index 532ab50d4..6fe5119e3 100644 --- a/dash/include/dash/view/PatternIndexSet.h +++ b/dash/include/dash/view/PatternIndexSet.h @@ -54,7 +54,6 @@ template class IndexSetBlock; -#if 0 template < class IndexSetType, class DomainType, @@ -150,6 +149,10 @@ class IndexSetBase return _domain; } + constexpr const typename view_origin_type::pattern_type & pattern() const { + return derived().pattern(); + } + constexpr auto domain() const // -> decltype(dash::index( // std::declval() @@ -264,7 +267,6 @@ class IndexSetBase ); } }; -#endif /** * \concept{DashIndexSetConcept} @@ -276,30 +278,50 @@ template < std::size_t NDim = PatternType::ndim() > class PatternIndexSetBase : public IndexSetBase< +// IndexSetType, PatternIndexSetBase< - IndexSetType, DomainType, PatternType, NDim >, - DomainType, NDim > + IndexSetType, DomainType, PatternType, NDim + >, + DomainType, + NDim > { typedef PatternIndexSetBase< - IndexSetType, DomainType, PatternType, NDim> + IndexSetType, + DomainType, + PatternType, + NDim + > self_t; typedef IndexSetBase< - IndexSetType, DomainType, NDim> +// IndexSetType, + PatternIndexSetBase< + IndexSetType, + DomainType, + PatternType, + NDim + >, + DomainType, NDim + > base_t; typedef typename std::decay::type DomainValueT; using typename base_t::index_range_t; + + public: using typename base_t::size_type; using typename base_t::index_type; - public: typedef PatternType pattern_type; private: - const pattern_type * _pattern; + const pattern_type * _pattern = nullptr; protected: + constexpr const IndexSetType & derived() const { + return static_cast(*this); + } + template static constexpr index_range_t index_range_g2l( const PatternT_ & pat, @@ -321,6 +343,12 @@ class PatternIndexSetBase } public: + constexpr PatternIndexSetBase() = delete; + constexpr PatternIndexSetBase(self_t &&) = default; + constexpr PatternIndexSetBase(const self_t &) = default; + self_t & operator=(self_t &&) = default; + self_t & operator=(const self_t &) = default; + constexpr explicit PatternIndexSetBase(const DomainType & domain) : base_t(domain) , _pattern(&dash::origin(this->domain()).pattern()) @@ -354,6 +382,10 @@ class PatternIndexSetBase pat_mapping_traits::diagonal; } + size_type size() const { + return derived().size(); + } + // ---- extents --------------------------------------------------------- constexpr std::array diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index f3de74fae..072b7c0ea 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -47,7 +47,7 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; +//typedef typename view_traits::pattern_type pattern_type; typedef ViewBlockMod image_type; typedef ViewBlockMod local_type; typedef ViewBlockMod global_type; @@ -456,7 +456,7 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; +//typedef typename view_traits::pattern_type pattern_type; typedef ViewBlocksMod image_type; typedef typename view_traits::local_type local_type; typedef ViewBlocksMod global_type; diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index b3c6e03c9..254e44684 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -316,7 +316,7 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; +//typedef typename view_traits::pattern_type pattern_type; typedef typename view_traits::local_type image_type; typedef ViewLocalMod local_type; typedef domain_type global_type; @@ -549,7 +549,7 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::pattern_type pattern_type; +//typedef typename view_traits::pattern_type pattern_type; typedef ViewSubMod image_type; typedef ViewLocalMod< ViewSubMod, NDim> local_type; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 790d03a97..7294a1294 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -989,10 +989,10 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; typedef std::integral_constant is_origin; -//typedef typename view_traits< -// typename std::decay::type -// >::is_local is_local; - typedef std::integral_constant is_local; + typedef typename view_traits< + typename std::decay::type + >::is_local is_local; +// typedef std::integral_constant is_local; }; /** @@ -1022,13 +1022,13 @@ class IteratorRange typedef typename domain_type::value_type value_type; -//typedef typename domain_type::pattern_type pattern_type; -//typedef std::integral_constant rank; typedef std::integral_constant rank; typedef self_t global_type; typedef ViewLocalMod local_type; + typedef typename RangeOrigin::pattern_type pattern_type; + typedef typename view_traits< typename std::decay::type >::is_local is_local; @@ -1038,14 +1038,6 @@ class IteratorRange typedef dash::IndexSetSub index_set_type; -// typedef typename -// std::conditional< -// dash::iterator_traits::is_local::value, -// iterator, -// typename iterator::local_type -// >::type -// local_iterator; - using reference = typename std::iterator_traits< iterator>::reference; using const_reference = diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index 6ea5e0933..b1b25ae25 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -30,11 +30,13 @@ domain(const Viewable & v); template struct view_traits { - typedef typename ViewT::domain_type domain_type; - typedef typename ViewT::image_type image_type; - typedef typename ViewT::origin_type origin_type; - typedef typename ViewT::local_type local_type; - typedef typename ViewT::global_type global_type; + typedef typename ViewT::domain_type domain_type; + typedef typename ViewT::image_type image_type; + typedef typename ViewT::origin_type origin_type; + typedef typename ViewT::local_type local_type; + typedef typename ViewT::global_type global_type; + + typedef typename ViewT::index_set_type index_set_type; typedef std::integral_constant rank; @@ -105,8 +107,8 @@ namespace detail { dash::is_range::value >::is_local::value > is_local; -// typedef typename ViewT::local_type local_type; - typedef typename view_traits::local_type local_type; + typedef typename ViewT::local_type local_type; +// typedef typename view_traits::local_type local_type; typedef typename ViewT::global_type global_type; typedef typename std::conditional rank; - typedef typename dash::view_traits::pattern_type - pattern_type; +// typedef typename dash::view_traits::pattern_type +// pattern_type; }; /** @@ -139,7 +141,7 @@ namespace detail { typedef typename ContainerT::size_type size_type; typedef typename dash::IndexSetIdentity index_set_type; - typedef typename ContainerT::pattern_type pattern_type; +// typedef typename ContainerT::pattern_type pattern_type; /// Whether the view type is a projection (has less dimensions than the /// view's domain type). From 09ca07ff55f31ccb02308ca2a0ae70252edff54f Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 07:41:31 +0200 Subject: [PATCH 056/161] Removed view_traits::pattern_type --- dash/include/dash/view/ViewBlocksMod.h | 2 -- dash/include/dash/view/ViewMod.h | 2 -- dash/include/dash/view/ViewMod1D.h | 30 +++++++++++++------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 072b7c0ea..a13d227b3 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -47,7 +47,6 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; -//typedef typename view_traits::pattern_type pattern_type; typedef ViewBlockMod image_type; typedef ViewBlockMod local_type; typedef ViewBlockMod global_type; @@ -456,7 +455,6 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; -//typedef typename view_traits::pattern_type pattern_type; typedef ViewBlocksMod image_type; typedef typename view_traits::local_type local_type; typedef ViewBlocksMod global_type; diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 254e44684..3a21e94ee 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -316,7 +316,6 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; -//typedef typename view_traits::pattern_type pattern_type; typedef typename view_traits::local_type image_type; typedef ViewLocalMod local_type; typedef domain_type global_type; @@ -549,7 +548,6 @@ template < struct view_traits > { typedef DomainType domain_type; typedef typename view_traits::origin_type origin_type; -//typedef typename view_traits::pattern_type pattern_type; typedef ViewSubMod image_type; typedef ViewLocalMod< ViewSubMod, NDim> local_type; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 7294a1294..5de33f577 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -491,8 +491,9 @@ struct view_traits > { typedef IteratorRangeOrigin origin_type; typedef RangeT image_type; - typedef typename Iterator::pattern_type pattern_type; - typedef std::integral_constant rank; +//typedef typename Iterator::pattern_type pattern_type; +//typedef std::integral_constant rank; + typedef std::integral_constant rank; typedef RangeT local_type; typedef IteratorRangeOrigin global_type; @@ -533,18 +534,17 @@ class IteratorRangeLocalOrigin self_t, domain_type, domain_type::rank::value > base_t; + typedef typename g_origin_iterator::pattern_type pattern_type; public: typedef typename g_origin_iterator::value_type value_type; typedef typename g_origin_iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef typename g_origin_iterator::pattern_type pattern_type; + typedef std::integral_constant rank; typedef IndexSetLocal index_set_type; - typedef std::integral_constant rank; - typedef std::integral_constant is_local; typedef typename g_origin_iterator::local_type @@ -656,8 +656,9 @@ struct view_traits > { typedef IteratorRangeOrigin origin_type; typedef IteratorRangeOrigin image_type; - typedef typename Iterator::pattern_type pattern_type; - typedef std::integral_constant rank; +//typedef typename Iterator::pattern_type pattern_type; +//typedef std::integral_constant rank; + typedef std::integral_constant rank; typedef RangeT global_type; typedef IteratorRangeLocalOrigin local_type; @@ -681,6 +682,7 @@ template < class IteratorRangeOrigin { typedef IteratorRangeOrigin self_t; + public: typedef Iterator iterator; typedef Iterator const_iterator; @@ -696,19 +698,17 @@ class IteratorRangeOrigin typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef typename iterator::pattern_type pattern_type; + typedef typename Iterator::pattern_type pattern_type; + typedef std::integral_constant rank; typedef std::integral_constant is_local; typedef self_t global_type; typedef IteratorRangeLocalOrigin local_type; - typedef std::integral_constant rank; - private: iterator _begin; sentinel _end; - public: constexpr IteratorRangeOrigin( const iterator & begin, @@ -974,9 +974,9 @@ struct view_traits > { typedef RangeOrigin origin_type; typedef RangeT image_type; - typedef typename RangeOrigin::pattern_type pattern_type; - - typedef std::integral_constant rank; +//typedef typename RangeOrigin::pattern_type pattern_type; +//typedef std::integral_constant rank; + typedef std::integral_constant rank; typedef RangeT global_type; typedef ViewLocalMod local_type; @@ -1027,7 +1027,7 @@ class IteratorRange typedef self_t global_type; typedef ViewLocalMod local_type; - typedef typename RangeOrigin::pattern_type pattern_type; +//typedef typename RangeOrigin::pattern_type pattern_type; typedef typename view_traits< typename std::decay::type From 527199c6de55e6583005d4436e40ef0e2e8e79d8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 08:12:43 +0200 Subject: [PATCH 057/161] hscale, fixed compiler error --- dash/include/dash/view/IndexSet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 1bdd6769c..cdd35c308 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -505,16 +505,16 @@ class IndexSetBase constexpr std::array extents() const { - return derived().extents(); + return pattern().extents(); } template constexpr size_type extent() const { - return derived().extents()[ShapeDim]; + return pattern().extents()[ShapeDim]; } constexpr size_type extent(std::size_t shape_dim) const { - return derived().extents()[shape_dim]; + return pattern().extents()[shape_dim]; } // ---- offsets --------------------------------------------------------- From 7701ef44c8694d32f32c25a5f8dc6acc22d52747 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 09:05:44 +0200 Subject: [PATCH 058/161] Fixed index set, passing view/nview tests --- dash/include/dash/view/IndexSet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index cdd35c308..8d420c468 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -478,7 +478,7 @@ class IndexSetBase constexpr bool is_sub() const noexcept { return ( - derived().size() < this->extents().size() + derived().size() < this->pattern().size() ); } @@ -510,11 +510,11 @@ class IndexSetBase template constexpr size_type extent() const { - return pattern().extents()[ShapeDim]; + return derived().extents()[ShapeDim]; } constexpr size_type extent(std::size_t shape_dim) const { - return pattern().extents()[shape_dim]; + return derived().extents()[shape_dim]; } // ---- offsets --------------------------------------------------------- From 6fb276291c77cb3838450862ba64a5ae3292df41 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 11:23:50 +0200 Subject: [PATCH 059/161] Fixing IndexSetLocalOriginBase --- dash/include/dash/view/Domain.h | 4 +-- dash/include/dash/view/ViewMod1D.h | 50 ++++++++++++++++++------------ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index 74402a318..2585a6430 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -36,9 +36,9 @@ constexpr auto domain(ViewT && view) -> typename std::enable_if< dash::detail::has_type_domain_type::value, - decltype(view.domain()) + decltype(std::forward(view).domain()) >::type { - return view.domain(); + return std::forward(view).domain(); } template diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 5de33f577..6dd44f0e4 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -472,13 +472,13 @@ class IteratorRange; // // ----------------------------------------------------------------------- -template < - class Iterator, - class Sentinel > -constexpr IteratorRangeLocalOrigin -local(const IteratorRangeOrigin & ir) { - return IteratorRangeLocalOrigin(ir); -} +// template < +// class Iterator, +// class Sentinel > +// constexpr IteratorRangeLocalOrigin +// local(const IteratorRangeOrigin & ir) { +// return IteratorRangeLocalOrigin(ir); +// } template < class Iterator, @@ -488,8 +488,10 @@ struct view_traits > { typedef IteratorRangeLocalOrigin RangeT; public: typedef IteratorRangeOrigin domain_type; - typedef IteratorRangeOrigin origin_type; - typedef RangeT image_type; +//typedef IteratorRangeOrigin origin_type; +//typedef RangeT image_type; + typedef typename view_traits::origin_type origin_type; + typedef typename view_traits::local_type image_type; //typedef typename Iterator::pattern_type pattern_type; //typedef std::integral_constant rank; @@ -576,34 +578,34 @@ class IteratorRangeLocalOrigin constexpr const_iterator begin() const { return const_iterator( dash::begin( - dash::local( - dash::origin(*this) )), + dash::origin(this->domain()) + ).local(), _index_set, 0); } iterator begin() { return iterator( dash::begin( - dash::local( - const_cast( - dash::origin(*this)) )), + const_cast( + dash::origin(this->domain()) ) + ).local(), _index_set, 0); } constexpr const_iterator end() const { return const_iterator( dash::begin( - dash::local( - dash::origin(*this) )), - _index_set, _index_set.size()); + dash::origin(this->domain()) + ).local(), + _index_set, _index_set.size()); } iterator end() { return iterator( dash::begin( - dash::local( - const_cast( - dash::origin(*this)) )), + const_cast( + dash::origin(this->domain()) ) + ).local(), _index_set, _index_set.size()); } @@ -634,6 +636,14 @@ class IteratorRangeLocalOrigin } }; +template < + class Iterator, + class Sentinel > +constexpr IteratorRangeLocalOrigin +local(const IteratorRangeLocalOrigin & ir) { + return ir; +} + // ----------------------------------------------------------------------- // Iterator Range Origin // From 32d51f359817173c057e0df62dc0a1095e4b7c89 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 15:32:40 +0200 Subject: [PATCH 060/161] Fixed IteratorRangeLocalOrigin --- dash/examples/ex.02.array-copy/main.cpp | 4 + dash/include/dash/view/ViewMod1D.h | 99 ++++++++++++------------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 727ee32e8..1619d7014 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -138,6 +138,10 @@ int main(int argc, char* argv[]) array.barrier(); + if (myid == 0) { + cout << range_str(array) + << endl; + } dash::finalize(); diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 6dd44f0e4..8c3e09d05 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -472,14 +472,6 @@ class IteratorRange; // // ----------------------------------------------------------------------- -// template < -// class Iterator, -// class Sentinel > -// constexpr IteratorRangeLocalOrigin -// local(const IteratorRangeOrigin & ir) { -// return IteratorRangeLocalOrigin(ir); -// } - template < class Iterator, class Sentinel > @@ -488,10 +480,8 @@ struct view_traits > { typedef IteratorRangeLocalOrigin RangeT; public: typedef IteratorRangeOrigin domain_type; -//typedef IteratorRangeOrigin origin_type; -//typedef RangeT image_type; - typedef typename view_traits::origin_type origin_type; - typedef typename view_traits::local_type image_type; + typedef IteratorRangeOrigin origin_type; + typedef RangeT image_type; //typedef typename Iterator::pattern_type pattern_type; //typedef std::integral_constant rank; @@ -550,19 +540,16 @@ class IteratorRangeLocalOrigin typedef std::integral_constant is_local; typedef typename g_origin_iterator::local_type - origin_iterator; - - typedef typename g_origin_iterator::local_type - const_origin_iterator; - - typedef ViewIterator< - origin_iterator, index_set_type > iterator; - typedef ViewIterator< - const_origin_iterator, index_set_type > + typedef typename g_origin_iterator::local_type const_iterator; - typedef IteratorRangeOrigin global_type; + typedef value_type & + reference; + typedef const value_type & + const_reference; + + typedef typename domain_type::global_type global_type; typedef self_t local_type; private: @@ -576,37 +563,57 @@ class IteratorRangeLocalOrigin { } constexpr const_iterator begin() const { - return const_iterator( + return dash::local( dash::begin( - dash::origin(this->domain()) - ).local(), - _index_set, 0); + const_cast( + dash::domain(*this)) + ) + _index_set.pattern().global(0) + ) + _index_set[0]; } iterator begin() { - return iterator( + return dash::local( dash::begin( - const_cast( - dash::origin(this->domain()) ) - ).local(), - _index_set, 0); + const_cast( + dash::domain(*this)) + ) + _index_set.pattern().global(0) + ) + _index_set[0]; } constexpr const_iterator end() const { - return const_iterator( + return dash::local( dash::begin( - dash::origin(this->domain()) - ).local(), - _index_set, _index_set.size()); + const_cast( + dash::domain(*this)) + ) + _index_set.pattern().global(0) + ) + _index_set[_index_set.size() - 1] + 1; } iterator end() { - return iterator( + return dash::local( dash::begin( - const_cast( - dash::origin(this->domain()) ) - ).local(), - _index_set, _index_set.size()); + const_cast( + dash::domain(*this)) + ) + _index_set.pattern().global(0) + ) + _index_set[_index_set.size() - 1] + 1; + } + + constexpr const_reference operator[](int offset) const { + return *(dash::local( + dash::begin( + const_cast( + dash::domain(*this)) + ) + _index_set.pattern().global(0) + ) + _index_set[offset]); + } + + reference operator[](int offset) { + return *(dash::local( + dash::begin( + const_cast( + dash::domain(*this)) + ) + _index_set.pattern().global(0) + ) + _index_set[offset]); } constexpr size_type size() const { return _index_set.size(); } @@ -628,22 +635,14 @@ class IteratorRangeLocalOrigin } constexpr const global_type & global() const { - return this->domain(); + return dash::global(dash::domain(*this)); } global_type & global() { - return this->domain(); + return dash::global(dash::domain(*this)); } }; -template < - class Iterator, - class Sentinel > -constexpr IteratorRangeLocalOrigin -local(const IteratorRangeLocalOrigin & ir) { - return ir; -} - // ----------------------------------------------------------------------- // Iterator Range Origin // From ca6de540336051ba6848a3c1529e13ce88bf2203 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 19:27:36 +0200 Subject: [PATCH 061/161] Fixed make_range --- dash/examples/ex.02.array-copy/main.cpp | 20 ++++++++++++++++++++ dash/include/dash/algorithm/Copy.h | 6 ++++++ dash/include/dash/view/ViewMod1D.h | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 1619d7014..780c804cc 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -125,11 +125,30 @@ int main(int argc, char* argv[]) if (myid == 0) { cout << "=== Global to Global ================================" << endl; + + auto g_out_range = + dash::make_range( + array.begin() + (array.size() / 4), + array.begin() + (array.size() / 4) + (num_elems_total / 2)); + cout << range_str(g_out_range) << endl; } dash::Array src_array(num_elems_total / 2); std::fill(src_array.lbegin(), src_array.lend(), (myid + 1) * 10); + + if (myid == 0) { + cout << "copy target: "; + cout << range_str(array) << endl; + cout << "copy target index range: " + << "[" << (array.size() / 4) + << "," << ((array.size() / 4) + src_array.size()) + << ")" + << endl; + cout << "copy source: "; + cout << range_str(src_array) << endl; + } + array.barrier(); dash::copy(src_array.begin(), @@ -139,6 +158,7 @@ int main(int argc, char* argv[]) array.barrier(); if (myid == 0) { + cout << "after copy:" << endl; cout << range_str(array) << endl; } diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 5c1ae9454..c4ca73b78 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1161,11 +1161,13 @@ GlobOutputIt copy( DASH_LOG_TRACE("dash::copy()", "range(out_gi, out_ge):", dash::typestr(out_g_range)); DASH_LOG_TRACE_VAR("dash::copy()", out_g_range); + DASH_LOG_TRACE_VAR("dash::copy()", dash::index(out_g_range)); auto in_g_range = dash::make_range(in_first, in_last); DASH_LOG_TRACE("dash::copy()", "range(in_gi, in_ge):", dash::typestr(in_g_range)); DASH_LOG_TRACE_VAR("dash::copy()", in_g_range); + DASH_LOG_TRACE_VAR("dash::copy()", dash::index(in_g_range)); // local view on in/out ranges: auto out_l_range = dash::local(out_g_range); @@ -1173,12 +1175,16 @@ GlobOutputIt copy( dash::typestr(out_l_range)); DASH_LOG_TRACE("dash::copy()", "local(range(out_gi, out_ge)):", out_l_range); + DASH_LOG_TRACE("dash::copy()", "index(local(range(out_gi, out_ge))):", + dash::index(out_l_range)); auto in_l_range = dash::local(in_g_range); DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", dash::typestr(in_l_range)); DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", in_l_range); + 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), diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 8c3e09d05..5e249876b 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -1130,11 +1130,13 @@ class IteratorRange } constexpr const_iterator end() const { - return dash::domain(*this).end(); + return dash::domain(*this).begin() + + (_index_set[_index_set.size() - 1] + 1); } iterator end() { - return dash::domain(*this).end(); + return dash::domain(*this).begin() + + (_index_set[_index_set.size() - 1] + 1); } constexpr const_reference operator[](int offset) const { From 514e47c71aca0b020a2485921270419b403f9d37 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 6 Jun 2017 20:20:50 +0200 Subject: [PATCH 062/161] Fixed make_range --- dash/include/dash/Range.h | 28 ++++++++++++++++++++++++++ dash/include/dash/algorithm/Copy.h | 6 ++++++ dash/include/dash/view/ViewBlocksMod.h | 13 +++++++----- dash/include/dash/view/ViewMod1D.h | 11 ++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index f8a0bf301..94fa5acab 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -167,6 +167,15 @@ constexpr auto begin(RangeType && range) return std::forward(range).begin(); } +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto begin(const RangeType & range) + -> decltype(range.begin()) { + return range.begin(); +} + /** * \concept{DashRangeConcept} */ @@ -176,6 +185,15 @@ constexpr auto end(RangeType && range) return std::forward(range).end(); } +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto end(const RangeType & range) + -> decltype(range.end()) { + return range.end(); +} + /** * \concept{DashRangeConcept} */ @@ -186,6 +204,16 @@ size(RangeType && r) return std::forward(r).size(); } +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto +size(const RangeType & r) + -> decltype(r.size()) { + return r.size(); +} + } // namespace dash #endif // DASH__RANGES_H__INCLUDED diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index c4ca73b78..a6bb7e2aa 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1169,6 +1169,12 @@ GlobOutputIt copy( DASH_LOG_TRACE_VAR("dash::copy()", in_g_range); DASH_LOG_TRACE_VAR("dash::copy()", dash::index(in_g_range)); + auto in_blocks = dash::blocks(in_g_range); + DASH_LOG_TRACE_VAR("dash::copy()", in_blocks); + + auto out_blocks = dash::blocks(out_g_range); + DASH_LOG_TRACE_VAR("dash::copy()", out_blocks); + // 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)):", diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index a13d227b3..aac6b1385 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -480,7 +480,8 @@ class ViewBlocksMod : public ViewModBase< ViewBlocksMod, DomainType, NDim > { private: typedef ViewBlocksMod self_t; - typedef ViewBlocksMod const_self_t; +//typedef ViewBlocksMod const_self_t; + typedef ViewBlocksMod const_self_t; typedef ViewModBase, DomainType, NDim> base_t; public: @@ -634,19 +635,21 @@ class ViewBlocksMod // ---- access ---------------------------------------------------------- constexpr const_iterator begin() const { - return const_iterator(*const_cast(this), + return const_iterator(*this, _index_set.first()); } iterator begin() { - return iterator(*this, _index_set.first()); + return iterator(const_cast(*this), + _index_set.first()); } constexpr const_iterator end() const { - return const_iterator(*const_cast(this), + return const_iterator(*this, _index_set.last() + 1); } iterator end() { - return iterator(*this, _index_set.last() + 1); + return iterator(const_cast(*this), + _index_set.last() + 1); } constexpr block_type operator[](int offset) const { diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 5e249876b..6c04df364 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -704,6 +704,9 @@ class IteratorRangeOrigin typedef typename iterator::value_type value_type; + typedef typename iterator::reference reference; + typedef typename iterator::const_reference const_reference; + typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; @@ -743,6 +746,14 @@ class IteratorRangeOrigin iterator begin() { return _begin; } sentinel end() { return _end; } + constexpr const_reference operator[](int offset) const { + return *(this->begin() + offset); + } + + reference operator[](int offset) { + return *(this->begin() + offset); + } + constexpr size_type size() const noexcept { return std::distance(_begin, _end); } From acccf220553254b38306d4069ff316b9e8cb42c4 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 7 Jun 2017 06:06:21 +0200 Subject: [PATCH 063/161] Extended nview, copy tests --- dash/examples/ex.02.matrix-copy/main.cpp | 56 +++++++++++++++ dash/include/dash/algorithm/Copy.h | 21 ++++-- .../dash/iterator/internal/IteratorBase.h | 4 +- dash/include/dash/view/IndexSet.h | 18 +++++ dash/include/dash/view/Origin.h | 17 +++-- dash/include/dash/view/ViewIterator.h | 11 +-- dash/include/dash/view/ViewMod.h | 11 ++- dash/include/dash/view/ViewMod1D.h | 32 ++++----- dash/include/dash/view/ViewTraits.h | 8 --- dash/test/TestBase.h | 51 ++++++++++++++ dash/test/algorithm/CopyTest.cc | 69 ++++++++++++++++++- dash/test/view/NViewTest.cc | 25 +++++-- 12 files changed, 271 insertions(+), 52 deletions(-) create mode 100644 dash/examples/ex.02.matrix-copy/main.cpp diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp new file mode 100644 index 000000000..59faccbf7 --- /dev/null +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -0,0 +1,56 @@ + +#include + +#include +#include + +using std::cout; +using std::endl; + + +int main(int argc, char **argv) +{ + constexpr int elem_per_unit = 1000; + dash::init(&argc, &argv); + + std::vector vec(100); + std::fill(vec.begin(), vec.end(), dash::myid()); + + dash::NArray 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(dest_range.begin() + 100) + << endl; + + dash::copy(&vec[0], + &vec[0] + vec.size(), + static_cast(dest_range.begin())); + } + + matrix.barrier(); + dash::finalize(); + + return 0; +} diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index a6bb7e2aa..21a0f3bb9 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -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)):", @@ -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; } diff --git a/dash/include/dash/iterator/internal/IteratorBase.h b/dash/include/dash/iterator/internal/IteratorBase.h index 1abe61b36..bb9d9cf72 100644 --- a/dash/include/dash/iterator/internal/IteratorBase.h +++ b/dash/include/dash/iterator/internal/IteratorBase.h @@ -85,12 +85,12 @@ class IndexIteratorBase } derived_t & operator++() { - _pos++; + ++_pos; return derived(); } derived_t & operator--() { - _pos--; + ++_pos; return derived(); } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 8d420c468..939716c8c 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1010,6 +1010,24 @@ class IndexSetLocal return this->pattern().local_extents()[shape_dim]; } + // ---- offsets --------------------------------------------------------- + +#if TODO + constexpr std::array + offsets() const { + return std::array { }; + } + + template + 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 { diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index b1e139b58..575992166 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -70,16 +70,25 @@ global_origin(const ViewT & view) template constexpr auto -origin(const ViewT & view) +origin(ViewT && view) -> typename std::enable_if< - ( dash::view_traits::is_view::value && + ( dash::view_traits< + typename std::decay::type + >::is_view::value && dash::view_traits< - typename dash::view_traits::domain_type + typename dash::view_traits< + typename std::decay::type + >::domain_type >::is_local::value ), const typename dash::view_traits::origin_type::local_type & + // typename dash::view_traits< + // typename std::decay::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(view).domain())); } template diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 4240b8010..d776ba16a 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -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; @@ -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(); } @@ -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(); diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 3a21e94ee..91b13877d 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -451,10 +451,12 @@ class ViewLocalMod template constexpr size_type extent() const { return _index_set.template extent(); +// 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 --------------------------------------------------------- @@ -483,7 +485,8 @@ class ViewLocalMod return iterator( dash::begin( dash::local( - const_cast(dash::origin(*this)) )), + const_cast( + dash::origin(*this)) )), _index_set, 0); } @@ -499,7 +502,8 @@ class ViewLocalMod return iterator( dash::begin( dash::local( - const_cast(dash::origin(*this)) )), + const_cast( + dash::origin(*this)) )), _index_set, _index_set.size()); } @@ -515,7 +519,8 @@ class ViewLocalMod return *iterator( dash::begin( dash::local( - const_cast(dash::origin(*this)) )), + const_cast( + dash::origin(*this)) )), _index_set, offset); } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 6c04df364..fda41201e 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -129,14 +129,14 @@ class ViewSubMod 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( dash::origin(*this) ).begin(), - _index_set, _index_set.size()); + _index_set, _index_set.size() - 1) + 1; } constexpr const_reference operator[](int offset) const { @@ -483,8 +483,6 @@ struct view_traits > { typedef IteratorRangeOrigin origin_type; typedef RangeT image_type; -//typedef typename Iterator::pattern_type pattern_type; -//typedef std::integral_constant rank; typedef std::integral_constant rank; typedef RangeT local_type; @@ -641,7 +639,7 @@ class IteratorRangeLocalOrigin global_type & global() { return dash::global(dash::domain(*this)); } -}; +}; // IteratorRangeLocalOrigin // ----------------------------------------------------------------------- // Iterator Range Origin @@ -665,8 +663,6 @@ struct view_traits > { typedef IteratorRangeOrigin origin_type; typedef IteratorRangeOrigin image_type; -//typedef typename Iterator::pattern_type pattern_type; -//typedef std::integral_constant rank; typedef std::integral_constant rank; typedef RangeT global_type; @@ -773,7 +769,7 @@ class IteratorRangeOrigin self_t & global() { return *this; } -}; +}; // IteratorRangeOrigin // ----------------------------------------------------------------------- // Iterator Range Origin (local pointers) @@ -975,7 +971,7 @@ class IteratorRangeOrigin< constexpr size_type size() const { return std::distance(_begin, _end); } -}; +}; // IteratorRangeOrigin #endif // ---------------------------------------------------------------------- @@ -994,8 +990,6 @@ struct view_traits > { typedef RangeOrigin origin_type; typedef RangeT image_type; -//typedef typename RangeOrigin::pattern_type pattern_type; -//typedef std::integral_constant rank; typedef std::integral_constant rank; typedef RangeT global_type; @@ -1047,8 +1041,6 @@ class IteratorRange typedef self_t global_type; typedef ViewLocalMod local_type; -//typedef typename RangeOrigin::pattern_type pattern_type; - typedef typename view_traits< typename std::decay::type >::is_local is_local; @@ -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()) { } @@ -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()) { } @@ -1177,7 +1173,9 @@ class IteratorRange self_t & global() { return *this; } -}; +}; // IteratorRange + +#endif // DOXYGEN // ----------------------------------------------------------------------- // dash::make_range @@ -1197,8 +1195,6 @@ make_range(Iterator && begin, Sentinel && end) { std::forward(end)); } -#endif // DOXYGEN - } // namespace dash #endif // DASH__VIEW__VIEW_MOD_1D_H__INCLUDED diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index b1b25ae25..288c63044 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -108,7 +108,6 @@ namespace detail { >::is_local::value > is_local; typedef typename ViewT::local_type local_type; -// typedef typename view_traits::local_type local_type; typedef typename ViewT::global_type global_type; typedef typename std::conditional::origin_type origin_type; typedef std::integral_constant rank; - -// typedef typename dash::view_traits::pattern_type -// pattern_type; }; /** @@ -136,13 +132,10 @@ namespace detail { typedef ContainerT image_type; typedef ContainerT global_type; typedef typename ContainerT::local_type local_type; - //typedef typename view_traits::local_type local_type; typedef typename ContainerT::index_type index_type; typedef typename ContainerT::size_type size_type; typedef typename dash::IndexSetIdentity index_set_type; -// typedef typename ContainerT::pattern_type pattern_type; - /// Whether the view type is a projection (has less dimensions than the /// view's domain type). typedef std::integral_constant is_projection; @@ -155,7 +148,6 @@ namespace detail { typedef std::integral_constant::value > is_local; typedef std::integral_constant +#include +#include + + namespace testing { namespace internal { @@ -224,6 +229,52 @@ static std::string range_str( return ss.str(); } +template +std::string nview_str( + const NViewType & nview) { + using value_t = typename NViewType::value_type; + auto view_nrows = nview.extents()[0]; + auto view_ncols = nview.extents()[1]; + auto nindex = dash::index(nview); + std::ostringstream ss; + for (int r = 0; r < view_nrows; ++r) { + for (int c = 0; c < view_ncols; ++c) { + int offset = r * view_ncols + c; + ss << std::fixed << std::setw(3) + << offset << ":" + << std::fixed << std::setw(2) + << nindex[offset] + << ":" + << std::fixed << std::setprecision(3) + << static_cast(nview[r][c]) + << " "; + } + ss << '\n'; + } + return ss.str(); +} + +template +std::string nrange_str( + const NViewType & nview) { + using value_t = typename NViewType::value_type; + auto view_nrows = nview.extents()[0]; + auto view_ncols = nview.extents()[1]; + std::ostringstream ss; + for (int r = 0; r < view_nrows; ++r) { + for (int c = 0; c < view_ncols; ++c) { + int offset = r * view_ncols + c; + ss << std::fixed << std::setw(3) + << offset << ":" + << std::fixed << std::setprecision(3) + << static_cast(nview[r][c]) + << " "; + } + ss << '\n'; + } + return ss.str(); +} + template static bool expect_range_values_equal( const RangeA & rng_a, diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 7882a2942..05085bb5e 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -1,4 +1,6 @@ +#include "CopyTest.h" + #include #include @@ -8,15 +10,16 @@ #include #include #include + #include #include #include -#include "../TestBase.h" -#include "../TestLogHelpers.h" -#include "CopyTest.h" +#include #include +#include + TEST_F(CopyTest, BlockingGlobalToLocalBlock) @@ -466,6 +469,66 @@ TEST_F(CopyTest, AsyncLocalToGlobPtr) array.barrier(); } +TEST_F(CopyTest, BlockingLocalToGlobalBlockNDim) +{ + // Copy all elements contained in a single, continuous block. + const int num_rows_per_unit = 3; + const int num_cols_per_unit = 7; + + // Distribute row-wise, 3 rows per units: + dash::SizeSpec<2> sizespec(num_rows_per_unit * dash::size(), + num_cols_per_unit); + dash::DistributionSpec<2> distspec(dash::BLOCKED, dash::NONE); + dash::TeamSpec<2> teamspec(dash::size(), 1); + + using pattern_t = dash::BlockPattern<2>; + + dash::NArray matrix( + sizespec, distspec, dash::Team::All(), teamspec); + + std::iota(matrix.local.begin(), + matrix.local.end(), + (dash::myid() + 1) * 100); + matrix.barrier(); + + if (dash::myid() == 0) { + DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", + "initial matrix:"); + DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", + dash::test::nrange_str(matrix)); + } + + auto dest_row = ((dash::myid() + 1) * num_rows_per_unit) + % matrix.extents()[0]; + + DASH_LOG_DEBUG_VAR("CopyTest.BlockingLocalToGlobalBlockNDim", + matrix.local.row(1)); + DASH_LOG_DEBUG_VAR("CopyTest.BlockingLocalToGlobalBlockNDim", + matrix.local.row(1).begin()); + DASH_LOG_DEBUG_VAR("CopyTest.BlockingLocalToGlobalBlockNDim", + matrix.local.row(1).end()); + +// auto in_range = dash::make_range(matrix.local.row(1).begin(), +// matrix.local.row(1).end()); + + // Copy second local row into matrix row at next unit: + dash::copy(matrix.local.row(1).begin(), + matrix.local.row(1).end(), + static_cast( + dash::sub<0>( + dest_row, + dest_row + 1, + matrix).begin() + )); + + if (dash::myid() == 0) { + DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", + "result matrix:"); + DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", + dash::test::nrange_str(matrix)); + } +} + TEST_F(CopyTest, BlockingGlobalToLocalSubBlock) { // Copy all elements contained in a single, continuous block, diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index e82aa95c5..ab94c68b9 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -552,21 +552,23 @@ TEST_F(NViewTest, MatrixBlocked1DimChained) DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", "== nview_rows_l"); auto nview_rows_l = dash::local(nview_rows_g); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", + "local(sub<0>(1,3, mat)):", "extents:", nview_rows_l.extents(), "offsets:", nview_rows_l.offsets()); -// EXPECT_EQ_U(2, nview_rows_l.extent<0>()); -// EXPECT_EQ_U(block_cols, nview_rows_l.extent<1>()); -// -// dash::test::print_nview("nview_rows_l", nview_rows_l); + EXPECT_EQ_U(2, nview_rows_l.extent<0>()); + EXPECT_EQ_U(block_cols, nview_rows_l.extent<1>()); + + dash::test::print_nview("nview_rows_l", nview_rows_l); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", "== nview_cols_l"); auto nview_cols_l = dash::local(nview_cols_g); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", + "local(sub<1>(2,7, mat)):", "extents:", nview_cols_l.extents(), "offsets:", nview_cols_l.offsets()); -// dash::test::print_nview("nview_cols_l", nview_cols_l); + dash::test::print_nview("nview_cols_l", nview_cols_l); } TEST_F(NViewTest, MatrixBlocked1DimSub) @@ -605,6 +607,19 @@ TEST_F(NViewTest, MatrixBlocked1DimSub) DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", mat.pattern().local_size()); + // Initial plausibility check: equality of iterator on n-dim view and + // matrix view proxy iterator: + auto view_expr_it = dash::sub<0>(1,2, mat) + .begin() + 2; + auto mat_ref_glob_it = (mat.row(1).begin() + 2); + + using globiter_t = decltype(mat.begin()); + + EXPECT_EQ_U(static_cast(view_expr_it), + (mat_ref_glob_it)); + EXPECT_EQ_U(view_expr_it.dart_gptr(), + mat_ref_glob_it.dart_gptr()); + if (dash::myid() == 0) { auto all_sub = dash::sub<0>( 0, mat.extents()[0], From e869352b040ddbdb8b291b7f50cdfb79e6f9ab73 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 7 Jun 2017 12:47:18 +0200 Subject: [PATCH 064/161] Extending view examples, fix in IndexSetBase --- dash/examples/ex.02.array-copy/main.cpp | 6 +++--- dash/include/dash/algorithm/Copy.h | 10 ++++++++-- dash/include/dash/iterator/internal/IteratorBase.h | 2 +- dash/include/dash/view/Origin.h | 6 ++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 780c804cc..9ababa50e 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) size_t num_units = dash::Team::All().size(); size_t num_elems_unit = (argc > 1) ? static_cast(atoi(argv[1])) - : 6; + : 8; size_t num_elems_total = num_elems_unit * num_units; size_t start_index = (argc > 2) ? static_cast(atoi(argv[2])) @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) ? static_cast(atoi(argv[3])) : num_elems_total / 2; - dash::Array array(num_elems_total); + dash::Array array(num_elems_total, dash::BLOCKCYCLIC(3)); if (myid == 0) { cout << endl @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) cout << range_str(g_out_range) << endl; } - dash::Array src_array(num_elems_total / 2); + dash::Array src_array(num_elems_total / 2, dash::BLOCKCYCLIC(2)); std::fill(src_array.lbegin(), src_array.lend(), (myid + 1) * 10); diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 21a0f3bb9..28bfc4447 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1178,11 +1178,15 @@ GlobOutputIt copy( auto out_blocks = dash::blocks(out_g_range); DASH_LOG_TRACE_VAR("dash::copy()", out_blocks); + auto l_out_blocks = dash::local(out_blocks); + 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); + for (auto l_out_block : l_out_blocks) { + DASH_LOG_TRACE_VAR("dash::copy()", l_out_block); + DASH_LOG_TRACE_VAR("dash::copy()", dash::global(dash::index(l_out_block))); } // local view on in/out ranges: @@ -1193,6 +1197,8 @@ GlobOutputIt copy( out_l_range); DASH_LOG_TRACE("dash::copy()", "index(local(range(out_gi, out_ge))):", dash::index(out_l_range)); + DASH_LOG_TRACE("dash::copy()", "global(index(local(range(o_gi,o_ge)))):", + dash::global(dash::index(out_l_range))); auto in_l_range = dash::local(in_g_range); DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", diff --git a/dash/include/dash/iterator/internal/IteratorBase.h b/dash/include/dash/iterator/internal/IteratorBase.h index bb9d9cf72..8908250d7 100644 --- a/dash/include/dash/iterator/internal/IteratorBase.h +++ b/dash/include/dash/iterator/internal/IteratorBase.h @@ -90,7 +90,7 @@ class IndexIteratorBase } derived_t & operator--() { - ++_pos; + --_pos; return derived(); } diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index 575992166..f8d11ba6f 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -80,10 +80,8 @@ origin(ViewT && view) typename std::decay::type >::domain_type >::is_local::value ), - const typename dash::view_traits::origin_type::local_type & - // typename dash::view_traits< - // typename std::decay::type - // >::origin_type::local_type + decltype(dash::local( + dash::global_origin(std::forward(view).domain()))) >::type { // Recurse to origin of local view: return dash::local( From 50fae61b5547bd5ddad0a7eda911a5e13fa378cd Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 8 Jun 2017 22:38:30 +0200 Subject: [PATCH 065/161] ShiftTilePattern.local_block_at, ViewIterator.local --- dash/examples/ex.02.array-copy/main.cpp | 3 +-- dash/include/dash/pattern/ShiftTilePattern.h | 21 +++++++++++++++++--- dash/include/dash/view/ViewIterator.h | 10 +++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/dash/examples/ex.02.array-copy/main.cpp b/dash/examples/ex.02.array-copy/main.cpp index 9ababa50e..24ffb2ab4 100644 --- a/dash/examples/ex.02.array-copy/main.cpp +++ b/dash/examples/ex.02.array-copy/main.cpp @@ -114,8 +114,7 @@ int main(int argc, char* argv[]) for(size_t i = 0; i < num_elems_copy; ++i) { ss << local_array[i] << " "; } - ss << endl; - cout << ss.str(); + cout << ss.str() << endl; array.barrier(); diff --git a/dash/include/dash/pattern/ShiftTilePattern.h b/dash/include/dash/pattern/ShiftTilePattern.h index c2e052671..6ddb6eaf1 100644 --- a/dash/include/dash/pattern/ShiftTilePattern.h +++ b/dash/include/dash/pattern/ShiftTilePattern.h @@ -1154,9 +1154,24 @@ class ShiftTilePattern /// Global coordinates of element const std::array & g_coords) const { - DASH_THROW( - dash::exception::NotImplemented, - "ShiftTilePattern.local_block_at is not implemented"); + local_index_t l_pos; + l_pos.unit = 0; + + std::array l_block_coords; + for (dim_t d = 0; d < NumDimensions; ++d) { + auto nunits_d = _teamspec.extent(d); + auto blocksize_d = _blocksize_spec.extent(d); + auto block_coord_d = g_coords[d] / blocksize_d; + l_block_coords[d] = block_coord_d / nunits_d; + l_pos.unit = (l_pos.unit + block_coord_d) % _teamspec.size(); + } + l_pos.index = _local_blockspec.at(l_block_coords); + + DASH_LOG_TRACE("ShiftTilePattern.local_block_at >", + "coords", g_coords, + "unit:", l_pos.unit, + "local block index:", l_pos.index); + return l_pos; } /** diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index d776ba16a..39dfe2312 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -92,14 +92,18 @@ class ViewIterator return (_index_set)[this->pos()]; } - constexpr const local_type local() const { - return (_domain_it + (_index_set[this->pos()])).local(); + constexpr bool is_local() const { + return (_domain_it + (_index_set[this->pos()])).is_local(); } - inline local_type local() { + constexpr local_type local() const { return (_domain_it + (_index_set[this->pos()])).local(); } + constexpr const self_t & global() const { + return *this; + } + constexpr dart_gptr_t dart_gptr() const { return (_domain_it + _index_set[this->pos()]).dart_gptr(); } From c9004abe90c946aa881f677b60298f9a0bd64662 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 8 Jun 2017 22:39:23 +0200 Subject: [PATCH 066/161] Added dash::sub(offset, domain) --- dash/include/dash/view/Sub.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dash/include/dash/view/Sub.h b/dash/include/dash/view/Sub.h index 0c042f47c..5718a5c24 100644 --- a/dash/include/dash/view/Sub.h +++ b/dash/include/dash/view/Sub.h @@ -77,8 +77,7 @@ ViewSubMod< DomainValueT, SubDim, dash::view_traits::rank::value > -sub( - OffsetFirstT begin, +sub(OffsetFirstT begin, OffsetFinalT end, DomainT && domain) { return ViewSubMod< @@ -90,6 +89,17 @@ sub( end); } +template < + dim_t SubDim = 0, + class DomainT, + class OffsetT > +constexpr auto +sub(OffsetT offset, + DomainT && domain) + -> decltype(dash::sub(offset, offset+1, domain)) { + return dash::sub(offset, offset+1, domain); +} + } // namespace dash #endif // DASH__VIEW__SUB_H__INCLUDED From e46d541df82cf8b5965c12e37717941817c334e8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 9 Jun 2017 03:42:47 +0200 Subject: [PATCH 067/161] Fixing n-dim make_range --- dash/include/dash/algorithm/Copy.h | 127 +++++++++++++++++++------- dash/include/dash/view/IndexSet.h | 19 ++-- dash/include/dash/view/ViewIterator.h | 6 ++ dash/include/dash/view/ViewMod1D.h | 28 +++--- dash/test/TestBase.h | 14 +-- dash/test/algorithm/CopyTest.cc | 113 +++++++++++++++-------- 6 files changed, 209 insertions(+), 98 deletions(-) diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 28bfc4447..8eeb50712 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -798,36 +798,83 @@ dash::Future copy_async( * * \ingroup DashAlgorithms */ + template < class ValueType, - class GlobInputIt > -ValueType * copy( - GlobInputIt in_first, - GlobInputIt in_last, - ValueType * out_first) + class GlobInputRange > +auto copy( + GlobInputRange in_range, + ValueType * out_first) + -> typename std::enable_if< + GlobInputRange::rank::value == 1, + ValueType * + >::type { - const auto & team = in_first.team(); - dash::util::UnitLocality uloc(team, team.myid()); - // Size of L2 data cache line: - int l2_line_size = uloc.hwinfo().cache_line_sizes[1]; - bool use_memcpy = ((in_last - in_first) * sizeof(ValueType)) - <= l2_line_size; + DASH_LOG_TRACE("dash::copy:range()", "ND = 1, blocking, global to local"); + if (in_range.size() == 0) { + DASH_LOG_TRACE("dash::copy:range", "input range empty"); + return out_first; + } + auto out_last = out_first; + auto in_blocks = dash::blocks(in_range); + DASH_LOG_TRACE("dash::copy:range", "number of blocks:", in_blocks.size()); + + for (auto block : in_blocks) { + DASH_LOG_TRACE("dash::copy:range", "block size:", block.size()); + auto in_copy_it = block.begin(); + auto in_copy_lp = in_copy_it.local(); + out_last = static_cast( + false && in_copy_lp != nullptr + ? std::copy( + in_copy_lp, + in_copy_lp + block.size(), + out_last) + : dash::internal::copy_block( + in_copy_it, + in_copy_it + block.size(), + out_last) ); + } + DASH_LOG_TRACE("dash::copy:range >", "finished,", "out_last:", out_last); + return out_last; +} - DASH_LOG_TRACE("dash::copy()", "blocking, global to local"); +template < + class ValueType, + class GlobInputRange > +auto copy( + GlobInputRange in_range, + ValueType * out_first) + -> typename std::enable_if< + (GlobInputRange::rank::value > 1), + ValueType * + >::type +{ + DASH_LOG_TRACE("dash::copy:range()", "ND > 1, blocking, global to local"); + + auto dest_first = out_first; + auto out_last = out_first; + auto in_first = in_range.begin(); + auto in_last = in_range.end(); + auto li_range_in = dash::index( + dash::local( + in_range)); + DASH_LOG_TRACE("dash::copy", "source local index range:", + li_range_in); + DASH_LOG_TRACE("dash::copy", "source g(local) index range:", + dash::global(li_range_in)); - ValueType * dest_first = out_first; - // Return value, initialize with begin of output range, indicating no - // values have been copied: - ValueType * out_last = out_first; - // Check if part of the input range is local: - DASH_LOG_TRACE_VAR("dash::copy", in_first.dart_gptr()); - DASH_LOG_TRACE_VAR("dash::copy", in_last.dart_gptr()); - DASH_LOG_TRACE_VAR("dash::copy", out_first); - auto li_range_in = local_index_range(in_first, in_last); // Number of elements in the local subrange: - auto num_local_elem = li_range_in.end - li_range_in.begin; +//auto num_local_elem = li_range_in.end - li_range_in.begin; + auto num_local_elem = li_range_in.size(); // Total number of elements to be copied: - auto total_copy_elem = in_last - in_first; + auto total_copy_elem = in_range.size(); + + const auto & team = in_first.team(); + dash::util::UnitLocality uloc(team, team.myid()); + // Size of L2 data cache line: + int l2_line_size = uloc.hwinfo().cache_line_sizes[1]; + bool use_memcpy = ((in_last - in_first) * sizeof(ValueType)) + <= l2_line_size; // Instead of testing in_first.local() and in_last.local(), this test // for a local-only range only requires one call to in_first.local() @@ -835,7 +882,6 @@ ValueType * copy( if (num_local_elem == total_copy_elem) { // Entire input range is local: DASH_LOG_TRACE("dash::copy", "entire input range is local"); - ValueType * out_last = out_first + total_copy_elem; // Use memcpy for data ranges below 64 KB if (use_memcpy) { std::memcpy(out_first, // destination @@ -853,11 +899,6 @@ ValueType * copy( (out_last - out_first), "elements"); return out_last; } - - DASH_LOG_TRACE("dash::copy", "local range:", - li_range_in.begin, - li_range_in.end, - "in_first.is_local:", in_first.is_local()); // Check if global input range is partially local: if (num_local_elem > 0) { // Part of the input range is local, copy local input subrange to @@ -870,12 +911,12 @@ ValueType * copy( DASH_LOG_TRACE_VAR("dash::copy", num_local_elem); // Local index range to global input index range: // Global index of local range begin index: - auto g_l_offset_begin = pattern.global(li_range_in.begin); + auto g_l_offset_begin = pattern.global(li_range_in.first()); // Global index of local range end index: // // NOTE: definition as pat.global(l_end-1)+1 as // pat.global(l_end) would be out of range - auto g_l_offset_end = pattern.global(li_range_in.end-1) + 1; + auto g_l_offset_end = pattern.global(li_range_in.last()) + 1; DASH_LOG_TRACE("dash::copy", "global index range of local subrange:", "begin:", g_l_offset_begin, "end:", g_l_offset_end); @@ -984,6 +1025,30 @@ ValueType * copy( return out_last; } +template < + class ValueType, + class GlobInputIt > +ValueType * copy( + GlobInputIt in_first, + GlobInputIt in_last, + ValueType * out_first) +{ + DASH_LOG_TRACE("dash::copy()", "blocking, global to local"); + // Check if part of the input range is local: + DASH_LOG_TRACE_VAR("dash::copy", in_first.dart_gptr()); + DASH_LOG_TRACE_VAR("dash::copy", in_last.dart_gptr()); + DASH_LOG_TRACE_VAR("dash::copy", out_first); + +//auto li_range_in_old = local_index_range(in_first, in_last); +//DASH_LOG_TRACE("dash::copy", "source index range (old):", +// "(", li_range_in_old.begin, ",", li_range_in_old.end, ")"); + auto in_range = dash::make_range(in_first, in_last); + DASH_LOG_TRACE("dash::copy", "source value range:", in_range); + DASH_LOG_TRACE("dash::copy", "source index range:", dash::index(in_range)); + + return dash::copy(in_range, out_first); +} + // ====================================================================== // Local to Global, Distributed Range diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 939716c8c..e13b5709b 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -421,8 +421,8 @@ class IndexSetBase const PatternT_ & pat, const index_range_t & grng) noexcept { return index_range_t { - pat.local_coords({{ grng.begin }})[0], - pat.local_coords({{ grng.end }})[0] + pat.local_coords({{ static_cast(grng.begin) }})[0], + pat.local_coords({{ static_cast(grng.end) }})[0] }; } @@ -1555,7 +1555,8 @@ class IndexSetBlock index_type _block_idx; index_type _size; - constexpr static dim_t NBlockDim = pattern_ndim::value; + constexpr static dim_t NDomainDim = pattern_ndim::value; + constexpr static dim_t NBlockDim = pattern_ndim::value; constexpr static bool view_domain_is_local = dash::view_traits::is_local::value; public: @@ -1623,14 +1624,16 @@ class IndexSetBlock this->pattern().local_block(_block_idx) ) ) : ( // translate block phase to global index: - this->pattern().global_at( - // global coords + dash::CartesianIndexSpace( + this->pattern().extents() + ).at( + // in-block coords dash::CartesianIndexSpace( this->pattern().block(_block_idx).extents() ).coords(block_phase), - // viewspec - this->pattern().block(_block_idx) - ) ) + // block viewspec + this->pattern().block(_block_idx)) + ) ); } diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 39dfe2312..22b5cde5c 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -44,6 +44,8 @@ class ViewIterator typedef typename IndexSetType::index_type index_type; typedef typename DomainIterator::pattern_type pattern_type; typedef typename DomainIterator::local_type local_type; + + typedef std::integral_constant has_view; private: DomainIterator _domain_it; IndexSetType _index_set; @@ -112,6 +114,10 @@ class ViewIterator return dart_gptr(); } + constexpr const dash::Team & team() const { + return _domain_it.team(); + } + constexpr explicit operator DomainIterator() const { return (_domain_it + _index_set[this->pos()]); } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index fda41201e..e5f6ea02f 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -658,12 +658,14 @@ template < struct view_traits > { private: typedef IteratorRangeOrigin RangeT; + typedef typename Iterator::pattern_type PatternT; public: typedef IteratorRangeOrigin domain_type; typedef IteratorRangeOrigin origin_type; typedef IteratorRangeOrigin image_type; - typedef std::integral_constant rank; + typedef std::integral_constant< + dim_t, static_cast(PatternT::ndim())> rank; typedef RangeT global_type; typedef IteratorRangeLocalOrigin local_type; @@ -671,8 +673,7 @@ struct view_traits > { typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef dash::IndexSetIdentity< - IteratorRangeOrigin > index_set_type; + typedef dash::IndexSetIdentity index_set_type; typedef std::integral_constant is_projection; typedef std::integral_constant is_view; @@ -993,7 +994,7 @@ struct view_traits > { typedef std::integral_constant rank; typedef RangeT global_type; - typedef ViewLocalMod local_type; + typedef ViewLocalMod local_type; typedef typename RangeT::index_type index_type; typedef typename RangeT::size_type size_type; @@ -1017,12 +1018,11 @@ template class IteratorRange : public ViewModBase< IteratorRange, - RangeOrigin, - 1 > + RangeOrigin > { typedef IteratorRange self_t; - typedef ViewModBase, RangeOrigin, 1 > + typedef ViewModBase, RangeOrigin> base_t; public: typedef typename RangeOrigin::iterator iterator; @@ -1036,10 +1036,12 @@ class IteratorRange typedef typename domain_type::value_type value_type; - typedef std::integral_constant rank; + typedef typename dash::view_traits< + typename std::decay::type + >::rank rank; typedef self_t global_type; - typedef ViewLocalMod local_type; + typedef ViewLocalMod local_type; typedef typename view_traits< typename std::decay::type @@ -1065,8 +1067,8 @@ 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()) - // end + // begin + (begin.pattern().size() - begin.pos()) + end )) // Convert iterator positions to sub-range index set: , _index_set(this->domain(), begin.pos(), end.pos()) @@ -1077,8 +1079,8 @@ 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(end) + // 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()) diff --git a/dash/test/TestBase.h b/dash/test/TestBase.h index c00abd75c..72edd75ea 100644 --- a/dash/test/TestBase.h +++ b/dash/test/TestBase.h @@ -14,6 +14,7 @@ #include #include +#include #include @@ -241,12 +242,10 @@ std::string nview_str( for (int c = 0; c < view_ncols; ++c) { int offset = r * view_ncols + c; ss << std::fixed << std::setw(3) - << offset << ":" - << std::fixed << std::setw(2) << nindex[offset] << ":" - << std::fixed << std::setprecision(3) - << static_cast(nview[r][c]) + << std::fixed << std::setprecision(5) + << static_cast(nview[offset]) << " "; } ss << '\n'; @@ -262,12 +261,13 @@ std::string nrange_str( auto view_ncols = nview.extents()[1]; std::ostringstream ss; for (int r = 0; r < view_nrows; ++r) { - for (int c = 0; c < view_ncols; ++c) { + auto row_view = dash::sub<0>(r, r+1, nview); + for (int c = 0; c < row_view.size(); ++c) { int offset = r * view_ncols + c; ss << std::fixed << std::setw(3) << offset << ":" - << std::fixed << std::setprecision(3) - << static_cast(nview[r][c]) + << std::fixed << std::setprecision(5) + << static_cast(row_view[c]) << " "; } ss << '\n'; diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 05085bb5e..7f734b595 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -99,7 +99,6 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) // Assign initial values: for (size_t lb = 0; lb < num_blocks_per_unit; ++lb) { - LOG_MESSAGE("initialize values in local block %zu", lb); auto lblock = matrix.local.block(lb); auto lblock_view = lblock.begin().viewspec(); auto lblock_extents = lblock_view.extents(); @@ -107,10 +106,6 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) dash__unused(lblock_offsets); EXPECT_EQ_U(block_size_x, lblock_extents[0]); EXPECT_EQ_U(block_size_y, lblock_extents[1]); - LOG_MESSAGE("local block %zu offset: (%li,%li) extent: (%lu,%lu)", - lb, - lblock_offsets[0], lblock_offsets[1], - lblock_extents[0], lblock_extents[1]); for (auto bx = 0; bx < static_cast(lblock_extents[0]); ++bx) { for (auto by = 0; by < static_cast(lblock_extents[1]); ++by) { // Phase coordinates (bx,by) to global coordinates (gx,gy): @@ -124,8 +119,6 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) ((bx + 1) * 100) + by + 1 )); - LOG_MESSAGE("set local block %zu at phase:(%d,%d) g:(%li,%li) = %f", - lb, bx, by, gx, gy, value); lblock[bx][by] = value; } } @@ -139,9 +132,6 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) for (size_t x = 0; x < extent_x; ++x) { std::vector row; for (size_t y = 0; y < extent_y; ++y) { - DASH_LOG_DEBUG("CopyTest.Blocking2Dim", "get matrix value at", - "x:", x, - "y:", y); value_t value = matrix[x][y]; row.push_back(value); } @@ -155,10 +145,10 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) matrix.barrier(); // Array to store local copy: - value_t * local_copy = new value_t[num_elem_per_unit]; + std::vector local_copy(num_elem_per_unit); // Pointer to first value in next copy destination range: - value_t * copy_dest_begin = local_copy; - value_t * copy_dest_last = local_copy; + value_t * copy_dest_begin = local_copy.data(); + value_t * copy_dest_last = local_copy.data(); // // Create local copy of all blocks from a single remote unit: @@ -178,18 +168,57 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) LOG_MESSAGE("Block %zu: assigned to unit %d", gb, g_block_unit.id); if (g_block_unit == remote_unit_id) { // Block is assigned to selecte remote unit, create local copy: - LOG_MESSAGE("Creating local copy of block %zu", gb); - auto remote_block = matrix.block(gb); - auto remote_block_view = remote_block.begin().viewspec(); - dash__unused(remote_block_view); - LOG_MESSAGE("Block %zu index range: (%li..%li] " - "offset: (%li,%li) extent: (%lu,%lu)", - gb, remote_block.begin().pos(), remote_block.end().pos(), - remote_block_view.offset(0), remote_block_view.offset(1), - remote_block_view.extent(0), remote_block_view.extent(1)); - copy_dest_last = dash::copy(remote_block.begin(), - remote_block.end(), - copy_dest_begin); + auto remote_block_matrix = matrix.block(gb); + auto remote_block_view = dash::blocks(matrix)[gb]; + auto remote_block_range = dash::make_range( + remote_block_view.begin(), + remote_block_view.end()); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block extents:", remote_block_view.extents(), + "offsets:", remote_block_view.offsets(), + "size:", remote_block_view.size()); + + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block view:", + dash::typestr(remote_block_view)); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block view domain:", + dash::typestr(dash::domain(remote_block_view))); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block view iterator:", + dash::typestr(remote_block_view.begin()), + "begin.pos:", remote_block_view.begin().pos(), + "end.pos:", remote_block_view.end().pos()); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + dash::test::nview_str(remote_block_view)); + + EXPECT_EQ_U(remote_block_matrix.viewspec().offsets(), + dash::index(remote_block_view).offsets()); + EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), + dash::index(remote_block_view).extents()); + + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block range:", + dash::typestr(remote_block_range)); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block range domain:", + dash::typestr(dash::domain(remote_block_range))); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block range iterator:", + dash::typestr(remote_block_range.begin()), + "begin.pos:", remote_block_range.begin().pos(), + "end.pos:", remote_block_range.end().pos()); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + dash::test::nview_str(remote_block_range)); + + EXPECT_EQ_U(remote_block_matrix.viewspec().offsets(), + dash::index(remote_block_range).offsets()); + EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), + dash::index(remote_block_range).extents()); + + copy_dest_last = dash::copy(remote_block_view.begin(), + remote_block_view.end(), + copy_dest_begin); // Validate number of copied elements: auto num_copied = copy_dest_last - copy_dest_begin; EXPECT_EQ_U(num_copied, block_size); @@ -233,7 +262,6 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) } } } - delete[] local_copy; // // Create local copy of first local block (local to local): @@ -497,9 +525,7 @@ TEST_F(CopyTest, BlockingLocalToGlobalBlockNDim) DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", dash::test::nrange_str(matrix)); } - - auto dest_row = ((dash::myid() + 1) * num_rows_per_unit) - % matrix.extents()[0]; + matrix.barrier(); DASH_LOG_DEBUG_VAR("CopyTest.BlockingLocalToGlobalBlockNDim", matrix.local.row(1)); @@ -508,18 +534,27 @@ TEST_F(CopyTest, BlockingLocalToGlobalBlockNDim) DASH_LOG_DEBUG_VAR("CopyTest.BlockingLocalToGlobalBlockNDim", matrix.local.row(1).end()); -// auto in_range = dash::make_range(matrix.local.row(1).begin(), -// matrix.local.row(1).end()); + DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", + "source range:"); + auto in_range = dash::sub<0>(1, dash::local(matrix)); + DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", + dash::test::nview_str(in_range)); + + auto dest_row = ((dash::myid() + 1) * num_rows_per_unit) + % matrix.extents()[0]; + DASH_LOG_DEBUG_VAR("CopyTest.BlockingLocalToGlobalBlockNDim", + dest_row); + + matrix.barrier(); // Copy second local row into matrix row at next unit: - dash::copy(matrix.local.row(1).begin(), - matrix.local.row(1).end(), - static_cast( - dash::sub<0>( - dest_row, - dest_row + 1, - matrix).begin() - )); + dash::copy(in_range.begin(), + in_range.end(), + dash::sub<0>( + dest_row, + dest_row + 1, + matrix).begin() + ); if (dash::myid() == 0) { DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", From 37fc1d66f12d307b2d7a9078a47b97475181ac72 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 17 Jun 2017 12:56:53 +0200 Subject: [PATCH 068/161] Intermediate experiments with view iterator ranges --- dash/include/dash/view/IndexSet.h | 6 +- dash/include/dash/view/ViewIterator.h | 2 + dash/include/dash/view/ViewMod1D.h | 258 +++++++++++++++++++++++++- dash/test/algorithm/CopyTest.cc | 26 ++- 4 files changed, 272 insertions(+), 20 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index e13b5709b..1154a4562 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1540,17 +1540,17 @@ class IndexSetBlock public: typedef typename DomainType::index_type index_type; typedef typename DomainType::size_type size_type; - + typedef self_t local_type; typedef IndexSetGlobal global_type; typedef global_type preimage_type; typedef typename base_t::iterator iterator; typedef typename base_t::pattern_type pattern_type; - + typedef dash::local_index_t local_index_type; typedef dash::global_index_t global_index_type; - + private: index_type _block_idx; index_type _size; diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 22b5cde5c..27dbac186 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -46,6 +46,8 @@ class ViewIterator typedef typename DomainIterator::local_type local_type; typedef std::integral_constant has_view; + + typedef IndexSetType index_set_type; private: DomainIterator _domain_it; IndexSetType _index_set; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index e5f6ea02f..e44bb1a4e 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -454,7 +454,10 @@ template < class Sentinel > class IteratorRangeOrigin; -template +template +class IteratorRangeViewDomain; + +template class IteratorRange; // ----------------------------------------------------------------------- @@ -652,6 +655,216 @@ class IteratorRangeLocalOrigin // // ----------------------------------------------------------------------- +namespace detail { + template < + class RangeType, + bool has_index_set = dash::detail::has_type_index_set_type< + typename std::decay< + typename RangeType::iterator>::type + >::value > + struct iterator_range_traits; + + template + struct iterator_range_traits { + typedef typename std::decay< + typename RangeType::iterator + >::type::index_set_type + index_set_type; + }; + + template + struct iterator_range_traits { + typedef dash::IndexSetIdentity + index_set_type; + }; +} // namespace detail + +template < + class RangeOrigin, + class IndexSet > +struct view_traits> { + private: + typedef IteratorRangeViewDomain RangeT; + typedef typename RangeOrigin::pattern_type PatternT; + typedef typename RangeOrigin::iterator iterator; + public: + typedef typename std::decay::type origin_type; + typedef typename std::decay::type domain_type; + typedef typename std::decay::type image_type; + + typedef IndexSet index_set_type; + + typedef std::integral_constant< + dim_t, static_cast(PatternT::ndim())> rank; + + typedef RangeT global_type; + typedef ViewLocalMod local_type; + + typedef typename iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; +}; + + +template < + class RangeOrigin, + class IndexSet> +class IteratorRangeViewDomain +: public ViewModBase< + IteratorRangeViewDomain, + RangeOrigin > +{ + typedef IteratorRangeViewDomain self_t; + typedef ViewModBase< + IteratorRangeViewDomain, + RangeOrigin > base_t; + + public: + typedef typename std::decay::type origin_type; + typedef typename std::decay::type domain_type; + typedef typename std::decay::type image_type; + + typedef IndexSet index_set_type; + + typedef typename domain_type::iterator iterator; + typedef typename domain_type::const_iterator const_iterator; + typedef typename domain_type::sentinel sentinel; + typedef typename domain_type::const_sentinel const_sentinel; + + typedef typename iterator::value_type value_type; + + typedef typename iterator::reference reference; + typedef typename iterator::const_reference const_reference; + + typedef typename iterator::index_type index_type; + typedef typename std::make_unsigned::type size_type; + + typedef typename iterator::pattern_type pattern_type; + typedef typename index_set_type::rank rank; + + typedef std::integral_constant is_local; + + typedef self_t global_type; + typedef ViewLocalMod local_type; + + private: + static const dim_t NDim = rank::value; + + const index_set_type & _index_set; + + public: + constexpr IteratorRangeViewDomain(const domain_type & dom) + : base_t(dom) + , _index_set(dom.begin().index_set()) + { } + + constexpr IteratorRangeViewDomain() = delete; + constexpr IteratorRangeViewDomain(const self_t & other) = default; + constexpr IteratorRangeViewDomain(self_t && other) = default; + self_t & operator=(const self_t & other) = default; + self_t & operator=(self_t && other) = default; + + // ---- extents --------------------------------------------------------- + + constexpr std::array extents() const { + return _index_set.extents(); + } + + template + constexpr size_type extent() const { + return _index_set.template extent(); + } + + constexpr size_type extent(dim_t shape_dim) const { + return _index_set.extent(shape_dim); + } + + // ---- offsets --------------------------------------------------------- + + template + constexpr index_type offset() const { + return _index_set.template offset(); + } + + constexpr std::array offsets() const { + return _index_set.offsets(); + } + + constexpr index_type offset(dim_t shape_dim) const { + return _index_set.offset(shape_dim); + } + + // ---- size ------------------------------------------------------------ + + constexpr size_type size(dim_t sub_dim = 0) const { + return _index_set.size(sub_dim); + } + + // ---- access ---------------------------------------------------------- + + constexpr const_iterator begin() const { + return const_iterator( + dash::origin(*this).begin(), + _index_set, 0); + } + + iterator begin() { + return iterator( + const_cast( + dash::origin(*this) + ).begin(), + _index_set, 0); + } + + constexpr const_iterator end() const { + return const_iterator( + dash::origin(*this).begin(), + _index_set, _index_set.size()); + } + + iterator end() { + return iterator( + const_cast( + dash::origin(*this) + ).begin(), + _index_set, _index_set.size()); + } + + constexpr const_reference operator[](int offset) const { + return *(const_iterator(dash::origin(*this).begin(), + _index_set, offset)); + } + + reference operator[](int offset) { + return *(iterator(const_cast( + dash::origin(*this) + ).begin(), + _index_set, offset)); + } + + + constexpr const pattern_type & pattern() const noexcept { + return this->begin().pattern(); + } + + constexpr const local_type local() const noexcept { + return local_type(*this); + } + + constexpr const self_t & global() const { + return *this; + } + + self_t & global() { + return *this; + } +}; // IteratorRangeViewDomain + + template < class Iterator, class Sentinel > @@ -673,7 +886,8 @@ struct view_traits > { typedef typename Iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef dash::IndexSetIdentity index_set_type; + typedef typename detail::iterator_range_traits::index_set_type + index_set_type; typedef std::integral_constant is_projection; typedef std::integral_constant is_view; @@ -752,7 +966,7 @@ class IteratorRangeOrigin } constexpr size_type size() const noexcept { - return std::distance(_begin, _end); + return dash::distance(_begin, _end); } constexpr const pattern_type & pattern() const noexcept { @@ -879,7 +1093,7 @@ class IteratorRangeOrigin< sentinel end() { return _end; } constexpr size_type size() const { - return std::distance(_begin, _end); + return dash::distance(_begin, _end); } }; #else @@ -970,7 +1184,7 @@ class IteratorRangeOrigin< sentinel end() { return _end; } constexpr size_type size() const { - return std::distance(_begin, _end); + return dash::distance(_begin, _end); } }; // IteratorRangeOrigin #endif @@ -1184,10 +1398,14 @@ class IteratorRange // ----------------------------------------------------------------------- template -constexpr dash::IteratorRange< - dash::IteratorRangeOrigin< - typename std::decay::type, - typename std::decay::type > > +constexpr + typename std::enable_if< + !dash::detail::has_type_index_set_type::value, + dash::IteratorRange< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type > > + >::type make_range(Iterator && begin, Sentinel && end) { return dash::IteratorRange< dash::IteratorRangeOrigin< @@ -1197,6 +1415,28 @@ make_range(Iterator && begin, Sentinel && end) { std::forward(end)); } +template +constexpr + typename std::enable_if< + dash::detail::has_type_index_set_type::value, + dash::IteratorRange< + dash::IteratorRangeViewDomain< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type >, + typename Iterator::index_set_type > > + >::type +make_range(Iterator && begin, Sentinel && end) { + return dash::IteratorRange< + dash::IteratorRangeViewDomain< + dash::IteratorRangeOrigin< + typename std::decay::type, + typename std::decay::type >, + typename Iterator::index_set_type > + >(std::forward(begin), + std::forward(end)); +} + } // namespace dash #endif // DASH__VIEW__VIEW_MOD_1D_H__INCLUDED diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 7f734b595..93ab6a5a6 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -184,13 +184,18 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view domain:", dash::typestr(dash::domain(remote_block_view))); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block view domain extents:", + dash::domain(remote_block_view).extents()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view iterator:", dash::typestr(remote_block_view.begin()), - "begin.pos:", remote_block_view.begin().pos(), - "end.pos:", remote_block_view.end().pos()); - DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", - dash::test::nview_str(remote_block_view)); + "begin.pos:", remote_block_view.begin().pos(), + "end.pos:", remote_block_view.end().pos(), + "begin.gpos:", remote_block_view.begin().gpos(), + "end.gpos:", remote_block_view.end().gpos()); + DASH_LOG_DEBUG_VAR("CopyTest.Blocking2DimGlobalToLocalBlock", + dash::test::nview_str(remote_block_view)); EXPECT_EQ_U(remote_block_matrix.viewspec().offsets(), dash::index(remote_block_view).offsets()); @@ -203,13 +208,18 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range domain:", dash::typestr(dash::domain(remote_block_range))); + // DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + // "source block range domain extents:", + // dash::domain(remote_block_range).extents()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range iterator:", dash::typestr(remote_block_range.begin()), - "begin.pos:", remote_block_range.begin().pos(), - "end.pos:", remote_block_range.end().pos()); - DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", - dash::test::nview_str(remote_block_range)); + "begin.pos:", remote_block_range.begin().pos(), + "end.pos:", remote_block_range.end().pos(), + "begin.gpos:", remote_block_range.begin().gpos(), + "end.gpos:", remote_block_range.end().gpos()); + DASH_LOG_DEBUG_VAR("CopyTest.Blocking2DimGlobalToLocalBlock", + dash::test::nview_str(remote_block_range)); EXPECT_EQ_U(remote_block_matrix.viewspec().offsets(), dash::index(remote_block_range).offsets()); From 0b9997239e1e15e71c2c1b6fb89fb84543ecab60 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 17 Jun 2017 19:54:30 +0200 Subject: [PATCH 069/161] Intermediate, adding view iterator ranges --- dash/include/dash/Range.h | 6 ++ dash/include/dash/view/IndexSet.h | 8 +- dash/include/dash/view/Local.h | 13 ++- dash/include/dash/view/Origin.h | 105 +++++++++++++++++++------ dash/include/dash/view/ViewBlocksMod.h | 8 +- dash/include/dash/view/ViewIterator.h | 4 + dash/include/dash/view/ViewMod.h | 8 +- dash/include/dash/view/ViewMod1D.h | 59 ++++++++++---- 8 files changed, 155 insertions(+), 56 deletions(-) diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index 94fa5acab..a62b8303c 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -4,6 +4,12 @@ /** * \defgroup DashRangeConcept Multidimensional Range Concept * + * TODO: The Range concept as specified in the following diverges from + * the conventional definition of ranges as in Boost and rangesV3 + * (begin, end, next operations). + * It should be renamed to *Span*. + * + * * \ingroup DashNDimConcepts * \{ * \par Description diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 1154a4562..63ac214cd 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -32,7 +32,9 @@ * An \c IndexSet specifies a injective, non-surjective map from a * random-accessible sequence \f$ I = { i : (0...n) } \f$ to elements in * another index set \$ F \$ (\em family or \em image set). - * More general, an index set is an enumeration of elements in a domain. + * More general, an index set can be considered an enumeration of elements + * in a domain. + * Index sets do not provide the inverse mapping, from integer to element. * * In the context of views and ranges, the function \c dash::index returns * the index set of a view expression. @@ -66,7 +68,7 @@ * Type | Synopsis * ------------------- | -------------------------------------------------- * IndexSetT | Specific index set, CRTP type - * DomainT | Indexed data domain, model of the \c View concept + * DomainT | Indexed domain set, model of \c View concept * NDim | Number of dimensions in the index set * * @@ -206,7 +208,7 @@ class IndexSetIterator index_type, int, std::nullptr_t, index_type > base_t; private: const IndexSetType * _index_set; - index_type _stride = BaseStride; + index_type _stride = BaseStride; public: constexpr IndexSetIterator() = delete; constexpr IndexSetIterator(self_t &&) = default; diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index 095a0ac75..c0347b6fd 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -71,6 +71,7 @@ template < constexpr typename std::enable_if< ( !dash::view_traits::is_local::value && + !dash::view_traits::is_view::value && std::is_member_function_pointer< decltype(&ContainerDecayType::local)>::value ), decltype(std::declval().local()) @@ -86,6 +87,7 @@ template < constexpr typename std::enable_if< ( !dash::view_traits::is_local::value && + !dash::view_traits::is_view::value && std::is_member_function_pointer< decltype(&ContainerDecayType::local)>::value ), decltype(std::declval().local()) @@ -110,20 +112,24 @@ local(const ViewType & v) return IndexSetIdentity( v.local()); } -#endif /** * \concept{DashViewConcept} */ -template +template < + class ViewType, + typename ViewValueT = typename std::decay::type > constexpr auto local(const ViewType & v) -> typename std::enable_if< - dash::view_traits::is_view::value, + ( dash::view_traits::is_view::value && + !dash::view_traits::is_origin::value && + !dash::view_traits::is_local::value ), decltype(v.local()) >::type { return v.local(); } +#endif template < class ViewType, @@ -132,6 +138,7 @@ constexpr auto local(ViewType && v) -> typename std::enable_if< ( dash::view_traits::is_view::value && + !dash::view_traits::is_origin::value && !dash::view_traits::is_local::value ), decltype(std::forward(v).local()) >::type { diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index f8d11ba6f..07d125df8 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -24,6 +24,7 @@ origin(ViewT & view); #else +#if 0 template typename std::enable_if< view_traits::type>::is_origin::value || @@ -33,52 +34,101 @@ typename std::enable_if< origin(ContainerT && container) { return std::forward(container); } +#else +template < + class ContainerT, + typename ContainerValueT = typename std::decay::type > +typename std::enable_if< + view_traits::is_origin::value || + !view_traits::is_view::value, + const ContainerT & +>::type +origin(const ContainerT & container) { + return container; +} +#endif -template +template < + class ViewT, + typename ViewValueT = typename std::decay::type > constexpr auto origin(const ViewT & view) -> typename std::enable_if< - ( dash::view_traits::is_view::value && - !dash::view_traits::is_origin::value && - !dash::view_traits::is_local::value ), - const typename dash::view_traits::origin_type & + ( dash::view_traits::is_view::value && + !dash::view_traits::is_origin::value && + !dash::view_traits::is_local::value ), + const typename dash::view_traits::origin_type & +// decltype(dash::origin(view.domain())) >::type { // Recurse to origin of global view: return dash::origin(view.domain()); } +template < + class ViewT, + typename ViewValueT = typename std::decay::type > +constexpr auto +origin(ViewT && view) + -> typename std::enable_if< + ( dash::view_traits::is_view::value && + std::is_copy_constructible< + typename dash::view_traits::origin_type + >::value && + !dash::view_traits::is_origin::value && + !dash::view_traits::is_local::value ), + typename dash::view_traits::origin_type +// decltype(dash::origin(std::forward(view).domain())) + >::type { + // Recurse to origin of global view: + return dash::origin(std::forward(view).domain()); +} -template -typename std::enable_if< - dash::view_traits::is_origin::value, - ContainerT & ->::type -global_origin(ContainerT & container) { +template < + class ContainerT, + typename ContainerValueT = typename std::decay::type > +constexpr auto +global_origin(const ContainerT & container) + -> typename std::enable_if< + dash::view_traits::is_origin::value, + const ContainerT & + >::type { return container; } -template +template < + class ContainerT, + typename ContainerValueT = typename std::decay::type > +constexpr auto +global_origin(ContainerT && container) + -> typename std::enable_if< + dash::view_traits::is_origin::value, + decltype(std::forward(container)) + >::type { + return std::forward(container); +} + +template < + class ViewT, + typename ViewValueT = typename std::decay::type > constexpr auto global_origin(const ViewT & view) -> typename std::enable_if< - !dash::view_traits::is_origin::value, - const typename dash::view_traits::origin_type & + !dash::view_traits::is_origin::value, + const typename dash::view_traits::origin_type & >::type { // Recurse to origin of local view: return dash::global_origin(view.domain()); } -template +template < + class ViewT, + typename ViewValueT = typename std::decay::type > constexpr auto origin(ViewT && view) -> typename std::enable_if< - ( dash::view_traits< - typename std::decay::type - >::is_view::value && + ( dash::view_traits::is_view::value && dash::view_traits< - typename dash::view_traits< - typename std::decay::type - >::domain_type + typename dash::view_traits::domain_type >::is_local::value ), decltype(dash::local( dash::global_origin(std::forward(view).domain()))) @@ -89,16 +139,19 @@ origin(ViewT && view) std::forward(view).domain())); } -template +template < + class ViewT, + typename ViewValueT = typename std::decay::type > constexpr auto origin(const ViewT & view) -> typename std::enable_if< - ( dash::view_traits::is_view::value && - dash::view_traits::is_local::value && + ( dash::view_traits::is_view::value && + dash::view_traits::is_local::value && !dash::view_traits< - typename dash::view_traits::domain_type + typename dash::view_traits::domain_type >::is_local::value ), - const typename dash::view_traits::origin_type & +// const typename dash::view_traits::origin_type & + decltype(dash::global_origin(view.domain())) >::type { // Recurse to global origin of local view: return dash::global_origin(view.domain()); diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index aac6b1385..4f2073a63 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -346,8 +346,8 @@ class ViewBlockMod } iterator begin() { - return iterator(const_cast( - dash::origin(*this) + return iterator(dash::origin( + const_cast(*this) ).begin(), _index_set, 0); } @@ -358,8 +358,8 @@ class ViewBlockMod } iterator end() { - return iterator(const_cast( - dash::origin(*this) + return iterator(dash::origin( + const_cast(*this) ).begin(), _index_set, _index_set.size()); } diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index 27dbac186..facb4ffd3 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -131,6 +131,10 @@ class ViewIterator constexpr const pattern_type & pattern() const { return _domain_it.pattern(); } + + constexpr const index_set_type & index_set() const { + return _index_set; + } }; template < diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 91b13877d..f3fc4b063 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -160,6 +160,8 @@ class ViewModBase public: typedef DomainType domain_type; + // TODO: Clarify if origins should always be considered const + // typedef typename std::conditional<( view_traits::is_origin::value && !view_traits::is_view::value && @@ -248,11 +250,11 @@ class ViewModBase self_t & operator=(const self_t &) = default; self_t & operator=(self_t &&) = default; - constexpr const domain_type & domain() const & { + constexpr domain_type domain() const && { return _domain; } - constexpr domain_type domain() const && { + constexpr const domain_type & domain() const & { return _domain; } @@ -429,7 +431,7 @@ class ViewLocalMod constexpr explicit ViewLocalMod( const DomainType & domain) : base_t(domain) - , _index_set(domain) + , _index_set(this->domain()) { } constexpr bool operator==(const self_t & rhs) const { diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index e44bb1a4e..f68fca27d 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -646,13 +646,12 @@ class IteratorRangeLocalOrigin // ----------------------------------------------------------------------- // Iterator Range Origin -// +// ----------------------------------------------------------------------- // Concept adapter for iterator range // // range(Container.iter, Container.iter) // -// to semantics of type Container. -// +// to model of Container concept. // ----------------------------------------------------------------------- namespace detail { @@ -688,9 +687,12 @@ struct view_traits> { typedef typename RangeOrigin::pattern_type PatternT; typedef typename RangeOrigin::iterator iterator; public: - typedef typename std::decay::type origin_type; - typedef typename std::decay::type domain_type; - typedef typename std::decay::type image_type; +//typedef typename std::decay::type origin_type; +//typedef typename std::decay::type domain_type; +//typedef typename std::decay::type image_type; + typedef RangeOrigin origin_type; + typedef RangeOrigin domain_type; + typedef RangeT image_type; typedef IndexSet index_set_type; @@ -698,7 +700,8 @@ struct view_traits> { dim_t, static_cast(PatternT::ndim())> rank; typedef RangeT global_type; - typedef ViewLocalMod local_type; +//typedef ViewLocalMod local_type; + typedef ViewLocalMod local_type; typedef typename iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; @@ -724,9 +727,11 @@ class IteratorRangeViewDomain RangeOrigin > base_t; public: - typedef typename std::decay::type origin_type; - typedef typename std::decay::type domain_type; - typedef typename std::decay::type image_type; +//typedef typename std::decay::type origin_type; +//typedef typename std::decay::type domain_type; + typedef RangeOrigin origin_type; + typedef RangeOrigin domain_type; + typedef self_t image_type; typedef IndexSet index_set_type; @@ -749,7 +754,8 @@ class IteratorRangeViewDomain typedef std::integral_constant is_local; typedef self_t global_type; - typedef ViewLocalMod local_type; +//typedef ViewLocalMod local_type; + typedef ViewLocalMod local_type; private: static const dim_t NDim = rank::value; @@ -762,6 +768,20 @@ class IteratorRangeViewDomain , _index_set(dom.begin().index_set()) { } + constexpr IteratorRangeViewDomain( + const iterator & begin, + const sentinel & end) + : base_t(domain_type(begin, end)) + , _index_set(begin.index_set()) + { } + + constexpr IteratorRangeViewDomain( + iterator && begin, + sentinel && end) + : base_t(domain_type(std::move(begin), std::move(end))) + , _index_set(begin.index_set()) // TODO: dangling + { } + constexpr IteratorRangeViewDomain() = delete; constexpr IteratorRangeViewDomain(const self_t & other) = default; constexpr IteratorRangeViewDomain(self_t && other) = default; @@ -851,7 +871,7 @@ class IteratorRangeViewDomain return this->begin().pattern(); } - constexpr const local_type local() const noexcept { + constexpr local_type local() const noexcept { return local_type(*this); } @@ -862,6 +882,10 @@ class IteratorRangeViewDomain self_t & global() { return *this; } + + constexpr const index_set_type & index_set() const { + return _index_set; + } }; // IteratorRangeViewDomain @@ -973,7 +997,7 @@ class IteratorRangeOrigin return this->begin().pattern(); } - constexpr const local_type local() const noexcept { + constexpr local_type local() const noexcept { return local_type(*this); } @@ -1267,9 +1291,9 @@ class IteratorRange typedef dash::IndexSetSub index_set_type; using reference = - typename std::iterator_traits< iterator>::reference; + typename std::iterator_traits< iterator>::reference; using const_reference = - typename std::iterator_traits::reference; + typename std::iterator_traits::reference; private: static const dim_t NDim = rank::value; @@ -1424,15 +1448,16 @@ constexpr dash::IteratorRangeOrigin< typename std::decay::type, typename std::decay::type >, - typename Iterator::index_set_type > > + typename std::decay::type::index_set_type > > >::type make_range(Iterator && begin, Sentinel && end) { + // begin, end are view iterators: return dash::IteratorRange< dash::IteratorRangeViewDomain< dash::IteratorRangeOrigin< typename std::decay::type, typename std::decay::type >, - typename Iterator::index_set_type > + typename std::decay::type::index_set_type > >(std::forward(begin), std::forward(end)); } From 16cad8f812dcb5fee25cef71fa201c236640e935 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 02:11:19 +0200 Subject: [PATCH 070/161] Cleanup dash::origin --- dash/include/dash/meta/TypeInfo.h | 26 ++++++++++++++++---------- dash/include/dash/view/ViewMod1D.h | 7 +------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/dash/include/dash/meta/TypeInfo.h b/dash/include/dash/meta/TypeInfo.h index b0e2bb5e8..87a9d4d27 100644 --- a/dash/include/dash/meta/TypeInfo.h +++ b/dash/include/dash/meta/TypeInfo.h @@ -11,29 +11,35 @@ namespace internal { } /** - * Returns string containing the type name of the given object. + * Returns string containing the name of the specified type. * * Similar to the `typeid` operator but ensures human-readable, demangled * format. */ template -std::string typestr(const T & obj) { - return dash::internal::demangle( - typeid(obj).name() - ); +std::string typestr() { + typedef typename std::remove_reference::type TR; + std::string r = dash::internal::demangle(typeid(TR).name()); + if (std::is_const::value) + r = "const " + r; + if (std::is_volatile::value) + r = "volatile " + r; + if (std::is_lvalue_reference::value) + r += "&"; + else if (std::is_rvalue_reference::value) + r += "&&"; + return r; } /** - * Returns string containing the name of the specified type. + * Returns string containing the type name of the given object. * * Similar to the `typeid` operator but ensures human-readable, demangled * format. */ template -std::string typestr() { - return dash::internal::demangle( - typeid(T).name() - ); +std::string typestr(T && val) { + return typestr(val))>(); } } // namespace dash diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index f68fca27d..0d1b61182 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -687,9 +687,6 @@ struct view_traits> { typedef typename RangeOrigin::pattern_type PatternT; typedef typename RangeOrigin::iterator iterator; public: -//typedef typename std::decay::type origin_type; -//typedef typename std::decay::type domain_type; -//typedef typename std::decay::type image_type; typedef RangeOrigin origin_type; typedef RangeOrigin domain_type; typedef RangeT image_type; @@ -701,7 +698,7 @@ struct view_traits> { typedef RangeT global_type; //typedef ViewLocalMod local_type; - typedef ViewLocalMod local_type; + typedef ViewLocalMod local_type; typedef typename iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; @@ -727,8 +724,6 @@ class IteratorRangeViewDomain RangeOrigin > base_t; public: -//typedef typename std::decay::type origin_type; -//typedef typename std::decay::type domain_type; typedef RangeOrigin origin_type; typedef RangeOrigin domain_type; typedef self_t image_type; From d0551b022c216323ee0030c4d28cb82568cf6a5d Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 02:42:03 +0200 Subject: [PATCH 071/161] Removed cast workaround for dash::origin --- dash/include/dash/view/ViewBlocksMod.h | 8 ++++---- dash/test/algorithm/CopyTest.cc | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 4f2073a63..12a90fd9b 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -207,8 +207,8 @@ class ViewBlockMod } iterator begin() { - return iterator(const_cast( - dash::origin(*this) + return iterator(dash::origin( + const_cast(*this) ).begin(), _index_set, 0); } @@ -219,8 +219,8 @@ class ViewBlockMod } iterator end() { - return iterator(const_cast( - dash::origin(*this) + return iterator(dash::origin( + const_cast(*this) ).begin(), _index_set, _index_set.size()); } diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 93ab6a5a6..68753b619 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -557,14 +557,14 @@ TEST_F(CopyTest, BlockingLocalToGlobalBlockNDim) matrix.barrier(); - // Copy second local row into matrix row at next unit: - dash::copy(in_range.begin(), - in_range.end(), - dash::sub<0>( - dest_row, - dest_row + 1, - matrix).begin() - ); +// // Copy second local row into matrix row at next unit: +// dash::copy(in_range.begin(), +// in_range.end(), +// dash::sub<0>( +// dest_row, +// dest_row + 1, +// matrix).begin() +// ); if (dash::myid() == 0) { DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", From 767967d4ac57d468881aa85665412d3a7eb43018 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 04:38:06 +0200 Subject: [PATCH 072/161] Fixes in iterator range types --- dash/include/dash/view/IndexSet.h | 8 ++++---- dash/include/dash/view/ViewMod1D.h | 17 ++++++++++++----- dash/test/algorithm/CopyTest.cc | 16 ++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 63ac214cd..3ca3efd36 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -459,10 +459,10 @@ class IndexSetBase } constexpr auto domain() const -// -> decltype(dash::index( -// std::declval() -// )) { - -> typename view_traits::index_set_type { + -> decltype(dash::index( + std::declval() + )) { +// -> typename view_traits::index_set_type { return dash::index(_domain); } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 0d1b61182..9bfdbce61 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -749,7 +749,6 @@ class IteratorRangeViewDomain typedef std::integral_constant is_local; typedef self_t global_type; -//typedef ViewLocalMod local_type; typedef ViewLocalMod local_type; private: @@ -758,7 +757,7 @@ class IteratorRangeViewDomain const index_set_type & _index_set; public: - constexpr IteratorRangeViewDomain(const domain_type & dom) + constexpr explicit IteratorRangeViewDomain(const domain_type & dom) : base_t(dom) , _index_set(dom.begin().index_set()) { } @@ -959,7 +958,9 @@ class IteratorRangeOrigin , _end(end) { } - constexpr IteratorRangeOrigin(iterator && begin, sentinel && end) + constexpr IteratorRangeOrigin( + iterator && begin, + sentinel && end) : _begin(std::move(begin)) , _end(std::move(end)) { } @@ -1221,7 +1222,10 @@ struct view_traits > { typedef IteratorRange RangeT; public: typedef RangeOrigin domain_type; - typedef RangeOrigin origin_type; +//typedef RangeOrigin origin_type; + typedef typename dash::view_traits< + typename std::decay::type + >::origin_type origin_type; typedef RangeT image_type; typedef std::integral_constant rank; @@ -1264,7 +1268,10 @@ class IteratorRange typedef typename RangeOrigin::const_sentinel const_sentinel; typedef RangeOrigin domain_type; - typedef RangeOrigin origin_type; +//typedef RangeOrigin origin_type; + typedef typename dash::view_traits< + typename std::decay::type + >::origin_type origin_type; typedef self_t image_type; typedef typename domain_type::value_type value_type; diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 68753b619..93ab6a5a6 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -557,14 +557,14 @@ TEST_F(CopyTest, BlockingLocalToGlobalBlockNDim) matrix.barrier(); -// // Copy second local row into matrix row at next unit: -// dash::copy(in_range.begin(), -// in_range.end(), -// dash::sub<0>( -// dest_row, -// dest_row + 1, -// matrix).begin() -// ); + // Copy second local row into matrix row at next unit: + dash::copy(in_range.begin(), + in_range.end(), + dash::sub<0>( + dest_row, + dest_row + 1, + matrix).begin() + ); if (dash::myid() == 0) { DASH_LOG_DEBUG("CopyTest.BlockingLocalToGlobalBlockNDim", From ae89a884a2c9eb6e7f59a6554ccec38506215b7d Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 05:42:37 +0200 Subject: [PATCH 073/161] Updating nview tests --- dash/include/dash/view/ViewMod1D.h | 2 +- dash/test/view/NViewTest.cc | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 9bfdbce61..38fbdbd58 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -754,7 +754,7 @@ class IteratorRangeViewDomain private: static const dim_t NDim = rank::value; - const index_set_type & _index_set; + index_set_type _index_set; public: constexpr explicit IteratorRangeViewDomain(const domain_type & dom) diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index ab94c68b9..5a97ca549 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -47,9 +47,7 @@ namespace test { std::ostringstream row_ss; for (int c = 0; c < view_ncols; ++c) { int offset = r * view_ncols + c; - row_ss << std::fixed << std::setw(3) - << offset << ":" - << std::fixed << std::setw(2) + row_ss << std::fixed << std::setw(2) << nindex[offset] << ":" << std::fixed << std::setprecision(3) @@ -553,6 +551,7 @@ TEST_F(NViewTest, MatrixBlocked1DimChained) auto nview_rows_l = dash::local(nview_rows_g); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", "local(sub<0>(1,3, mat)):", + dash::typestr(nview_rows_l), "extents:", nview_rows_l.extents(), "offsets:", nview_rows_l.offsets()); @@ -615,8 +614,6 @@ TEST_F(NViewTest, MatrixBlocked1DimSub) using globiter_t = decltype(mat.begin()); - EXPECT_EQ_U(static_cast(view_expr_it), - (mat_ref_glob_it)); EXPECT_EQ_U(view_expr_it.dart_gptr(), mat_ref_glob_it.dart_gptr()); @@ -954,7 +951,10 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) "offsets:", block.offsets(), "extents:", block.extents()); - dash::test::print_nview(" block row", block); + DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", + "blocks(mat)[b]:"); + DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", + dash::test::nview_str(block)); const auto & block_idx = dash::index(block); const auto & pat_block = mat.pattern().block(bi); @@ -966,6 +966,10 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) bphase_row + pat_block.offsets()[0], bphase_col + pat_block.offsets()[1] }); + DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", + "block phase:", bphase, + "pattern gidx:", pat_g_index, + "block gidx:", block_idx[bphase]); EXPECT_EQ(pat_g_index, block_idx[bphase]); } From aeffecac4f0ce1bfb42a129bb74792fbd705d507 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 06:07:23 +0200 Subject: [PATCH 074/161] Updating nview tests --- dash/test/view/NViewTest.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 5a97ca549..32d7d6c46 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -951,31 +951,37 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) "offsets:", block.offsets(), "extents:", block.extents()); + const auto & block_idx = dash::index(block); + const auto & pat_block = mat.pattern().block(bi); + DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", "blocks(mat)[b]:"); DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", dash::test::nview_str(block)); + DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", + "pattern.block(b):", + pat_block); - const auto & block_idx = dash::index(block); - const auto & pat_block = mat.pattern().block(bi); + EXPECT_EQ(pat_block.size(), block.size()); + EXPECT_EQ(pat_block.offsets(), block.offsets()); + EXPECT_EQ(pat_block.extents(), block.extents()); for (int bphase = 0; bphase < pat_block.size(); ++bphase) { - int bphase_row = bphase / pat_block.extents()[1]; - int bphase_col = bphase % pat_block.extents()[1]; - auto pat_g_index = mat.pattern().global_at({ - bphase_row + pat_block.offsets()[0], - bphase_col + pat_block.offsets()[1] - }); + auto pat_g_index = dash::CartesianIndexSpace<2>( + mat.pattern().extents() + ).at( + // in-block coords + dash::CartesianIndexSpace<2>( + pat_block.extents() + ).coords(bphase), + // block viewspec + pat_block); DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", - "block phase:", bphase, + "block phase:", bphase, "pattern gidx:", pat_g_index, - "block gidx:", block_idx[bphase]); + "block gidx:", block_idx[bphase]); EXPECT_EQ(pat_g_index, block_idx[bphase]); } - - EXPECT_EQ(pat_block.size(), block.size()); - EXPECT_EQ(pat_block.offsets(), block.offsets()); - EXPECT_EQ(pat_block.extents(), block.extents()); bi++; } } From ef50fafc7584392de0fd2cf3995489c70f150918 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 07:46:50 +0200 Subject: [PATCH 075/161] Fixing view iterator range types --- dash/include/dash/Exception.h | 1 + dash/include/dash/view/IndexSet.h | 11 ++++++-- dash/include/dash/view/ViewMod1D.h | 42 ++++++++++++++++++------------ dash/test/algorithm/CopyTest.cc | 20 +++++++------- dash/test/view/NViewTest.cc | 4 --- 5 files changed, 46 insertions(+), 32 deletions(-) diff --git a/dash/include/dash/Exception.h b/dash/include/dash/Exception.h index be1980cd8..bc5a0c46a 100644 --- a/dash/include/dash/Exception.h +++ b/dash/include/dash/Exception.h @@ -26,6 +26,7 @@ os << "[ Unit " << dash::myid() << " ] "; \ os << msg_stream; \ DASH_LOG_ERROR(dash__toxstr(excep_type), os.str()); \ + DASH_STACK_TRACE(); \ throw(excep_type(os.str())); \ } while(0) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 3ca3efd36..f5e292eb0 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1632,10 +1632,17 @@ class IndexSetBlock // in-block coords dash::CartesianIndexSpace( this->pattern().block(_block_idx).extents() - ).coords(block_phase), + ).coords( + block_phase >= this->pattern().block(_block_idx).size() + ? block_phase - 1 + : block_phase ), // block viewspec this->pattern().block(_block_idx)) - ) + ) + ( + block_phase >= this->pattern().block(_block_idx).size() + ? 1 + : 0) + ); } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 38fbdbd58..c5fcd18fd 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -773,7 +773,7 @@ class IteratorRangeViewDomain iterator && begin, sentinel && end) : base_t(domain_type(std::move(begin), std::move(end))) - , _index_set(begin.index_set()) // TODO: dangling + , _index_set(begin.index_set()) { } constexpr IteratorRangeViewDomain() = delete; @@ -815,7 +815,7 @@ class IteratorRangeViewDomain // ---- size ------------------------------------------------------------ constexpr size_type size(dim_t sub_dim = 0) const { - return _index_set.size(sub_dim); + return _index_set.size(); } // ---- access ---------------------------------------------------------- @@ -828,8 +828,8 @@ class IteratorRangeViewDomain iterator begin() { return iterator( - const_cast( - dash::origin(*this) + dash::origin( + const_cast(*this) ).begin(), _index_set, 0); } @@ -842,8 +842,8 @@ class IteratorRangeViewDomain iterator end() { return iterator( - const_cast( - dash::origin(*this) + dash::origin( + const_cast(*this) ).begin(), _index_set, _index_set.size()); } @@ -854,8 +854,8 @@ class IteratorRangeViewDomain } reference operator[](int offset) { - return *(iterator(const_cast( - dash::origin(*this) + return *(iterator(dash::origin( + const_cast(*this) ).begin(), _index_set, offset)); } @@ -985,10 +985,16 @@ class IteratorRangeOrigin return *(this->begin() + offset); } + // TODO: Not well-defined, should be identical to pattern().size() + // constexpr size_type size() const noexcept { return dash::distance(_begin, _end); } + constexpr const std::array extents() const { + return this->pattern().extents(); + } + constexpr const pattern_type & pattern() const noexcept { return this->begin().pattern(); } @@ -1307,8 +1313,8 @@ 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()) - end + begin + (begin.pattern().size() - begin.pos()) + // end )) // Convert iterator positions to sub-range index set: , _index_set(this->domain(), begin.pos(), end.pos()) @@ -1319,8 +1325,8 @@ 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(end) + 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()) @@ -1445,23 +1451,25 @@ template constexpr typename std::enable_if< dash::detail::has_type_index_set_type::value, - dash::IteratorRange< + // dash::IteratorRange< dash::IteratorRangeViewDomain< dash::IteratorRangeOrigin< typename std::decay::type, typename std::decay::type >, - typename std::decay::type::index_set_type > > + typename std::decay::type::index_set_type > + // > >::type make_range(Iterator && begin, Sentinel && end) { // begin, end are view iterators: - return dash::IteratorRange< + return // dash::IteratorRange< dash::IteratorRangeViewDomain< dash::IteratorRangeOrigin< typename std::decay::type, typename std::decay::type >, typename std::decay::type::index_set_type > - >(std::forward(begin), - std::forward(end)); + // > + (std::forward(begin), + std::forward(end)); } } // namespace dash diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 93ab6a5a6..0a5bc7aab 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -189,13 +189,14 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) dash::domain(remote_block_view).extents()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view iterator:", - dash::typestr(remote_block_view.begin()), + dash::typestr(remote_block_view.begin())); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "begin.pos:", remote_block_view.begin().pos(), "end.pos:", remote_block_view.end().pos(), "begin.gpos:", remote_block_view.begin().gpos(), "end.gpos:", remote_block_view.end().gpos()); - DASH_LOG_DEBUG_VAR("CopyTest.Blocking2DimGlobalToLocalBlock", - dash::test::nview_str(remote_block_view)); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + dash::test::nview_str(remote_block_view)); EXPECT_EQ_U(remote_block_matrix.viewspec().offsets(), dash::index(remote_block_view).offsets()); @@ -208,18 +209,19 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range domain:", dash::typestr(dash::domain(remote_block_range))); - // DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", - // "source block range domain extents:", - // dash::domain(remote_block_range).extents()); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block range domain extents:", + dash::domain(remote_block_range).extents()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range iterator:", - dash::typestr(remote_block_range.begin()), + dash::typestr(remote_block_range.begin())); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "begin.pos:", remote_block_range.begin().pos(), "end.pos:", remote_block_range.end().pos(), "begin.gpos:", remote_block_range.begin().gpos(), "end.gpos:", remote_block_range.end().gpos()); - DASH_LOG_DEBUG_VAR("CopyTest.Blocking2DimGlobalToLocalBlock", - dash::test::nview_str(remote_block_range)); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + dash::test::nview_str(remote_block_range)); EXPECT_EQ_U(remote_block_matrix.viewspec().offsets(), dash::index(remote_block_range).offsets()); diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 32d7d6c46..5c6d93e9a 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -976,10 +976,6 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) ).coords(bphase), // block viewspec pat_block); - DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic2DSub", - "block phase:", bphase, - "pattern gidx:", pat_g_index, - "block gidx:", block_idx[bphase]); EXPECT_EQ(pat_g_index, block_idx[bphase]); } bi++; From 3da8a245bb30c3a0c0d65d6ca648dfd63ae7966e Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 19 Jun 2017 10:02:46 +0200 Subject: [PATCH 076/161] Fixing view iterator range types --- dash/include/dash/view/ViewMod1D.h | 65 +++++++++++++++++++++++++----- dash/test/algorithm/CopyTest.cc | 18 ++++++--- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index c5fcd18fd..d12428dda 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -687,8 +687,11 @@ struct view_traits> { typedef typename RangeOrigin::pattern_type PatternT; typedef typename RangeOrigin::iterator iterator; public: - typedef RangeOrigin origin_type; typedef RangeOrigin domain_type; +//typedef RangeOrigin origin_type; + typedef typename dash::view_traits< + typename std::decay::type + >::origin_type origin_type; typedef RangeT image_type; typedef IndexSet index_set_type; @@ -724,8 +727,11 @@ class IteratorRangeViewDomain RangeOrigin > base_t; public: - typedef RangeOrigin origin_type; typedef RangeOrigin domain_type; +//typedef RangeOrigin origin_type; + typedef typename dash::view_traits< + typename std::decay::type + >::origin_type origin_type; typedef self_t image_type; typedef IndexSet index_set_type; @@ -754,26 +760,40 @@ class IteratorRangeViewDomain private: static const dim_t NDim = rank::value; + // TODO: index_set_type should be IndexSetSub index_set_type _index_set; + index_type _begin_idx; + index_type _end_idx; public: constexpr explicit IteratorRangeViewDomain(const domain_type & dom) : base_t(dom) , _index_set(dom.begin().index_set()) + , _begin_idx(0) + , _end_idx(dom.begin().index_set().size()) { } constexpr IteratorRangeViewDomain( const iterator & begin, const sentinel & end) - : base_t(domain_type(begin, end)) + : base_t(domain_type( + begin, // - begin.pos(), + end)) // begin + (begin.pattern().size() - begin.pos()))) , _index_set(begin.index_set()) + , _begin_idx(begin.pos()) + , _end_idx(end.pos()) { } constexpr IteratorRangeViewDomain( iterator && begin, sentinel && end) - : base_t(domain_type(std::move(begin), std::move(end))) + : base_t(domain_type( + std::move(begin), // - begin.pos(), + std::move(end))) + // std::move(begin) + (begin.pattern().size() - begin.pos()))) , _index_set(begin.index_set()) + , _begin_idx(begin.pos()) + , _end_idx(end.pos()) { } constexpr IteratorRangeViewDomain() = delete; @@ -820,10 +840,11 @@ class IteratorRangeViewDomain // ---- access ---------------------------------------------------------- +#if 0 constexpr const_iterator begin() const { return const_iterator( dash::origin(*this).begin(), - _index_set, 0); + _index_set, _begin_idx); } iterator begin() { @@ -831,13 +852,13 @@ class IteratorRangeViewDomain dash::origin( const_cast(*this) ).begin(), - _index_set, 0); + _index_set, _begin_idx); } constexpr const_iterator end() const { return const_iterator( dash::origin(*this).begin(), - _index_set, _index_set.size()); + _index_set, _end_idx); } iterator end() { @@ -845,7 +866,7 @@ class IteratorRangeViewDomain dash::origin( const_cast(*this) ).begin(), - _index_set, _index_set.size()); + _index_set, _end_idx); } constexpr const_reference operator[](int offset) const { @@ -857,9 +878,33 @@ class IteratorRangeViewDomain return *(iterator(dash::origin( const_cast(*this) ).begin(), - _index_set, offset)); + _index_set, _begin_idx + offset)); + } +#else + constexpr const_iterator begin() const { + return dash::domain(*this).begin(); + } + + iterator begin() { + return dash::domain(*this).begin(); + } + + constexpr const_iterator end() const { + return dash::domain(*this).end(); + } + + iterator end() { + return dash::domain(*this).end(); } + constexpr const_reference operator[](int offset) const { + return *(this->begin() + offset); + } + + reference operator[](int offset) { + return *(this->begin() + offset); + } +#endif constexpr const pattern_type & pattern() const noexcept { return this->begin().pattern(); @@ -985,7 +1030,7 @@ class IteratorRangeOrigin return *(this->begin() + offset); } - // TODO: Not well-defined, should be identical to pattern().size() + // TODO: Not well-defined, should be identical to extents size // constexpr size_type size() const noexcept { return dash::distance(_begin, _end); diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 0a5bc7aab..f36d99fb5 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -165,7 +165,9 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) auto g_block_unit = pattern.unit_at( std::array {0,0}, g_block_view); - LOG_MESSAGE("Block %zu: assigned to unit %d", gb, g_block_unit.id); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", " ---- ", + "block gidx:", gb, + "assigned to unit", g_block_unit.id); if (g_block_unit == remote_unit_id) { // Block is assigned to selecte remote unit, create local copy: auto remote_block_matrix = matrix.block(gb); @@ -173,14 +175,15 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) auto remote_block_range = dash::make_range( remote_block_view.begin(), remote_block_view.end()); - DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", - "source block extents:", remote_block_view.extents(), - "offsets:", remote_block_view.offsets(), - "size:", remote_block_view.size()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view:", dash::typestr(remote_block_view)); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block view", + "extents:", remote_block_view.extents(), + "offsets:", remote_block_view.offsets(), + "size:", remote_block_view.size()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view domain:", dash::typestr(dash::domain(remote_block_view))); @@ -206,6 +209,11 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range:", dash::typestr(remote_block_range)); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block range", + "extents:", remote_block_range.extents(), + "offsets:", remote_block_range.offsets(), + "size:", remote_block_range.size()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range domain:", dash::typestr(dash::domain(remote_block_range))); From 24bec10c43d7e97306474a64cc0dbf421ca57c82 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 20 Jun 2017 01:30:04 +0200 Subject: [PATCH 077/161] Fixing n-dim. local views --- dash/examples/ex.02.matrix_views/main.cpp | 279 ++++++++++++++++++---- dash/include/dash/algorithm/Copy.h | 4 + dash/include/dash/view/ViewMod.h | 24 +- dash/test/algorithm/CopyTest.cc | 18 +- dash/test/view/NViewTest.cc | 8 +- 5 files changed, 262 insertions(+), 71 deletions(-) diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix_views/main.cpp index cd48906c7..1dcfa0430 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix_views/main.cpp @@ -1,49 +1,230 @@ -#include - -using std::cout; -using std::cin; -using std::endl; -using std::vector; - -using uint = unsigned int; - -inline void sum(const uint nelts, - const dash::NArray &matIn, - const uint myid) { - uint lclRows = matIn.pattern().local_extents()[0]; - - uint const *mPtr; - uint localSum = 0; - - for (uint i = 0; i < lclRows; ++i) { - mPtr = matIn.local.row(i).lbegin(); - - for (uint j = 0; j < nelts; ++j) { - localSum += *(mPtr++); - } - } -} - -int main(int argc, char *argv[]) -{ - dash::init(&argc, &argv); - - uint myid = static_cast(dash::Team::GlobalUnitID().id); - - const uint nelts = 40; - - dash::NArray mat(nelts, nelts); - - // Initialize matrix values: - uint counter = myid + 20; - if (0 == myid) { - for (uint *i = mat.lbegin(); i < mat.lend(); ++i) { - *i = ++counter; - } - } - dash::barrier(); - - sum(nelts, mat, myid); - - dash::finalize(); -} +#include + +using std::cout; +using std::cerr; +using std::cin; +using std::endl; +using std::vector; + +using uint = unsigned int; + +template +std::string nview_str( + const NViewType & nview) { + using value_t = typename NViewType::value_type; + auto view_nrows = nview.extents()[0]; + auto view_ncols = nview.extents()[1]; + auto nindex = dash::index(nview); + std::ostringstream ss; + for (int r = 0; r < view_nrows; ++r) { + ss << '\n'; + for (int c = 0; c < view_ncols; ++c) { + int offset = r * view_ncols + c; + ss << std::fixed << std::setw(3) + << nindex[offset] + << ":" + << std::fixed << std::setprecision(5) + << static_cast(nview[offset]) + << " "; + } + } + return ss.str(); +} + +inline void sum(const uint nelts, + const dash::NArray &matIn, + const uint myid) { + uint lclRows = matIn.pattern().local_extents()[0]; + + uint const *mPtr; + uint localSum = 0; + + for (uint i = 0; i < lclRows; ++i) { + mPtr = matIn.local.row(i).lbegin(); + + for (uint j = 0; j < nelts; ++j) { + localSum += *(mPtr++); + } + } +} + +int main(int argc, char *argv[]) +{ + dash::init(&argc, &argv); + + auto myid = dash::myid(); + auto nunits = dash::size(); + + const size_t block_size_x = 2; + const size_t block_size_y = 3; + const size_t block_size = block_size_x * block_size_y; + size_t num_local_blocks_x = 2; + size_t num_local_blocks_y = 2; + size_t num_blocks_x = nunits * num_local_blocks_x; + size_t num_blocks_y = nunits * num_local_blocks_y; + size_t num_blocks_total = num_blocks_x * num_blocks_y; + size_t extent_x = block_size_x * num_blocks_x; + size_t extent_y = block_size_y * num_blocks_y; + size_t num_elem_total = extent_x * extent_y; + // Assuming balanced mapping: + size_t num_elem_per_unit = num_elem_total / nunits; + size_t num_blocks_per_unit = num_elem_per_unit / block_size; + + if (nunits < 2) { + cerr << "requires > 1 units" << endl; + return 1; + } + + typedef dash::ShiftTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + pattern_t pattern( + dash::SizeSpec<2>( + extent_y, + extent_x), + dash::DistributionSpec<2>( + dash::TILE(block_size_y), + dash::TILE(block_size_x)) + ); + + dash::Matrix + matrix(pattern); + + // Initialize matrix values: + for (size_t lb = 0; lb < num_blocks_per_unit; ++lb) { + auto lblock = matrix.local.block(lb); + auto lblock_view = lblock.begin().viewspec(); + auto lblock_extents = lblock_view.extents(); + auto lblock_offsets = lblock_view.offsets(); + dash__unused(lblock_offsets); + for (auto bx = 0; bx < static_cast(lblock_extents[0]); ++bx) { + for (auto by = 0; by < static_cast(lblock_extents[1]); ++by) { + // Phase coordinates (bx,by) to global coordinates (gx,gy): + value_t value = static_cast(dash::myid().id + 1) + + 0.00001 * ( + ((lb + 1) * 10000) + ((bx + 1) * 100) + by + 1); + lblock[bx][by] = value; + } + } + } + dash::barrier(); + + if (myid == 0) { + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(dash::sub(0, matrix.extents()[0], matrix))); + } + dash::barrier(); + + // Array to store local copy: + std::vector local_copy(num_elem_per_unit); + // Pointer to first value in next copy destination range: + value_t * copy_dest_begin = local_copy.data(); + value_t * copy_dest_last = local_copy.data(); + + for (size_t gb = 0; gb < num_blocks_total; ++gb) { + // View of block at global block index gb: + auto g_block_view = pattern.block(gb); + // Unit assigned to block at global block index gb: + auto g_block_unit = pattern.unit_at( + std::array {0,0}, + g_block_view); + dash::team_unit_t remote_unit_id( + (dash::Team::All().myid().id + 1) % nunits); + if (g_block_unit == remote_unit_id) { + DASH_LOG_DEBUG("MatrixViewsExample", "==========================="); + DASH_LOG_DEBUG("MatrixViewsExample", + "block gidx", gb, + "at unit", g_block_unit.id); + DASH_LOG_DEBUG("MatrixViewsExample", "vvvvvvvvvvvvvvvvvvvvvvvvvvv"); + // Block is assigned to selecte remote unit, create local copy: + auto remote_block_matrix = matrix.block(gb); + + auto remote_block_view = // dash::sub(1,2, + dash::blocks(matrix)[gb]; + auto remote_block_range = dash::make_range( + remote_block_view.begin(), + remote_block_view.end()); + + DASH_LOG_DEBUG("MatrixViewsExample", + "source block view:", + dash::typestr(remote_block_view)); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block view", + "extents:", remote_block_view.extents(), + "offsets:", remote_block_view.offsets(), + "size:", remote_block_view.size()); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block view domain:", + dash::typestr(dash::domain(remote_block_view))); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block view origin:", + dash::typestr(dash::origin(remote_block_view))); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block view domain extents:", + dash::domain(remote_block_view).extents()); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block view iterator:", + dash::typestr(remote_block_view.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", + "begin.pos:", remote_block_view.begin().pos(), + "end.pos:", remote_block_view.end().pos(), + "begin.gpos:", remote_block_view.begin().gpos(), + "end.gpos:", remote_block_view.end().gpos()); + DASH_LOG_DEBUG("MatrixViewsExample", "block view:", + nview_str(remote_block_view)); + DASH_LOG_DEBUG("MatrixViewsExample", "local(block view):", + nview_str(dash::local(remote_block_view))); + + DASH_ASSERT(remote_block_matrix.viewspec().offsets() == + dash::index(remote_block_view).offsets()); + DASH_ASSERT(remote_block_matrix.viewspec().extents() == + dash::index(remote_block_view).extents()); + + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range:", + dash::typestr(remote_block_range)); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range", + "extents:", remote_block_range.extents(), + "offsets:", remote_block_range.offsets(), + "size:", remote_block_range.size()); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range domain:", + dash::typestr(dash::domain(remote_block_range))); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range origin:", + dash::typestr(dash::origin(remote_block_range))); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range domain extents:", + dash::domain(remote_block_range).extents()); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range iterator:", + dash::typestr(remote_block_range.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", + "begin.pos:", remote_block_range.begin().pos(), + "end.pos:", remote_block_range.end().pos(), + "begin.gpos:", remote_block_range.begin().gpos(), + "end.gpos:", remote_block_range.end().gpos()); + DASH_LOG_DEBUG("MatrixViewsExample", "block range:", + nview_str(remote_block_range)); + DASH_LOG_DEBUG("MatrixViewsExample", "local(block range):", + nview_str(dash::local(remote_block_range))); +#if 0 + copy_dest_last = dash::copy(remote_block_view.begin(), + remote_block_view.end(), + copy_dest_begin); + + // Test number of copied elements: + auto num_copied = copy_dest_last - copy_dest_begin; + DASH_ASSERT(num_copied == block_size); + + // Advance local copy destination pointer: + copy_dest_begin = copy_dest_last; +#endif + DASH_LOG_DEBUG("MatrixViewsExample", "^^^^^^^^^^^^^^^^^^^^^^^^^^^"); + } + } + + dash::finalize(); +} diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 8eeb50712..b4557afbf 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -855,9 +855,13 @@ auto copy( auto out_last = out_first; auto in_first = in_range.begin(); auto in_last = in_range.end(); + auto l_range_in = dash::local( + in_range); auto li_range_in = dash::index( dash::local( in_range)); + DASH_LOG_TRACE("dash::copy", "source local range:", + l_range_in); DASH_LOG_TRACE("dash::copy", "source local index range:", li_range_in); DASH_LOG_TRACE("dash::copy", "source g(local) index range:", diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index f3fc4b063..e50177b79 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -487,8 +487,8 @@ class ViewLocalMod return iterator( dash::begin( dash::local( - const_cast( - dash::origin(*this)) )), + dash::origin( + const_cast(*this) ))), _index_set, 0); } @@ -504,8 +504,8 @@ class ViewLocalMod return iterator( dash::begin( dash::local( - const_cast( - dash::origin(*this)) )), + dash::origin( + const_cast(*this) ))), _index_set, _index_set.size()); } @@ -521,8 +521,8 @@ class ViewLocalMod return *iterator( dash::begin( dash::local( - const_cast( - dash::origin(*this)) )), + dash::origin( + const_cast(*this) ))), _index_set, offset); } @@ -687,8 +687,8 @@ class ViewSubMod iterator begin() { return iterator( - const_cast( - dash::origin(*this) + dash::origin( + const_cast(*this) ).begin(), _index_set, 0); } @@ -701,8 +701,8 @@ class ViewSubMod iterator end() { return iterator( - const_cast( - dash::origin(*this) + dash::origin( + const_cast(*this) ).begin(), _index_set, _index_set.size()); } @@ -713,8 +713,8 @@ class ViewSubMod } reference operator[](int offset) { - return *(iterator(const_cast( - dash::origin(*this) + return *(iterator(dash::origin( + const_cast(*this) ).begin(), _index_set, offset)); } diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index f36d99fb5..2abe0cf32 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -187,6 +187,9 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view domain:", dash::typestr(dash::domain(remote_block_view))); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block view origin:", + dash::typestr(dash::origin(remote_block_view))); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view domain extents:", dash::domain(remote_block_view).extents()); @@ -217,6 +220,9 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range domain:", dash::typestr(dash::domain(remote_block_range))); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", + "source block range origin:", + dash::typestr(dash::origin(remote_block_range))); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range domain extents:", dash::domain(remote_block_range).extents()); @@ -236,12 +242,12 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), dash::index(remote_block_range).extents()); - copy_dest_last = dash::copy(remote_block_view.begin(), - remote_block_view.end(), - copy_dest_begin); - // Validate number of copied elements: - auto num_copied = copy_dest_last - copy_dest_begin; - EXPECT_EQ_U(num_copied, block_size); +// copy_dest_last = dash::copy(remote_block_view.begin(), +// remote_block_view.end(), +// copy_dest_begin); +// // Validate number of copied elements: +// auto num_copied = copy_dest_last - copy_dest_begin; +// EXPECT_EQ_U(num_copied, block_size); // Advance local copy destination pointer: copy_dest_begin = copy_dest_last; ++rb; diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 5c6d93e9a..8e07aa018 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -555,10 +555,10 @@ TEST_F(NViewTest, MatrixBlocked1DimChained) "extents:", nview_rows_l.extents(), "offsets:", nview_rows_l.offsets()); - EXPECT_EQ_U(2, nview_rows_l.extent<0>()); - EXPECT_EQ_U(block_cols, nview_rows_l.extent<1>()); +// EXPECT_EQ_U(2, nview_rows_l.extent<0>()); +// EXPECT_EQ_U(block_cols, nview_rows_l.extent<1>()); - dash::test::print_nview("nview_rows_l", nview_rows_l); +// dash::test::print_nview("nview_rows_l", nview_rows_l); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", "== nview_cols_l"); auto nview_cols_l = dash::local(nview_cols_g); @@ -567,7 +567,7 @@ TEST_F(NViewTest, MatrixBlocked1DimChained) "extents:", nview_cols_l.extents(), "offsets:", nview_cols_l.offsets()); - dash::test::print_nview("nview_cols_l", nview_cols_l); +// dash::test::print_nview("nview_cols_l", nview_cols_l); } TEST_F(NViewTest, MatrixBlocked1DimSub) From 95e16d6996456abfcf6214f306bf966304726b76 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 23 Jun 2017 00:05:48 +0200 Subject: [PATCH 078/161] Fixing n-dim. view iterator ranges --- dash/examples/ex.02.matrix_views/main.cpp | 117 ++++++++++++++++------ dash/include/dash/view/IndexSet.h | 13 ++- dash/include/dash/view/ViewMod.h | 2 +- dash/include/dash/view/ViewMod1D.h | 8 +- 4 files changed, 95 insertions(+), 45 deletions(-) diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix_views/main.cpp index 1dcfa0430..5e649f990 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix_views/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) if (nunits < 2) { cerr << "requires > 1 units" << endl; - return 1; +// return 1; } typedef dash::ShiftTilePattern<2> pattern_t; @@ -113,9 +113,46 @@ int main(int argc, char *argv[]) if (myid == 0) { DASH_LOG_DEBUG("MatrixViewsExample", nview_str(dash::sub(0, matrix.extents()[0], matrix))); + + auto matrix_region = dash::size() > 1 + ? dash::sub<0>( + 2, matrix.extents()[0] - 2, + dash::sub<1>( + 2, matrix.extents()[1] - 3, + matrix)) + : dash::sub<0>( + 0, matrix.extents()[0], + dash::sub<1>( + 0, matrix.extents()[1], + matrix)); + + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(matrix_region)); + + auto matrix_reg_blocks = dash::blocks(matrix_region); + for (const auto & reg_block : matrix_reg_blocks) { + DASH_LOG_DEBUG("MatrixViewsExample", "==============================", + nview_str(reg_block)); + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(dash::sub<0>(1,2, reg_block))); + + auto block_rg = dash::make_range(reg_block.begin(), + reg_block.end()); + auto block_srg = dash::sub<0>(1,2, block_rg); + + DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", + nview_str(block_rg)); + DASH_LOG_DEBUG_VAR("MatrixViewsExample", + block_srg.begin().pos()); + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(block_srg)); + } } dash::barrier(); + dash::finalize(); + return EXIT_SUCCESS; + // Array to store local copy: std::vector local_copy(num_elem_per_unit); // Pointer to first value in next copy destination range: @@ -142,30 +179,34 @@ int main(int argc, char *argv[]) auto remote_block_view = // dash::sub(1,2, dash::blocks(matrix)[gb]; - auto remote_block_range = dash::make_range( + auto remote_block_range = dash::sub(1,2, + dash::make_range( remote_block_view.begin(), - remote_block_view.end()); + remote_block_view.end())); DASH_LOG_DEBUG("MatrixViewsExample", - "source block view:", + "source block view:", "-- type:", dash::typestr(remote_block_view)); - DASH_LOG_DEBUG("MatrixViewsExample", - "source block view", - "extents:", remote_block_view.extents(), - "offsets:", remote_block_view.offsets(), - "size:", remote_block_view.size()); - DASH_LOG_DEBUG("MatrixViewsExample", + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", + "source block view iterator:", + dash::typestr(remote_block_view.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", "source block view domain:", dash::typestr(dash::domain(remote_block_view))); - DASH_LOG_DEBUG("MatrixViewsExample", + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", "source block view origin:", dash::typestr(dash::origin(remote_block_view))); + DASH_LOG_DEBUG("MatrixViewsExample", - "source block view domain extents:", - dash::domain(remote_block_view).extents()); + "source block view:", + "extents:", remote_block_view.extents(), + "offsets:", remote_block_view.offsets(), + "size:", remote_block_view.size()); DASH_LOG_DEBUG("MatrixViewsExample", - "source block view iterator:", - dash::typestr(remote_block_view.begin())); + "source block view domain:", + "extents:", dash::domain(remote_block_view).extents(), + "offsets:", dash::domain(remote_block_view).offsets(), + "size:", dash::domain(remote_block_view).size()); DASH_LOG_DEBUG("MatrixViewsExample", "begin.pos:", remote_block_view.begin().pos(), "end.pos:", remote_block_view.end().pos(), @@ -173,39 +214,48 @@ int main(int argc, char *argv[]) "end.gpos:", remote_block_view.end().gpos()); DASH_LOG_DEBUG("MatrixViewsExample", "block view:", nview_str(remote_block_view)); - DASH_LOG_DEBUG("MatrixViewsExample", "local(block view):", - nview_str(dash::local(remote_block_view))); + DASH_LOG_DEBUG("MatrixViewsExample", "block view is strided:", + dash::index(remote_block_view).is_strided()); + // DASH_LOG_DEBUG("MatrixViewsExample", "local(block view):", + // nview_str(dash::local(remote_block_view))); - DASH_ASSERT(remote_block_matrix.viewspec().offsets() == - dash::index(remote_block_view).offsets()); - DASH_ASSERT(remote_block_matrix.viewspec().extents() == - dash::index(remote_block_view).extents()); + // DASH_ASSERT(remote_block_matrix.viewspec().offsets() == + // dash::index(remote_block_view).offsets()); + // DASH_ASSERT(remote_block_matrix.viewspec().extents() == + // dash::index(remote_block_view).extents()); DASH_LOG_DEBUG("MatrixViewsExample", - "source block range:", + "source block range:", "-- type:", dash::typestr(remote_block_range)); - DASH_LOG_DEBUG("MatrixViewsExample", - "source block range", - "extents:", remote_block_range.extents(), - "offsets:", remote_block_range.offsets(), - "size:", remote_block_range.size()); - DASH_LOG_DEBUG("MatrixViewsExample", + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", + "source block range iterator:", + dash::typestr(remote_block_range.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", "source block range domain:", dash::typestr(dash::domain(remote_block_range))); - DASH_LOG_DEBUG("MatrixViewsExample", + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", "source block range origin:", dash::typestr(dash::origin(remote_block_range))); + DASH_LOG_DEBUG("MatrixViewsExample", - "source block range domain extents:", - dash::domain(remote_block_range).extents()); + "source block range:", + "extents:", remote_block_range.extents(), + "offsets:", remote_block_range.offsets(), + "size:", remote_block_range.size()); DASH_LOG_DEBUG("MatrixViewsExample", - "source block range iterator:", - dash::typestr(remote_block_range.begin())); + "source block range domain:", + "extents:", dash::domain(remote_block_range).extents(), + "offsets:", dash::domain(remote_block_range).offsets(), + "size:", dash::domain(remote_block_range).size()); DASH_LOG_DEBUG("MatrixViewsExample", "begin.pos:", remote_block_range.begin().pos(), "end.pos:", remote_block_range.end().pos(), "begin.gpos:", remote_block_range.begin().gpos(), "end.gpos:", remote_block_range.end().gpos()); + DASH_LOG_DEBUG("MatrixViewsExample", "block range index:", + nview_str(dash::index(remote_block_range))); + DASH_LOG_DEBUG("MatrixViewsExample", "block range index is strided:", + dash::index(remote_block_range).is_strided()); DASH_LOG_DEBUG("MatrixViewsExample", "block range:", nview_str(remote_block_range)); DASH_LOG_DEBUG("MatrixViewsExample", "local(block range):", @@ -227,4 +277,5 @@ int main(int argc, char *argv[]) } dash::finalize(); + return EXIT_SUCCESS; } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index f5e292eb0..d7a345cf5 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -260,17 +260,16 @@ index(ContainerType && c) } template < - class ContainerType, - class ContainerDecayType = typename std::decay::type > + class ContainerType > constexpr auto index(const ContainerType & c) -> typename std::enable_if < - dash::view_traits::is_origin::value || - !dash::view_traits::is_view::value, - IndexSetIdentity + dash::view_traits::is_origin::value || + !dash::view_traits::is_view::value, + IndexSetIdentity >::type { - return IndexSetIdentity(c); -} + return IndexSetIdentity(c); + } // ----------------------------------------------------------------------- // IndexSetBase diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index e50177b79..3b7421808 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -541,7 +541,7 @@ class ViewLocalMod constexpr const index_set_type & index_set() const { return _index_set; } -}; +}; // ViewLocalMod // ------------------------------------------------------------------------ diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index d12428dda..7fdbc9010 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -1358,8 +1358,8 @@ 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()) - // end + // begin + (begin.pattern().size() - begin.pos()) + end )) // Convert iterator positions to sub-range index set: , _index_set(this->domain(), begin.pos(), end.pos()) @@ -1370,8 +1370,8 @@ 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(end) + // 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()) From bef690a417dc11573b5c3ccc17457032a0b46958 Mon Sep 17 00:00:00 2001 From: Roger Kowalewski Date: Mon, 26 Jun 2017 08:32:35 +0200 Subject: [PATCH 079/161] added unit test for local blocks --- dash/test/view/NViewTest.cc | 130 +++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 8 deletions(-) diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 8e07aa018..7e0e443fa 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -525,7 +525,7 @@ TEST_F(NViewTest, MatrixBlocked1DimChained) "extents:", nview_cr_s_g.extents(), "size:", nview_cr_s_g.size()); dash::test::print_nview("nview_cr_s_g", nview_cr_s_g); - + DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", "sub<0>(1,3, sub<1>(2,7, mat) ->", "offsets:", nview_rc_s_g.offsets(), @@ -557,7 +557,7 @@ TEST_F(NViewTest, MatrixBlocked1DimChained) // EXPECT_EQ_U(2, nview_rows_l.extent<0>()); // EXPECT_EQ_U(block_cols, nview_rows_l.extent<1>()); - + // dash::test::print_nview("nview_rows_l", nview_rows_l); DASH_LOG_DEBUG("NViewTest.MatrixBlocked1DimChained", "== nview_cols_l"); @@ -640,7 +640,7 @@ TEST_F(NViewTest, MatrixBlocked1DimSub) // -- Sub-Section ---------------------------------- // - + if (dash::myid() == 0) { DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", mat.extents()); @@ -679,7 +679,7 @@ TEST_F(NViewTest, MatrixBlocked1DimSub) // -- Local View ----------------------------------- // - + auto lsub_view = dash::local( dash::sub<0>( 0, mat.extents()[0], @@ -687,7 +687,7 @@ TEST_F(NViewTest, MatrixBlocked1DimSub) EXPECT_EQ_U(2, decltype(lsub_view)::rank::value); EXPECT_EQ_U(2, lsub_view.ndim()); - + int lrows = lsub_view.extent<0>(); int lcols = lsub_view.extent<1>(); @@ -701,14 +701,14 @@ TEST_F(NViewTest, MatrixBlocked1DimSub) DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", lsub_view.size()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", index(lsub_view).size()); - + DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", lsub_view.begin().pos()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", lsub_view.end().pos()); DASH_LOG_DEBUG_VAR("NViewTest.MatrixBlocked1DimSub", (lsub_view.end() - lsub_view.begin())); - + EXPECT_EQ_U(mat.local_size(), lrows * lcols); dash::test::print_nview("lsub_view", lsub_view); @@ -792,7 +792,7 @@ TEST_F(NViewTest, MatrixBlockCyclic1DimSub) int bi = 0; for (const auto & block : nview_blocks) { DASH_LOG_DEBUG("NViewTest.MatrixBlockCyclic1DSingle", - "block", bi, ":", "extents:", block.extents(), + "block", bi, ":", "extents:", block.extents(), range_str(block)); bi++; } @@ -1012,3 +1012,117 @@ TEST_F(NViewTest, MatrixBlockCyclic2DimSub) dash::test::print_nview("mat_local", mat_local); } + +TEST_F(NViewTest, Matrix2DTiledLocalBlocks) +{ + dart_unit_t myid = dash::myid(); + size_t num_units = dash::Team::All().size(); + + dash::TeamSpec<2> teamspec_2d(num_units, 1); + teamspec_2d.balance_extents(); + + //Number of blocks per dimension + size_t size_factor = 3; + size_t tile_size = 3; + size_t rows = tile_size * teamspec_2d.num_units(0) * size_factor; + size_t cols = tile_size * teamspec_2d.num_units(1) * size_factor; + size_t matrix_size = rows * cols; + + if (matrix_size <= 1024 && 0 == myid) { + std::cout << "Matrix size: " << rows + << " x " << cols + << " == " << matrix_size + << std::endl; + } + + dash::Matrix matrix( + dash::SizeSpec<2>( + rows, + cols), + dash::DistributionSpec<2>( + dash::TILE(tile_size), + dash::TILE(tile_size)), + dash::Team::All(), + teamspec_2d); + DASH_ASSERT(matrix_size == matrix.size()); + DASH_ASSERT(rows == matrix.extent(0)); + DASH_ASSERT(cols == matrix.extent(1)); + + std::fill(matrix.lbegin(), matrix.lend(), (double)myid); + + dash::barrier(); + + auto pattern = matrix.pattern(); + using pattern_t = decltype(pattern); + using index_t = pattern_t::index_type; + using viewspec_t = pattern_t::viewspec_type; + + + if (dash::myid() == 0) { + dash::test::print_pattern_mapping( + "matrix.pattern.unit_at", pattern, 3, + [](const pattern_t & _pattern, int _x, int _y) -> dart_unit_t { + return _pattern.unit_at( + std::array {{ _x, _y }}); + }); + dash::test::print_pattern_mapping( + "matrix.pattern.global_index", pattern, 3, + [](const pattern_t & _pattern, int _x, int _y) -> index_t { + return _x * _pattern.extent(1) + _y; + }); + dash::test::print_pattern_mapping( + "matrix.pattern.local_index", pattern, 3, + [](const pattern_t & _pattern, int _x, int _y) -> index_t { + return _pattern.local_index( + std::array {{ _x, _y }}).index; + }); + + + } + + auto nlblocks = pattern.local_blockspec().size(); + + std::vector local_blocks; + + for (auto b = 0; b < nlblocks; ++b) { + auto block = pattern.local_block(b); + local_blocks.push_back(block); + DASH_LOG_DEBUG("NViewTest.Matrix2DTiledLocalBlocks", + "matrix local_blockspec", + "extents:", block.extents(), + "offsets:", block.offsets(), + "size:", block.size()); + } + + auto const last_block = local_blocks[local_blocks.size() - 1]; + auto const gend_row = (last_block.offset(0) + last_block.extent(0) - 1); + auto const gend_col = (last_block.offset(1) + last_block.extent(1)); + + auto const gbegin_row = local_blocks[0].offset(0); + auto const gbegin_col = local_blocks[0].offset(1); + + auto loc = dash::local(matrix); + + DASH_LOG_DEBUG("NViewTest.Matrix2DTiledLocalBlocks", + "first_block gbegin", gbegin_row * cols + gbegin_col); + DASH_LOG_DEBUG("NViewTest.Matrix2DTiledLocalBlocks", + "last_block gend", gend_row * cols + gend_col); + + DASH_LOG_DEBUG("NViewTest.Matrix2DTiledLocalBlocks", + "local block view", + "extents:", loc.extents(), + "offsets:", loc.offsets(), + "size:", loc.size()); + DASH_LOG_DEBUG("NViewTest.Matrix2DTiledLocalBlocks", + "local block view domain extents:", + dash::domain(loc).extents()); + DASH_LOG_DEBUG("NViewTest.Matrix2DTiledLocalBlocks", + "begin.pos:", loc.begin().pos(), + "end.pos:", loc.end().pos(), + "begin.gpos:", loc.begin().gpos(), + "end.gpos:", loc.end().gpos()); + + + DASH_ASSERT(loc.begin().gpos() == gbegin_row * cols + gbegin_col); + DASH_ASSERT(loc.end().gpos() == gend_row * cols + gend_col); +} From 7dde45c5aa2874cfc568319449634235e48e5a2c Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 29 Jun 2017 14:22:12 +0200 Subject: [PATCH 080/161] Adding chunked view concepts --- .../examples/ex.02.matrix-halo-views/main.cpp | 150 ++++++++++++++++++ dash/examples/ex.02.matrix_views/main.cpp | 14 +- dash/include/dash/Iterator.h | 17 +- dash/include/dash/View.h | 1 + dash/include/dash/view/{Chunked.h => Chunk.h} | 0 dash/include/dash/view/Sup.h | 59 +++++++ dash/include/dash/view/ViewIterator.h | 10 +- dash/include/dash/view/ViewMod.h | 8 +- dash/include/dash/view/ViewMod1D.h | 2 - doc/Views/ViewConcepts.md | 51 ++++++ 10 files changed, 293 insertions(+), 19 deletions(-) create mode 100644 dash/examples/ex.02.matrix-halo-views/main.cpp rename dash/include/dash/view/{Chunked.h => Chunk.h} (100%) create mode 100644 dash/include/dash/view/Sup.h create mode 100644 doc/Views/ViewConcepts.md diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp new file mode 100644 index 000000000..0ed869ae4 --- /dev/null +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -0,0 +1,150 @@ +#include + +using std::cout; +using std::cerr; +using std::cin; +using std::endl; +using std::vector; + +using uint = unsigned int; + +template +std::string nview_str( + const NViewType & nview) { + using value_t = typename NViewType::value_type; + auto view_nrows = nview.extents()[0]; + auto view_ncols = nview.extents()[1]; + auto nindex = dash::index(nview); + std::ostringstream ss; + for (int r = 0; r < view_nrows; ++r) { + ss << '\n'; + for (int c = 0; c < view_ncols; ++c) { + int offset = r * view_ncols + c; + ss << std::fixed << std::setw(3) + << nindex[offset] + << ":" + << std::fixed << std::setprecision(5) + << static_cast(nview[offset]) + << " "; + } + } + return ss.str(); +} + +inline void sum(const uint nelts, + const dash::NArray &matIn, + const uint myid) { + uint lclRows = matIn.pattern().local_extents()[0]; + + uint const *mPtr; + uint localSum = 0; + + for (uint i = 0; i < lclRows; ++i) { + mPtr = matIn.local.row(i).lbegin(); + + for (uint j = 0; j < nelts; ++j) { + localSum += *(mPtr++); + } + } +} + +int main(int argc, char *argv[]) +{ + dash::init(&argc, &argv); + + auto myid = dash::myid(); + auto nunits = dash::size(); + + const size_t block_size_x = 2; + const size_t block_size_y = 3; + const size_t block_size = block_size_x * block_size_y; + size_t num_local_blocks_x = 2; + size_t num_local_blocks_y = 2; + size_t num_blocks_x = nunits * num_local_blocks_x; + size_t num_blocks_y = nunits * num_local_blocks_y; + size_t num_blocks_total = num_blocks_x * num_blocks_y; + size_t extent_x = block_size_x * num_blocks_x; + size_t extent_y = block_size_y * num_blocks_y; + size_t num_elem_total = extent_x * extent_y; + // Assuming balanced mapping: + size_t num_elem_per_unit = num_elem_total / nunits; + size_t num_blocks_per_unit = num_elem_per_unit / block_size; + + typedef dash::SeqTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + pattern_t pattern( + dash::SizeSpec<2>( + extent_y, + extent_x), + dash::DistributionSpec<2>( + dash::TILE(block_size_y), + dash::TILE(block_size_x)) + ); + + dash::Matrix + matrix(pattern); + + // Initialize matrix values: + for (size_t lb = 0; lb < num_blocks_per_unit; ++lb) { + auto lblock = matrix.local.block(lb); + auto lblock_view = lblock.begin().viewspec(); + auto lblock_extents = lblock_view.extents(); + auto lblock_offsets = lblock_view.offsets(); + dash__unused(lblock_offsets); + for (auto bx = 0; bx < static_cast(lblock_extents[0]); ++bx) { + for (auto by = 0; by < static_cast(lblock_extents[1]); ++by) { + // Phase coordinates (bx,by) to global coordinates (gx,gy): + value_t value = static_cast(dash::myid().id + 1) + + 0.00001 * ( + ((lb + 1) * 10000) + ((bx + 1) * 100) + by + 1); + lblock[bx][by] = value; + } + } + } + dash::barrier(); + + if (myid == 0) { + auto matrix_view = dash::sub(0, matrix.extents()[0], matrix); + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(matrix_view)); + DASH_LOG_DEBUG("MatrixViewsExample", "matrix", + "offsets:", matrix_view.offsets(), + "extents:", matrix_view.extents()); + + auto matrix_blocks = dash::blocks(matrix_view); + for (const auto & m_block : matrix_blocks) { + DASH_LOG_DEBUG("MatrixViewsExample", "==============================", + nview_str(m_block)); + // halo view: + auto b_halo = dash::sub<0>( + m_block.offsets()[0] > 0 + ? m_block.offsets()[0] -1 + : m_block.offsets()[0], + m_block.offsets()[0] + m_block.extents()[0] + < matrix_view.extents()[0] + ? m_block.offsets()[0] + m_block.extents()[0] + 1 + : m_block.offsets()[0] + m_block.extents()[0], + dash::sub<1>( + m_block.offsets()[1] > 0 + ? m_block.offsets()[1] -1 + : m_block.offsets()[1], + m_block.offsets()[1] + m_block.extents()[1] + < matrix_view.extents()[1] + ? m_block.offsets()[1] + m_block.extents()[1] + 1 + : m_block.offsets()[1] + m_block.extents()[1], + matrix_view)); + DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", + nview_str(b_halo)); + + auto b_halo_sup = dash::sup<0>(-1, 1, m_block); + DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", + nview_str(b_halo_sup)); + } + } + dash::barrier(); + + dash::finalize(); + return EXIT_SUCCESS; +} diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix_views/main.cpp index 5e649f990..146cb1450 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix_views/main.cpp @@ -24,7 +24,7 @@ std::string nview_str( << nindex[offset] << ":" << std::fixed << std::setprecision(5) - << static_cast(nview[offset]) + << static_cast(nview[offset]) << " "; } } @@ -131,10 +131,14 @@ int main(int argc, char *argv[]) auto matrix_reg_blocks = dash::blocks(matrix_region); for (const auto & reg_block : matrix_reg_blocks) { + auto sreg_block = dash::sub<0>(1,2, reg_block); + DASH_LOG_DEBUG("MatrixViewsExample", "==============================", nview_str(reg_block)); DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(dash::sub<0>(1,2, reg_block))); + dash::typestr(sreg_block.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(sreg_block)); auto block_rg = dash::make_range(reg_block.begin(), reg_block.end()); @@ -142,8 +146,10 @@ int main(int argc, char *argv[]) DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", nview_str(block_rg)); - DASH_LOG_DEBUG_VAR("MatrixViewsExample", - block_srg.begin().pos()); + DASH_LOG_DEBUG("MatrixViewsExample", "block range origin iterator:", + dash::typestr(dash::origin(block_srg).begin())); + DASH_LOG_DEBUG("MatrixViewsExample", "block range origin:", + nview_str(dash::origin(block_srg))); DASH_LOG_DEBUG("MatrixViewsExample", nview_str(block_srg)); } diff --git a/dash/include/dash/Iterator.h b/dash/include/dash/Iterator.h index 6bdd2f82c..cc43dc00e 100644 --- a/dash/include/dash/Iterator.h +++ b/dash/include/dash/Iterator.h @@ -56,24 +56,27 @@ namespace detail { DASH__META__DEFINE_TRAIT__HAS_TYPE(const_reference); DASH__META__DEFINE_TRAIT__HAS_TYPE(pointer); DASH__META__DEFINE_TRAIT__HAS_TYPE(const_pointer); + + DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_iterator); } template struct iterator_traits : public std::iterator_traits { - private: - using iterator = typename std::decay::type; - using is_local = typename std::integral_constant::value - >; - + using is_local + = typename std::integral_constant::value + >; + using is_view_iterator + = typename dash::detail::has_type_domain_iterator; }; template struct iterator_traits : public std::iterator_traits { - using is_local = typename std::integral_constant; + using is_local = typename std::integral_constant; + using is_view_iterator = std::integral_constant; }; diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index edfe34ffc..82ab9b553 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -80,6 +80,7 @@ #include #include #include +#include #include #include diff --git a/dash/include/dash/view/Chunked.h b/dash/include/dash/view/Chunk.h similarity index 100% rename from dash/include/dash/view/Chunked.h rename to dash/include/dash/view/Chunk.h diff --git a/dash/include/dash/view/Sup.h b/dash/include/dash/view/Sup.h new file mode 100644 index 000000000..5e706ba81 --- /dev/null +++ b/dash/include/dash/view/Sup.h @@ -0,0 +1,59 @@ +#ifndef DASH__VIEW__SUP_H__INCLUDED +#define DASH__VIEW__SUP_H__INCLUDED + +#include +#include + +#include + + +namespace dash { + +template < + dim_t SubDim = 0, + class DomainT, + class OffsetFirstT, + class OffsetFinalT, + typename DomainValueT = typename std::decay::type, + typename SupDomainT = typename dash::view_traits::domain_type, + typename OriginT = typename dash::view_traits::origin_type +> +constexpr +ViewSubMod< + SupDomainT, + SubDim, + dash::view_traits::rank::value > +sup(OffsetFirstT begin, + OffsetFinalT end, + DomainT && domain) { + return ViewSubMod< + SupDomainT, + SubDim, + dash::view_traits::rank::value + >(dash::domain( + std::forward(domain)), + domain.offsets()[SubDim] + + ( domain.offsets()[SubDim] > 0 + ? begin + : 0 ), + domain.offsets()[SubDim] + domain.extents()[SubDim] + + ( domain.offsets()[SubDim] + domain.extents()[SubDim] + < dash::domain(domain).extents()[SubDim] + ? end + : 0 )); +} + +template < + dim_t SubDim = 0, + class DomainT, + class OffsetT > +constexpr auto +sup(OffsetT offset, + DomainT && domain) + -> decltype(dash::sup(offset, offset+1, domain)) { + return dash::sup(offset, offset+1, domain); +} + +} // namespace dash + +#endif // DASH__VIEW__SUP_H__INCLUDED diff --git a/dash/include/dash/view/ViewIterator.h b/dash/include/dash/view/ViewIterator.h index facb4ffd3..c7e62e824 100644 --- a/dash/include/dash/view/ViewIterator.h +++ b/dash/include/dash/view/ViewIterator.h @@ -48,6 +48,8 @@ class ViewIterator typedef std::integral_constant has_view; typedef IndexSetType index_set_type; + + typedef DomainIterator domain_iterator; private: DomainIterator _domain_it; IndexSetType _index_set; @@ -120,11 +122,15 @@ class ViewIterator return _domain_it.team(); } - constexpr explicit operator DomainIterator() const { + constexpr explicit operator domain_iterator() const { + return (_domain_it + _index_set[this->pos()]); + } + + explicit operator domain_iterator() { return (_domain_it + _index_set[this->pos()]); } - explicit operator DomainIterator() { + constexpr domain_iterator domain() const { return (_domain_it + _index_set[this->pos()]); } diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 3b7421808..604849093 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -452,13 +452,13 @@ class ViewLocalMod template constexpr size_type extent() const { - return _index_set.template extent(); -// return _index_set.extents()[ShapeDim]; +// return _index_set.template extent(); + 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]; +// return _index_set.extent(shape_dim); + return _index_set.extents()[shape_dim]; } // ---- offsets --------------------------------------------------------- diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index 7fdbc9010..ba2610585 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -1295,7 +1295,6 @@ struct view_traits > { typedef typename view_traits< typename std::decay::type >::is_local is_local; -// typedef std::integral_constant is_local; }; /** @@ -1319,7 +1318,6 @@ class IteratorRange typedef typename RangeOrigin::const_sentinel const_sentinel; typedef RangeOrigin domain_type; -//typedef RangeOrigin origin_type; typedef typename dash::view_traits< typename std::decay::type >::origin_type origin_type; diff --git a/doc/Views/ViewConcepts.md b/doc/Views/ViewConcepts.md new file mode 100644 index 000000000..0f471fed1 --- /dev/null +++ b/doc/Views/ViewConcepts.md @@ -0,0 +1,51 @@ + +# Range- and View Expressions + +## Cartesian Set Operations + +### `index` + +Maps elements in a view to their index in the view's origin domain. + + +### `sub(ob,oe)` + +Subsection in dimension `D` in offset range `(ob,oe]` with default +dimension `D = 0`. + +In a two-dimensional matrix, for example, `sub(1,3)` selects the second +and third row. + + +### `section(ib,ie)` + +Subsection delimited by n-dimensional indices `(ib,ie]`. + + +### `intersect(r)` + + + + + +## Operations based on Memory Space + +### `local` + + +### `global` + + +### `blocks` + +Group range into domain decomposition blocks. +Elements in single block are not necessarily contiguous. + + +### `chunks` + +Group range into chunks of sequential elements. +Elements in a chunk are contiguous in memory. + + + From 95e4934f6095d7283750d6c066c296b86f08df74 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 29 Jun 2017 14:24:56 +0200 Subject: [PATCH 081/161] Adding chunked view concepts --- .../examples/ex.02.matrix-halo-views/main.cpp | 17 +++- dash/include/dash/View.h | 5 +- dash/include/dash/view/Chunk.h | 58 ++---------- dash/include/dash/view/Expand.h | 94 +++++++++++++++++++ dash/include/dash/view/IndexSet.h | 10 +- dash/include/dash/view/SetDifference.h | 43 +++++++++ dash/include/dash/view/Sup.h | 59 ------------ dash/include/dash/view/ViewBlocksMod.h | 18 ++-- dash/include/dash/view/ViewChunksMod.h | 33 +++++++ dash/include/dash/view/ViewMod.h | 13 ++- dash/include/dash/view/ViewMod1D.h | 28 ++++-- dash/include/dash/view/ViewTraits.h | 8 +- 12 files changed, 252 insertions(+), 134 deletions(-) create mode 100644 dash/include/dash/view/Expand.h create mode 100644 dash/include/dash/view/SetDifference.h delete mode 100644 dash/include/dash/view/Sup.h create mode 100644 dash/include/dash/view/ViewChunksMod.h diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 0ed869ae4..dffbb2eed 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -138,9 +138,22 @@ int main(int argc, char *argv[]) DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", nview_str(b_halo)); - auto b_halo_sup = dash::sup<0>(-1, 1, m_block); + auto b_halo_isect = dash::difference( + m_block, + dash::sub<0>( + 1, m_block.extents()[0] - 1, + dash::sub<1>( + 1, m_block.extents()[1] - 1, + m_block))); +#if 0 + auto b_halo_exp = dash::expand<0>( + -1, 1, + dash::expand<1>( + -1, 1, + m_block)); DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", - nview_str(b_halo_sup)); + nview_str(b_halo_exp)); +#endif } } dash::barrier(); diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index 82ab9b553..b977a4d1c 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -72,7 +72,7 @@ */ #include -#include +#include #include #include #include @@ -80,10 +80,11 @@ #include #include #include -#include +#include #include #include +#include #include #include diff --git a/dash/include/dash/view/Chunk.h b/dash/include/dash/view/Chunk.h index b4ab172db..0d01c5f96 100644 --- a/dash/include/dash/view/Chunk.h +++ b/dash/include/dash/view/Chunk.h @@ -1,15 +1,16 @@ -#ifndef DASH__VIEW__CHUNKED_H__INCLUDED -#define DASH__VIEW__CHUNKED_H__INCLUDED +#ifndef DASH__VIEW__CHUNK_H__INCLUDED +#define DASH__VIEW__CHUNK_H__INCLUDED #include #include +#include #include #include #include #include #include -#include +#include namespace dash { @@ -18,66 +19,25 @@ namespace dash { // Forward-declarations // ------------------------------------------------------------------------ -template < - class DomainType, - dim_t NDim = dash::view_traits< - typename std::decay::type>::rank::value > -class ViewBlockMod; - -#if 0 -template < - class ContainerType, - class OffsetT > -constexpr auto -block( - OffsetT block_idx, - const ContainerType & container) - -> typename std::enable_if< - !dash::view_traits::is_view::value, - decltype(container.blocks()[0]) - >::type { - return container.blocks()[block_idx]; -} -#endif - /** - * Blocks view from global view + * Chunked view from global view. * */ template < class ViewType, class OffsetT > constexpr auto -block( +chunks( OffsetT block_idx, const ViewType & view) -> typename std::enable_if< (// dash::view_traits::is_view::value && !dash::view_traits::is_local::value ), - ViewBlockMod - >::type { - return ViewBlockMod(view, block_idx); -} - -/** - * Blocks view from local view - * - */ -template < - class ViewType, - class OffsetT > -constexpr auto -block( - OffsetT block_idx, - const ViewType & view) - -> typename std::enable_if< - (// dash::view_traits::is_view::value && - dash::view_traits::is_local::value ), - decltype(dash::block(block_idx, dash::local(dash::origin(view)))) + ViewChunksMod >::type { - return dash::local(dash::origin(view)).block(block_idx); + return ViewChunksMod(view, block_idx); } } // namespace dash -#endif // DASH__VIEW__CHUNKED_H__INCLUDED +#endif // DASH__VIEW__CHUNK_H__INCLUDED diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h new file mode 100644 index 000000000..d52594ff4 --- /dev/null +++ b/dash/include/dash/view/Expand.h @@ -0,0 +1,94 @@ +#ifndef DASH__VIEW__EXPAND_H__INCLUDED +#define DASH__VIEW__EXPAND_H__INCLUDED + +#include +#include + +#include + + +namespace dash { + +template < + dim_t SubDim = 0, + class DomainT, + class OffsetFirstT, + class OffsetFinalT, + typename DomainValueT + = typename std::decay::type, + typename SecDomainT + = typename dash::view_traits::domain_type +> +constexpr auto +expand( + OffsetFirstT begin, + OffsetFinalT end, + DomainT && domain) + -> typename std::enable_if< + true || + dash::view_traits< + typename dash::view_traits::domain_type + >::is_origin::value, + ViewSubMod::rank::value > + >::type { + return ViewSubMod< + SecDomainT, + SubDim, + dash::view_traits::rank::value + >(dash::domain( + std::forward(domain)), + domain.offsets()[SubDim] + + ( domain.offsets()[SubDim] > 0 + ? begin + : 0 ), + domain.offsets()[SubDim] + domain.extents()[SubDim] + + ( domain.offsets()[SubDim] + domain.extents()[SubDim] + < dash::domain(domain).extents()[SubDim] + ? end + : 0 )); +} + +#if 0 +template < + dim_t SubDim = 0, + class DomainT, + class OffsetFirstT, + class OffsetFinalT, + typename DomainValueT + = typename std::decay::type, + typename SecDomainT + = typename dash::view_traits::domain_type +> +constexpr auto +expand( + OffsetFirstT begin, + OffsetFinalT end, + DomainT && domain) + -> typename std::enable_if< + !dash::view_traits< + typename dash::view_traits::domain_type + >::is_origin::value, + ViewSubMod::rank::value > + >::type { + return ViewSubMod< + DomainValueT, + SubDim, + dash::view_traits::rank::value + >(std::forward(domain), + domain.offsets()[SubDim] + + ( domain.offsets()[SubDim] > 0 + ? begin + : 0 ), + domain.offsets()[SubDim] + domain.extents()[SubDim] + + ( domain.offsets()[SubDim] + domain.extents()[SubDim] + < dash::domain(domain).extents()[SubDim] + ? end + : 0 )); +} +#endif + +} // namespace dash + +#endif // DASH__VIEW__EXPAND_H__INCLUDED diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index d7a345cf5..c825018fa 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -269,7 +269,7 @@ index(const ContainerType & c) IndexSetIdentity >::type { return IndexSetIdentity(c); - } +} // ----------------------------------------------------------------------- // IndexSetBase @@ -458,10 +458,10 @@ class IndexSetBase } constexpr auto domain() const - -> decltype(dash::index( - std::declval() - )) { -// -> typename view_traits::index_set_type { +// -> decltype(dash::index( +// std::declval() +// )) { + -> typename view_traits::index_set_type { return dash::index(_domain); } diff --git a/dash/include/dash/view/SetDifference.h b/dash/include/dash/view/SetDifference.h new file mode 100644 index 000000000..3b6fc8bd2 --- /dev/null +++ b/dash/include/dash/view/SetDifference.h @@ -0,0 +1,43 @@ +#ifndef DASH__VIEW__SET_DIFFERENCE_H__INCLUDED +#define DASH__VIEW__SET_DIFFERENCE_H__INCLUDED + +#include +#include + +#include + + +namespace dash { + +/** + * \concept{DashViewConcept} + */ +template < + class ViewTypeA, + class ViewTypeB > +constexpr auto +difference( + const ViewTypeA & va, + const ViewTypeB & vb) + -> decltype(dash::sub(0, 0, va)) +{ + return dash::sub( + dash::index(va).pre()[ + std::max( + *dash::begin(dash::index(va)), + *dash::begin(dash::index(vb)) + ) + ], + dash::index(va).pre()[ + std::min( + *dash::end(dash::index(va)), + *dash::end(dash::index(vb)) + ) + ], + va + ); +} + +} // namespace dash + +#endif // DASH__VIEW__SET_DIFFERENCE_H__INCLUDED diff --git a/dash/include/dash/view/Sup.h b/dash/include/dash/view/Sup.h deleted file mode 100644 index 5e706ba81..000000000 --- a/dash/include/dash/view/Sup.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef DASH__VIEW__SUP_H__INCLUDED -#define DASH__VIEW__SUP_H__INCLUDED - -#include -#include - -#include - - -namespace dash { - -template < - dim_t SubDim = 0, - class DomainT, - class OffsetFirstT, - class OffsetFinalT, - typename DomainValueT = typename std::decay::type, - typename SupDomainT = typename dash::view_traits::domain_type, - typename OriginT = typename dash::view_traits::origin_type -> -constexpr -ViewSubMod< - SupDomainT, - SubDim, - dash::view_traits::rank::value > -sup(OffsetFirstT begin, - OffsetFinalT end, - DomainT && domain) { - return ViewSubMod< - SupDomainT, - SubDim, - dash::view_traits::rank::value - >(dash::domain( - std::forward(domain)), - domain.offsets()[SubDim] + - ( domain.offsets()[SubDim] > 0 - ? begin - : 0 ), - domain.offsets()[SubDim] + domain.extents()[SubDim] + - ( domain.offsets()[SubDim] + domain.extents()[SubDim] - < dash::domain(domain).extents()[SubDim] - ? end - : 0 )); -} - -template < - dim_t SubDim = 0, - class DomainT, - class OffsetT > -constexpr auto -sup(OffsetT offset, - DomainT && domain) - -> decltype(dash::sup(offset, offset+1, domain)) { - return dash::sup(offset, offset+1, domain); -} - -} // namespace dash - -#endif // DASH__VIEW__SUP_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 12a90fd9b..8d57dff19 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include @@ -29,7 +29,12 @@ namespace dash { // ------------------------------------------------------------------------ // Forward-declarations // ------------------------------------------------------------------------ -// + +template < + class DomainType, + dim_t NDim > +class ViewBlockMod; + template < class DomainType, dim_t NDim = dash::view_traits< @@ -62,8 +67,9 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; typedef std::integral_constant is_origin; - typedef std::integral_constant::is_local::value > is_local; + typedef typename view_traits::is_local is_local; + + typedef std::integral_constant is_contiguous; typedef std::integral_constant rank; }; @@ -467,8 +473,8 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; typedef std::integral_constant is_origin; - typedef std::integral_constant::is_local::value > is_local; + typedef typename view_traits::is_local is_local; + typedef typename view_traits::is_contiguous is_contiguous; typedef std::integral_constant rank; }; diff --git a/dash/include/dash/view/ViewChunksMod.h b/dash/include/dash/view/ViewChunksMod.h new file mode 100644 index 000000000..f64202e48 --- /dev/null +++ b/dash/include/dash/view/ViewChunksMod.h @@ -0,0 +1,33 @@ +#ifndef DASH__VIEW__VIEW_CHUNKS_MOD_H__INCLUDED +#define DASH__VIEW__VIEW_CHUNKS_MOD_H__INCLUDED + +#include +#include +#include + +#include +#include +#include + + +namespace dash { + +#ifndef DOXYGEN + +// ------------------------------------------------------------------------ +// Forward-declarations +// ------------------------------------------------------------------------ +// +template < + class DomainType, + dim_t NDim = dash::view_traits< + typename std::decay::type>::rank::value > +class ViewChunksMod; + + + +#endif // DOXYGEN + +} // namespace dash + +#endif // DASH__VIEW__VIEW_CHUNKS_MOD_H__INCLUDED diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 604849093..f264648bc 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -220,6 +220,12 @@ class ViewModBase protected: domain_member_type _domain; + // TODO: Index set should be member of ViewModBase as all models of the + // view concept depend on an index set type. + // As constructors of index set classes depend on the concrete view + // type, index sets should be instantiated in derived view subclass + // and passed to ViewModBase base constructor. + ViewModType & derived() { return static_cast(*this); } @@ -331,6 +337,8 @@ struct view_traits > { typedef std::integral_constant is_origin; typedef std::integral_constant is_local; + typedef typename view_traits::is_contiguous is_contiguous; + typedef std::integral_constant rank; }; @@ -567,8 +575,9 @@ struct view_traits > { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; typedef std::integral_constant is_origin; - typedef std::integral_constant::is_local::value > is_local; + typedef typename view_traits::is_local is_local; + + typedef std::integral_constant is_contiguous; typedef std::integral_constant rank; }; diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index ba2610585..cae2a397d 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -500,6 +500,8 @@ struct view_traits > { typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant is_local; + + typedef std::integral_constant is_contiguous; }; template < @@ -706,10 +708,12 @@ struct view_traits> { typedef typename iterator::index_type index_type; typedef typename std::make_unsigned::type size_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; - typedef std::integral_constant is_local; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; + typedef std::integral_constant is_local; + + typedef typename view_traits::is_contiguous is_contiguous; }; @@ -956,6 +960,8 @@ struct view_traits > { typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant is_local; + + typedef std::integral_constant is_contiguous; }; @@ -1201,6 +1207,8 @@ struct view_traits< typedef std::integral_constant is_view; typedef std::integral_constant is_origin; typedef std::integral_constant is_local; + + typedef std::integral_constant is_contiguous; }; template < @@ -1289,12 +1297,16 @@ struct view_traits > { typedef dash::IndexSetSub index_set_type; - typedef std::integral_constant is_projection; - typedef std::integral_constant is_view; - typedef std::integral_constant is_origin; + typedef std::integral_constant is_projection; + typedef std::integral_constant is_view; + typedef std::integral_constant is_origin; typedef typename view_traits< typename std::decay::type - >::is_local is_local; + >::is_local is_local; + + typedef typename view_traits< + typename std::decay::type + >::is_contiguous is_contiguous; }; /** diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index 288c63044..aa343913f 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -43,7 +43,10 @@ struct view_traits typedef std::integral_constant is_origin; typedef std::integral_constant is_view; typedef std::integral_constant is_projection; + typedef std::integral_constant is_local; + + typedef std::integral_constant is_contiguous; }; #else // DOXYGEN @@ -91,7 +94,6 @@ namespace detail { { typedef std::integral_constant is_projection; typedef std::integral_constant is_view; - /// Whether the view is the origin domain. typedef std::integral_constant is_origin; typedef typename ViewT::index_type index_type; @@ -107,6 +109,8 @@ namespace detail { dash::is_range::value >::is_local::value > is_local; + typedef std::integral_constant is_contiguous; + typedef typename ViewT::local_type local_type; typedef typename ViewT::global_type global_type; typedef typename std::conditional::value > is_local; + typedef std::integral_constant is_contiguous; + typedef std::integral_constant rank; }; From 729564b80331128fa4bc7d46aac0d158b3f91189 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 16 Sep 2017 13:30:43 +0200 Subject: [PATCH 082/161] Tentative switch to c++14 --- CMakeExt/CompilerFlags.cmake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeExt/CompilerFlags.cmake b/CMakeExt/CompilerFlags.cmake index 0045deaa7..3e64aa028 100644 --- a/CMakeExt/CompilerFlags.cmake +++ b/CMakeExt/CompilerFlags.cmake @@ -9,6 +9,8 @@ find_package(OpenMP) +set(CPP_STD_VERSION 14) + # The following warning options are intentionally not enabled: # # ,--------------------------.-------------------------------------------. @@ -49,6 +51,8 @@ if (ENABLE_DEV_COMPILER_WARNINGS "${DASH_DEVELOPER_CCXX_FLAGS} -Wunused -Wtrigraphs") set (DASH_DEVELOPER_CCXX_FLAGS "${DASH_DEVELOPER_CCXX_FLAGS} -Wdeprecated -Wno-float-equal") + set (DASH_DEVELOPER_CCXX_FLAGS + "${DASH_DEVELOPER_CCXX_FLAGS} -ftemplate-backtrace-limit=0") if (OPENMP_FOUND) set (DASH_DEVELOPER_CCXX_FLAGS @@ -134,7 +138,7 @@ endif() # Set C++ compiler flags: if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") # using Clang - set (CXX_STD_FLAG "--std=c++11" + set (CXX_STD_FLAG "--std=c++${CPP_STD_VERSION}" CACHE STRING "C++ compiler std flag") set (CXX_GDB_FLAG "-g" CACHE STRING "C++ compiler (clang++) debug symbols flag") @@ -147,7 +151,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") # using GCC - set (CXX_STD_FLAG "--std=c++11" + set (CXX_STD_FLAG "--std=c++${CPP_STD_VERSION}" CACHE STRING "C++ compiler std flag") set (CXX_GDB_FLAG "-ggdb3 -rdynamic" CACHE STRING "C++ compiler GDB debug symbols flag") @@ -163,7 +167,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") # using Intel C++ - set (CXX_STD_FLAG "-std=c++11" + set (CXX_STD_FLAG "-std=c++${CPP_STD_VERSION}" CACHE STRING "C++ compiler std flag") set (CXX_OMP_FLAG ${OpenMP_CXX_FLAGS}) set (CC_OMP_FLAG ${OpenMP_CC_FLAGS}) @@ -182,7 +186,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Cray") # Cray compiler not supported for C++ message(FATAL_ERROR, - "Cray compiler does not support C++11 features and is only " + "Cray compiler does not support C++${CPP_STD_VERSION} features and is only " "eligible for building DART.") endif() From 1bc3b41ee13151abfa149e42b2b71b04ff6745f6 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 16 Sep 2017 13:44:22 +0200 Subject: [PATCH 083/161] Deduction of domain index set type via declval --- dash/include/dash/view/IndexSet.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index c825018fa..107d2a15d 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -458,10 +458,10 @@ class IndexSetBase } constexpr auto domain() const -// -> decltype(dash::index( -// std::declval() -// )) { - -> typename view_traits::index_set_type { + -> decltype(dash::index( + std::declval() + )) { +// -> typename view_traits::index_set_type { return dash::index(_domain); } From 8aab38bb3c1875d2e15f6be7372c9cb106d00be8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 16 Sep 2017 20:21:17 +0200 Subject: [PATCH 084/161] Added LocalMatrixRef.pattern(), returning global pattern --- dash/include/dash/matrix/LocalMatrixRef.h | 2 +- dash/include/dash/matrix/internal/LocalMatrixRef-inl.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dash/include/dash/matrix/LocalMatrixRef.h b/dash/include/dash/matrix/LocalMatrixRef.h index 11dab1a19..9038735f8 100644 --- a/dash/include/dash/matrix/LocalMatrixRef.h +++ b/dash/include/dash/matrix/LocalMatrixRef.h @@ -205,7 +205,7 @@ class LocalMatrixRef * not have a pattern. The pattern of the referenced matrix * refers to the global data domain. */ - constexpr const PatternT & pattern() const; + constexpr const PatternT & pattern() const noexcept; inline iterator begin() noexcept; constexpr const_iterator begin() const noexcept; diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index e48d6f060..25b6caaeb 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -201,6 +201,15 @@ ::empty() const noexcept return size() == 0; } +template +constexpr const +typename LocalMatrixRef::pattern_type & +LocalMatrixRef +::pattern() const noexcept +{ + return _refview._mat->_pattern; +} + template inline typename LocalMatrixRef::iterator LocalMatrixRef From 25f18474d5e676e3bf306f5308f8a428bf65b2b8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 16 Sep 2017 20:28:16 +0200 Subject: [PATCH 085/161] Extending matrix halo views example --- dash/examples/ex.02.matrix-halo-views/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index dffbb2eed..bb0753816 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) auto matrix_blocks = dash::blocks(matrix_view); for (const auto & m_block : matrix_blocks) { - DASH_LOG_DEBUG("MatrixViewsExample", "==============================", + DASH_LOG_DEBUG("MatrixViewsExample", "m_block ======================", nview_str(m_block)); // halo view: auto b_halo = dash::sub<0>( @@ -135,9 +135,9 @@ int main(int argc, char *argv[]) ? m_block.offsets()[1] + m_block.extents()[1] + 1 : m_block.offsets()[1] + m_block.extents()[1], matrix_view)); - DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", + DASH_LOG_DEBUG("MatrixViewsExample", "b_halo -----------------------", nview_str(b_halo)); - +#if 0 auto b_halo_isect = dash::difference( m_block, dash::sub<0>( @@ -145,7 +145,7 @@ int main(int argc, char *argv[]) dash::sub<1>( 1, m_block.extents()[1] - 1, m_block))); -#if 0 + auto b_halo_exp = dash::expand<0>( -1, 1, dash::expand<1>( From 9037281c265a629c01cf904183f3a305814d1bd3 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 19 Sep 2017 13:28:06 +0200 Subject: [PATCH 086/161] Added pipe utils --- CMakeExt/CompilerFlags.cmake | 4 +- dash/CMakeLists.txt | 14 ++- dash/examples/CMakeLists.txt | 4 +- .../examples/ex.02.matrix-halo-views/main.cpp | 1 + dash/examples/ex.02.matrix_views/main.cpp | 34 +++++- dash/include/dash/View.h | 2 + dash/include/dash/view/Utility.h | 115 ++++++++++++++++++ 7 files changed, 158 insertions(+), 16 deletions(-) create mode 100644 dash/include/dash/view/Utility.h diff --git a/CMakeExt/CompilerFlags.cmake b/CMakeExt/CompilerFlags.cmake index 3e64aa028..9bf9daa48 100644 --- a/CMakeExt/CompilerFlags.cmake +++ b/CMakeExt/CompilerFlags.cmake @@ -151,7 +151,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") # using GCC - set (CXX_STD_FLAG "--std=c++${CPP_STD_VERSION}" + set (CXX_STD_FLAG "-std=c++${CPP_STD_VERSION}" CACHE STRING "C++ compiler std flag") set (CXX_GDB_FLAG "-ggdb3 -rdynamic" CACHE STRING "C++ compiler GDB debug symbols flag") @@ -199,7 +199,7 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang") CACHE STRING "C compiler (clang) debug symbols flag") elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") # using GCC - set (CC_STD_FLAG "--std=c99" + set (CC_STD_FLAG "-std=c99" CACHE STRING "C compiler std flag") set (CC_GDB_FLAG "-ggdb3" CACHE STRING "C compiler GDB debug symbols flag") diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt index 28d07de2f..0813f6dfd 100644 --- a/dash/CMakeLists.txt +++ b/dash/CMakeLists.txt @@ -41,6 +41,8 @@ set(ENABLE_PAPI ${ENABLE_PAPI} PARENT_SCOPE) set(ENABLE_COMPTIME_RED ${ENABLE_COMPTIME_RED} PARENT_SCOPE) +set(CPP_STD_VERSION ${CPP_STD_VERSION} + PARENT_SCOPE) # Source- and header files to be compiled (OBJ): @@ -301,7 +303,7 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) ) set_target_properties( ${DASH_LIBRARY} PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD ${CPP_STD_VERSION} ) if(ENABLE_COMPTIME_RED) @@ -310,7 +312,7 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) set_target_properties( ${DASH_LIBRARY} PROPERTIES - CXX_STANDARD_REQUIRED 11 + CXX_STANDARD_REQUIRED ${CPP_STD_VERSION} ) include_directories( ${ADDITIONAL_INCLUDES} @@ -403,11 +405,11 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) ) set_target_properties( ${exampletarget} PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD ${CPP_STD_VERSION} ) set_target_properties( ${exampletarget} PROPERTIES - CXX_STANDARD_REQUIRED 11 + CXX_STANDARD_REQUIRED ${CPP_STD_VERSION} ) # Installation @@ -464,7 +466,7 @@ include(${CMAKE_SOURCE_DIR}/CMakeExt/GoogleTest.cmake) ) set_target_properties( ${DASH_TEST} PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD ${CPP_STD_VERSION} ) if(ENABLE_COMPTIME_RED) @@ -473,7 +475,7 @@ include(${CMAKE_SOURCE_DIR}/CMakeExt/GoogleTest.cmake) set_target_properties( ${DASH_TEST} PROPERTIES - CXX_STANDARD_REQUIRED 11 + CXX_STANDARD_REQUIRED ${CPP_STD_VERSION} ) # Installation diff --git a/dash/examples/CMakeLists.txt b/dash/examples/CMakeLists.txt index 7ac3d5be4..ffeb206e1 100644 --- a/dash/examples/CMakeLists.txt +++ b/dash/examples/CMakeLists.txt @@ -117,11 +117,11 @@ foreach(dart_variant ${DART_IMPLEMENTATIONS_LIST}) ) set_target_properties( ${exampletarget} PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD 14 ) set_target_properties( ${exampletarget} PROPERTIES - CXX_STANDARD_REQUIRED 11 + CXX_STANDARD_REQUIRED 14 ) # Installation DeployBinary(${exampletarget}) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index bb0753816..94c5b03ed 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -137,6 +137,7 @@ int main(int argc, char *argv[]) matrix_view)); DASH_LOG_DEBUG("MatrixViewsExample", "b_halo -----------------------", nview_str(b_halo)); + DASH_LOG_DEBUG("MatrixViewsExample", "size:", b_halo.size()); #if 0 auto b_halo_isect = dash::difference( m_block, diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix_views/main.cpp index 146cb1450..f99adecd0 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix_views/main.cpp @@ -48,10 +48,32 @@ inline void sum(const uint nelts, } } +auto addvalue() { + return dash::make_pipeable( + [](auto && x) { + return std::forward(x) + 10; + }); +} + +auto subvalue() { + return dash::make_pipeable( + [](auto && x) { + return std::forward(x) - 3; + }); +} + +using namespace dash; + int main(int argc, char *argv[]) { dash::init(&argc, &argv); + int val = 100; + int mod = val | addvalue() | subvalue(); + + cout << "mod: " << mod << endl; + return 0; + auto myid = dash::myid(); auto nunits = dash::size(); @@ -148,16 +170,16 @@ int main(int argc, char *argv[]) nview_str(block_rg)); DASH_LOG_DEBUG("MatrixViewsExample", "block range origin iterator:", dash::typestr(dash::origin(block_srg).begin())); - DASH_LOG_DEBUG("MatrixViewsExample", "block range origin:", - nview_str(dash::origin(block_srg))); - DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(block_srg)); + // DASH_LOG_DEBUG("MatrixViewsExample", "block range origin:", + // nview_str(dash::origin(block_srg))); + // DASH_LOG_DEBUG("MatrixViewsExample", + // nview_str(block_srg)); } } dash::barrier(); - dash::finalize(); - return EXIT_SUCCESS; +//dash::finalize(); +//return EXIT_SUCCESS; // Array to store local copy: std::vector local_copy(num_elem_per_unit); diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index b977a4d1c..dfdcf2404 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -71,6 +71,8 @@ * \} */ +#include + #include #include #include diff --git a/dash/include/dash/view/Utility.h b/dash/include/dash/view/Utility.h new file mode 100644 index 000000000..2064d7a24 --- /dev/null +++ b/dash/include/dash/view/Utility.h @@ -0,0 +1,115 @@ +#ifndef DASH__VIEW__UTILITY_H__INCLUDED +#define DASH__VIEW__UTILITY_H__INCLUDED + +#include +#include + + +namespace dash { + +namespace internal { + + struct PipeableBase + {}; + + template + struct is_pipeable : std::is_base_of + {}; + + template + struct is_pipeable : is_pipeable + {}; + + struct PipeableAccess + { + template + struct impl : PipeableT { + using PipeableT::pipe; + }; + + template + struct impl : impl + {}; + }; + + template + struct Pipeable : PipeableBase { + private: + friend PipeableAccess; + template + static auto pipe(Arg && arg, Pipe p) + -> decltype(p(static_cast(arg))) { + p(static_cast(arg)); + } + }; + + template + struct PipeableBinder : Bind, Pipeable< PipeableBinder > { + PipeableBinder(Bind bind) + : Bind(std::move(bind)) + {} + }; + + template + struct ComposedPipe { + PipeA pipe_a; + PipeB pipe_b; + template + auto operator()(Arg && arg) const + -> decltype(static_cast(arg) | pipe_a | pipe_b) { + return static_cast(arg) | pipe_a | pipe_b; + } + }; + + struct make_pipeable_fn { + template + PipeableBinder operator()(Fun fun) const { + return { std::move(fun) }; + } + }; + +} // namespace internal + +inline namespace { + constexpr internal::make_pipeable_fn make_pipeable { }; +} + +/** + * Compose pipes. + * + * ... | + */ +template < + typename PipeA, + typename PipeB, + typename std::enable_if< + ( internal::is_pipeable::value && + internal::is_pipeable::value ), + int + >::type = 0 > +auto operator|(PipeA a, PipeB b) +-> decltype(make_pipeable(internal::ComposedPipe { a, b })) { + return make_pipeable(internal::ComposedPipe { a, b }); +} + +/** + * Evaluate a pipe. + * + * arg | + */ +template < + typename Arg, + typename Pipe, + typename std::enable_if< + (!internal::is_pipeable::value && + internal::is_pipeable::value ), + int + >::type = 0 > +auto operator|(Arg && arg, Pipe pipe) +-> decltype(pipe(arg)) { + return pipe(arg); +} + +} // namespace dash + +#endif // DASH__VIEW__UTILITY_H__INCLUDED From acb61a829c3b7beadc520f963f8ac8dbde2e022a Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 19 Sep 2017 14:13:23 +0200 Subject: [PATCH 087/161] Added local() pipeable --- dash/examples/ex.02.array-views/main.cpp | 18 +++++++++++++++--- dash/examples/ex.02.matrix_views/main.cpp | 6 ------ dash/include/dash/view/Local.h | 10 +++++++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 349974474..34987560d 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -11,8 +11,9 @@ using std::vector; #define print(stream_expr__) \ do { \ std::ostringstream ss; \ - ss << stream_expr__; \ - cout << ss.str() << endl; \ + ss << "[unit: " << dash::myid() << "] "; \ + ss << stream_expr__ << endl; \ + cout << ss.str(); \ } while(0) @@ -55,6 +56,8 @@ auto initialize_array(ArrayT & array) int main(int argc, char *argv[]) { + using namespace dash; + dash::init(&argc, &argv); int elem_per_unit = 5; @@ -65,6 +68,16 @@ int main(int argc, char *argv[]) dash::Array a(array_size, dash::BLOCKCYCLIC(3)); initialize_array(a); + dash::barrier(); + if (dash::myid() == 0) { + print("array: " << range_str(a)); + } + + auto l_array = a | local(); + print("array | local(): " << range_str(l_array)); + + dash::barrier(); + auto copy_num_elem = a.size() / 2; auto copy_dest_begin_idx = a.size() / 4; auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; @@ -75,7 +88,6 @@ int main(int argc, char *argv[]) a.barrier(); if (dash::myid() == 0) { - print("array: " << range_str(a)); print("copy target index range: " << "[" << copy_dest_begin_idx << "," << copy_dest_end_idx << ")"); diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix_views/main.cpp index f99adecd0..b4662c3b5 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix_views/main.cpp @@ -68,12 +68,6 @@ int main(int argc, char *argv[]) { dash::init(&argc, &argv); - int val = 100; - int mod = val | addvalue() | subvalue(); - - cout << "mod: " << mod << endl; - return 0; - auto myid = dash::myid(); auto nunits = dash::size(); diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index c0347b6fd..ff9c8ff14 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -3,6 +3,7 @@ #include +#include #include @@ -142,7 +143,14 @@ local(ViewType && v) !dash::view_traits::is_local::value ), decltype(std::forward(v).local()) >::type { - return std::forward(v).local(); + return std::forward(v).local(); +} + +static inline auto local() { + return dash::make_pipeable( + [](auto && x) { + return local(std::forward(x)); + }); } #if 0 From c4f1f0cbe29e6c864ef94cd4468cc9f49a3b54cf Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 19 Sep 2017 20:13:02 +0200 Subject: [PATCH 088/161] Added sub, domain pipeables --- .gitignore | 1 + dash/examples/ex.02.array-views/main.cpp | 3 +++ dash/examples/ex.02.matrix_views/main.cpp | 18 ++--------------- dash/include/dash/view/Domain.h | 10 ++++++++++ dash/include/dash/view/Local.h | 14 ++++++------- dash/include/dash/view/Sub.h | 24 ++++++++++++++++++++++- 6 files changed, 46 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 8a22fc945..0c25c45e8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ build.nasty* build.cov* build.gcc* build.clang* +build.icc* build.analyze* build-ci* compile_commands.json diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 34987560d..dc9237c0f 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -76,6 +76,9 @@ int main(int argc, char *argv[]) auto l_array = a | local(); print("array | local(): " << range_str(l_array)); + auto sl_array = a | sub<0>(2, a.size()-1) | local(); + print("array | sub | local(): " << range_str(sl_array)); + dash::barrier(); auto copy_num_elem = a.size() / 2; diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix_views/main.cpp index b4662c3b5..acc5fb00a 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix_views/main.cpp @@ -48,24 +48,10 @@ inline void sum(const uint nelts, } } -auto addvalue() { - return dash::make_pipeable( - [](auto && x) { - return std::forward(x) + 10; - }); -} - -auto subvalue() { - return dash::make_pipeable( - [](auto && x) { - return std::forward(x) - 3; - }); -} - -using namespace dash; - int main(int argc, char *argv[]) { + using namespace dash; + dash::init(&argc, &argv); auto myid = dash::myid(); diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index 2585a6430..20a892fcb 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -4,6 +4,9 @@ #include #include +#include + + namespace dash { namespace detail { @@ -85,6 +88,13 @@ domain(const ContainerT & container) { return container; } +static inline auto domain() { + return dash::make_pipeable( + [](auto && x) { + return domain(std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__DOMAIN_H__INCLUDED diff --git a/dash/include/dash/view/Local.h b/dash/include/dash/view/Local.h index ff9c8ff14..60ba21c62 100644 --- a/dash/include/dash/view/Local.h +++ b/dash/include/dash/view/Local.h @@ -146,13 +146,6 @@ local(ViewType && v) return std::forward(v).local(); } -static inline auto local() { - return dash::make_pipeable( - [](auto && x) { - return local(std::forward(x)); - }); -} - #if 0 template constexpr auto local(const ContainerType & c) @@ -190,6 +183,13 @@ constexpr auto local( return g_it.local(); } +static inline auto local() { + return dash::make_pipeable( + [](auto && x) { + return local(std::forward(x)); + }); +} + // ========================================================================= // Multidimensional Views // ========================================================================= diff --git a/dash/include/dash/view/Sub.h b/dash/include/dash/view/Sub.h index 5718a5c24..c14ab6548 100644 --- a/dash/include/dash/view/Sub.h +++ b/dash/include/dash/view/Sub.h @@ -5,6 +5,7 @@ #include #include +#include namespace dash { @@ -92,7 +93,12 @@ sub(OffsetFirstT begin, template < dim_t SubDim = 0, class DomainT, - class OffsetT > + class OffsetT, + typename std::enable_if< + (!std::is_integral::value && + std::is_integral::value ), + int + >::type = 0 > constexpr auto sub(OffsetT offset, DomainT && domain) @@ -100,6 +106,22 @@ sub(OffsetT offset, return dash::sub(offset, offset+1, domain); } +template < + dim_t SubDim = 0, + class OffsetT0, + class OffsetT1, + typename std::enable_if< + ( std::is_integral::value && + std::is_integral::value ), + int + >::type = 0 > +static inline auto sub(OffsetT0 a, OffsetT1 b) { + return dash::make_pipeable( + [=](auto && x) { + return sub(a,b, std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__SUB_H__INCLUDED From 393adbee7a4cfce4aa3fb07aef99b60fa8dfccca Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 19 Sep 2017 20:34:44 +0200 Subject: [PATCH 089/161] Added origin, blocks, index, global pipeables --- dash/examples/ex.02.array-views/main.cpp | 18 ++++++++++++++---- dash/include/dash/view/Global.h | 8 ++++++++ dash/include/dash/view/IndexSet.h | 8 ++++++++ dash/include/dash/view/Origin.h | 7 +++++++ dash/include/dash/view/ViewBlocksMod.h | 8 ++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index dc9237c0f..17a45a062 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -68,16 +68,26 @@ int main(int argc, char *argv[]) dash::Array a(array_size, dash::BLOCKCYCLIC(3)); initialize_array(a); - dash::barrier(); if (dash::myid() == 0) { print("array: " << range_str(a)); + + auto sb_array = a | sub(1, a.size()-1) | blocks(); + for (const auto & b : sb_array) { + print("array | sub | block: " << range_str(b)); + } + + auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); + for (const auto & b : slb_array) { + print("array | sub | local | block: " << range_str(b)); + } } + dash::barrier(); auto l_array = a | local(); - print("array | local(): " << range_str(l_array)); + print("array | local: " << range_str(l_array)); - auto sl_array = a | sub<0>(2, a.size()-1) | local(); - print("array | sub | local(): " << range_str(sl_array)); + auto sl_array = a | sub(1, a.size()-1) | local(); + print("array | sub | local: " << range_str(sl_array)); dash::barrier(); diff --git a/dash/include/dash/view/Global.h b/dash/include/dash/view/Global.h index 2999e07a5..b53a47bbf 100644 --- a/dash/include/dash/view/Global.h +++ b/dash/include/dash/view/Global.h @@ -1,6 +1,7 @@ #ifndef DASH__VIEW__GLOBAL_H__INCLUDED #define DASH__VIEW__GLOBAL_H__INCLUDED +#include #include @@ -34,6 +35,13 @@ global(ContainerType & c) { return c; } +static inline auto global() { + return dash::make_pipeable( + [](auto && x) { + return global(std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__GLOBAL_H__INCLUDED diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 107d2a15d..7dfec14ed 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -1672,6 +1673,13 @@ class IndexSetBlock } }; // class IndexSetBlock +static inline auto index() { + return dash::make_pipeable( + [](auto && x) { + return index(std::forward(x)); + }); +} + } // namespace dash #endif // DOXYGEN diff --git a/dash/include/dash/view/Origin.h b/dash/include/dash/view/Origin.h index 07d125df8..dea4e4e25 100644 --- a/dash/include/dash/view/Origin.h +++ b/dash/include/dash/view/Origin.h @@ -159,6 +159,13 @@ origin(const ViewT & view) #endif // DOXYGEN +static inline auto origin() { + return dash::make_pipeable( + [](auto && x) { + return origin(std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__ORIGIN_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 8d57dff19..dc569b95e 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -684,6 +685,13 @@ class ViewBlocksMod #endif // DOXYGEN +static inline auto blocks() { + return dash::make_pipeable( + [](auto && x) { + return blocks(std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__VIEW_BLOCKS_MOD_H__INCLUDED From 068077c1a4ae16162e86508ef5a1c458d85457ed Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 19 Sep 2017 20:49:21 +0200 Subject: [PATCH 090/161] Minor --- dash/examples/ex.02.array-views/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 17a45a062..20bda6114 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -69,26 +69,26 @@ int main(int argc, char *argv[]) initialize_array(a); if (dash::myid() == 0) { - print("array: " << range_str(a)); + print("a: " << range_str(a)); auto sb_array = a | sub(1, a.size()-1) | blocks(); for (const auto & b : sb_array) { - print("array | sub | block: " << range_str(b)); + print("a | sub | block: " << range_str(b)); } auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); for (const auto & b : slb_array) { - print("array | sub | local | block: " << range_str(b)); + print("a | sub | local | block: " << range_str(b)); } } dash::barrier(); auto l_array = a | local(); - print("array | local: " << range_str(l_array)); + print("a | local: " << range_str(l_array)); + dash::barrier(); auto sl_array = a | sub(1, a.size()-1) | local(); - print("array | sub | local: " << range_str(sl_array)); - + print("a | sub | local: " << range_str(sl_array)); dash::barrier(); auto copy_num_elem = a.size() / 2; From cdd90c02f58d39393856534cfeeb8567e6d87bb1 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 19 Sep 2017 22:31:54 +0200 Subject: [PATCH 091/161] Added missing (c) header --- dash/include/dash/view/Utility.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dash/include/dash/view/Utility.h b/dash/include/dash/view/Utility.h index 2064d7a24..fd32d6eff 100644 --- a/dash/include/dash/view/Utility.h +++ b/dash/include/dash/view/Utility.h @@ -4,6 +4,17 @@ #include #include +/* + * Pipe utils adapted from implementation in range-v3, + * published under Boost Software License Version 1.0 + * (c) Eric Niebler, Casey Carter + * + * See: + * https://github.com/ericniebler/range-v3/ + * Source: + * include/range/v3/utility/functional.hpp + * + */ namespace dash { From dff4a8b21e81060d551b7523de22a5af8960e572 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 20 Sep 2017 02:06:27 +0200 Subject: [PATCH 092/161] Cleanup in view examples --- dash/examples/ex.02.array-views/main.cpp | 26 +------ .../examples/ex.02.matrix-halo-views/main.cpp | 40 +--------- dash/examples/ex.02.matrix-sub-views/main.cpp | 75 +++++++++++++++++++ .../Makefile | 0 .../main.cpp | 44 +---------- dash/examples/util.h | 66 ++++++++++++++++ 6 files changed, 146 insertions(+), 105 deletions(-) create mode 100644 dash/examples/ex.02.matrix-sub-views/main.cpp rename dash/examples/{ex.02.matrix_views => ex.02.matrix-views}/Makefile (100%) rename dash/examples/{ex.02.matrix_views => ex.02.matrix-views}/main.cpp (90%) create mode 100644 dash/examples/util.h diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 20bda6114..7f7737cab 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -1,4 +1,5 @@ #include +#include "../util.h" using std::cout; using std::cerr; @@ -8,31 +9,6 @@ using std::endl; using std::vector; -#define print(stream_expr__) \ - do { \ - std::ostringstream ss; \ - ss << "[unit: " << dash::myid() << "] "; \ - ss << stream_expr__ << endl; \ - cout << ss.str(); \ - } while(0) - - -template -static std::string range_str( - const ValueRange & vrange) { - typedef typename ValueRange::value_type value_t; - std::ostringstream ss; - auto idx = dash::index(vrange); - int i = 0; - for (const auto & v : vrange) { - ss << std::setw(2) << *(dash::begin(idx) + i) << "|" - << std::fixed << std::setprecision(4) - << static_cast(v) << " "; - ++i; - } - return ss.str(); -} - template auto initialize_array(ArrayT & array) -> typename std::enable_if< diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 94c5b03ed..adf4b6a4f 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -1,4 +1,5 @@ #include +#include "../util.h" using std::cout; using std::cerr; @@ -8,45 +9,6 @@ using std::vector; using uint = unsigned int; -template -std::string nview_str( - const NViewType & nview) { - using value_t = typename NViewType::value_type; - auto view_nrows = nview.extents()[0]; - auto view_ncols = nview.extents()[1]; - auto nindex = dash::index(nview); - std::ostringstream ss; - for (int r = 0; r < view_nrows; ++r) { - ss << '\n'; - for (int c = 0; c < view_ncols; ++c) { - int offset = r * view_ncols + c; - ss << std::fixed << std::setw(3) - << nindex[offset] - << ":" - << std::fixed << std::setprecision(5) - << static_cast(nview[offset]) - << " "; - } - } - return ss.str(); -} - -inline void sum(const uint nelts, - const dash::NArray &matIn, - const uint myid) { - uint lclRows = matIn.pattern().local_extents()[0]; - - uint const *mPtr; - uint localSum = 0; - - for (uint i = 0; i < lclRows; ++i) { - mPtr = matIn.local.row(i).lbegin(); - - for (uint j = 0; j < nelts; ++j) { - localSum += *(mPtr++); - } - } -} int main(int argc, char *argv[]) { diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp new file mode 100644 index 000000000..003b264c6 --- /dev/null +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -0,0 +1,75 @@ +#include +#include "../util.h" + +using std::cout; +using std::cerr; +using std::cin; +using std::endl; +using std::vector; + +using uint = unsigned int; + + +int main(int argc, char *argv[]) +{ + using namespace dash; + + dash::init(&argc, &argv); + + auto myid = dash::myid(); + auto nunits = dash::size(); + + const size_t block_size_x = 3; + const size_t block_size_y = 3; + const size_t block_size = block_size_x * block_size_y; + size_t extent_x = block_size_x * nunits - 1; + size_t extent_y = block_size_y * nunits - 1; + + if (nunits < 2) { + cerr << "requires > 1 units" << endl; + return 1; + } + + typedef dash::ShiftTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + pattern_t pattern( + dash::SizeSpec<2>( + extent_y, + extent_x), + dash::DistributionSpec<2>( + dash::TILE(block_size_y), + dash::TILE(block_size_x)) + ); + + dash::Matrix + matrix(pattern); + + // Initialize matrix values: + int li = 0; + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { return dash::myid() + 0.01 * li++; }); + dash::barrier(); + + if (myid == 0) { + print("matrix:" << + nview_str(matrix | sub(0,extent_y)) << '\n'); + print("matrix | sub<0>(2,-2) | sub<1>(2,-3):" << + nview_str(matrix | sub<0>(2, extent_y-2) + | sub<1>(2, extent_x-3)) << '\n'); + + auto m_blocks = matrix | sub<0>(2, extent_y-2) + | sub<1>(2, extent_x-3) + | blocks(); + for (const auto & m_block : m_blocks) { + print("matrix | sub<0>(2,-2) | sub<1>(2,-3) | blocks():" << + nview_str(m_block) << '\n'); + } + } + dash::barrier(); + + dash::finalize(); + return EXIT_SUCCESS; +}; diff --git a/dash/examples/ex.02.matrix_views/Makefile b/dash/examples/ex.02.matrix-views/Makefile similarity index 100% rename from dash/examples/ex.02.matrix_views/Makefile rename to dash/examples/ex.02.matrix-views/Makefile diff --git a/dash/examples/ex.02.matrix_views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp similarity index 90% rename from dash/examples/ex.02.matrix_views/main.cpp rename to dash/examples/ex.02.matrix-views/main.cpp index acc5fb00a..3801eb861 100644 --- a/dash/examples/ex.02.matrix_views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -1,4 +1,5 @@ #include +#include "../util.h" using std::cout; using std::cerr; @@ -8,45 +9,6 @@ using std::vector; using uint = unsigned int; -template -std::string nview_str( - const NViewType & nview) { - using value_t = typename NViewType::value_type; - auto view_nrows = nview.extents()[0]; - auto view_ncols = nview.extents()[1]; - auto nindex = dash::index(nview); - std::ostringstream ss; - for (int r = 0; r < view_nrows; ++r) { - ss << '\n'; - for (int c = 0; c < view_ncols; ++c) { - int offset = r * view_ncols + c; - ss << std::fixed << std::setw(3) - << nindex[offset] - << ":" - << std::fixed << std::setprecision(5) - << static_cast(nview[offset]) - << " "; - } - } - return ss.str(); -} - -inline void sum(const uint nelts, - const dash::NArray &matIn, - const uint myid) { - uint lclRows = matIn.pattern().local_extents()[0]; - - uint const *mPtr; - uint localSum = 0; - - for (uint i = 0; i < lclRows; ++i) { - mPtr = matIn.local.row(i).lbegin(); - - for (uint j = 0; j < nelts; ++j) { - localSum += *(mPtr++); - } - } -} int main(int argc, char *argv[]) { @@ -113,8 +75,8 @@ int main(int argc, char *argv[]) dash::barrier(); if (myid == 0) { - DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(dash::sub(0, matrix.extents()[0], matrix))); + print("matrix:" << + nview_str(dash::sub(0, matrix.extents()[0], matrix))); auto matrix_region = dash::size() > 1 ? dash::sub<0>( diff --git a/dash/examples/util.h b/dash/examples/util.h new file mode 100644 index 000000000..4d5771540 --- /dev/null +++ b/dash/examples/util.h @@ -0,0 +1,66 @@ +#ifndef DASH__EXAMPLES__UTIL_H__INCLUDED +#define DASH__EXAMPLES__UTIL_H__INCLUDED + +#include +#include +#include +#include + + +#define print(stream_expr__) \ + do { \ + std::ostringstream mss; \ + mss << stream_expr__; \ + std::ostringstream oss; \ + std::istringstream iss(mss.str()); \ + std::string item; \ + while (std::getline(iss, item)) { \ + oss << "[ " << dash::myid() << " ] "; \ + oss << item << endl; \ + } \ + cout << oss.str(); \ + } while(0) + + +template +static std::string range_str( + const ValueRange & vrange, + int prec = 4) { + typedef typename ValueRange::value_type value_t; + std::ostringstream ss; + auto idx = dash::index(vrange); + int i = 0; + for (const auto & v : vrange) { + ss << std::setw(2) << *(dash::begin(idx) + i) << "|" + << std::fixed << std::setprecision(prec) + << static_cast(v) << " "; + ++i; + } + return ss.str(); +} + +template +std::string nview_str( + const NViewType & nview, + int prec = 2) { + using value_t = typename NViewType::value_type; + auto view_nrows = nview.extents()[0]; + auto view_ncols = nview.extents()[1]; + auto nindex = dash::index(nview); + std::ostringstream ss; + for (int r = 0; r < view_nrows; ++r) { + ss << '\n' << r << " "; + for (int c = 0; c < view_ncols; ++c) { + int offset = r * view_ncols + c; + ss << std::fixed << std::setw(3) + << nindex[offset] + << " " + << std::fixed << std::setprecision(prec) + << static_cast(nview[offset]) + << " "; + } + } + return ss.str(); +} + +#endif // DASH__EXAMPLES__UTIL_H__INCLUDED From c46b3a035ae7b32f6b6c1e17c70ad837e34d8f25 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 20 Sep 2017 11:16:28 +0200 Subject: [PATCH 093/161] Extending view examples --- dash/examples/bench.05.array-range/main.cpp | 11 +++--- dash/examples/ex.02.matrix-sub-views/main.cpp | 35 ++++++++++++------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/dash/examples/bench.05.array-range/main.cpp b/dash/examples/bench.05.array-range/main.cpp index 8a857255f..d0a5f7fa1 100644 --- a/dash/examples/bench.05.array-range/main.cpp +++ b/dash/examples/bench.05.array-range/main.cpp @@ -202,12 +202,12 @@ double test_view_gups( for (auto i = 0; i < REPEAT; ++i) { for (auto lidx = 0; lidx < a.lsize(); ++lidx) { - auto lrange = dash::index( - dash::local( - dash::sub( + auto lrange = a | dash::sub( lbegin_gidx, - lbegin_gidx + lidx, - a) ) ); + lbegin_gidx + lidx) + | dash::local() + | dash::index(); + int lrange_begin = *dash::begin(lrange); int lrange_end = *dash::end(lrange); @@ -245,6 +245,7 @@ double test_algo_gups( auto a_size = a.size(); auto ts_start = Timer::Now(); auto myid = pattern.team().myid(); + for (auto i = 0; i < REPEAT; ++i) { for (auto lidx = 1; lidx < a.lsize(); ++lidx) { auto lrange = dash::local_index_range( diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 003b264c6..5e9366e7f 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -19,28 +19,32 @@ int main(int argc, char *argv[]) auto myid = dash::myid(); auto nunits = dash::size(); - const size_t block_size_x = 3; - const size_t block_size_y = 3; + const size_t block_size_x = 2; + const size_t block_size_y = 2; const size_t block_size = block_size_x * block_size_y; - size_t extent_x = block_size_x * nunits - 1; - size_t extent_y = block_size_y * nunits - 1; + size_t extent_x = block_size_x * nunits; + size_t extent_y = block_size_y * nunits; if (nunits < 2) { cerr << "requires > 1 units" << endl; return 1; } - typedef dash::ShiftTilePattern<2> pattern_t; + typedef dash::TilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; typedef float value_t; + dash::TeamSpec<2> teamspec(dash::Team::All()); + teamspec.balance_extents(); + pattern_t pattern( dash::SizeSpec<2>( extent_y, extent_x), dash::DistributionSpec<2>( dash::TILE(block_size_y), - dash::TILE(block_size_x)) + dash::TILE(block_size_x)), + teamspec ); dash::Matrix @@ -56,20 +60,27 @@ int main(int argc, char *argv[]) if (myid == 0) { print("matrix:" << nview_str(matrix | sub(0,extent_y)) << '\n'); - print("matrix | sub<0>(2,-2) | sub<1>(2,-3):" << - nview_str(matrix | sub<0>(2, extent_y-2) - | sub<1>(2, extent_x-3)) << '\n'); + print("matrix | sub<0>(1,-1) | sub<1>(1,-1):" << + nview_str(matrix | sub<0>(1, extent_y-1) + | sub<1>(1, extent_x-1)) << '\n'); - auto m_blocks = matrix | sub<0>(2, extent_y-2) - | sub<1>(2, extent_x-3) + auto m_blocks = matrix | sub<0>(1, extent_y-1) + | sub<1>(1, extent_x-1) | blocks(); for (const auto & m_block : m_blocks) { - print("matrix | sub<0>(2,-2) | sub<1>(2,-3) | blocks():" << + print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks():" << nview_str(m_block) << '\n'); } + + print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | local:" << + nview_str(matrix | sub<0>(1, extent_y-1) + | sub<1>(1, extent_x-1) + | local()) << '\n'); } dash::barrier(); dash::finalize(); return EXIT_SUCCESS; }; + + From c23cc8527a6f1f0bb741f078417a1390d95d151b Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 20 Sep 2017 16:54:22 +0200 Subject: [PATCH 094/161] Extending view examples --- dash/examples/ex.02.matrix-halo-views/main.cpp | 18 +++++++++--------- dash/examples/ex.02.matrix-sub-views/main.cpp | 6 +++--- dash/examples/ex.02.matrix-views/main.cpp | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index adf4b6a4f..365c78696 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -69,16 +69,16 @@ int main(int argc, char *argv[]) if (myid == 0) { auto matrix_view = dash::sub(0, matrix.extents()[0], matrix); - DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(matrix_view)); - DASH_LOG_DEBUG("MatrixViewsExample", "matrix", - "offsets:", matrix_view.offsets(), - "extents:", matrix_view.extents()); + print("matrix" << nview_str(matrix_view)); + + DASH_LOG_DEBUG("MatrixViewsExample", "matrix", + "offsets:", matrix_view.offsets(), + "extents:", matrix_view.extents()); auto matrix_blocks = dash::blocks(matrix_view); for (const auto & m_block : matrix_blocks) { - DASH_LOG_DEBUG("MatrixViewsExample", "m_block ======================", - nview_str(m_block)); + print("matrix | block(n)" << + nview_str(m_block)); // halo view: auto b_halo = dash::sub<0>( m_block.offsets()[0] > 0 @@ -97,8 +97,8 @@ int main(int argc, char *argv[]) ? m_block.offsets()[1] + m_block.extents()[1] + 1 : m_block.offsets()[1] + m_block.extents()[1], matrix_view)); - DASH_LOG_DEBUG("MatrixViewsExample", "b_halo -----------------------", - nview_str(b_halo)); + print("matrix | block(n) | expand({ -1,1 } , { -1,1 })" << + nview_str(b_halo)); DASH_LOG_DEBUG("MatrixViewsExample", "size:", b_halo.size()); #if 0 auto b_halo_isect = dash::difference( diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 5e9366e7f..528b4c2c5 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) return 1; } - typedef dash::TilePattern<2> pattern_t; + typedef dash::ShiftTilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; typedef float value_t; @@ -52,8 +52,8 @@ int main(int argc, char *argv[]) // Initialize matrix values: int li = 0; - std::generate(matrix.lbegin(), - matrix.lend(), + std::generate(matrix.local.begin(), + matrix.local.end(), [&]() { return dash::myid() + 0.01 * li++; }); dash::barrier(); diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index 3801eb861..42cde5398 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -90,8 +90,8 @@ int main(int argc, char *argv[]) 0, matrix.extents()[1], matrix)); - DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(matrix_region)); + print("matrix | sub<0>(2,-2) | sub<1>(2,-3) \n" << + nview_str(matrix_region)); auto matrix_reg_blocks = dash::blocks(matrix_region); for (const auto & reg_block : matrix_reg_blocks) { From c502ef23d4c9a9f5dff894a057c56d3358ec8da7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 21 Sep 2017 01:04:46 +0200 Subject: [PATCH 095/161] Introducing LocalViewIter, extending view examples --- dash/examples/bench.05.array-range/main.cpp | 8 +- dash/examples/ex.02.matrix-sub-views/main.cpp | 57 +- dash/examples/util.h | 17 +- dash/include/dash/Meta.h | 65 ++ dash/include/dash/iterator/GlobIter.h | 23 +- dash/include/dash/iterator/GlobViewIter.h | 6 +- dash/include/dash/iterator/LocalViewIter.h | 1001 +++++++++++++++++ dash/include/dash/matrix/LocalMatrixRef.h | 15 +- .../dash/matrix/internal/LocalMatrixRef-inl.h | 20 + 9 files changed, 1170 insertions(+), 42 deletions(-) create mode 100644 dash/include/dash/iterator/LocalViewIter.h diff --git a/dash/examples/bench.05.array-range/main.cpp b/dash/examples/bench.05.array-range/main.cpp index d0a5f7fa1..0baea2715 100644 --- a/dash/examples/bench.05.array-range/main.cpp +++ b/dash/examples/bench.05.array-range/main.cpp @@ -20,9 +20,7 @@ typedef dash::util::Timer< dash::util::TimeMeasure::Clock > Timer; -#ifndef TYPE -#define TYPE int -#endif +typedef int value_t; typedef dash::TilePattern< 1, @@ -31,12 +29,12 @@ typedef dash::TilePattern< > TilePattern_t; typedef dash::Array< - TYPE, + value_t, int, TilePattern_t > ArrayTiledDist_t; -typedef dash::Array +typedef dash::Array ArrayBlockedDist_t; template diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 528b4c2c5..a7c47ff80 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) return 1; } - typedef dash::ShiftTilePattern<2> pattern_t; + typedef dash::TilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; typedef float value_t; @@ -50,32 +50,57 @@ int main(int argc, char *argv[]) dash::Matrix matrix(pattern); - // Initialize matrix values: + if (myid == 0) { + int gi = 0; + std::generate(matrix.begin(), + matrix.end(), + [&]() { + auto u = matrix.pattern().unit_at( + matrix.pattern().coords(gi)); + return u + 0.01 * gi++; + }); + } + +#if 0 int li = 0; - std::generate(matrix.local.begin(), - matrix.local.end(), - [&]() { return dash::myid() + 0.01 * li++; }); + for (auto lit = matrix.local.begin(); + lit != matrix.local.end(); + ++li, ++lit) { + print("matrix.local[" << li << "] = " << static_cast(*lit)); + } +#endif + dash::barrier(); if (myid == 0) { print("matrix:" << nview_str(matrix | sub(0,extent_y)) << '\n'); - print("matrix | sub<0>(1,-1) | sub<1>(1,-1):" << + print("matrix.local.size(): " << matrix.local.size()); + print("matrix | sub<0>(1,-1) | sub<1>(1,-1)" << nview_str(matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1)) << '\n'); - auto m_blocks = matrix | sub<0>(1, extent_y-1) - | sub<1>(1, extent_x-1) - | blocks(); - for (const auto & m_block : m_blocks) { - print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks():" << - nview_str(m_block) << '\n'); + print("matrix | local | blocks"); + auto m_l_blocks = matrix | local() + | blocks(); + for (const auto & blk : m_l_blocks) { + print("---" << nview_str(blk) << '\n'); } - print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | local:" << - nview_str(matrix | sub<0>(1, extent_y-1) - | sub<1>(1, extent_x-1) - | local()) << '\n'); + print("matrix | blocks | local"); + auto m_blocks_l = matrix | blocks() + | local(); + for (const auto & blk : m_l_blocks) { + print("---" << nview_str(blk) << '\n'); + } + + print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); + auto m_s_blocks = matrix | sub<0>(1, extent_y-1) + | sub<1>(1, extent_x-1) + | blocks(); + for (const auto & blk : m_s_blocks) { + print("---" << nview_str(blk) << '\n'); + } } dash::barrier(); diff --git a/dash/examples/util.h b/dash/examples/util.h index 4d5771540..db9759eaf 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -39,25 +39,30 @@ static std::string range_str( return ss.str(); } +using namespace dash::internal::logging; + template std::string nview_str( const NViewType & nview, - int prec = 2) { + int prec = 2) +{ using value_t = typename NViewType::value_type; auto view_nrows = nview.extents()[0]; auto view_ncols = nview.extents()[1]; auto nindex = dash::index(nview); std::ostringstream ss; for (int r = 0; r < view_nrows; ++r) { - ss << '\n' << r << " "; + ss << '\n' << " " << std::right << std::setw(2) << r << " "; for (int c = 0; c < view_ncols; ++c) { - int offset = r * view_ncols + c; + int offset = r * view_ncols + c; + value_t val = nview[offset]; ss << std::fixed << std::setw(3) << nindex[offset] + << TermColorMod(unit_term_colors[(int)val]) << " " - << std::fixed << std::setprecision(prec) - << static_cast(nview[offset]) - << " "; + << std::fixed << std::setprecision(prec) << val + << " " + << TermColorMod(TCOL_DEFAULT); } } return ss.str(); diff --git a/dash/include/dash/Meta.h b/dash/include/dash/Meta.h index 65110d59b..80dfaabaa 100644 --- a/dash/include/dash/Meta.h +++ b/dash/include/dash/Meta.h @@ -79,6 +79,20 @@ DASH__META__DEFINE_TRAIT__HAS_TYPE(value_type); */ DASH__META__DEFINE_TRAIT__HAS_TYPE(pattern_type); +/** + * Definition of type trait \c dash::detail::has_type_const_type + * with static member \c value indicating whether type \c T provides + * dependent type \c const_type. + */ +DASH__META__DEFINE_TRAIT__HAS_TYPE(const_type); + +/** + * Definition of type trait \c dash::detail::has_type_const_type + * with static member \c value indicating whether type \c T provides + * dependent type \c nonconst_type. + */ +DASH__META__DEFINE_TRAIT__HAS_TYPE(nonconst_type); + } // namespace dash #include @@ -88,6 +102,57 @@ DASH__META__DEFINE_TRAIT__HAS_TYPE(pattern_type); namespace dash { +template +struct const_value_cast; + +template +struct const_value_cast { + typedef const T * type; +}; + +template +struct const_value_cast { + typedef const T & type; +}; + +template +struct const_value_cast { + typedef typename + std::conditional< + dash::has_type_const_type::value, + typename T::const_type, + const T + >::type + type; +}; + + + +template +struct nonconst_value_cast; + +template +struct nonconst_value_cast { + typedef T * type; +}; + +template +struct nonconst_value_cast { + typedef T & type; +}; + +template +struct nonconst_value_cast { + typedef typename + std::conditional< + dash::has_type_nonconst_type::value, + typename T::nonconst_type, + typename std::remove_const::type + >::type + type; +}; + + /* * For reference, see * diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index 8d9bb7c1b..c7e5b3787 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -82,21 +82,24 @@ class GlobIter nonconst_value_type; public: typedef typename std::random_access_iterator_tag iterator_category; - typedef typename PatternType::index_type difference_type; - typedef ElementType value_type; + typedef typename PatternType::index_type difference_type; - typedef ReferenceType reference; - typedef typename ReferenceType::const_type const_reference; + typedef ElementType value_type; - typedef PointerType pointer; - typedef typename PointerType::const_type const_pointer; + typedef ReferenceType reference; + typedef typename dash::const_value_cast::type + const_reference; - typedef typename GlobMemType::local_pointer local_pointer; - typedef typename GlobMemType::local_pointer local_type; + typedef PointerType pointer; + typedef typename dash::const_value_cast::type + const_pointer; - typedef PatternType pattern_type; - typedef typename PatternType::index_type index_type; + typedef typename GlobMemType::local_pointer local_pointer; + typedef typename GlobMemType::local_pointer local_type; + + typedef PatternType pattern_type; + typedef typename PatternType::index_type index_type; private: typedef GlobIter< diff --git a/dash/include/dash/iterator/GlobViewIter.h b/dash/include/dash/iterator/GlobViewIter.h index 2117df0e3..b0bc60d2b 100644 --- a/dash/include/dash/iterator/GlobViewIter.h +++ b/dash/include/dash/iterator/GlobViewIter.h @@ -92,10 +92,12 @@ class GlobViewIter typedef ElementType value_type; typedef ReferenceType reference; - typedef typename ReferenceType::const_type const_reference; + typedef typename dash::const_value_cast::type + const_reference; typedef PointerType pointer; - typedef typename PointerType::const_type const_pointer; + typedef typename dash::const_value_cast::type + const_pointer; typedef typename GlobMemType::local_pointer local_pointer; typedef typename GlobMemType::local_pointer local_type; diff --git a/dash/include/dash/iterator/LocalViewIter.h b/dash/include/dash/iterator/LocalViewIter.h new file mode 100644 index 000000000..ec7a07129 --- /dev/null +++ b/dash/include/dash/iterator/LocalViewIter.h @@ -0,0 +1,1001 @@ +#ifndef DASH__LOCAL_VIEW_ITER_H__INCLUDED +#define DASH__LOCAL_VIEW_ITER_H__INCLUDED + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace dash { + +#ifndef DOXYGEN +// Forward-declaration +template< + typename ElementType, + class PatternType, + class GlobMemType, + class PointerType, + class ReferenceType > +class GlobIter; +// Forward-declaration +template< + typename ElementType, + class PatternType, + class GlobMemType, + class PointerType, + class ReferenceType > +class GlobStencilIter; +#endif + +/** + * Global iterator on an index set specified by a view modifier. + * + * \concept{DashGlobalIteratorConcept} + */ +template< + typename ElementType, + class PatternType, + class GlobMemType = GlobStaticMem< + typename std::decay::type + >, + class PointerType = ElementType *, + class ReferenceType = ElementType & > +class LocalViewIter +: public std::iterator< + std::random_access_iterator_tag, + ElementType, + typename PatternType::index_type, + PointerType, + ReferenceType > { +private: + typedef LocalViewIter< + ElementType, + PatternType, + GlobMemType, + PointerType, + ReferenceType> + self_t; + + typedef GlobIter< + ElementType, + PatternType, + GlobMemType, + PointerType, + ReferenceType> + global_type; + + typedef GlobIter< + const ElementType, + PatternType, + GlobMemType, + PointerType, + ReferenceType> + const_global_type; + + typedef typename std::remove_const::type + nonconst_value_type; + + typedef typename PatternType::viewspec_type + ViewSpecType; + typedef typename PatternType::index_type + IndexType; + +public: + typedef ElementType value_type; + + typedef ReferenceType reference; + typedef typename dash::const_value_cast::type + const_reference; + + typedef PointerType pointer; + typedef typename dash::const_value_cast::type + const_pointer; + + typedef typename GlobMemType::local_pointer local_pointer; + typedef typename GlobMemType::local_pointer local_type; + + typedef PatternType pattern_type; + typedef typename PatternType::index_type index_type; + +private: + typedef LocalViewIter< + const ElementType, + PatternType, + GlobMemType, + const_pointer, + const_reference > + self_const_t; + +public: + typedef std::integral_constant has_view; + +public: + // For ostream output + template < + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + friend std::ostream & operator<<( + std::ostream & os, + const LocalViewIter & it); + + // For conversion to GlobStencilIter + template< + typename T_, + class P_, + class Ptr_, + class GM_, + class Ref_ > + friend class GlobStencilIter; + + template< + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + friend class LocalViewIter; + + template< + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + friend class GlobIter; + +private: + static const dim_t NumDimensions = PatternType::ndim(); + static const MemArrange Arrangement = PatternType::memory_order(); + +protected: + /// Global memory used to dereference iterated values. + GlobMemType * _globmem; + /// Pattern that specifies the iteration order (access pattern). + const PatternType * _pattern; + /// View that specifies the iterator's index range relative to the global + /// index range of the iterator's pattern. + const ViewSpecType * _viewspec; + /// Current position of the iterator relative to the iterator's view. + IndexType _idx = 0; + /// The iterator's view index start offset. + IndexType _view_idx_offset = 0; + /// Maximum position relative to the viewspec allowed for this iterator. + IndexType _max_idx = 0; + /// Unit id of the active unit + team_unit_t _myid; + /// Pointer to first element in local memory + local_pointer _lbegin = nullptr; + +public: + /** + * Default constructor. + */ + constexpr LocalViewIter() + : _globmem(nullptr) + , _pattern(nullptr) + , _viewspec(nullptr) + , _idx(0) + , _view_idx_offset(0) + , _max_idx(0) + , _myid(dash::Team::All().myid()) + , _lbegin(nullptr) + { } + + /** + * Constructor, creates a global iterator on global memory following + * the element order specified by the given pattern and view spec. + */ + template + constexpr LocalViewIter( + GlobStaticMemT_ * gmem, + const PatternType & pat, + const ViewSpecType & viewspec, + IndexType position = 0, + IndexType view_index_offset = 0) + : _globmem(reinterpret_cast(gmem)) + , _pattern(&pat) + , _viewspec(&viewspec) + , _idx(position) + , _view_idx_offset(view_index_offset) + , _max_idx(viewspec.size() - 1) + , _myid(pat.team().myid()) + , _lbegin(_globmem->lbegin()) + { } + + /** + * Constructor, creates a global iterator on global memory following + * the element order specified by the given pattern and view spec. + */ + template + constexpr LocalViewIter( + GlobStaticMemT_ * gmem, + const PatternType & pat, + IndexType position = 0, + IndexType view_index_offset = 0) + : _globmem(reinterpret_cast(gmem)) + , _pattern(&pat) + , _viewspec(nullptr) + , _idx(position) + , _view_idx_offset(view_index_offset) + , _max_idx(pat.size() - 1) + , _myid(dash::Team::GlobalUnitID()) + , _lbegin(_globmem->lbegin()) + { } + + /** + * Constructor, creates a global view iterator from a global iterator. + */ + template < + class P_, + class GM_, + class Ptr_, + class Ref_ > + constexpr LocalViewIter( + const GlobIter & other, + const ViewSpecType & viewspec, + IndexType view_offs = 0) + : _globmem(other._globmem) + , _pattern(other._pattern) + , _viewspec(&viewspec) + , _idx(other._idx) + , _view_idx_offset(view_offs) + , _max_idx(other._max_idx) + , _myid(other._myid) + , _lbegin(other._lbegin) + { } + + /** + * Copy constructor. + */ + template < + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + constexpr LocalViewIter( +// const LocalViewIter & other) + const LocalViewIter & other) + : _globmem (other._globmem) + , _pattern (other._pattern) + , _viewspec (other._viewspec) + , _idx (other._idx) + , _view_idx_offset(other._view_idx_offset) + , _max_idx (other._max_idx) + , _myid (other._myid) + , _lbegin (other._lbegin) + { } + + /** + * Move constructor. + */ + template < + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + constexpr LocalViewIter( +// LocalViewIter && other) + LocalViewIter && other) + : _globmem (other._globmem) + , _pattern (other._pattern) + , _viewspec (other._viewspec) + , _idx (other._idx) + , _view_idx_offset(other._view_idx_offset) + , _max_idx (other._max_idx) + , _myid (other._myid) + , _lbegin (other._lbegin) + { } + + /** + * Assignment operator. + */ + template < + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + self_t & operator=( + const LocalViewIter & other) + { + _globmem = other._globmem; + _pattern = other._pattern; + _viewspec = other._viewspec; + _idx = other._idx; + _view_idx_offset = other._view_idx_offset; + _max_idx = other._max_idx; + _myid = other._myid; + _lbegin = other._lbegin; + } + + /** + * Move-assignment operator. + */ + template < + typename T_, + class P_, + class GM_, + class Ptr_, + class Ref_ > + self_t & operator=( + LocalViewIter && other) + { + _globmem = other._globmem; + _pattern = other._pattern; + _viewspec = other._viewspec; + _idx = other._idx; + _view_idx_offset = other._view_idx_offset; + _max_idx = other._max_idx; + _myid = other._myid; + _lbegin = other._lbegin; + // no ownership to transfer + return *this; + } + + /** + * The number of dimensions of the iterator's underlying pattern. + */ + static dim_t ndim() + { + return NumDimensions; + } + + /** + * Type conversion operator to \c GlobPtr. + * + * \return A global reference to the element at the iterator's position + */ + explicit operator const_pointer() const + { + return local(); + } + + /** + * Type conversion operator to native pointer. + * + * \return A global reference to the element at the iterator's position + */ + explicit operator pointer() + { + return local(); + } + + /** + * Explicit conversion to \c dart_gptr_t. + * + * \return A DART global pointer to the element at the iterator's + * position + */ + dart_gptr_t dart_gptr() const + { + DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr()", _idx); + typedef typename pattern_type::local_index_t + local_pos_t; + IndexType idx = _idx; + IndexType offset = 0; + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; + DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr", _max_idx); + DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr", idx); + DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr", offset); + } + // Global index to local index and unit: + local_pos_t local_pos = lpos(); + DASH_LOG_TRACE("LocalViewIter.dart_gptr", + "unit:", local_pos.unit, + "local index:", local_pos.index); + // Global pointer to element at given position: + dash::GlobPtr gptr( + _globmem->at( + local_pos.unit, + local_pos.index) + ); + DASH_LOG_TRACE_VAR("GlobIter.dart_gptr >", gptr); + return (gptr + offset).dart_gptr(); + } + + /** + * Dereference operator. + * + * \return A global reference to the element at the iterator's position. + */ + inline reference operator*() + { + return this->operator[](_idx); + } + + /** + * Dereference operator. + * + * \return A global reference to the element at the iterator's position. + */ + inline const_reference operator*() const + { + return this->operator[](_idx); + } + + /** + * Subscript operator, returns global reference to element at given + * global index. + */ + reference operator[]( + /// The global position of the element + index_type idx) + { + if (_viewspec != nullptr) { + // Viewspec projection required: + auto l_coords = coords(idx); + DASH_LOG_TRACE_VAR("LocalViewIter.[]", l_coords); + idx = _pattern->local_memory_layout().at(l_coords); + } + DASH_LOG_TRACE_VAR("LocalViewIter.[]", idx); + // Global reference to element at given position: + return *(_globmem->lbegin() + idx); + } + + /** + * Subscript operator, returns global reference to element at given + * global index. + */ + const_reference operator[]( + /// The global position of the element + index_type idx) const + { + if (_viewspec != nullptr) { + // Viewspec projection required: + auto l_coords = coords(idx); + DASH_LOG_TRACE_VAR("LocalViewIter.[]", l_coords); + idx = _pattern->local_memory_layout().at(); + } + DASH_LOG_TRACE_VAR("LocalViewIter.[]", idx); + // Global reference to element at given position: + return *(_globmem->lbegin() + idx); + } + + /** + * Checks whether the element referenced by this global iterator is in + * the calling unit's local memory. + */ + constexpr bool is_local() const + { + return true; + } + + /** + * Convert global iterator to native pointer. + */ + local_pointer local() const + { + DASH_LOG_TRACE_VAR("LocalViewIter.local=()", _idx); + typedef typename pattern_type::local_index_t + local_pos_t; + IndexType idx = _idx; + IndexType offset = 0; + DASH_LOG_TRACE_VAR("LocalViewIter.local=", _max_idx); + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; + } + DASH_LOG_TRACE_VAR("LocalViewIter.local=", idx); + DASH_LOG_TRACE_VAR("LocalViewIter.local=", offset); + + if (_viewspec != nullptr) { + // Viewspec projection required: + idx = _pattern->local_memory_layout().at(coords(idx)); + } + DASH_LOG_TRACE_VAR("LocalViewIter.local= >", idx); + DASH_LOG_TRACE_VAR("LocalViewIter.local= >", offset); + return (_lbegin + idx + offset); + } + + /** + * Map iterator to global index domain by projecting the iterator's view. + */ + inline const_global_type global() const + { + auto g_idx = gpos(); + return const_global_type( + _globmem, + *_pattern, + g_idx + ); + } + + /** + * Map iterator to global index domain by projecting the iterator's view. + */ + inline global_type global() + { + return global_type( + _globmem, + *_pattern, + gpos() + ); + } + + /** + * Position of the iterator in its view's iteration space and the view's + * offset in global index space. + */ + constexpr index_type pos() const noexcept + { + return _idx + _view_idx_offset; + } + + /** + * Position of the iterator in its view's iteration space, disregarding + * the view's offset in global index space. + */ + inline index_type rpos() const noexcept + { + return _idx; + } + + /** + * Position of the iterator in global index range. + * Projects iterator position from its view spec to global index domain. + */ + inline index_type gpos() const + { + DASH_LOG_TRACE_VAR("LocalViewIter.gpos()", _idx); + if (_viewspec == nullptr) { + // No viewspec mapping required: + DASH_LOG_TRACE_VAR("LocalViewIter.gpos >", _idx); + return _idx; + } else { + IndexType idx = _idx; + IndexType offset = 0; + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", *_viewspec); + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", _max_idx); + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset = _idx - _max_idx; + } + // Viewspec projection required: + auto g_coords = coords(idx); + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", _idx); + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", g_coords); + auto g_idx = _pattern->memory_layout().at(g_coords); + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", g_idx); + g_idx += offset; + DASH_LOG_TRACE_VAR("LocalViewIter.gpos >", g_idx); + return g_idx; + } + } + + /** + * Unit and local offset at the iterator's position. + * Projects iterator position from its view spec to global index domain. + */ + inline typename pattern_type::local_index_t lpos() const + { + DASH_LOG_TRACE_VAR("LocalViewIter.lpos()", _idx); + typedef typename pattern_type::local_index_t + local_pos_t; + IndexType idx = _idx; + IndexType offset = 0; + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset = _idx - _max_idx; + DASH_LOG_TRACE_VAR("LocalViewIter.lpos", _max_idx); + DASH_LOG_TRACE_VAR("LocalViewIter.lpos", idx); + DASH_LOG_TRACE_VAR("LocalViewIter.lpos", offset); + } + // Global index to local index and unit: + local_pos_t local_pos; + if (_viewspec == nullptr) { + // No viewspec mapping required: + local_pos = _pattern->local(idx); + } else { + // Viewspec projection required: + DASH_LOG_TRACE_VAR("LocalViewIter.lpos", *_viewspec); + auto glob_coords = coords(idx); + local_pos = _pattern->local_index(glob_coords); + } + local_pos.index += offset; + DASH_LOG_TRACE("LocalViewIter.lpos >", + "unit:", local_pos.unit, + "local index:", local_pos.index); + return local_pos; + } + + /** + * Whether the iterator's position is relative to a view. + */ + inline bool is_relative() const noexcept + { + return _viewspec != nullptr; + } + + /** + * The view that specifies this iterator's index range. + */ + inline ViewSpecType viewspec() const + { + if (_viewspec != nullptr) { + return *_viewspec; + } + return ViewSpecType(_pattern->memory_layout().extents()); + } + + /** + * The instance of \c GlobStaticMem used by this iterator to resolve addresses + * in global memory. + */ + constexpr const GlobMemType & globmem() const noexcept + { + return *_globmem; + } + + /** + * The instance of \c GlobStaticMem used by this iterator to resolve addresses + * in global memory. + */ + inline GlobMemType & globmem() noexcept + { + return *_globmem; + } + + /** + * Prefix increment operator. + */ + self_t & operator++() noexcept + { + ++_idx; + return *this; + } + + /** + * Postfix increment operator. + */ + self_t operator++(int) noexcept + { + self_t result = *this; + ++_idx; + return result; + } + + /** + * Prefix decrement operator. + */ + self_t & operator--() noexcept + { + --_idx; + return *this; + } + + /** + * Postfix decrement operator. + */ + self_t operator--(int) noexcept + { + self_t result = *this; + --_idx; + return result; + } + + self_t & operator+=(index_type n) noexcept + { + _idx += n; + return *this; + } + + self_t & operator-=(index_type n) noexcept + { + _idx -= n; + return *this; + } + + self_t operator+(index_type n) const noexcept + { + if (_viewspec == nullptr) { + self_t res( + _globmem, + *_pattern, + _idx + static_cast(n), + _view_idx_offset); + return res; + } + self_t res( + _globmem, + *_pattern, + *_viewspec, + _idx + static_cast(n), + _view_idx_offset); + return res; + } + + self_t operator-(index_type n) const noexcept + { + if (_viewspec == nullptr) { + self_t res( + _globmem, + *_pattern, + _idx - static_cast(n), + _view_idx_offset); + return res; + } + self_t res( + _globmem, + *_pattern, + *_viewspec, + _idx - static_cast(n), + _view_idx_offset); + return res; + } + + index_type operator+( + const self_t & other) const noexcept + { + return _idx + other._idx; + } + + index_type operator-( + const self_t & other) const + { + return _idx - other._idx; + } + + inline bool operator<(const self_t & other) const noexcept + { + // NOTE: + // This function call is significantly slower than the explicit + // implementation in operator== and operator!=. + return compare(other, + std::less(), + std::less()); + } + + inline bool operator<=(const self_t & other) const noexcept + { + // NOTE: + // This function call is significantly slower than the explicit + // implementation in operator== and operator!=. + return compare(other, + std::less_equal(), + std::less_equal()); + } + + inline bool operator>(const self_t & other) const noexcept + { + // NOTE: + // This function call is significantly slower than the explicit + // implementation in operator== and operator!=. + return compare(other, + std::greater(), + std::greater()); + } + + inline bool operator>=(const self_t & other) const noexcept + { + // NOTE: + // This function call is significantly slower than the explicit + // implementation in operator== and operator!=. + return compare(other, + std::greater_equal(), + std::greater_equal()); + } + + inline bool operator==(const self_t & other) const noexcept + { + // NOTE: See comments in method compare(). + if (_viewspec == other._viewspec) { + // Same viewspec pointer + return _idx == other._idx; + } + if ((_viewspec != nullptr && other._viewspec != nullptr) && + (*_viewspec) == *(other._viewspec)) { + // Viewspec instances are equal + return _idx == other._idx; + } + auto lhs_local = lpos(); + auto rhs_local = other.lpos(); + return (lhs_local.unit == rhs_local.unit && + lhs_local.index == rhs_local.index); + } + + inline bool operator!=(const self_t & other) const noexcept + { + // NOTE: See comments in method compare(). + if (_viewspec == other._viewspec) { + // Same viewspec pointer + return _idx != other._idx; + } + if ((_viewspec != nullptr && other._viewspec != nullptr) && + (*_viewspec) == *(other._viewspec)) { + // Viewspec instances are equal + return _idx != other._idx; + } + auto lhs_local = lpos(); + auto rhs_local = other.lpos(); + return (lhs_local.unit != rhs_local.unit || + lhs_local.index != rhs_local.index); + } + + constexpr const PatternType & pattern() const noexcept + { + return *_pattern; + } + + constexpr dash::Team & team() const noexcept + { + return _pattern->team(); + } + +private: + /** + * Compare position of this global iterator to the position of another + * global iterator with respect to viewspec projection. + */ + template< + class LocalIndexCmpFun, + class LocalPtrCmpFun > + bool compare( + const self_t & other, + const LocalIndexCmpFun & lidx_cmp, + const LocalPtrCmpFun & lptr_cmp) const noexcept + { +#if __REMARK__ + // Usually this is a best practice check, but it's an infrequent case + // so we rather avoid this comparison: + if (this == &other) { + return true; + } +#endif + // NOTE: + // Do not check _idx first, as it would never match for comparison with + // an end iterator. + if (_viewspec == other._viewspec) { + // Same viewspec pointer + return lidx_cmp(_idx, other._idx); + } + if ((_viewspec != nullptr && other._viewspec != nullptr) && + (*_viewspec) == *(other._viewspec)) { + // Viewspec instances are equal + return lidx_cmp(_idx, other._idx); + } + // View projection at lhs and/or rhs set. + // Convert both to GlobPtr (i.e. apply view projection) and compare. + // + // NOTE: + // This conversion is quite expensive but will never be necessary + // if both iterators have been created from the same range. + // Example: + // a.block(1).begin() == a.block(1).end(). + // does not require viewspace projection while + // a.block(1).begin() == a.end() + // does. The latter case should be avoided for this reason. + const pointer lhs_ptr(dart_gptr()); + const pointer rhs_ptr(other.dart_gptr()); + return lptr_cmp(lhs_ptr, rhs_ptr); + } + + /** + * Convert a local offset within the local iterator's range to + * corresponding local coordinates with respect to viewspec projection. + * + * This method is bounds-checked and might throw. + * + * \note + * This method could be specialized for NumDimensions = 1 for performance + * tuning. + */ + std::array coords( + IndexType l_index) const + { + DASH_LOG_TRACE_VAR("LocalViewIter.coords()", l_index); + // Global cartesian coords of current iterator position: + std::array l_coords; + if (_viewspec != nullptr) { + DASH_LOG_TRACE_VAR("LocalViewIter.coords", *_viewspec); + // Create cartesian index space from extents of view projection: + CartesianIndexSpace index_space( + _viewspec->extents()); + // Initialize global coords with view coords (coords of iterator + // position in view index space): + l_coords = index_space.coords(l_index); + // Apply offset of view projection to view coords: + for (dim_t d = 0; d < NumDimensions; ++d) { + auto dim_offset = _viewspec->offset(d); + l_coords[d] += dim_offset; + } + } else { + l_coords = _pattern->local_memory_layout().coords(l_index); + } + DASH_LOG_TRACE_VAR("LocalViewIter.coords >", l_coords); + return l_coords; + } + +}; // class LocalViewIter + +/** + * Resolve the number of elements between two global iterators. + * + * The difference of global pointers is not well-defined if their range + * spans over more than one block. + * The corresponding invariant is: + * g_last == g_first + (l_last - l_first) + * Example: + * + * \code + * unit: 0 1 0 + * local offset: | 0 1 2 | 0 1 2 | 3 4 5 | ... + * global offset: | 0 1 2 3 4 5 6 7 8 ... + * range: [- - - - -] + * \endcode + * + * When iterating in local memory range [0,5[ of unit 0, the position of the + * global iterator to return is 8 != 5 + * + * \tparam ElementType Type of the elements in the range + * \complexity O(1) + * + * \ingroup Algorithms + */ +template< + typename ElementT, + class Pattern, + class GlobStaticMem, + class Pointer, + class Reference > +auto distance( + const LocalViewIter & + first, + /// Global iterator to the final position in the global sequence + const LocalViewIter & + last) +-> typename Pattern::index_type +{ + return last - first; +} + +template < + typename ElementT, + class Pattern, + class GlobStaticMem, + class Pointer, + class Reference > +std::ostream & operator<<( + std::ostream & os, + const dash::LocalViewIter< + ElementT, Pattern, GlobStaticMem, Pointer, Reference> & it) +{ + std::ostringstream ss; + ss << "dash::LocalViewIter<" + << typeid(ElementT).name() << ", " + << typeid(Pointer).name() + << ">(" + << "idx:" << it._idx << ", " + << "gptr:" << it.global().dart_gptr() << ")"; + return operator<<(os, ss.str()); +} + +} // namespace dash + +#endif // DASH__LOCAL_VIEW_ITER_H__INCLUDED diff --git a/dash/include/dash/matrix/LocalMatrixRef.h b/dash/include/dash/matrix/LocalMatrixRef.h index 9038735f8..bfe75178c 100644 --- a/dash/include/dash/matrix/LocalMatrixRef.h +++ b/dash/include/dash/matrix/LocalMatrixRef.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -90,18 +91,26 @@ class LocalMatrixRef typedef typename PatternT::size_type size_type; typedef typename PatternT::index_type difference_type; +#if 1 + typedef LocalViewIter< value_type, PatternT> iterator; + typedef LocalViewIter const_iterator; + + typedef LocalViewIter< value_type, PatternT> pointer; + typedef LocalViewIter const_pointer; +#else typedef GlobViewIter< value_type, PatternT> iterator; typedef GlobViewIter const_iterator; + typedef GlobViewIter< value_type, PatternT> pointer; + typedef GlobViewIter const_pointer; +#endif + typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; typedef GlobRef< value_type> reference; typedef GlobRef const_reference; - typedef GlobViewIter< value_type, PatternT> pointer; - typedef GlobViewIter const_pointer; - typedef T * local_pointer; typedef const T * const_local_pointer; diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index 25b6caaeb..f070284d9 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -210,6 +210,26 @@ ::pattern() const noexcept return _refview._mat->_pattern; } +#if 0 +template +inline typename LocalMatrixRef::iterator +LocalMatrixRef +::begin() noexcept +{ + return iterator( + _refview._mat->_glob_mem, + _refview._mat->_pattern, + _refview._viewspec, + // iterator position in view index space + 0, + // view index start offset + _refview._mat->_pattern.local_at( + _refview._coord, + _refview._l_viewspec) + ); +} +#endif + template inline typename LocalMatrixRef::iterator LocalMatrixRef From d78ac8dad65b5dfac11bbf6a80c26095ff26c1af Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 21 Sep 2017 01:27:19 +0200 Subject: [PATCH 096/161] Intermediate fix --- dash/examples/ex.02.matrix-sub-views/main.cpp | 9 +-------- dash/include/dash/iterator/GlobIter.h | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index a7c47ff80..1e7a76c01 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -80,17 +80,10 @@ int main(int argc, char *argv[]) nview_str(matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1)) << '\n'); - print("matrix | local | blocks"); - auto m_l_blocks = matrix | local() - | blocks(); - for (const auto & blk : m_l_blocks) { - print("---" << nview_str(blk) << '\n'); - } - print("matrix | blocks | local"); auto m_blocks_l = matrix | blocks() | local(); - for (const auto & blk : m_l_blocks) { + for (const auto & blk : m_blocks_l) { print("---" << nview_str(blk) << '\n'); } diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index c7e5b3787..a7d594020 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -399,7 +399,15 @@ class GlobIter "unit:", local_pos.unit, "local index:", local_pos.index); // Global pointer to element at given position: +#if 0 const_pointer gptr( +#else + // TODO: Intermediate, should be `const_pointer`. + // Actual issue is `const_pointer` defined as local pointer + // type, should be global pointer for global iterator like + // `GlobIter`: + dash::GlobPtr gptr( +#endif _globmem->at( team_unit_t(local_pos.unit), local_pos.index) From b08f6db62a1d8e0055ec4c1213f1ff4148448b95 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 21 Sep 2017 01:46:20 +0200 Subject: [PATCH 097/161] Extending view examples --- dash/examples/ex.02.array-views/main.cpp | 7 ++++++- dash/examples/util.h | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 7f7737cab..5a02ce6fd 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -71,8 +71,13 @@ int main(int argc, char *argv[]) auto copy_dest_begin_idx = a.size() / 4; auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; + int buf_i = 0; std::vector buf(copy_num_elem); - std::iota(buf.begin(), buf.end(), 0.9999); + std::transform(buf.begin(), buf.end(), + buf.begin(), + [&](const double & a) { + return a + 6; + }); a.barrier(); diff --git a/dash/examples/util.h b/dash/examples/util.h index db9759eaf..1b311e3af 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -22,6 +22,8 @@ } while(0) +using namespace dash::internal::logging; + template static std::string range_str( const ValueRange & vrange, @@ -31,16 +33,17 @@ static std::string range_str( auto idx = dash::index(vrange); int i = 0; for (const auto & v : vrange) { - ss << std::setw(2) << *(dash::begin(idx) + i) << "|" + const value_t val = v; + ss << std::setw(3) << *(dash::begin(idx) + i) << "|" << std::fixed << std::setprecision(prec) - << static_cast(v) << " "; + << TermColorMod(unit_term_colors[(int)val]) + << val + << TermColorMod(TCOL_DEFAULT); ++i; } return ss.str(); } -using namespace dash::internal::logging; - template std::string nview_str( const NViewType & nview, From d40995d3d6197b26c7664c427fe3d88252e51be7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 21 Sep 2017 02:13:05 +0200 Subject: [PATCH 098/161] Extending view examples --- dash/examples/ex.02.array-views/main.cpp | 138 ++++++++++++----------- dash/examples/util.h | 2 +- 2 files changed, 71 insertions(+), 69 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 5a02ce6fd..c8f56b874 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -20,12 +20,12 @@ auto initialize_array(ArrayT & array) auto block_lidx = li / block_size; auto block_gidx = (block_lidx * dash::size()) + dash::myid().id; auto gi = (block_gidx * block_size) + (li % block_size); - array.local[li] = // unit - (1.0000 * dash::myid().id) + + array.local[li] = // unit + (1.0000 * dash::myid().id) + // local offset - (0.0100 * (li+1)) + + + (0.0100 * (li+1)); // global offset - (0.0001 * gi); + // + (0.0001 * gi); } array.barrier(); } @@ -41,77 +41,79 @@ int main(int argc, char *argv[]) int array_size = dash::size() * elem_per_unit + std::min(elem_additional, dash::size()); - dash::Array a(array_size, dash::BLOCKCYCLIC(3)); - initialize_array(a); + { + dash::Array a(array_size, dash::BLOCKCYCLIC(2)); + initialize_array(a); - if (dash::myid() == 0) { - print("a: " << range_str(a)); + if (dash::myid() == 0) { + print("a: " << range_str(a)); - auto sb_array = a | sub(1, a.size()-1) | blocks(); - for (const auto & b : sb_array) { - print("a | sub | block: " << range_str(b)); - } + auto sb_array = a | sub(1, a.size()-1) | blocks(); + for (const auto & b : sb_array) { + print("a | sub | block: " << range_str(b)); + } - auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); - for (const auto & b : slb_array) { - print("a | sub | local | block: " << range_str(b)); + auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); + for (const auto & b : slb_array) { + print("a | sub | local | block: " << range_str(b)); + } } - } - dash::barrier(); - - auto l_array = a | local(); - print("a | local: " << range_str(l_array)); - dash::barrier(); - - auto sl_array = a | sub(1, a.size()-1) | local(); - print("a | sub | local: " << range_str(sl_array)); - dash::barrier(); - - auto copy_num_elem = a.size() / 2; - auto copy_dest_begin_idx = a.size() / 4; - auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; - - int buf_i = 0; - std::vector buf(copy_num_elem); - std::transform(buf.begin(), buf.end(), - buf.begin(), - [&](const double & a) { - return a + 6; - }); - - a.barrier(); - - if (dash::myid() == 0) { - print("copy target index range: " - << "[" << copy_dest_begin_idx - << "," << copy_dest_end_idx << ")"); - - auto copy_begin_it = a.begin() + copy_dest_begin_idx; - auto copy_end_it_exp = copy_begin_it + copy_num_elem; - - auto dest_range = dash::make_range(copy_begin_it, - copy_end_it_exp); - auto dest_blocks = dash::blocks(dest_range); - - // Printing temporaries from view expressions instead of - // named values for testing: - print("target index set: " << dash::index(dest_range)); - print("target block set: " << dash::index(dash::blocks(dest_range))); - print("copy target range: " << range_str(dest_range)); - - for (const auto & block : dest_blocks) { - print("copy to block: " << range_str(block)); + dash::barrier(); + + auto l_array = a | local(); + print("a | local: " << range_str(l_array)); + dash::barrier(); + + auto sl_array = a | sub(1, a.size()-1) | local(); + print("a | sub | local: " << range_str(sl_array)); + dash::barrier(); + + auto copy_num_elem = a.size() / 2; + auto copy_dest_begin_idx = a.size() / 4 - 1; + auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; + + int buf_i = 0; + std::vector buf(copy_num_elem); + std::transform(buf.begin(), buf.end(), + buf.begin(), + [&](const double & a) { + return a + 6; + }); + + a.barrier(); + + if (dash::myid() == 0) { + print("copy target index range: " + << "[" << copy_dest_begin_idx + << "," << copy_dest_end_idx << ")"); + + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_end_it_exp = copy_begin_it + copy_num_elem; + + auto dest_range = dash::make_range(copy_begin_it, + copy_end_it_exp); + auto dest_blocks = dash::blocks(dest_range); + + // Printing temporaries from view expressions instead of + // named values for testing: + print("target index set: " << dash::index(dest_range)); + print("target block set: " << dash::index(dash::blocks(dest_range))); + print("copy target range: " << range_str(dest_range)); + + for (const auto & block : dest_blocks) { + print("copy to block: " << range_str(block)); + } + + // copy local buffer to global array + auto copy_end_it = dash::copy( + buf.data(), + buf.data() + copy_num_elem, + copy_begin_it); } + a.barrier(); - // copy local buffer to global array - auto copy_end_it = dash::copy( - buf.data(), - buf.data() + copy_num_elem, - copy_begin_it); + print("modified array: " << range_str(a)); } - a.barrier(); - - print("modified array: " << range_str(a)); dash::finalize(); } diff --git a/dash/examples/util.h b/dash/examples/util.h index 1b311e3af..58ce1f17b 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -27,7 +27,7 @@ using namespace dash::internal::logging; template static std::string range_str( const ValueRange & vrange, - int prec = 4) { + int prec = 2) { typedef typename ValueRange::value_type value_t; std::ostringstream ss; auto idx = dash::index(vrange); From ab2073749c5081c560bc2867d2f8b315294f37a8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 00:08:53 +0200 Subject: [PATCH 099/161] Extending view examples --- dash/examples/ex.02.matrix-halo-views/main.cpp | 18 +++++++++--------- dash/examples/ex.02.matrix-sub-views/main.cpp | 10 ++++++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 365c78696..5506f40cf 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -18,9 +18,9 @@ int main(int argc, char *argv[]) auto nunits = dash::size(); const size_t block_size_x = 2; - const size_t block_size_y = 3; + const size_t block_size_y = 2; const size_t block_size = block_size_x * block_size_y; - size_t num_local_blocks_x = 2; + size_t num_local_blocks_x = 1; size_t num_local_blocks_y = 2; size_t num_blocks_x = nunits * num_local_blocks_x; size_t num_blocks_y = nunits * num_local_blocks_y; @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) size_t num_elem_per_unit = num_elem_total / nunits; size_t num_blocks_per_unit = num_elem_per_unit / block_size; - typedef dash::SeqTilePattern<2> pattern_t; + typedef dash::ShiftTilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; typedef float value_t; @@ -58,9 +58,9 @@ int main(int argc, char *argv[]) for (auto bx = 0; bx < static_cast(lblock_extents[0]); ++bx) { for (auto by = 0; by < static_cast(lblock_extents[1]); ++by) { // Phase coordinates (bx,by) to global coordinates (gx,gy): - value_t value = static_cast(dash::myid().id + 1) + - 0.00001 * ( - ((lb + 1) * 10000) + ((bx + 1) * 100) + by + 1); + value_t value = static_cast(dash::myid().id) + + 0.01 * lb + + 0.0001 * (bx * lblock_extents[0] + by); lblock[bx][by] = value; } } @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) if (myid == 0) { auto matrix_view = dash::sub(0, matrix.extents()[0], matrix); - print("matrix" << nview_str(matrix_view)); + print("matrix" << nview_str(matrix_view, 4)); DASH_LOG_DEBUG("MatrixViewsExample", "matrix", "offsets:", matrix_view.offsets(), @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) auto matrix_blocks = dash::blocks(matrix_view); for (const auto & m_block : matrix_blocks) { print("matrix | block(n)" << - nview_str(m_block)); + nview_str(m_block, 4)); // halo view: auto b_halo = dash::sub<0>( m_block.offsets()[0] > 0 @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) : m_block.offsets()[1] + m_block.extents()[1], matrix_view)); print("matrix | block(n) | expand({ -1,1 } , { -1,1 })" << - nview_str(b_halo)); + nview_str(b_halo, 4)); DASH_LOG_DEBUG("MatrixViewsExample", "size:", b_halo.size()); #if 0 auto b_halo_isect = dash::difference( diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 1e7a76c01..9f0f08d03 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -83,16 +83,22 @@ int main(int argc, char *argv[]) print("matrix | blocks | local"); auto m_blocks_l = matrix | blocks() | local(); + auto m_blocks_l_idx = m_blocks_l | index(); + int lb_idx = 0; for (const auto & blk : m_blocks_l) { - print("---" << nview_str(blk) << '\n'); + print("--- local blocks[" << m_blocks_l_idx[lb_idx++] << "]" << + nview_str(blk) << '\n'); } print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); auto m_s_blocks = matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1) | blocks(); + auto m_s_blocks_idx = m_s_blocks | index(); + int b_idx = 0; for (const auto & blk : m_s_blocks) { - print("---" << nview_str(blk) << '\n'); + print("--- blocks[" << m_s_blocks_idx[b_idx++] << "]" << + nview_str(blk) << '\n'); } } dash::barrier(); From 813dc571ccc6a939ae7c2dff69c595dff015d104 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 09:11:29 +0200 Subject: [PATCH 100/161] Fixing dash::expand view operation for matrix blocks --- dash/examples/ex.02.array-views/main.cpp | 240 +++++++++--------- .../examples/ex.02.matrix-halo-views/main.cpp | 35 ++- dash/include/dash/view/Expand.h | 183 ++++++++++++- 3 files changed, 324 insertions(+), 134 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index c8f56b874..77614194d 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -1,120 +1,120 @@ -#include -#include "../util.h" - -using std::cout; -using std::cerr; -using std::clog; -using std::cin; -using std::endl; -using std::vector; - - -template -auto initialize_array(ArrayT & array) --> typename std::enable_if< - std::is_floating_point::value, - void >::type -{ - auto block_size = array.pattern().blocksize(0); - for (auto li = 0; li != array.local.size(); ++li) { - auto block_lidx = li / block_size; - auto block_gidx = (block_lidx * dash::size()) + dash::myid().id; - auto gi = (block_gidx * block_size) + (li % block_size); - array.local[li] = // unit - (1.0000 * dash::myid().id) + - // local offset - + (0.0100 * (li+1)); - // global offset - // + (0.0001 * gi); - } - array.barrier(); -} - -int main(int argc, char *argv[]) -{ - using namespace dash; - - dash::init(&argc, &argv); - - int elem_per_unit = 5; - int elem_additional = 2; - int array_size = dash::size() * elem_per_unit + - std::min(elem_additional, dash::size()); - - { - dash::Array a(array_size, dash::BLOCKCYCLIC(2)); - initialize_array(a); - - if (dash::myid() == 0) { - print("a: " << range_str(a)); - - auto sb_array = a | sub(1, a.size()-1) | blocks(); - for (const auto & b : sb_array) { - print("a | sub | block: " << range_str(b)); - } - - auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); - for (const auto & b : slb_array) { - print("a | sub | local | block: " << range_str(b)); - } - } - dash::barrier(); - - auto l_array = a | local(); - print("a | local: " << range_str(l_array)); - dash::barrier(); - - auto sl_array = a | sub(1, a.size()-1) | local(); - print("a | sub | local: " << range_str(sl_array)); - dash::barrier(); - - auto copy_num_elem = a.size() / 2; - auto copy_dest_begin_idx = a.size() / 4 - 1; - auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; - - int buf_i = 0; - std::vector buf(copy_num_elem); - std::transform(buf.begin(), buf.end(), - buf.begin(), - [&](const double & a) { - return a + 6; - }); - - a.barrier(); - - if (dash::myid() == 0) { - print("copy target index range: " - << "[" << copy_dest_begin_idx - << "," << copy_dest_end_idx << ")"); - - auto copy_begin_it = a.begin() + copy_dest_begin_idx; - auto copy_end_it_exp = copy_begin_it + copy_num_elem; - - auto dest_range = dash::make_range(copy_begin_it, - copy_end_it_exp); - auto dest_blocks = dash::blocks(dest_range); - - // Printing temporaries from view expressions instead of - // named values for testing: - print("target index set: " << dash::index(dest_range)); - print("target block set: " << dash::index(dash::blocks(dest_range))); - print("copy target range: " << range_str(dest_range)); - - for (const auto & block : dest_blocks) { - print("copy to block: " << range_str(block)); - } - - // copy local buffer to global array - auto copy_end_it = dash::copy( - buf.data(), - buf.data() + copy_num_elem, - copy_begin_it); - } - a.barrier(); - - print("modified array: " << range_str(a)); - } - - dash::finalize(); -} - +#include +#include "../util.h" + +using std::cout; +using std::cerr; +using std::clog; +using std::cin; +using std::endl; +using std::vector; + + +template +auto initialize_array(ArrayT & array) +-> typename std::enable_if< + std::is_floating_point::value, + void >::type +{ + auto block_size = array.pattern().blocksize(0); + for (auto li = 0; li != array.local.size(); ++li) { + auto block_lidx = li / block_size; + auto block_gidx = (block_lidx * dash::size()) + dash::myid().id; + auto gi = (block_gidx * block_size) + (li % block_size); + array.local[li] = // unit + (1.0000 * dash::myid().id) + + // local offset + + (0.0100 * li); + // global offset + // + (0.0001 * gi); + } + array.barrier(); +} + +int main(int argc, char *argv[]) +{ + using namespace dash; + + dash::init(&argc, &argv); + + int elem_per_unit = 5; + int elem_additional = 2; + int array_size = dash::size() * elem_per_unit + + std::min(elem_additional, dash::size()); + + { + dash::Array a(array_size, dash::BLOCKCYCLIC(2)); + initialize_array(a); + + if (dash::myid() == 0) { + print("a: " << range_str(a)); + + auto sb_array = a | sub(1, a.size()-1) | blocks(); + for (const auto & b : sb_array) { + print("a | sub | block: " << range_str(b)); + } + + auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); + for (const auto & b : slb_array) { + print("a | sub | local | block: " << range_str(b)); + } + } + dash::barrier(); + + auto l_array = a | local(); + print("a | local: " << range_str(l_array)); + dash::barrier(); + + auto sl_array = a | sub(1, a.size()-1) | local(); + print("a | sub | local: " << range_str(sl_array)); + dash::barrier(); + + auto copy_num_elem = a.size() / 2; + auto copy_dest_begin_idx = a.size() / 4 - 1; + auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; + + int buf_i = 0; + std::vector buf(copy_num_elem); + std::transform(buf.begin(), buf.end(), + buf.begin(), + [&](const double & a) { + return a + 6; + }); + + a.barrier(); + + if (dash::myid() == 0) { + print("copy target index range: " + << "[" << copy_dest_begin_idx + << "," << copy_dest_end_idx << ")"); + + auto copy_begin_it = a.begin() + copy_dest_begin_idx; + auto copy_end_it_exp = copy_begin_it + copy_num_elem; + + auto dest_range = dash::make_range(copy_begin_it, + copy_end_it_exp); + auto dest_blocks = dash::blocks(dest_range); + + // Printing temporaries from view expressions instead of + // named values for testing: + print("target index set: " << dash::index(dest_range)); + print("target block set: " << dash::index(dash::blocks(dest_range))); + print("copy target range: " << range_str(dest_range)); + + for (const auto & block : dest_blocks) { + print("copy to block: " << range_str(block)); + } + + // copy local buffer to global array + auto copy_end_it = dash::copy( + buf.data(), + buf.data() + copy_num_elem, + copy_begin_it); + } + a.barrier(); + + print("modified array: " << range_str(a)); + } + + dash::finalize(); +} + diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 5506f40cf..2d149aed7 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -76,8 +76,14 @@ int main(int argc, char *argv[]) "extents:", matrix_view.extents()); auto matrix_blocks = dash::blocks(matrix_view); + auto matrix_b_idx = matrix_blocks | dash::index(); + int b_idx = 0; for (const auto & m_block : matrix_blocks) { - print("matrix | block(n)" << + auto b_offsets = m_block.offsets(); + auto b_extents = m_block.extents(); + print("matrix | block[" << matrix_b_idx[b_idx] << "]:\n " << + "offsets: " << b_offsets[0] << "," << b_offsets[1] << " " << + "extents: " << b_extents[0] << "," << b_extents[1] << nview_str(m_block, 4)); // halo view: auto b_halo = dash::sub<0>( @@ -97,9 +103,13 @@ int main(int argc, char *argv[]) ? m_block.offsets()[1] + m_block.extents()[1] + 1 : m_block.offsets()[1] + m_block.extents()[1], matrix_view)); - print("matrix | block(n) | expand({ -1,1 } , { -1,1 })" << + auto bh_offsets = b_halo.offsets(); + auto bh_extents = b_halo.extents(); + print("matrix | block[" << matrix_b_idx[b_idx] << "] | " << + "expand({ -1,1 }, { -1,1 })\n " << + "offsets: " << bh_offsets[0] << "," << bh_offsets[1] << " " << + "extents: " << bh_extents[0] << "," << bh_extents[1] << nview_str(b_halo, 4)); - DASH_LOG_DEBUG("MatrixViewsExample", "size:", b_halo.size()); #if 0 auto b_halo_isect = dash::difference( m_block, @@ -108,15 +118,20 @@ int main(int argc, char *argv[]) dash::sub<1>( 1, m_block.extents()[1] - 1, m_block))); +#endif - auto b_halo_exp = dash::expand<0>( - -1, 1, - dash::expand<1>( - -1, 1, - m_block)); - DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", - nview_str(b_halo_exp)); +#if 1 + auto b_halo_exp = dash::expand<1>( + static_cast(-1), + static_cast(1), + // dash::expand<1>( -1, 1, + m_block + // ) + ); + print("matrix | block(n) | expand<0>({ -1,1 })" << + nview_str(b_halo_exp, 4)); #endif + ++b_idx; } } dash::barrier(); diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index d52594ff4..28bd0cd51 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -5,10 +5,166 @@ #include #include +#include +#include namespace dash { +/** + * Origin cannot be expanded. + * + */ +template < + dim_t SubDim = 0, + class OriginT, + class OffsetFirstT, + class OffsetFinalT, + typename OriginValueT + = typename std::decay::type +> +constexpr auto +expand( + OffsetFirstT begin, + OffsetFinalT end, + OriginT && origin) + -> typename std::enable_if< + dash::view_traits::is_origin::value, + decltype(std::forward(origin)) + >::type { + return std::forward(origin); +} + + +namespace detail { + + template < + dim_t CurDim, + dim_t SubDim, + class DomainT, + class OffsetFirstT, + class OffsetFinalT, + typename DomainValueT + = typename std::decay::type, + typename IndexT + = typename DomainValueT::index_type, + typename SizeT + = typename DomainValueT::size_type, + typename OffsetsT, + typename ExtentsT, + typename std::enable_if< CurDim == 0, char >::type = 0 + > + constexpr auto + expand_dim( + OffsetFirstT begin, + OffsetFinalT end, + DomainT && domain, + OffsetsT cur_offsets, + ExtentsT cur_extents) { + return ( CurDim == SubDim + // span in current dimension is to be expanded + ? dash::sub( + ( cur_offsets[CurDim] + begin > 0 + ? cur_offsets[CurDim] + begin + : 0 ), + ( cur_offsets[CurDim] + cur_extents[CurDim] + end < + domain.extents()[CurDim] + ? cur_offsets[CurDim] + cur_extents[CurDim] + end + : domain.extents()[CurDim] ), + std::forward(domain)) + // span in current dimension is unchanged + : dash::sub( + (cur_offsets[CurDim]), + (cur_offsets[CurDim] + cur_extents[CurDim]), + std::forward(domain)) + ); + } + + template < + dim_t CurDim, + dim_t SubDim, + class DomainT, + class OffsetFirstT, + class OffsetFinalT, + typename DomainValueT + = typename std::decay::type, + typename IndexT + = typename DomainValueT::index_type, + typename SizeT + = typename DomainValueT::size_type, + typename OffsetsT, + typename ExtentsT, + typename std::enable_if< (CurDim > 0), char >::type = 0 + > + constexpr auto + expand_dim( + OffsetFirstT begin, + OffsetFinalT end, + DomainT && domain, + OffsetsT cur_offsets, + ExtentsT cur_extents) { + return expand_dim( + static_cast(begin), + static_cast(end), + ( CurDim == SubDim + // span in current dimension is to be expanded + ? dash::sub( + ( cur_offsets[CurDim] + begin > 0 + ? cur_offsets[CurDim] + begin + : 0 ), + ( cur_offsets[CurDim] + cur_extents[CurDim] + end < + domain.extents()[CurDim] + ? cur_offsets[CurDim] + cur_extents[CurDim] + end + : domain.extents()[CurDim] ), + std::forward(domain)) + // span in current dimension is unchanged + : dash::sub( + (cur_offsets[CurDim]), + (cur_offsets[CurDim] + cur_extents[CurDim]), + std::forward(domain)) + ), + cur_offsets, + cur_extents); + } + +} // namespace detail + + +template < + dim_t SubDim = 0, + class DomainT, +//class OffsetFirstT, +//class OffsetFinalT, + typename DomainValueT + = typename std::decay::type, + typename IndexT + = typename DomainValueT::index_type, + typename SizeT + = typename DomainValueT::size_type, + dim_t NDim + = dash::view_traits::rank::value, + typename std::enable_if< + !dash::view_traits::is_origin::value, + char >::type = 0 +> +constexpr auto +expand( + IndexT begin, + SizeT end, + DomainT && domain) { + return detail::expand_dim< + static_cast(NDim), + static_cast(SubDim) + >(begin, end, + dash::origin( + std::forward(domain)), + (domain.offsets()), + (domain.extents())); +} + + +#if 0 + template < dim_t SubDim = 0, class DomainT, @@ -35,21 +191,24 @@ expand( return ViewSubMod< SecDomainT, SubDim, - dash::view_traits::rank::value + dash::view_traits::rank::value >(dash::domain( std::forward(domain)), domain.offsets()[SubDim] + - ( domain.offsets()[SubDim] > 0 + ( domain.offsets()[SubDim] + begin > 0 ? begin : 0 ), domain.offsets()[SubDim] + domain.extents()[SubDim] + - ( domain.offsets()[SubDim] + domain.extents()[SubDim] + ( domain.offsets()[SubDim] + domain.extents()[SubDim] + end < dash::domain(domain).extents()[SubDim] ? end : 0 )); } -#if 0 + + + + template < dim_t SubDim = 0, class DomainT, @@ -89,6 +248,22 @@ expand( } #endif +template < + dim_t SubDim = 0, + class OffsetT0, + class OffsetT1, + typename std::enable_if< + ( std::is_integral::value && + std::is_integral::value ), + int + >::type = 0 > +static inline auto expand(OffsetT0 a, OffsetT1 b) { + return dash::make_pipeable( + [=](auto && x) { + return expand(a,b, std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__EXPAND_H__INCLUDED From 0abbeac80726621e7547cb785ce29d2ed74dd503 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 09:16:41 +0200 Subject: [PATCH 101/161] Fixed dash::expand view operation for matrix blocks --- .../examples/ex.02.matrix-halo-views/main.cpp | 8 +-- dash/include/dash/util/ArrayExpr.h | 18 +++++- dash/include/dash/util/IndexSequence.h | 58 ------------------- dash/include/dash/util/LocalityDomain.h | 1 - dash/include/dash/view/Expand.h | 2 +- 5 files changed, 19 insertions(+), 68 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 2d149aed7..4e50f3b31 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -121,12 +121,10 @@ int main(int argc, char *argv[]) #endif #if 1 - auto b_halo_exp = dash::expand<1>( - static_cast(-1), - static_cast(1), - // dash::expand<1>( -1, 1, + auto b_halo_exp = dash::expand<0>(-1, 1, + dash::expand<1>(-1, 1, m_block - // ) + ) ); print("matrix | block(n) | expand<0>({ -1,1 })" << nview_str(b_halo_exp, 4)); diff --git a/dash/include/dash/util/ArrayExpr.h b/dash/include/dash/util/ArrayExpr.h index a925c2a47..8ef8a7289 100644 --- a/dash/include/dash/util/ArrayExpr.h +++ b/dash/include/dash/util/ArrayExpr.h @@ -273,9 +273,21 @@ template < constexpr std::array reverse( const std::array & values) { - - return detail::take_impl( - values, dash::ce::make_rev_index_sequence()); + // + // NOTE: + // + // This is elegant, correct, of high didactic value and does + // not scale well. + // Should be implemented using index from parameter pack like + // + // { (std::get(values)... } + // + return (NElem > 1 + ? ( dash::ce::append( + dash::ce::reverse( + dash::ce::tail(values)), + dash::ce::head(values)) ) + : values); } // ------------------------------------------------------------------------- diff --git a/dash/include/dash/util/IndexSequence.h b/dash/include/dash/util/IndexSequence.h index fb8d77741..9f95092c1 100644 --- a/dash/include/dash/util/IndexSequence.h +++ b/dash/include/dash/util/IndexSequence.h @@ -10,31 +10,11 @@ namespace dash { namespace ce { - -/** - * Represents a compile-time sequence container - */ template < std::size_t... Is > struct index_sequence { }; -/** - * Generates a compile-sequence integer (size_t) sequence in ascending order - * - * Example: - * - * template - * void print(dash::ce::index_sequence&& s) - * { - * for (auto i : { Is... }) std::cout << i << " "; - * std::cout << "\n"; - * } - * - * print(dash::ce::make_rev_index_sequence<5>()); - * //output: 0 1 2 3 4 - * - */ template < std::size_t N, std::size_t... Is > @@ -42,50 +22,12 @@ struct make_index_sequence : make_index_sequence { }; -/** - * Stop condition for a compile-time integer (size_t) sequence in ascending - * order - */ template < std::size_t... Is> struct make_index_sequence<0, Is...> : index_sequence { }; -/** - * Generates a compile-sequence integer (size_t) sequence in descending order - * - * Example: - * - * template - * void print(dash::ce::index_sequence&& s) - * { - * for (auto i : { Is... }) std::cout << i << " "; - * std::cout << "\n"; - * } - * - * print(dash::ce::make_rev_index_sequence<5>()); - * //output: 4 3 2 1 0 - * - */ -template < - std::size_t N, - std::size_t... Is > -struct make_rev_index_sequence - : make_rev_index_sequence -{ }; - - -/** - * Stop condition for a compile-time integer (size_t) sequence in descending - * order - */ -template < - std::size_t... Is> -struct make_rev_index_sequence<0, Is...> - : index_sequence -{ }; - } // namespace ce } // namespace dash diff --git a/dash/include/dash/util/LocalityDomain.h b/dash/include/dash/util/LocalityDomain.h index d0ea5e89d..5c7d58be5 100644 --- a/dash/include/dash/util/LocalityDomain.h +++ b/dash/include/dash/util/LocalityDomain.h @@ -328,7 +328,6 @@ class LocalityDomain static_cast(scope), &num_scope_domains, &dart_scope_domains); - (void)ret; // suppress warning DASH_ASSERT(DART_OK == ret || DART_ERR_NOTFOUND == ret); DASH_LOG_TRACE_VAR("LocalityDomain.scope_domains", num_scope_domains); diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index 28bd0cd51..2523c9860 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -153,7 +153,7 @@ expand( SizeT end, DomainT && domain) { return detail::expand_dim< - static_cast(NDim), + static_cast(NDim - 1), static_cast(SubDim) >(begin, end, dash::origin( From 8dbf92695c31310b9056421a829461d961e0d72f Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 09:17:11 +0200 Subject: [PATCH 102/161] Using type dim_t for dimension template types in views --- dash/include/dash/view/IndexSet.h | 52 ++++++++++++------------ dash/include/dash/view/PatternIndexSet.h | 22 +++++----- dash/include/dash/view/ViewBlocksMod.h | 3 +- dash/include/dash/view/ViewMod1D.h | 4 +- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 7dfec14ed..5b1e7e181 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -135,7 +135,7 @@ using global_index_t // Forward-declarations -template +template class IndexSetBase; template @@ -147,7 +147,7 @@ class IndexSetLocal; template class IndexSetGlobal; -template +template class IndexSetSub; template @@ -291,7 +291,7 @@ index(const ContainerType & c) template < class IndexSetType, class DomainType, - std::size_t NDim > + dim_t NDim > constexpr auto local( const IndexSetBase & index_set) @@ -302,7 +302,7 @@ local( template < class IndexSetType, class DomainType, - std::size_t NDim > + dim_t NDim > constexpr auto global( const IndexSetBase & index_set) @@ -335,7 +335,7 @@ struct index_set_domain_bind_t { template < class IndexSetType, class DomainType, - std::size_t NDim = DomainType::rank::value > + dim_t NDim = DomainType::rank::value > class IndexSetBase { typedef IndexSetBase self_t; @@ -373,13 +373,13 @@ class IndexSetBase typedef typename detail::index_set_domain_bind_t::type domain_member_type; - typedef std::integral_constant + typedef std::integral_constant rank; typedef typename view_origin_type::pattern_type pattern_type; - static constexpr std::size_t ndim() { return NDim; } + static constexpr dim_t ndim() { return NDim; } protected: domain_member_type _domain; @@ -510,12 +510,12 @@ class IndexSetBase return pattern().extents(); } - template + template constexpr size_type extent() const { return derived().extents()[ShapeDim]; } - constexpr size_type extent(std::size_t shape_dim) const { + constexpr size_type extent(dim_t shape_dim) const { return derived().extents()[shape_dim]; } @@ -526,12 +526,12 @@ class IndexSetBase return std::array { }; } - template + template constexpr index_type offset() const { return derived().offsets()[ShapeDim]; } - constexpr index_type offset(std::size_t shape_dim) const { + constexpr index_type offset(dim_t shape_dim) const { return derived().offsets()[shape_dim]; } @@ -704,7 +704,7 @@ class IndexSetIdentity template < class DomainType, - std::size_t SubDim > + dim_t SubDim > constexpr auto local(const IndexSetSub & index_set) -> decltype(index_set.local()) { @@ -713,7 +713,7 @@ local(const IndexSetSub & index_set) template < class DomainType, - std::size_t SubDim > + dim_t SubDim > constexpr auto global(const IndexSetSub & index_set) -> decltype(index_set.global()) { @@ -725,7 +725,7 @@ global(const IndexSetSub & index_set) */ template < class DomainType, - std::size_t SubDim = 0 > + dim_t SubDim = 0 > class IndexSetSub : public IndexSetBase< IndexSetSub, @@ -754,7 +754,7 @@ class IndexSetSub index_type _domain_begin_idx; index_type _domain_end_idx; - static constexpr std::size_t NDim = base_t::ndim(); + static constexpr dim_t NDim = base_t::ndim(); public: /** * Constructor, creates index set for given view. @@ -782,7 +782,7 @@ class IndexSetSub // ---- extents --------------------------------------------------------- - template + template constexpr size_type extent() const { return ( ExtDim == SubDim ? _domain_end_idx - _domain_begin_idx @@ -790,7 +790,7 @@ class IndexSetSub ); } - constexpr size_type extent(std::size_t shape_dim) const { + constexpr size_type extent(dim_t shape_dim) const { return ( shape_dim == SubDim ? _domain_end_idx - _domain_begin_idx : this->domain().extent(shape_dim) @@ -805,7 +805,7 @@ class IndexSetSub // ---- offsets --------------------------------------------------------- - template + template constexpr index_type offset() const { return ( ExtDim == SubDim ? _domain_begin_idx @@ -813,7 +813,7 @@ class IndexSetSub ); } - constexpr index_type offset(std::size_t shape_dim) const { + constexpr index_type offset(dim_t shape_dim) const { return ( shape_dim == SubDim ? _domain_begin_idx : this->domain().offset(shape_dim) @@ -828,7 +828,7 @@ class IndexSetSub // ---- size ------------------------------------------------------------ - constexpr size_type size(std::size_t sub_dim = 0) const { + constexpr size_type size(dim_t sub_dim = 0) const { return extent(sub_dim) * (sub_dim + 1 < NDim && NDim > 0 ? size(sub_dim + 1) @@ -1003,12 +1003,12 @@ class IndexSetLocal return this->pattern().local_extents(); } - template + template constexpr index_type extent() const noexcept { return this->pattern().local_extents()[ShapeDim]; } - constexpr index_type extent(std::size_t shape_dim) const noexcept { + constexpr index_type extent(dim_t shape_dim) const noexcept { return this->pattern().local_extents()[shape_dim]; } @@ -1020,19 +1020,19 @@ class IndexSetLocal return std::array { }; } - template + template constexpr index_type offset() const { return derived().offsets()[ShapeDim]; } - constexpr index_type offset(std::size_t shape_dim) const { + constexpr index_type offset(dim_t shape_dim) const { return derived().offsets()[shape_dim]; } #endif // ---- size ------------------------------------------------------------ - constexpr size_type size(std::size_t sub_dim) const noexcept { + constexpr size_type size(dim_t sub_dim) const noexcept { return _size; } @@ -1375,7 +1375,7 @@ class IndexSetBlocks // Rank of blocks index set should depend on blockspec dimensions of // the domain's pattern type. - static constexpr std::size_t NBlocksDim = blocks_ndim::value; + static constexpr dim_t NBlocksDim = blocks_ndim::value; public: constexpr static bool view_domain_is_local diff --git a/dash/include/dash/view/PatternIndexSet.h b/dash/include/dash/view/PatternIndexSet.h index 6fe5119e3..8c59c3de9 100644 --- a/dash/include/dash/view/PatternIndexSet.h +++ b/dash/include/dash/view/PatternIndexSet.h @@ -29,10 +29,10 @@ namespace dash { // Forward-declarations -template +template class IndexSetBase; -template +template class PatternIndexSetBase; template @@ -44,7 +44,7 @@ class IndexSetLocal; template class IndexSetGlobal; -template +template class IndexSetSub; template @@ -57,7 +57,7 @@ class IndexSetBlock; template < class IndexSetType, class DomainType, - std::size_t NDim = DomainType::rank::value > + dim_t NDim = DomainType::rank::value > class IndexSetBase { typedef IndexSetBase self_t; @@ -95,10 +95,10 @@ class IndexSetBase typedef typename detail::index_set_domain_bind_t::type domain_member_type; - typedef std::integral_constant + typedef std::integral_constant rank; - static constexpr std::size_t ndim() { return NDim; } + static constexpr dim_t ndim() { return NDim; } protected: domain_member_type _domain; @@ -194,12 +194,12 @@ class IndexSetBase return derived().extents(); } - template + template constexpr size_type extent() const { return derived().extents()[ShapeDim]; } - constexpr size_type extent(std::size_t shape_dim) const { + constexpr size_type extent(dim_t shape_dim) const { return derived().extents()[shape_dim]; } @@ -210,12 +210,12 @@ class IndexSetBase return std::array { }; } - template + template constexpr index_type offset() const { return derived().offsets()[ShapeDim]; } - constexpr index_type offset(std::size_t shape_dim) const { + constexpr index_type offset(dim_t shape_dim) const { return derived().offsets()[shape_dim]; } @@ -275,7 +275,7 @@ template < class IndexSetType, class DomainType, class PatternType, - std::size_t NDim = PatternType::ndim() > + dim_t NDim = PatternType::ndim() > class PatternIndexSetBase : public IndexSetBase< // IndexSetType, diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index dc569b95e..bb99292cd 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -58,7 +58,8 @@ struct view_traits > { typedef ViewBlockMod global_type; typedef typename DomainType::index_type index_type; - typedef typename view_traits::size_type size_type; + typedef typename DomainType::size_type size_type; +//typedef typename view_traits::size_type size_type; typedef typename std::conditional< NDim == 1, dash::IndexSetSub, diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index cae2a397d..b9d5166ab 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -22,7 +22,7 @@ namespace dash { -template +template class IndexSetBase; template @@ -34,7 +34,7 @@ class IndexSetLocal; template class IndexSetGlobal; -template +template class IndexSetSub; template From d460493423f10d0b685aa33bcc7e47a6c7fbc7ca Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 09:34:07 +0200 Subject: [PATCH 103/161] Cleanup dash::expand --- dash/include/dash/view/Expand.h | 108 ++------------------------------ 1 file changed, 5 insertions(+), 103 deletions(-) diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index 2523c9860..d5e65926e 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -46,10 +46,6 @@ namespace detail { class OffsetFinalT, typename DomainValueT = typename std::decay::type, - typename IndexT - = typename DomainValueT::index_type, - typename SizeT - = typename DomainValueT::size_type, typename OffsetsT, typename ExtentsT, typename std::enable_if< CurDim == 0, char >::type = 0 @@ -88,10 +84,6 @@ namespace detail { class OffsetFinalT, typename DomainValueT = typename std::decay::type, - typename IndexT - = typename DomainValueT::index_type, - typename SizeT - = typename DomainValueT::size_type, typename OffsetsT, typename ExtentsT, typename std::enable_if< (CurDim > 0), char >::type = 0 @@ -104,8 +96,7 @@ namespace detail { OffsetsT cur_offsets, ExtentsT cur_extents) { return expand_dim( - static_cast(begin), - static_cast(end), + begin, end, ( CurDim == SubDim // span in current dimension is to be expanded ? dash::sub( @@ -133,14 +124,10 @@ namespace detail { template < dim_t SubDim = 0, class DomainT, -//class OffsetFirstT, -//class OffsetFinalT, + class OffsetFirstT, + class OffsetFinalT, typename DomainValueT = typename std::decay::type, - typename IndexT - = typename DomainValueT::index_type, - typename SizeT - = typename DomainValueT::size_type, dim_t NDim = dash::view_traits::rank::value, typename std::enable_if< @@ -149,8 +136,8 @@ template < > constexpr auto expand( - IndexT begin, - SizeT end, + OffsetFirstT begin, + OffsetFinalT end, DomainT && domain) { return detail::expand_dim< static_cast(NDim - 1), @@ -163,91 +150,6 @@ expand( } -#if 0 - -template < - dim_t SubDim = 0, - class DomainT, - class OffsetFirstT, - class OffsetFinalT, - typename DomainValueT - = typename std::decay::type, - typename SecDomainT - = typename dash::view_traits::domain_type -> -constexpr auto -expand( - OffsetFirstT begin, - OffsetFinalT end, - DomainT && domain) - -> typename std::enable_if< - true || - dash::view_traits< - typename dash::view_traits::domain_type - >::is_origin::value, - ViewSubMod::rank::value > - >::type { - return ViewSubMod< - SecDomainT, - SubDim, - dash::view_traits::rank::value - >(dash::domain( - std::forward(domain)), - domain.offsets()[SubDim] + - ( domain.offsets()[SubDim] + begin > 0 - ? begin - : 0 ), - domain.offsets()[SubDim] + domain.extents()[SubDim] + - ( domain.offsets()[SubDim] + domain.extents()[SubDim] + end - < dash::domain(domain).extents()[SubDim] - ? end - : 0 )); -} - - - - - -template < - dim_t SubDim = 0, - class DomainT, - class OffsetFirstT, - class OffsetFinalT, - typename DomainValueT - = typename std::decay::type, - typename SecDomainT - = typename dash::view_traits::domain_type -> -constexpr auto -expand( - OffsetFirstT begin, - OffsetFinalT end, - DomainT && domain) - -> typename std::enable_if< - !dash::view_traits< - typename dash::view_traits::domain_type - >::is_origin::value, - ViewSubMod::rank::value > - >::type { - return ViewSubMod< - DomainValueT, - SubDim, - dash::view_traits::rank::value - >(std::forward(domain), - domain.offsets()[SubDim] + - ( domain.offsets()[SubDim] > 0 - ? begin - : 0 ), - domain.offsets()[SubDim] + domain.extents()[SubDim] + - ( domain.offsets()[SubDim] + domain.extents()[SubDim] - < dash::domain(domain).extents()[SubDim] - ? end - : 0 )); -} -#endif - template < dim_t SubDim = 0, class OffsetT0, From 52b1bcef593e9e819ddc013511f9e545724fb03c Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 09:58:36 +0200 Subject: [PATCH 104/161] Cleanup dash::expand --- .../examples/ex.02.matrix-halo-views/main.cpp | 58 ++++++------------- dash/examples/ex.02.matrix-sub-views/main.cpp | 12 ++-- dash/include/dash/view/Expand.h | 40 ++++++------- 3 files changed, 44 insertions(+), 66 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 4e50f3b31..0b5e4400b 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -75,59 +75,39 @@ int main(int argc, char *argv[]) "offsets:", matrix_view.offsets(), "extents:", matrix_view.extents()); - auto matrix_blocks = dash::blocks(matrix_view); + auto matrix_blocks = dash::blocks(matrix); auto matrix_b_idx = matrix_blocks | dash::index(); int b_idx = 0; for (const auto & m_block : matrix_blocks) { auto b_offsets = m_block.offsets(); auto b_extents = m_block.extents(); - print("matrix | block[" << matrix_b_idx[b_idx] << "]:\n " << + // matrix block view: + print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "]:" << + "\n " << dash::typestr(m_block) << + "\n " << "offsets: " << b_offsets[0] << "," << b_offsets[1] << " " << "extents: " << b_extents[0] << "," << b_extents[1] << nview_str(m_block, 4)); - // halo view: - auto b_halo = dash::sub<0>( - m_block.offsets()[0] > 0 - ? m_block.offsets()[0] -1 - : m_block.offsets()[0], - m_block.offsets()[0] + m_block.extents()[0] - < matrix_view.extents()[0] - ? m_block.offsets()[0] + m_block.extents()[0] + 1 - : m_block.offsets()[0] + m_block.extents()[0], - dash::sub<1>( - m_block.offsets()[1] > 0 - ? m_block.offsets()[1] -1 - : m_block.offsets()[1], - m_block.offsets()[1] + m_block.extents()[1] - < matrix_view.extents()[1] - ? m_block.offsets()[1] + m_block.extents()[1] + 1 - : m_block.offsets()[1] + m_block.extents()[1], - matrix_view)); + // matrix block halo view: + auto b_halo = m_block | dash::expand<0>(-1, 1) + | dash::expand<1>(-1, 1); + auto bh_offsets = b_halo.offsets(); auto bh_extents = b_halo.extents(); - print("matrix | block[" << matrix_b_idx[b_idx] << "] | " << - "expand({ -1,1 }, { -1,1 })\n " << + print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + "expand({ -1,1 }, { -1,1 }):" << + "\n " << dash::typestr(b_halo) << + "\n " << "offsets: " << bh_offsets[0] << "," << bh_offsets[1] << " " << "extents: " << bh_extents[0] << "," << bh_extents[1] << nview_str(b_halo, 4)); #if 0 - auto b_halo_isect = dash::difference( - m_block, - dash::sub<0>( - 1, m_block.extents()[0] - 1, - dash::sub<1>( - 1, m_block.extents()[1] - 1, - m_block))); -#endif - -#if 1 - auto b_halo_exp = dash::expand<0>(-1, 1, - dash::expand<1>(-1, 1, - m_block - ) - ); - print("matrix | block(n) | expand<0>({ -1,1 })" << - nview_str(b_halo_exp, 4)); + auto bh_blocks = b_halo | dash::blocks(); + for (const auto & bh_block : bh_blocks) { + print("matrix | block[" << matrix_b_idx[b_idx] << "] | " << + "expand({ -1,1 }, { -1,1 }) | block(n)" << + nview_str(bh_block, 4)); + } #endif ++b_idx; } diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 9f0f08d03..1bcccdf5a 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -80,25 +80,25 @@ int main(int argc, char *argv[]) nview_str(matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1)) << '\n'); - print("matrix | blocks | local"); + print("\nmatrix | blocks | local"); auto m_blocks_l = matrix | blocks() | local(); auto m_blocks_l_idx = m_blocks_l | index(); int lb_idx = 0; for (const auto & blk : m_blocks_l) { - print("--- local blocks[" << m_blocks_l_idx[lb_idx++] << "]" << - nview_str(blk) << '\n'); + print("\n --- local blocks[" << m_blocks_l_idx[lb_idx++] << "]" << + nview_str(blk)); } - print("matrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); + print("\nmatrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); auto m_s_blocks = matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1) | blocks(); auto m_s_blocks_idx = m_s_blocks | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { - print("--- blocks[" << m_s_blocks_idx[b_idx++] << "]" << - nview_str(blk) << '\n'); + print("\n --- blocks[" << m_s_blocks_idx[b_idx++] << "]" << + nview_str(blk)); } } dash::barrier(); diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index d5e65926e..e0b9b117f 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -44,11 +44,9 @@ namespace detail { class DomainT, class OffsetFirstT, class OffsetFinalT, - typename DomainValueT - = typename std::decay::type, typename OffsetsT, typename ExtentsT, - typename std::enable_if< CurDim == 0, char >::type = 0 + typename std::enable_if< (CurDim < 0), char >::type = 0 > constexpr auto expand_dim( @@ -57,23 +55,7 @@ namespace detail { DomainT && domain, OffsetsT cur_offsets, ExtentsT cur_extents) { - return ( CurDim == SubDim - // span in current dimension is to be expanded - ? dash::sub( - ( cur_offsets[CurDim] + begin > 0 - ? cur_offsets[CurDim] + begin - : 0 ), - ( cur_offsets[CurDim] + cur_extents[CurDim] + end < - domain.extents()[CurDim] - ? cur_offsets[CurDim] + cur_extents[CurDim] + end - : domain.extents()[CurDim] ), - std::forward(domain)) - // span in current dimension is unchanged - : dash::sub( - (cur_offsets[CurDim]), - (cur_offsets[CurDim] + cur_extents[CurDim]), - std::forward(domain)) - ); + return std::forward(domain); } template < @@ -86,7 +68,7 @@ namespace detail { = typename std::decay::type, typename OffsetsT, typename ExtentsT, - typename std::enable_if< (CurDim > 0), char >::type = 0 + typename std::enable_if< (CurDim >= 0), char >::type = 0 > constexpr auto expand_dim( @@ -166,6 +148,22 @@ static inline auto expand(OffsetT0 a, OffsetT1 b) { }); } +template < + dim_t SubDim = 0, + class OffsetT0, + class OffsetT1, + typename std::enable_if< + ( std::is_integral::value && + std::is_integral::value ), + int + >::type = 0 > +static inline auto shift(OffsetT0 a, OffsetT1 b) { + return dash::make_pipeable( + [=](auto && x) { + return expand(a,b, std::forward(x)); + }); +} + } // namespace dash #endif // DASH__VIEW__EXPAND_H__INCLUDED From 87e37038d7927835ace97134939f4c086e3a8181 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 12:10:09 +0200 Subject: [PATCH 105/161] Added view operation dash::shift --- .../examples/ex.02.matrix-halo-views/main.cpp | 22 +++++++++++++++++++ dash/include/dash/view/Expand.h | 11 +++++----- dash/test/algorithm/CopyTest.cc | 22 ++++++++++--------- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 0b5e4400b..16903a3ee 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -12,6 +12,13 @@ using uint = unsigned int; int main(int argc, char *argv[]) { + using dash::local; + using dash::expand; + using dash::shift; + using dash::sub; + using dash::blocks; + using dash::index; + dash::init(&argc, &argv); auto myid = dash::myid(); @@ -81,6 +88,7 @@ int main(int argc, char *argv[]) for (const auto & m_block : matrix_blocks) { auto b_offsets = m_block.offsets(); auto b_extents = m_block.extents(); + // matrix block view: print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "]:" << "\n " << dash::typestr(m_block) << @@ -88,6 +96,7 @@ int main(int argc, char *argv[]) "offsets: " << b_offsets[0] << "," << b_offsets[1] << " " << "extents: " << b_extents[0] << "," << b_extents[1] << nview_str(m_block, 4)); + // matrix block halo view: auto b_halo = m_block | dash::expand<0>(-1, 1) | dash::expand<1>(-1, 1); @@ -101,6 +110,19 @@ int main(int argc, char *argv[]) "offsets: " << bh_offsets[0] << "," << bh_offsets[1] << " " << "extents: " << bh_extents[0] << "," << bh_extents[1] << nview_str(b_halo, 4)); + + // matrix shifted block halo: + auto b_halo_s = b_halo | shift<1>(1); + + auto bhs_offsets = b_halo_s.offsets(); + auto bhs_extents = b_halo_s.extents(); + print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + "expand({ -1,1 }, { -1,1 }) | shift(1):" << + "\n " << dash::typestr(b_halo_s) << + "\n " << + "offsets: " << bhs_offsets[0] << "," << bhs_offsets[1] << " " << + "extents: " << bhs_extents[0] << "," << bhs_extents[1] << + nview_str(b_halo_s, 4)); #if 0 auto bh_blocks = b_halo | dash::blocks(); for (const auto & bh_block : bh_blocks) { diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index e0b9b117f..bf964f5d3 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -150,17 +150,16 @@ static inline auto expand(OffsetT0 a, OffsetT1 b) { template < dim_t SubDim = 0, - class OffsetT0, - class OffsetT1, + class OffsetT, typename std::enable_if< - ( std::is_integral::value && - std::is_integral::value ), + std::is_integral::value, int >::type = 0 > -static inline auto shift(OffsetT0 a, OffsetT1 b) { +static inline auto shift(OffsetT offs) { return dash::make_pipeable( [=](auto && x) { - return expand(a,b, std::forward(x)); + return expand( + offs,offs, std::forward(x)); }); } diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 2abe0cf32..21d18d5f9 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -172,9 +172,6 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) // Block is assigned to selecte remote unit, create local copy: auto remote_block_matrix = matrix.block(gb); auto remote_block_view = dash::blocks(matrix)[gb]; - auto remote_block_range = dash::make_range( - remote_block_view.begin(), - remote_block_view.end()); DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block view:", @@ -209,6 +206,11 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), dash::index(remote_block_view).extents()); +#if 0 + auto remote_block_range = dash::make_range( + remote_block_view.begin(), + remote_block_view.end()); + DASH_LOG_DEBUG("CopyTest.Blocking2DimGlobalToLocalBlock", "source block range:", dash::typestr(remote_block_range)); @@ -241,13 +243,13 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) dash::index(remote_block_range).offsets()); EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), dash::index(remote_block_range).extents()); - -// copy_dest_last = dash::copy(remote_block_view.begin(), -// remote_block_view.end(), -// copy_dest_begin); -// // Validate number of copied elements: -// auto num_copied = copy_dest_last - copy_dest_begin; -// EXPECT_EQ_U(num_copied, block_size); +#endif + copy_dest_last = dash::copy(remote_block_view.begin(), + remote_block_view.end(), + copy_dest_begin); + // Validate number of copied elements: + auto num_copied = copy_dest_last - copy_dest_begin; + EXPECT_EQ_U(num_copied, block_size); // Advance local copy destination pointer: copy_dest_begin = copy_dest_last; ++rb; From 05be9523b9a2624e2ca11466e07bb02bb464bf0a Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 13:13:59 +0200 Subject: [PATCH 106/161] Using deduced return type for view.extents, view.offsets --- dash/include/dash/view/IndexSet.h | 6 ++++-- dash/include/dash/view/ViewBlocksMod.h | 4 ++-- dash/include/dash/view/ViewMod.h | 4 ++-- dash/include/dash/view/ViewMod1D.h | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 5b1e7e181..c4379f9eb 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1646,13 +1646,15 @@ class IndexSetBlock ); } - constexpr index_type operator[](index_type block_phase) const noexcept { + constexpr index_type operator[](index_type block_phase) + const noexcept { return rel(block_phase); } template constexpr index_type operator[]( - const std::array & block_phase_coords) const noexcept { + const std::array & block_phase_coords) + const noexcept { return -1; } diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index bb99292cd..1dabd1f62 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -606,7 +606,7 @@ class ViewBlocksMod // ---- extents --------------------------------------------------------- - constexpr std::array extents() const { + constexpr decltype(_index_set.extents()) extents() const { return _index_set.extents(); } @@ -626,7 +626,7 @@ class ViewBlocksMod return _index_set.template offset(); } - constexpr std::array offsets() const { + constexpr decltype(_index_set.offsets()) offsets() const { return _index_set.offsets(); } diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index f264648bc..667ea3ea0 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -652,7 +652,7 @@ class ViewSubMod // ---- extents --------------------------------------------------------- - constexpr std::array extents() const { + constexpr decltype(_index_set.extents()) extents() const { return _index_set.extents(); } @@ -672,7 +672,7 @@ class ViewSubMod return _index_set.template offset(); } - constexpr std::array offsets() const { + constexpr decltype(_index_set.offsets()) offsets() const { return _index_set.offsets(); } diff --git a/dash/include/dash/view/ViewMod1D.h b/dash/include/dash/view/ViewMod1D.h index b9d5166ab..9f7cae81e 100644 --- a/dash/include/dash/view/ViewMod1D.h +++ b/dash/include/dash/view/ViewMod1D.h @@ -1395,7 +1395,7 @@ class IteratorRange // ---- extents ------------------------------------------------------- - constexpr std::array extents() const { + constexpr decltype(_index_set.extents()) extents() const { return _index_set.extents(); } @@ -1415,7 +1415,7 @@ class IteratorRange return _index_set.template offset(); } - constexpr std::array offsets() const { + constexpr decltype(_index_set.offsets()) offsets() const { return _index_set.offsets(); } From f8840fb660d9cb35b65419ba638a166ef03d47e5 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 15:23:21 +0200 Subject: [PATCH 107/161] Fixed IndexSetLocal for ndim blocks --- dash/examples/ex.02.matrix-views/main.cpp | 106 ++++++++++++++-------- dash/examples/util.h | 2 +- dash/include/dash/algorithm/Copy.h | 52 ++++++----- dash/include/dash/view/IndexSet.h | 65 ++++++++++--- 4 files changed, 151 insertions(+), 74 deletions(-) diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index 42cde5398..b40c1e73d 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -40,8 +40,8 @@ int main(int argc, char *argv[]) } typedef dash::ShiftTilePattern<2> pattern_t; - typedef typename pattern_t::index_type index_t; - typedef float value_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; pattern_t pattern( dash::SizeSpec<2>( @@ -56,22 +56,26 @@ int main(int argc, char *argv[]) matrix(pattern); // Initialize matrix values: - for (size_t lb = 0; lb < num_blocks_per_unit; ++lb) { - auto lblock = matrix.local.block(lb); - auto lblock_view = lblock.begin().viewspec(); - auto lblock_extents = lblock_view.extents(); - auto lblock_offsets = lblock_view.offsets(); - dash__unused(lblock_offsets); - for (auto bx = 0; bx < static_cast(lblock_extents[0]); ++bx) { - for (auto by = 0; by < static_cast(lblock_extents[1]); ++by) { - // Phase coordinates (bx,by) to global coordinates (gx,gy): - value_t value = static_cast(dash::myid().id + 1) + - 0.00001 * ( - ((lb + 1) * 10000) + ((bx + 1) * 100) + by + 1); - lblock[bx][by] = value; - } - } +#if 0 + if (myid == 0) { + int gi = 0; + std::generate(matrix.begin(), + matrix.end(), + [&]() { + auto u = matrix.pattern().unit_at( + matrix.pattern().coords(gi)); + return u + 0.01 * gi++; + }); } +#else + int li = 0; + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { + auto u = dash::myid(); + return u + 0.01 * li++; + }); +#endif dash::barrier(); if (myid == 0) { @@ -154,8 +158,7 @@ int main(int argc, char *argv[]) remote_block_view.begin(), remote_block_view.end())); - DASH_LOG_DEBUG("MatrixViewsExample", - "source block view:", "-- type:", + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", dash::typestr(remote_block_view)); DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", "source block view iterator:", @@ -184,16 +187,54 @@ int main(int argc, char *argv[]) "end.gpos:", remote_block_view.end().gpos()); DASH_LOG_DEBUG("MatrixViewsExample", "block view:", nview_str(remote_block_view)); - DASH_LOG_DEBUG("MatrixViewsExample", "block view is strided:", - dash::index(remote_block_view).is_strided()); - // DASH_LOG_DEBUG("MatrixViewsExample", "local(block view):", - // nview_str(dash::local(remote_block_view))); - // DASH_ASSERT(remote_block_matrix.viewspec().offsets() == - // dash::index(remote_block_view).offsets()); - // DASH_ASSERT(remote_block_matrix.viewspec().extents() == - // dash::index(remote_block_view).extents()); + DASH_LOG_DEBUG("MatrixViewsExample", "block view index type:", + dash::typestr( + dash::index(remote_block_view))); + DASH_LOG_DEBUG("MatrixViewsExample", "block view index is strided:", + dash::index(remote_block_view) + .is_strided()); + + DASH_LOG_DEBUG("MatrixViewsExample", "local block view index type:", + dash::typestr( + dash::index(dash::local(remote_block_view)))); + DASH_LOG_DEBUG("MatrixViewsExample", + "local block view index is strided:", + dash::index(dash::local(remote_block_view)) + .is_strided()); + DASH_LOG_DEBUG("MatrixViewsExample", + "local block view index domain type:", + dash::typestr( + dash::domain( + dash::index(dash::local(remote_block_view))))); + DASH_LOG_DEBUG("MatrixViewsExample", + "local block view index domain is strided:", + dash::domain( + dash::index(dash::local(remote_block_view))) + .is_strided()); + + DASH_LOG_DEBUG("MatrixViewsExample", + "local block view index set size:", + dash::index(dash::local(remote_block_view)) + .size()); + + DASH_ASSERT(remote_block_matrix.viewspec().offsets() == + dash::index(remote_block_view).offsets()); + DASH_ASSERT(remote_block_matrix.viewspec().extents() == + dash::index(remote_block_view).extents()); + + copy_dest_last = dash::copy(remote_block_view, + copy_dest_begin); + + // Test number of copied elements: + auto num_copied = copy_dest_last - copy_dest_begin; + DASH_ASSERT(num_copied == block_size); + + // Advance local copy destination pointer: + copy_dest_begin = copy_dest_last; + +#if 0 DASH_LOG_DEBUG("MatrixViewsExample", "source block range:", "-- type:", dash::typestr(remote_block_range)); @@ -230,17 +271,6 @@ int main(int argc, char *argv[]) nview_str(remote_block_range)); DASH_LOG_DEBUG("MatrixViewsExample", "local(block range):", nview_str(dash::local(remote_block_range))); -#if 0 - copy_dest_last = dash::copy(remote_block_view.begin(), - remote_block_view.end(), - copy_dest_begin); - - // Test number of copied elements: - auto num_copied = copy_dest_last - copy_dest_begin; - DASH_ASSERT(num_copied == block_size); - - // Advance local copy destination pointer: - copy_dest_begin = copy_dest_last; #endif DASH_LOG_DEBUG("MatrixViewsExample", "^^^^^^^^^^^^^^^^^^^^^^^^^^^"); } diff --git a/dash/examples/util.h b/dash/examples/util.h index 58ce1f17b..5de6b8f93 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -15,7 +15,7 @@ std::istringstream iss(mss.str()); \ std::string item; \ while (std::getline(iss, item)) { \ - oss << "[ " << dash::myid() << " ] "; \ + oss << "[ " << dash::myid() << " ] 0) { - DASH_LOG_TRACE("dash::copy", + DASH_LOG_TRACE("dash::copy:range", "copy global range preceding local subrange", "g_in_first:", g_in_first.pos(), "g_in_last:", g_l_in_first.pos()); @@ -972,14 +980,14 @@ auto copy( // ValueType * l_in_first = g_l_in_first.local(); ValueType * l_in_last = l_in_first + num_local_elem; - DASH_LOG_TRACE_VAR("dash::copy", l_in_first); - DASH_LOG_TRACE_VAR("dash::copy", l_in_last); + DASH_LOG_TRACE_VAR("dash::copy:range", l_in_first); + DASH_LOG_TRACE_VAR("dash::copy:range", l_in_last); // Verify conversion of global input iterators to local pointers: DASH_ASSERT_MSG(l_in_first != nullptr, - "dash::copy: first index in global input (" << + "dash::copy:range: first index in global input (" << g_l_in_first.pos() << ") is not local"); - DASH_LOG_TRACE("dash::copy", "copy local subrange", + DASH_LOG_TRACE("dash::copy:range", "copy local subrange", "num_copy_elem:", l_in_last - l_in_first); // Use memcpy for data ranges below 64 KB if (use_memcpy) { @@ -997,7 +1005,7 @@ auto copy( "Expected to copy " << num_local_elem << " local elements " "but copied " << (out_last - dest_first)); - DASH_LOG_TRACE("dash::copy", "finished local copy of", + DASH_LOG_TRACE("dash::copy:range", "finished local copy of", (out_last - dest_first), "elements"); // Advance output pointers: dest_first = out_last; @@ -1006,7 +1014,7 @@ auto copy( // Copy remote elements succeeding the local subrange: // if (num_postlocal_elem > 0) { - DASH_LOG_TRACE("dash::copy", + DASH_LOG_TRACE("dash::copy:range", "copy global range succeeding local subrange", "in_first:", g_l_in_last.pos(), "in_last:", g_in_last.pos()); @@ -1018,13 +1026,13 @@ auto copy( dest_first); } } else { - DASH_LOG_TRACE("dash::copy", "no local subrange"); + DASH_LOG_TRACE("dash::copy:range", "no local subrange"); // All elements in input range are remote out_last = dash::internal::copy_block(in_first, in_last, dest_first); } - DASH_LOG_TRACE("dash::copy >", "finished,", + DASH_LOG_TRACE("dash::copy:range >", "finished,", "out_last:", out_last); return out_last; } @@ -1049,6 +1057,8 @@ ValueType * copy( auto in_range = dash::make_range(in_first, in_last); DASH_LOG_TRACE("dash::copy", "source value range:", in_range); DASH_LOG_TRACE("dash::copy", "source index range:", dash::index(in_range)); + DASH_LOG_TRACE("dash::copy", "source range extents:", in_range.extents()); + DASH_LOG_TRACE("dash::copy", "source range offsets:", in_range.offsets()); return dash::copy(in_range, out_first); } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index c4379f9eb..99a78dba3 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -480,7 +480,9 @@ class IndexSetBase constexpr bool is_sub() const noexcept { return ( - derived().size() < this->pattern().size() + this->is_local() + ? derived().size() < this->pattern().local_size() + : derived().size() < this->pattern().size() ); } @@ -973,6 +975,17 @@ class IndexSetLocal , _size(calc_size()) { } + constexpr bool is_strided() const noexcept { + return ( + // Local sub range of one-dimensional range is contiguous: + this->ndim() == 1 + ? base_t::is_strided() + : // Elements are contiguous within single block, block view + // is not strided: + this->domain().is_strided() + ); + } + constexpr const local_type & local() const noexcept { return *this; } @@ -1068,19 +1081,35 @@ class IndexSetLocal ? this->pattern().local_size() // parent domain is sub-space, calculate size from sub-range: : ( !this->is_strided() - // blocked (not blockcyclic) distribution: single local - // element space with contiguous global index range - ? this->index_range_size( - this->index_range_intersect( - // local range in global index space: - { this->pattern().lbegin(), - this->pattern().lend() - 1 }, - // domain range in global index space; - { this->domain().first(), - this->domain().last() } - )) + 1 - // blockcyclic distribution: local element space chunked - // in global index range + // blocked (not blockcyclic) distribution: single local + // element space with contiguous global index range + ? ( this->ndim() == 1 + // one-dimensional, simple intersect: + ? this->index_range_size( + this->index_range_intersect( + // local range in global index space: + { this->pattern().lbegin(), + this->pattern().lend() - 1 }, + // domain range in global index space; + { this->domain().first(), + this->domain().last() } + )) + 1 + // multi-dimensional, size calculation requires view spec: + : ( this->pattern().block_at( + this->pattern().coords(this->domain().first())) == + this->pattern().block_at( + this->pattern().coords(this->domain().last())) + // First and last element are in same block so entire + // range is within single block: + ? ( this->pattern().unit_at(this->domain().first()) == + this->pattern().team().myid() + ? this->domain().size() + : 0 ) + // Range spans multiple blocks: + : 123 ) + ) + // strided, e.g. blockcyclic distribution: local element space + // chunked in global index range : this->index_range_size( this->index_range_g2l( this->pattern(), @@ -1586,6 +1615,14 @@ class IndexSetBlock , _size(calc_size(block_idx)) { } + constexpr bool is_strided() const noexcept { + return ( + // Elements are contiguous within single block, block view + // is not strided: + !dash::pattern_layout_traits::type::blocked + ); + } + // ---- extents --------------------------------------------------------- constexpr std::array From d38dd866623b5318763555c89059b732ded79268 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 15:36:02 +0200 Subject: [PATCH 108/161] Fixed ex.02.matrix-views example --- dash/examples/ex.02.matrix-views/main.cpp | 1 + dash/include/dash/algorithm/Copy.h | 7 ------- dash/test/algorithm/CopyTest.cc | 14 +++++++++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index b40c1e73d..7522a3192 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -275,6 +275,7 @@ int main(int argc, char *argv[]) DASH_LOG_DEBUG("MatrixViewsExample", "^^^^^^^^^^^^^^^^^^^^^^^^^^^"); } } + print("local copy of all remote values:\n" << local_copy); dash::finalize(); return EXIT_SUCCESS; diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index fc4efa6ed..587c7215b 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -860,16 +860,9 @@ auto copy( DASH_LOG_TRACE("dash::copy:range", "source global in first:", in_first); DASH_LOG_TRACE("dash::copy:range", "source global in last:", in_last); - auto l_range_in = dash::local( - in_range); - - DASH_LOG_TRACE("dash::copy:range", "source global to local:", l_range_in); - auto li_range_in = dash::index( dash::local( in_range)); - DASH_LOG_TRACE("dash::copy:range", "source local range:", - l_range_in); DASH_LOG_TRACE("dash::copy:range", "source local index range:", li_range_in); DASH_LOG_TRACE("dash::copy:range", "source g(local) index range:", diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 21d18d5f9..3b18f41b7 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -205,6 +205,14 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) dash::index(remote_block_view).offsets()); EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), dash::index(remote_block_view).extents()); +#if 0 + copy_dest_last = dash::copy(remote_block_view.begin(), + remote_block_view.end(), + copy_dest_begin); +#else + copy_dest_last = dash::copy(remote_block_view, + copy_dest_begin); +#endif #if 0 auto remote_block_range = dash::make_range( @@ -243,10 +251,10 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) dash::index(remote_block_range).offsets()); EXPECT_EQ_U(remote_block_matrix.viewspec().extents(), dash::index(remote_block_range).extents()); -#endif - copy_dest_last = dash::copy(remote_block_view.begin(), - remote_block_view.end(), + + copy_dest_last = dash::copy(remote_block_range, copy_dest_begin); +#endif // Validate number of copied elements: auto num_copied = copy_dest_last - copy_dest_begin; EXPECT_EQ_U(num_copied, block_size); From 75e7da729c806837d8d560a6931ea1d8762bc146 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 16:46:52 +0200 Subject: [PATCH 109/161] Added dash::intersect view operation --- dash/examples/ex.02.matrix-sub-views/main.cpp | 13 ++- dash/examples/ex.02.matrix-views/main.cpp | 13 +-- dash/include/dash/view/SetIntersect.h | 86 ++++++++++++++++++- 3 files changed, 104 insertions(+), 8 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 1bcccdf5a..682119091 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -80,6 +80,7 @@ int main(int argc, char *argv[]) nview_str(matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1)) << '\n'); +#if 0 print("\nmatrix | blocks | local"); auto m_blocks_l = matrix | blocks() | local(); @@ -89,6 +90,7 @@ int main(int argc, char *argv[]) print("\n --- local blocks[" << m_blocks_l_idx[lb_idx++] << "]" << nview_str(blk)); } +#endif print("\nmatrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); auto m_s_blocks = matrix | sub<0>(1, extent_y-1) @@ -97,8 +99,17 @@ int main(int argc, char *argv[]) auto m_s_blocks_idx = m_s_blocks | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { - print("\n --- blocks[" << m_s_blocks_idx[b_idx++] << "]" << + print("\n --- blocks[" << m_s_blocks_idx[b_idx] << "]" << nview_str(blk)); + + auto m_isect = matrix | sub<0>(1, extent_y-1) + | sub<1>(1, extent_x-1) + | intersect(blk); + + print("\n --- blocks[" << m_s_blocks_idx[b_idx] << "] | isect" << + nview_str(m_isect)); + + ++b_idx; } } dash::barrier(); diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index 7522a3192..aa388e0d4 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -151,12 +151,8 @@ int main(int argc, char *argv[]) // Block is assigned to selecte remote unit, create local copy: auto remote_block_matrix = matrix.block(gb); - auto remote_block_view = // dash::sub(1,2, - dash::blocks(matrix)[gb]; - auto remote_block_range = dash::sub(1,2, - dash::make_range( - remote_block_view.begin(), - remote_block_view.end())); + auto remote_block_view = dash::sub(1,5, + dash::blocks(matrix)[gb]); DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", dash::typestr(remote_block_view)); @@ -235,6 +231,11 @@ int main(int argc, char *argv[]) copy_dest_begin = copy_dest_last; #if 0 + auto remote_block_range = dash::sub(1,5, + dash::make_range( + remote_block_view.begin(), + remote_block_view.end())); + DASH_LOG_DEBUG("MatrixViewsExample", "source block range:", "-- type:", dash::typestr(remote_block_range)); diff --git a/dash/include/dash/view/SetIntersect.h b/dash/include/dash/view/SetIntersect.h index ed3045eba..e05fd9f64 100644 --- a/dash/include/dash/view/SetIntersect.h +++ b/dash/include/dash/view/SetIntersect.h @@ -5,6 +5,7 @@ #include #include +#include namespace dash { @@ -14,7 +15,12 @@ namespace dash { */ template < class ViewTypeA, - class ViewTypeB > + class ViewTypeB, + typename std::enable_if< + dash::view_traits::rank::value == 1 && + dash::view_traits::rank::value == 1, + int >::type = 0 +> constexpr auto intersect( const ViewTypeA & va, @@ -38,6 +44,84 @@ intersect( ); } +namespace detail { + +template < + dim_t CurDim, + class ViewTypeA, + class ViewTypeB, + typename std::enable_if< (CurDim < 0), int >::type = 0 +> +constexpr auto +intersect_dim( + ViewTypeA && va, + ViewTypeB && vb) { + return std::forward(va); +} + +template < + dim_t CurDim, + class ViewTypeA, + class ViewTypeB, + dim_t NDimA = dash::view_traits::rank::value, + dim_t NDimB = dash::view_traits::rank::value, + typename std::enable_if< + (NDimA == NDimB) && (NDimA > 1) && (NDimB > 1) && + (CurDim >= 0), + int >::type = 0 +> +constexpr auto +intersect_dim( + const ViewTypeA & va, + ViewTypeB && vb) { + return intersect_dim( + dash::expand( + std::max( + 0, std::forward(vb).offsets()[CurDim] - + (va).offsets()[CurDim] + ), + std::min( + 0, ( std::forward(vb).offsets()[CurDim] + + std::forward(vb).extents()[CurDim] ) - + ( (va).offsets()[CurDim] + + (va).extents()[CurDim] ) + ), + (va) + ), + std::forward(vb)); +} + +} // namespace detail + +template < + class ViewTypeA, + class ViewTypeB, + dim_t NDimA = dash::view_traits::rank::value, + dim_t NDimB = dash::view_traits::rank::value, + typename std::enable_if< + (NDimA == NDimB) && (NDimA > 1) && (NDimB > 1), + int >::type = 0 +> +constexpr auto +intersect( + const ViewTypeA & va, + ViewTypeB && vb) { + return detail::intersect_dim( + va, + std::forward(vb)); +} + +template < + class ViewType > +static inline auto intersect(const ViewType & v_rhs) { + return dash::make_pipeable( + [=](auto && v_lhs) { + return intersect( + std::forward(v_lhs), + v_rhs); + }); +} + } // namespace dash #endif // DASH__VIEW__SET_INTERSECT_H__INCLUDED From 9e7fb8ce694758cab84b0c6627d320627ad97791 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 23 Sep 2017 17:00:28 +0200 Subject: [PATCH 110/161] Cleanup ex.02.matrix-sub-views example --- dash/examples/ex.02.matrix-sub-views/main.cpp | 42 ++++--------------- dash/include/dash/algorithm/Copy.h | 4 +- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 682119091..4c90b90e4 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -50,25 +50,13 @@ int main(int argc, char *argv[]) dash::Matrix matrix(pattern); - if (myid == 0) { - int gi = 0; - std::generate(matrix.begin(), - matrix.end(), - [&]() { - auto u = matrix.pattern().unit_at( - matrix.pattern().coords(gi)); - return u + 0.01 * gi++; - }); - } - -#if 0 int li = 0; - for (auto lit = matrix.local.begin(); - lit != matrix.local.end(); - ++li, ++lit) { - print("matrix.local[" << li << "] = " << static_cast(*lit)); - } -#endif + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { + auto u = dash::myid(); + return u + 0.01 * li++; + }); dash::barrier(); @@ -80,18 +68,6 @@ int main(int argc, char *argv[]) nview_str(matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1)) << '\n'); -#if 0 - print("\nmatrix | blocks | local"); - auto m_blocks_l = matrix | blocks() - | local(); - auto m_blocks_l_idx = m_blocks_l | index(); - int lb_idx = 0; - for (const auto & blk : m_blocks_l) { - print("\n --- local blocks[" << m_blocks_l_idx[lb_idx++] << "]" << - nview_str(blk)); - } -#endif - print("\nmatrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); auto m_s_blocks = matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1) @@ -99,14 +75,12 @@ int main(int argc, char *argv[]) auto m_s_blocks_idx = m_s_blocks | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { - print("\n --- blocks[" << m_s_blocks_idx[b_idx] << "]" << - nview_str(blk)); - auto m_isect = matrix | sub<0>(1, extent_y-1) | sub<1>(1, extent_x-1) | intersect(blk); - print("\n --- blocks[" << m_s_blocks_idx[b_idx] << "] | isect" << + print("\n --- matrix | sub {1,-1} {1-1} | intersect(" << + "block(" << m_s_blocks_idx[b_idx] << "))" << nview_str(m_isect)); ++b_idx; diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 587c7215b..a80cdc9ed 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1022,8 +1022,8 @@ auto copy( DASH_LOG_TRACE("dash::copy:range", "no local subrange"); // All elements in input range are remote out_last = dash::internal::copy_block(in_first, - in_last, - dest_first); + in_last, + dest_first); } DASH_LOG_TRACE("dash::copy:range >", "finished,", "out_last:", out_last); From f038f984ac7d27f257c0574db9ac634c75690854 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sun, 24 Sep 2017 03:38:36 +0200 Subject: [PATCH 111/161] Migrating dash::Matrix to view expressions --- .../examples/ex.02.matrix-halo-views/main.cpp | 7 - dash/examples/ex.02.matrix-ranges/main.cpp | 194 ++++++++++++++++++ dash/examples/ex.02.matrix-sub-views/main.cpp | 68 +++--- dash/examples/ex.02.matrix-views/main.cpp | 63 ------ dash/include/dash/Cartesian.h | 50 +++++ dash/include/dash/Meta.h | 36 ++++ dash/include/dash/util/ArrayExpr.h | 18 +- dash/include/dash/util/IndexSequence.h | 58 ++++++ dash/include/dash/util/LocalityDomain.h | 1 + dash/include/dash/view/Block.h | 49 ++++- dash/include/dash/view/IndexSet.h | 37 ++++ dash/include/dash/view/ViewBlocksMod.h | 24 +++ dash/include/dash/view/ViewMod.h | 22 ++ dash/test/container/MatrixTest.cc | 20 +- 14 files changed, 517 insertions(+), 130 deletions(-) create mode 100644 dash/examples/ex.02.matrix-ranges/main.cpp diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 16903a3ee..1f2cfaaf1 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -78,10 +78,6 @@ int main(int argc, char *argv[]) auto matrix_view = dash::sub(0, matrix.extents()[0], matrix); print("matrix" << nview_str(matrix_view, 4)); - DASH_LOG_DEBUG("MatrixViewsExample", "matrix", - "offsets:", matrix_view.offsets(), - "extents:", matrix_view.extents()); - auto matrix_blocks = dash::blocks(matrix); auto matrix_b_idx = matrix_blocks | dash::index(); int b_idx = 0; @@ -91,7 +87,6 @@ int main(int argc, char *argv[]) // matrix block view: print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "]:" << - "\n " << dash::typestr(m_block) << "\n " << "offsets: " << b_offsets[0] << "," << b_offsets[1] << " " << "extents: " << b_extents[0] << "," << b_extents[1] << @@ -105,7 +100,6 @@ int main(int argc, char *argv[]) auto bh_extents = b_halo.extents(); print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "] | " << "expand({ -1,1 }, { -1,1 }):" << - "\n " << dash::typestr(b_halo) << "\n " << "offsets: " << bh_offsets[0] << "," << bh_offsets[1] << " " << "extents: " << bh_extents[0] << "," << bh_extents[1] << @@ -118,7 +112,6 @@ int main(int argc, char *argv[]) auto bhs_extents = b_halo_s.extents(); print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "] | " << "expand({ -1,1 }, { -1,1 }) | shift(1):" << - "\n " << dash::typestr(b_halo_s) << "\n " << "offsets: " << bhs_offsets[0] << "," << bhs_offsets[1] << " " << "extents: " << bhs_extents[0] << "," << bhs_extents[1] << diff --git a/dash/examples/ex.02.matrix-ranges/main.cpp b/dash/examples/ex.02.matrix-ranges/main.cpp new file mode 100644 index 000000000..c47e635dd --- /dev/null +++ b/dash/examples/ex.02.matrix-ranges/main.cpp @@ -0,0 +1,194 @@ +#include +#include "../util.h" + +using std::cout; +using std::cerr; +using std::cin; +using std::endl; +using std::vector; + +using uint = unsigned int; + + +int main(int argc, char *argv[]) +{ + using namespace dash; + + dash::init(&argc, &argv); + + auto myid = dash::myid(); + auto nunits = dash::size(); + + const size_t block_size_x = 2; + const size_t block_size_y = 3; + const size_t block_size = block_size_x * block_size_y; + size_t num_local_blocks_x = 2; + size_t num_local_blocks_y = 2; + size_t num_blocks_x = nunits * num_local_blocks_x; + size_t num_blocks_y = nunits * num_local_blocks_y; + size_t num_blocks_total = num_blocks_x * num_blocks_y; + size_t extent_x = block_size_x * num_blocks_x; + size_t extent_y = block_size_y * num_blocks_y; + size_t num_elem_total = extent_x * extent_y; + // Assuming balanced mapping: + size_t num_elem_per_unit = num_elem_total / nunits; + size_t num_blocks_per_unit = num_elem_per_unit / block_size; + + typedef dash::ShiftTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + pattern_t pattern( + dash::SizeSpec<2>( + extent_y, + extent_x), + dash::DistributionSpec<2>( + dash::TILE(block_size_y), + dash::TILE(block_size_x)) + ); + + dash::Matrix + matrix(pattern); + + // Initialize matrix values: + int li = 0; + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { + auto u = dash::myid(); + return u + 0.01 * li++; + }); + dash::barrier(); + + if (myid == 0) { + print("matrix:" << + nview_str(dash::sub(0, matrix.extents()[0], matrix))); + + auto matrix_region = dash::size() > 1 + ? dash::sub<0>( + 2, matrix.extents()[0] - 2, + dash::sub<1>( + 2, matrix.extents()[1] - 3, + matrix)) + : dash::sub<0>( + 0, matrix.extents()[0], + dash::sub<1>( + 0, matrix.extents()[1], + matrix)); + + print("matrix | sub<0>(2,-2) | sub<1>(2,-3) \n" << + nview_str(matrix_region)); + + auto matrix_reg_blocks = dash::blocks(matrix_region); + for (const auto & reg_block : matrix_reg_blocks) { + auto sreg_block = dash::sub<0>(1,2, reg_block); + + DASH_LOG_DEBUG("MatrixViewsExample", "==============================", + nview_str(reg_block)); + DASH_LOG_DEBUG("MatrixViewsExample", + dash::typestr(sreg_block.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", + nview_str(sreg_block)); + + auto block_rg = dash::make_range(reg_block.begin(), + reg_block.end()); + auto block_srg = dash::sub<0>(1,2, block_rg); + + DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", + nview_str(block_rg)); + DASH_LOG_DEBUG("MatrixViewsExample", "block range origin iterator:", + dash::typestr(dash::origin(block_srg).begin())); + // DASH_LOG_DEBUG("MatrixViewsExample", "block range origin:", + // nview_str(dash::origin(block_srg))); + // DASH_LOG_DEBUG("MatrixViewsExample", + // nview_str(block_srg)); + } + } + dash::barrier(); + + // Array to store local copy: + std::vector local_copy(num_elem_per_unit); + // Pointer to first value in next copy destination range: + value_t * copy_dest_begin = local_copy.data(); + value_t * copy_dest_last = local_copy.data(); + + for (size_t gb = 0; gb < num_blocks_total; ++gb) { + // View of block at global block index gb: + auto g_block_view = pattern.block(gb); + // Unit assigned to block at global block index gb: + auto g_block_unit = pattern.unit_at( + std::array {0,0}, + g_block_view); + dash::team_unit_t remote_unit_id( + (dash::Team::All().myid().id + 1) % nunits); + if (g_block_unit == remote_unit_id) { + DASH_LOG_DEBUG("MatrixViewsExample", "==========================="); + DASH_LOG_DEBUG("MatrixViewsExample", + "block gidx", gb, + "at unit", g_block_unit.id); + DASH_LOG_DEBUG("MatrixViewsExample", "vvvvvvvvvvvvvvvvvvvvvvvvvvv"); + // Block is assigned to selecte remote unit, create local copy: + auto remote_block_matrix = matrix.block(gb); + + auto remote_block_view = dash::blocks(matrix)[gb]; + + // Test number of copied elements: + auto num_copied = copy_dest_last - copy_dest_begin; + DASH_ASSERT(num_copied == block_size); + + // Advance local copy destination pointer: + copy_dest_begin = copy_dest_last; + + auto remote_block_range = dash::sub(1,3, + dash::make_range( + remote_block_view.begin(), + remote_block_view.end())); + + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range:", "-- type:", + dash::typestr(remote_block_range)); + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", + "source block range iterator:", + dash::typestr(remote_block_range.begin())); + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", + "source block range domain:", + dash::typestr(dash::domain(remote_block_range))); + DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", + "source block range origin:", + dash::typestr(dash::origin(remote_block_range))); + + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range:", + "extents:", remote_block_range.extents(), + "offsets:", remote_block_range.offsets(), + "size:", remote_block_range.size()); + DASH_LOG_DEBUG("MatrixViewsExample", + "source block range domain:", + "extents:", dash::domain(remote_block_range).extents(), + "offsets:", dash::domain(remote_block_range).offsets(), + "size:", dash::domain(remote_block_range).size()); + DASH_LOG_DEBUG("MatrixViewsExample", + "begin.pos:", remote_block_range.begin().pos(), + "end.pos:", remote_block_range.end().pos(), + "begin.gpos:", remote_block_range.begin().gpos(), + "end.gpos:", remote_block_range.end().gpos()); + DASH_LOG_DEBUG("MatrixViewsExample", "block range index:", + nview_str(dash::index(remote_block_range))); + DASH_LOG_DEBUG("MatrixViewsExample", "block range index is strided:", + dash::index(remote_block_range).is_strided()); + DASH_LOG_DEBUG("MatrixViewsExample", "block range:", + nview_str(remote_block_range)); + DASH_LOG_DEBUG("MatrixViewsExample", "local(block range):", + nview_str(dash::local(remote_block_range))); + + copy_dest_last = dash::copy(remote_block_range, + copy_dest_begin); + + DASH_LOG_DEBUG("MatrixViewsExample", "^^^^^^^^^^^^^^^^^^^^^^^^^^^"); + } + } + print("local copy of all remote values:\n" << local_copy); + + dash::finalize(); + return EXIT_SUCCESS; +} diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 4c90b90e4..3eaf79209 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -25,12 +25,7 @@ int main(int argc, char *argv[]) size_t extent_x = block_size_x * nunits; size_t extent_y = block_size_y * nunits; - if (nunits < 2) { - cerr << "requires > 1 units" << endl; - return 1; - } - - typedef dash::TilePattern<2> pattern_t; + typedef dash::TilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; typedef float value_t; @@ -64,26 +59,47 @@ int main(int argc, char *argv[]) print("matrix:" << nview_str(matrix | sub(0,extent_y)) << '\n'); print("matrix.local.size(): " << matrix.local.size()); - print("matrix | sub<0>(1,-1) | sub<1>(1,-1)" << - nview_str(matrix | sub<0>(1, extent_y-1) - | sub<1>(1, extent_x-1)) << '\n'); - - print("\nmatrix | sub<0>(1,-1) | sub<1>(1,-1) | blocks()"); - auto m_s_blocks = matrix | sub<0>(1, extent_y-1) - | sub<1>(1, extent_x-1) - | blocks(); - auto m_s_blocks_idx = m_s_blocks | index(); - int b_idx = 0; - for (const auto & blk : m_s_blocks) { - auto m_isect = matrix | sub<0>(1, extent_y-1) - | sub<1>(1, extent_x-1) - | intersect(blk); - - print("\n --- matrix | sub {1,-1} {1-1} | intersect(" << - "block(" << m_s_blocks_idx[b_idx] << "))" << - nview_str(m_isect)); - - ++b_idx; + + auto matrix_sub = matrix | sub<0>(3, extent_y-1) + | sub<1>(1, extent_x-1); + + print("matrix | sub<0>(3,-1) | sub<1>(1,-1)" << + nview_str(matrix_sub) << "\n\n"); + + print("matrix | sub<0>(3,-1) | sub<1>(1,-1) | blocks()\n"); + { + auto m_s_blocks = matrix_sub | blocks(); + auto m_s_blocks_idx = m_s_blocks | index(); + int b_idx = 0; + for (const auto & blk : m_s_blocks) { + auto m_isect = matrix_sub | intersect(blk); + + print("--- matrix | sub {3,-1} {1-1} | intersect(" << + "block(" << m_s_blocks_idx[b_idx] << ")) " << + "--- block[0,0] = " << std::fixed << std::setprecision(2) << + static_cast(blk[{0,0}]) << + nview_str(m_isect) << '\n'); + + ++b_idx; + } + } + print("matrix | sub<0>(3,-1) | sub<1>(1,-1) | local | blocks()\n"); + { + auto m_s_l_blocks = matrix_sub | local() | blocks(); + auto m_s_l_blocks_idx = m_s_l_blocks | index(); + int b_idx = 0; + print("--- number of blocks: " << m_s_l_blocks.size()); + for (const auto & blk : m_s_l_blocks) { + auto block_gidx = m_s_l_blocks_idx[b_idx]; + print("--- matrix | sub {3,-1} {1-1} | local | " << + "block(" << block_gidx << ") " << + "offsets: " << blk.offsets() << " " << + "extents: " << blk.extents()); + + print(nview_str(blk) << '\n'); + + ++b_idx; + } } } dash::barrier(); diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index aa388e0d4..cfe2ddf90 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -34,10 +34,6 @@ int main(int argc, char *argv[]) size_t num_elem_per_unit = num_elem_total / nunits; size_t num_blocks_per_unit = num_elem_per_unit / block_size; - if (nunits < 2) { - cerr << "requires > 1 units" << endl; -// return 1; - } typedef dash::ShiftTilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; @@ -56,18 +52,6 @@ int main(int argc, char *argv[]) matrix(pattern); // Initialize matrix values: -#if 0 - if (myid == 0) { - int gi = 0; - std::generate(matrix.begin(), - matrix.end(), - [&]() { - auto u = matrix.pattern().unit_at( - matrix.pattern().coords(gi)); - return u + 0.01 * gi++; - }); - } -#else int li = 0; std::generate(matrix.lbegin(), matrix.lend(), @@ -75,7 +59,6 @@ int main(int argc, char *argv[]) auto u = dash::myid(); return u + 0.01 * li++; }); -#endif dash::barrier(); if (myid == 0) { @@ -124,9 +107,6 @@ int main(int argc, char *argv[]) } dash::barrier(); -//dash::finalize(); -//return EXIT_SUCCESS; - // Array to store local copy: std::vector local_copy(num_elem_per_unit); // Pointer to first value in next copy destination range: @@ -230,49 +210,6 @@ int main(int argc, char *argv[]) // Advance local copy destination pointer: copy_dest_begin = copy_dest_last; -#if 0 - auto remote_block_range = dash::sub(1,5, - dash::make_range( - remote_block_view.begin(), - remote_block_view.end())); - - DASH_LOG_DEBUG("MatrixViewsExample", - "source block range:", "-- type:", - dash::typestr(remote_block_range)); - DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", - "source block range iterator:", - dash::typestr(remote_block_range.begin())); - DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", - "source block range domain:", - dash::typestr(dash::domain(remote_block_range))); - DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", - "source block range origin:", - dash::typestr(dash::origin(remote_block_range))); - - DASH_LOG_DEBUG("MatrixViewsExample", - "source block range:", - "extents:", remote_block_range.extents(), - "offsets:", remote_block_range.offsets(), - "size:", remote_block_range.size()); - DASH_LOG_DEBUG("MatrixViewsExample", - "source block range domain:", - "extents:", dash::domain(remote_block_range).extents(), - "offsets:", dash::domain(remote_block_range).offsets(), - "size:", dash::domain(remote_block_range).size()); - DASH_LOG_DEBUG("MatrixViewsExample", - "begin.pos:", remote_block_range.begin().pos(), - "end.pos:", remote_block_range.end().pos(), - "begin.gpos:", remote_block_range.begin().gpos(), - "end.gpos:", remote_block_range.end().gpos()); - DASH_LOG_DEBUG("MatrixViewsExample", "block range index:", - nview_str(dash::index(remote_block_range))); - DASH_LOG_DEBUG("MatrixViewsExample", "block range index is strided:", - dash::index(remote_block_range).is_strided()); - DASH_LOG_DEBUG("MatrixViewsExample", "block range:", - nview_str(remote_block_range)); - DASH_LOG_DEBUG("MatrixViewsExample", "local(block range):", - nview_str(dash::local(remote_block_range))); -#endif DASH_LOG_DEBUG("MatrixViewsExample", "^^^^^^^^^^^^^^^^^^^^^^^^^^^"); } } diff --git a/dash/include/dash/Cartesian.h b/dash/include/dash/Cartesian.h index db6e67ee1..045e11358 100644 --- a/dash/include/dash/Cartesian.h +++ b/dash/include/dash/Cartesian.h @@ -474,6 +474,7 @@ class CartesianIndexSpace return offs; } + /** * Convert the given cartesian point to a linear index, respective to * the offsets specified in the given ViewSpec. @@ -496,6 +497,28 @@ class CartesianIndexSpace return at(coords); } + /** + * Convert the given cartesian point to a linear index, respective to + * the specified offsets. + * + * \param point An array containing the coordinates, ordered by + * dimension (x, y, z, ...) + * \param offsets Offsets to apply on point coordinates + * before resolving the linear index. + */ + template< + MemArrange AtArrangement = Arrangement, + typename OffsetType> + IndexType at( + const std::array & point, + const std::array & offsets) const { + std::array coords; + for (auto d = 0; d < NumDimensions; ++d) { + coords[d] = point[d] + offsets[d]; + } + return at(coords); + } + /** * Convert given linear offset (index) to cartesian coordinates. * Inverse of \c at(...). @@ -773,6 +796,33 @@ class LocalMemoryLayout : return at(coords); } + /** + * Convert the given cartesian point to a linear index, respective to + * the specified offsets. + * + * \param point An array containing the coordinates, ordered by + * dimension (x, y, z, ...) + * \param offsets Offsets to apply on point coordinates + * before resolving the linear index. + */ + template< + MemArrange AtArrangement = Arrangement, + typename OffsetType> + IndexType at( + const std::array & point, + const std::array & offsets) const { + std::array coords; + for (auto d = 0; d < NumDimensions; ++d) { + coords[d] = point[d] + offsets[d]; + } + if (!_distspec.is_tiled()) { + // Default case, no tiles + return parent_t::at(coords); + } + // Tiles in at least one dimension + return at(coords); + } + /** * Convert given linear offset (index) to cartesian coordinates. * Inverse of \c at(...). diff --git a/dash/include/dash/Meta.h b/dash/include/dash/Meta.h index 80dfaabaa..11ba51a08 100644 --- a/dash/include/dash/Meta.h +++ b/dash/include/dash/Meta.h @@ -3,6 +3,7 @@ #include #include +#include #include @@ -102,6 +103,12 @@ DASH__META__DEFINE_TRAIT__HAS_TYPE(nonconst_type); namespace dash { +// ========================================================================== +// dash::const_value_cast::type -> const T & +// dash::const_value_cast::type -> const T * +// dash::const_value_cast::type -> const T +// -------------------------------------------------------------------------- + template struct const_value_cast; @@ -127,6 +134,11 @@ struct const_value_cast { }; +// ========================================================================== +// dash::nonconst_value_cast::type -> T & +// dash::nonconst_value_cast::type -> T * +// dash::nonconst_value_cast::type -> T +// -------------------------------------------------------------------------- template struct nonconst_value_cast; @@ -153,6 +165,30 @@ struct nonconst_value_cast { }; +// ========================================================================== +// dash::array_value_cast(std::array)::type -> std::array +// -------------------------------------------------------------------------- + +namespace detail { + +template +constexpr auto array_value_cast_indexed( + const std::array &a, dash::ce::index_sequence) + -> std::array { + return {{ static_cast(std::get(a))... }}; +} + +} // namespace detail + +template +constexpr auto array_value_cast( + const std::array & a) -> std::array { + // tag dispatch to helper with array indices + return detail::array_value_cast_indexed( + a, dash::ce::make_index_sequence()); +} + + /* * For reference, see * diff --git a/dash/include/dash/util/ArrayExpr.h b/dash/include/dash/util/ArrayExpr.h index 8ef8a7289..a925c2a47 100644 --- a/dash/include/dash/util/ArrayExpr.h +++ b/dash/include/dash/util/ArrayExpr.h @@ -273,21 +273,9 @@ template < constexpr std::array reverse( const std::array & values) { - // - // NOTE: - // - // This is elegant, correct, of high didactic value and does - // not scale well. - // Should be implemented using index from parameter pack like - // - // { (std::get(values)... } - // - return (NElem > 1 - ? ( dash::ce::append( - dash::ce::reverse( - dash::ce::tail(values)), - dash::ce::head(values)) ) - : values); + + return detail::take_impl( + values, dash::ce::make_rev_index_sequence()); } // ------------------------------------------------------------------------- diff --git a/dash/include/dash/util/IndexSequence.h b/dash/include/dash/util/IndexSequence.h index 9f95092c1..fb8d77741 100644 --- a/dash/include/dash/util/IndexSequence.h +++ b/dash/include/dash/util/IndexSequence.h @@ -10,11 +10,31 @@ namespace dash { namespace ce { + +/** + * Represents a compile-time sequence container + */ template < std::size_t... Is > struct index_sequence { }; +/** + * Generates a compile-sequence integer (size_t) sequence in ascending order + * + * Example: + * + * template + * void print(dash::ce::index_sequence&& s) + * { + * for (auto i : { Is... }) std::cout << i << " "; + * std::cout << "\n"; + * } + * + * print(dash::ce::make_rev_index_sequence<5>()); + * //output: 0 1 2 3 4 + * + */ template < std::size_t N, std::size_t... Is > @@ -22,12 +42,50 @@ struct make_index_sequence : make_index_sequence { }; +/** + * Stop condition for a compile-time integer (size_t) sequence in ascending + * order + */ template < std::size_t... Is> struct make_index_sequence<0, Is...> : index_sequence { }; +/** + * Generates a compile-sequence integer (size_t) sequence in descending order + * + * Example: + * + * template + * void print(dash::ce::index_sequence&& s) + * { + * for (auto i : { Is... }) std::cout << i << " "; + * std::cout << "\n"; + * } + * + * print(dash::ce::make_rev_index_sequence<5>()); + * //output: 4 3 2 1 0 + * + */ +template < + std::size_t N, + std::size_t... Is > +struct make_rev_index_sequence + : make_rev_index_sequence +{ }; + + +/** + * Stop condition for a compile-time integer (size_t) sequence in descending + * order + */ +template < + std::size_t... Is> +struct make_rev_index_sequence<0, Is...> + : index_sequence +{ }; + } // namespace ce } // namespace dash diff --git a/dash/include/dash/util/LocalityDomain.h b/dash/include/dash/util/LocalityDomain.h index 5c7d58be5..d0ea5e89d 100644 --- a/dash/include/dash/util/LocalityDomain.h +++ b/dash/include/dash/util/LocalityDomain.h @@ -328,6 +328,7 @@ class LocalityDomain static_cast(scope), &num_scope_domains, &dart_scope_domains); + (void)ret; // suppress warning DASH_ASSERT(DART_OK == ret || DART_ERR_NOTFOUND == ret); DASH_LOG_TRACE_VAR("LocalityDomain.scope_domains", num_scope_domains); diff --git a/dash/include/dash/view/Block.h b/dash/include/dash/view/Block.h index c04f3e7f3..574c7ef7c 100644 --- a/dash/include/dash/view/Block.h +++ b/dash/include/dash/view/Block.h @@ -6,26 +6,57 @@ #include #include +#include namespace dash { -#if 0 /** * * \concept{DashViewConcept} */ template < - class ViewT, - class BlockIndexT > -constexpr typename std::enable_if< - dash::view_traits::is_view::value, - dash::ViewBlockMod ->::type + class ViewT, + class BlockIndexT, + dim_t NDim + = dash::view_traits::rank::value, + typename std::enable_if< + dash::view_traits::is_view::value, + int >::type = 0 +> +constexpr auto block(BlockIndexT block_index, const ViewT & view) { - return ViewBlockMod(view, block_index); + return ViewBlockMod(view, block_index); +} + +template < + class ViewT, + class BlockIndexT, + dim_t NDim + = dash::view_traits::rank::value, + typename std::enable_if< + !dash::view_traits::is_view::value, + int >::type = 0 +> +constexpr auto +block(BlockIndexT block_index, const ViewT & view) { + return dash::blocks(view)[block_index]; +} + +template < + class BlockIndexT, + typename std::enable_if< + std::is_integral< + typename std::decay::type + >::value, + int + >::type = 0 > +static inline auto block(BlockIndexT b) { + return dash::make_pipeable( + [=](auto && x) { + return block(b, std::forward(x)); + }); } -#endif } diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 99a78dba3..362f7477a 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -185,6 +186,30 @@ index(const DomainType & v) return v.index_set(); } +template < + MemArrange MemOrder = dash::ROW_MAJOR, + class ViewType, + typename CoordT, + dim_t NDim = dash::view_traits< + typename dash::view_traits::origin_type + >::rank::value, + class IndexT = typename dash::view_traits::index_type > +auto linearize( + const ViewType & view, + const std::array< + CoordT, + static_cast(NDim)> & coords) + -> IndexT { + return dash::CartesianIndexSpace< NDim, MemOrder, IndexT >( + view.extents()).at( + // coords: + dash::array_value_cast(coords) + // offsets: + // , + // dash::array_value_cast(view.offsets()) + ); +} + namespace detail { @@ -1045,6 +1070,18 @@ class IndexSetLocal // ---- size ------------------------------------------------------------ + constexpr bool empty() const noexcept { + return size() == 0; + } + + constexpr bool operator!() const noexcept { + return empty(); + } + + constexpr explicit operator bool() const noexcept { + return !empty(); + } + constexpr size_type size(dim_t sub_dim) const noexcept { return _size; } diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 1dabd1f62..92d2c3617 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -238,6 +238,17 @@ class ViewBlockMod _index_set, offset)); } + constexpr const_reference operator[]( + const std::array< + typename self_t::index_set_type::index_type, + self_t::rank::value + > & coords) const { + return *(const_iterator(dash::origin(*this).begin(), + _index_set, + // offset: + dash::linearize(*this, coords))); + } + constexpr const index_set_type & index_set() const { return _index_set; } @@ -457,6 +468,19 @@ blocks(ViewType && domain) { return ViewBlocksMod(std::forward(domain)); } +#if 0 +/** + * `blocks(block(D)) -> block(D)` + */ +template < + class BlockDomain, + dim_t NBlockDim > +constexpr ViewBlockMod & +blocks(ViewBlockMod & block_view) { + return block_view; +} +#endif + template < class DomainType, dim_t NDim > diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index 667ea3ea0..e57fc2727 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -311,6 +311,28 @@ class ViewModBase constexpr index_type size() const { return dash::index(derived()).size(); } + + constexpr bool empty() const noexcept { + return size() == 0; + } + + constexpr bool operator!() const noexcept { + return empty(); + } + + constexpr explicit operator bool() const noexcept { + return !empty(); + } + + // ---- access ---------------------------------------------------------- + + template + constexpr const_reference operator[]( + const std::array< + IdxT, self_t::rank::value + > & coords) const { + return derived()[ dash::linearize(derived(), coords) ]; + } }; diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index d37a45ec4..4b6457c02 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -688,7 +688,7 @@ TEST_F(MatrixTest, ViewIteration) } } -TEST_F(MatrixTest, BlockCopy) +TEST_F(MatrixTest, BlockCopyGlobalToGlobal) { typedef int element_t; int myid = dash::myid().id; @@ -721,8 +721,8 @@ TEST_F(MatrixTest, BlockCopy) dash::Team::All(), team_spec); // Fill matrix - auto block_a = matrix_a.block(1); - auto block_b = matrix_b.block(0); + auto block_a = matrix_a | dash::block(1); + auto block_b = matrix_b | dash::block(0); if (myid == 0) { LOG_MESSAGE("Assigning matrix values"); for(size_t row = 0; row < matrix_a.extent(0); ++row) { @@ -739,18 +739,18 @@ TEST_F(MatrixTest, BlockCopy) LOG_MESSAGE("Copying block"); // Copy block 1 of matrix_a to block 0 of matrix_b: - dash::copy(block_a.begin(), - block_a.end(), - block_b.begin()); + dash::copy(block_a, + block_b); matrix_b.barrier(); LOG_MESSAGE("Checking copy result"); if (myid == 0) { LOG_MESSAGE("Checking copied matrix block values"); - for(size_t col = 0; col < block_a.extent(0); ++col) { - for(size_t row = 0; row < block_a.extent(1); ++row) { - ASSERT_EQ_U(static_cast(block_b[col][row]), - static_cast(block_a[col][row])); + for(ssize_t col = 0; col < block_a.extent(0); ++col) { + for(ssize_t row = 0; row < block_a.extent(1); ++row) { + ASSERT_EQ_U( + static_cast(block_b[{ col, row }]), + static_cast(block_a[{ col, row }])); } } } From 75d63ec8e16023c9c0000b32d6ba5d2ef517dec2 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sun, 24 Sep 2017 14:58:50 +0200 Subject: [PATCH 112/161] Implementing range-based global to global copy --- dash/examples/ex.02.matrix-sub-views/main.cpp | 4 +- dash/include/dash/algorithm/Copy.h | 84 +++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 3eaf79209..ffeff62fd 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) "block(" << m_s_blocks_idx[b_idx] << ")) " << "--- block[0,0] = " << std::fixed << std::setprecision(2) << static_cast(blk[{0,0}]) << - nview_str(m_isect) << '\n'); + nview_str(m_isect) << std::endl); ++b_idx; } @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) "offsets: " << blk.offsets() << " " << "extents: " << blk.extents()); - print(nview_str(blk) << '\n'); + print(nview_str(blk) << std::endl); ++b_idx; } diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index a80cdc9ed..ce37160d4 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1202,6 +1202,90 @@ GlobOutputIt copy( return out_last; } +// ====================================================================== +// Global to Global, Distributed Range +// ====================================================================== + +/** + * Specialization of \c dash::copy as global-to-global blocking copy + * operation. + * + * \ingroup DashAlgorithms + */ +template < + class GlobInputRange, + class GlobOutputRange, + typename std::enable_if< + ( dash::view_traits::is_view::value && + dash::view_traits::is_view::value ), + int >::type = 0 +> +GlobOutputRange copy( + GlobInputRange in_g_range, + GlobOutputRange out_g_range) +{ + DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); + + DASH_LOG_TRACE("dash::copy()", "range(out_gi, out_ge):", + dash::typestr(out_g_range)); + DASH_LOG_TRACE_VAR("dash::copy()", out_g_range); + DASH_LOG_TRACE_VAR("dash::copy()", dash::index(out_g_range)); + + DASH_LOG_TRACE("dash::copy()", "range(in_gi, in_ge):", + dash::typestr(in_g_range)); + DASH_LOG_TRACE_VAR("dash::copy()", in_g_range); + DASH_LOG_TRACE_VAR("dash::copy()", dash::index(in_g_range)); + + 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); + + auto l_out_blocks = dash::local(out_blocks); + 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_out_block : l_out_blocks) { + DASH_LOG_TRACE_VAR("dash::copy()", l_out_block); + DASH_LOG_TRACE_VAR("dash::copy()", + dash::global(dash::index(l_out_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)):", + dash::typestr(out_l_range)); + DASH_LOG_TRACE("dash::copy()", "local(range(out_gi, out_ge)):", + out_l_range); + DASH_LOG_TRACE("dash::copy()", "index(local(range(out_gi, out_ge))):", + dash::index(out_l_range)); + DASH_LOG_TRACE("dash::copy()", "global(index(local(range(o_gi,o_ge)))):", + dash::global(dash::index(out_l_range))); + + auto in_l_range = dash::local(in_g_range); + DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", + dash::typestr(in_l_range)); + DASH_LOG_TRACE("dash::copy()", "local(range(in_gi, in_ge)):", + in_l_range); + DASH_LOG_TRACE("dash::copy()", "index(local(range(in_gi, in_ge))):", + dash::index(in_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_g_range; +} + /** * Specialization of \c dash::copy as global-to-global blocking copy * operation. From 7ab8b40819d6a25d9f0ff4e938bff35c44bce5a8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sun, 24 Sep 2017 17:40:04 -0700 Subject: [PATCH 113/161] Adding dash::is_view_region, dash::rank, restructuring headers --- dash/include/dash/Cartesian.h | 2 + dash/include/dash/Dimensional.h | 389 +--------------- dash/include/dash/View.h | 50 ++- dash/include/dash/view/{Chunk.h => Chunks.h} | 2 +- dash/include/dash/view/Expand.h | 2 +- dash/include/dash/view/IndexSet.h | 6 +- .../dash/view/{SetIntersect.h => Intersect.h} | 18 +- dash/include/dash/view/ViewBlocksMod.h | 2 +- dash/include/dash/view/ViewSpec.h | 421 ++++++++++++++++++ dash/include/dash/view/ViewTraits.h | 18 + 10 files changed, 493 insertions(+), 417 deletions(-) rename dash/include/dash/view/{Chunk.h => Chunks.h} (96%) rename dash/include/dash/view/{SetIntersect.h => Intersect.h} (83%) create mode 100644 dash/include/dash/view/ViewSpec.h diff --git a/dash/include/dash/Cartesian.h b/dash/include/dash/Cartesian.h index 045e11358..420aa2eeb 100644 --- a/dash/include/dash/Cartesian.h +++ b/dash/include/dash/Cartesian.h @@ -6,6 +6,8 @@ #include #include +#include + #include #include #include diff --git a/dash/include/dash/Dimensional.h b/dash/include/dash/Dimensional.h index 1772492f7..d1d75ae7e 100644 --- a/dash/include/dash/Dimensional.h +++ b/dash/include/dash/Dimensional.h @@ -58,6 +58,7 @@ constexpr dim_t ndim(const DimensionalType & d) { return d.ndim(); } +#if 0 /** * \concept{DashDimensionalConcept} */ @@ -65,6 +66,7 @@ template constexpr dim_t rank(const DimensionalType & d) { return d.rank(); } +#endif /** * \concept{DashDimensionalConcept} @@ -344,368 +346,6 @@ std::ostream & operator<<( return os; } -/** - * Offset and extent in a single dimension. - */ -template -struct ViewPair { - typedef typename std::make_unsigned::type SizeType; - /// Offset in dimension. - IndexType offset; - /// Extent in dimension. - SizeType extent; -}; - -/** - * Representation of a ViewPair as region specified by origin and end - * coordinates. - */ -template< - dim_t NumDimensions, - typename IndexType = dash::default_index_t> -struct ViewRegion { - // Region origin coordinates. - std::array begin; - // Region end coordinates. - std::array end; -}; - -template< - typename IndexType = dash::default_index_t> -struct ViewRange { - // Range begin offset. - IndexType begin; - // Range end offset. - IndexType end; -}; - -template -std::ostream & operator<<( - std::ostream & os, - const ViewRange & viewrange) { - os << "dash::ViewRange<" << typeid(IndexType).name() << ">(" - << "begin:" << viewrange.begin << " " - << "end:" << viewrange.end << ")"; - return os; -} - -/** - * Equality comparison operator for ViewPair. - */ -template -static bool operator==( - const ViewPair & lhs, - const ViewPair & rhs) { - if (&lhs == &rhs) { - return true; - } - return ( - lhs.offset == rhs.offset && - lhs.extent == rhs.extent); -} - -/** - * Inequality comparison operator for ViewPair. - */ -template -static bool operator!=( - const ViewPair & lhs, - const ViewPair & rhs) { - return !(lhs == rhs); -} - -template -std::ostream & operator<<( - std::ostream & os, - const ViewPair & viewpair) { - os << "dash::ViewPair<" << typeid(IndexType).name() << ">(" - << "offset:" << viewpair.offset << " " - << "extent:" << viewpair.extent << ")"; - return os; -} - -/** - * Specifies view parameters for implementing submat, rows and cols - * - * \concept(DashCartesianSpaceConcept) - */ -template< - dim_t NumDimensions, - typename IndexType = dash::default_index_t > -class ViewSpec -{ -private: - typedef ViewSpec - self_t; - typedef typename std::make_unsigned::type - SizeType; - typedef ViewPair - ViewPair_t; - -public: - typedef ViewRegion region_type; - typedef ViewRange range_type; - -public: - template - friend std::ostream& operator<<( - std::ostream & os, - const ViewSpec & viewspec); - -private: - SizeType _size = 0; - SizeType _rank = NumDimensions; - std::array _extents = {{ }}; - std::array _offsets = {{ }}; - -public: - /** - * Default constructor, initialize with extent and offset 0 in all - * dimensions. - */ - ViewSpec() - : _size(0), - _rank(NumDimensions) - { - for (dim_t i = 0; i < NumDimensions; i++) { - _extents[i] = 0; - _offsets[i] = 0; - } - } - - /** - * Constructor, initialize with given extents and offset 0 in all - * dimensions. - */ - ViewSpec( - const std::array & extents) - : _size(1), - _rank(NumDimensions), - _extents(extents) - { - for (auto i = 0; i < NumDimensions; ++i) { - _offsets[i] = 0; - _size *= _extents[i]; - } - } - - /** - * Constructor, initialize with given extents and offsets. - */ - ViewSpec( - const std::array & offsets, - const std::array & extents) - : _size(1), - _rank(NumDimensions), - _extents(extents), - _offsets(offsets) - { - for (auto i = 0; i < NumDimensions; ++i) { - _size *= _extents[i]; - } - } - - /** - * Copy constructor. - */ - constexpr ViewSpec(const self_t & other) = default; - - /** - * Move constructor. - */ - constexpr ViewSpec(self_t && other) = default; - - /** - * Assignment operator. - */ - self_t & operator=(const self_t & other) = default; - - /** - * Move-assignment operator. - */ - self_t & operator=(self_t && other) = default; - - /** - * Equality comparison operator. - */ - constexpr bool operator==(const self_t & other) const - { - return (_extents == other._extents && - _offsets == other._offsets && - _rank == other._rank); - } - - /** - * Equality comparison operator. - */ - constexpr bool operator!=(const self_t & other) const - { - return !(*this == other); - } - - /** - * Change the view specification's extent in every dimension. - */ - template - void resize(SizeType arg, Args... args) - { - static_assert( - sizeof...(Args) == (NumDimensions-1), - "Invalid number of arguments"); - std::array extents = - { arg, (SizeType)(args)... }; - resize(extents); - } - - /** - * Change the view specification's extent and offset in every dimension. - */ - void resize(const std::array & view) - { - _rank = NumDimensions; - for (dim_t i = 0; i < NumDimensions; i++) { - _offsets[i] = view[i].offset; - _extents[i] = view[i].extent; - } - update_size(); - } - - /** - * Change the view specification's extent in every dimension. - */ - template - void resize(const std::array & extents) - { - _rank = NumDimensions; - for (dim_t i = 0; i < NumDimensions; i++) { - _extents[i] = extents[i]; - } - update_size(); - } - - /** - * Change the view specification's extent and offset in the - * given dimension. - */ - void resize_dim( - dim_t dimension, - IndexType offset, - SizeType extent) - { - _offsets[dimension] = offset; - _extents[dimension] = extent; - update_size(); - } - - /** - * Slice the view in the specified dimension at the given offset. - * This is different from resizing the dimension to extent 1 - * (\c resize_dim) which does not affect the view dimensionality or - * rank. - * Slicing removes the specified dimension and reduces the view - * dimensionality by 1. - * - * All dimensions higher than the sliced dimension are projected - * downwards. - * Example: - * - * dimensions: 0 1 2 3 - * : : : : - * extents: 3 4 5 6 - * | - * slice_dim(1, 2) - * | - * v - * dimensions: 0 x 1 2 - * : : : - * extents: 3 5 6 - * - * \return A copy if this view spec as a new instance of `ViewSpec` - * with the sliced dimension removed - */ - ViewSpec - slice(dim_t dimension) - { - std::array slice_extents; - std::array slice_offsets; - for (dim_t d = dimension; d < _rank-1; d++) { - slice_offsets[d] = _offsets[d+1]; - slice_extents[d] = _extents[d+1]; - } - return ViewSpec(slice_offsets, - slice_extents); - } - - /** - * Set rank of the view spec to a dimensionality between 1 and - * \c NumDimensions. - */ - void set_rank(dim_t dimensions) - { - DASH_ASSERT_LT( - dimensions, NumDimensions+1, - "Maximum dimension for ViewSpec::set_rank is " << NumDimensions); - _rank = dimensions; - update_size(); - } - - constexpr SizeType size() const - { - return _size; - } - - constexpr SizeType size(dim_t dimension) const - { - return _extents[dimension]; - } - - constexpr const std::array & extents() const - { - return _extents; - } - - constexpr SizeType extent(dim_t dim) const { - return _extents[dim]; - } - - constexpr const std::array & offsets() const - { - return _offsets; - } - - constexpr range_type range(dim_t dim) const - { - return range_type { - static_cast(_offsets[dim]), - static_cast(_offsets[dim] + _extents[dim]) }; - } - - constexpr IndexType offset(dim_t dim) const - { - return _offsets[dim]; - } - - region_type region() const - { - region_type reg; - reg.begin = _offsets; - reg.end = _offsets; - for (dim_t d = 0; d < NumDimensions; ++d) { - reg.end[d] += static_cast(_extents[d]); - } - return reg; - } - -private: - void update_size() - { - _size = 1; - for (SizeType d = 0; d < NumDimensions; ++d) { - _size *= _extents[d]; - } - } -}; - template std::ostream & operator<<( std::ostream & os, @@ -722,31 +362,6 @@ std::ostream & operator<<( return operator<<(os, ss.str()); } -template -std::ostream& operator<<( - std::ostream & os, - const ViewSpec & viewspec) -{ - std::ostringstream ss; - ss << "dash::ViewSpec<" << NumDimensions << ">" - << "(offsets:"; - for (auto d = 0; d < NumDimensions; ++d) { - if (d > 0) { - ss << ","; - } - ss << viewspec.offsets()[d]; - } - ss << " extents:"; - for (auto d = 0; d < NumDimensions; ++d) { - if (d > 0) { - ss << ","; - } - ss << viewspec.extents()[d]; - } - ss << ")"; - return operator<<(os, ss.str()); -} - } // namespace dash #endif // DASH__DIMENSIONAL_H_ diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index dfdcf2404..cec32a03c 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -35,20 +35,37 @@ * * \par Expressions * - * View Specifier | Synopsis - * ------------------------- | -------------------------------------------------- - * dash::sub | Subrange of domain in a specified dimension - * dash::intersect | View from intersection of two domains - * dash::difference | View from difference of two domains - * dash::combine | Composite view of two possibply unconnected domains - * dash::local | Local subspace of domain - * dash::global | Maps subspace to elements in global domain - * dash::apply | Obtain image of domain view (inverse of \c domain) - * dash::domain | Obtain domain of view image (inverse of \c apply) - * dash::origin | Obtain the view origin (root domain) - * dash::blocks | Decompose domain into blocks - * dash::block | Subspace of decomposed domain in a specific block - * dash::index | Returns a view's index set + * View Specifier | Synopsis + * ---------------------------- | -------------------------------------------------- + * dash::sub | Subrange of domain in a specified dimension + * dash::intersect(v) | View from intersection of two domains, result \ + * remains regular rectangle for regular operands + * dash::difference | View from difference of two domains + * dash::expand(ob,oe) | Resize Cartesian view by specified begin-\ + * | and end offset + * + * dash::combine(v) | Composite possibly unconnected domain into \ + * view + * dash::group | Group domains in view, group members are not\ + * combined + * + * dash::local | Local subspace of domain + * dash::remote | Non-local subspace of domain + * dash::global | Maps subspace to elements in global domain + * + * dash::domain | Obtain domain of view image (inverse of \c apply) + * dash::origin | Obtain the view origin (local or global root\ + * domain) + * dash::global_origin | Obtain the view origin (global root domain) + * + * dash::blocks | Decompose domain into blocks in data distribution + * dash::block | Subspace of decomposed domain in a specific block + * dash::chunks | Decompose domain into single contiguous ranges + * dash::strides | Decompose domain into ranges with specified size + * + * dash::index | Returns a view's index set + * dash::owner | Maps elements in view to unit id of its memory \ + * space * * \par Examples * @@ -73,8 +90,9 @@ #include +#include #include -#include +#include #include #include #include @@ -85,7 +103,7 @@ #include #include -#include +#include #include #include diff --git a/dash/include/dash/view/Chunk.h b/dash/include/dash/view/Chunks.h similarity index 96% rename from dash/include/dash/view/Chunk.h rename to dash/include/dash/view/Chunks.h index 0d01c5f96..d7583581f 100644 --- a/dash/include/dash/view/Chunk.h +++ b/dash/include/dash/view/Chunks.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index bf964f5d3..4fd008fca 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -111,7 +111,7 @@ template < typename DomainValueT = typename std::decay::type, dim_t NDim - = dash::view_traits::rank::value, + = dash::rank::value, typename std::enable_if< !dash::view_traits::is_origin::value, char >::type = 0 diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 362f7477a..04acb1d7f 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -484,10 +484,12 @@ class IndexSetBase } constexpr auto domain() const +#if DASH_CXX_VERSION < 14 -> decltype(dash::index( - std::declval() - )) { + std::declval() )) // -> typename view_traits::index_set_type { +#endif + { return dash::index(_domain); } diff --git a/dash/include/dash/view/SetIntersect.h b/dash/include/dash/view/Intersect.h similarity index 83% rename from dash/include/dash/view/SetIntersect.h rename to dash/include/dash/view/Intersect.h index e05fd9f64..bd8c43069 100644 --- a/dash/include/dash/view/SetIntersect.h +++ b/dash/include/dash/view/Intersect.h @@ -1,5 +1,5 @@ -#ifndef DASH__VIEW__SET_INTERSECT_H__INCLUDED -#define DASH__VIEW__SET_INTERSECT_H__INCLUDED +#ifndef DASH__VIEW__INTERSECT_H__INCLUDED +#define DASH__VIEW__INTERSECT_H__INCLUDED #include #include @@ -17,8 +17,8 @@ template < class ViewTypeA, class ViewTypeB, typename std::enable_if< - dash::view_traits::rank::value == 1 && - dash::view_traits::rank::value == 1, + dash::rank::value == 1 && + dash::rank::value == 1, int >::type = 0 > constexpr auto @@ -63,8 +63,8 @@ template < dim_t CurDim, class ViewTypeA, class ViewTypeB, - dim_t NDimA = dash::view_traits::rank::value, - dim_t NDimB = dash::view_traits::rank::value, + dim_t NDimA = dash::rank::value, + dim_t NDimB = dash::rank::value, typename std::enable_if< (NDimA == NDimB) && (NDimA > 1) && (NDimB > 1) && (CurDim >= 0), @@ -96,8 +96,8 @@ intersect_dim( template < class ViewTypeA, class ViewTypeB, - dim_t NDimA = dash::view_traits::rank::value, - dim_t NDimB = dash::view_traits::rank::value, + dim_t NDimA = dash::rank::value, + dim_t NDimB = dash::rank::value, typename std::enable_if< (NDimA == NDimB) && (NDimA > 1) && (NDimB > 1), int >::type = 0 @@ -124,4 +124,4 @@ static inline auto intersect(const ViewType & v_rhs) { } // namespace dash -#endif // DASH__VIEW__SET_INTERSECT_H__INCLUDED +#endif // DASH__VIEW__INTERSECT_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 92d2c3617..7050fd19b 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/dash/include/dash/view/ViewSpec.h b/dash/include/dash/view/ViewSpec.h new file mode 100644 index 000000000..749108609 --- /dev/null +++ b/dash/include/dash/view/ViewSpec.h @@ -0,0 +1,421 @@ +#ifndef DASH__VIEW__VIEW_SPEC_H__INCLUDED +#define DASH__VIEW__VIEW_SPEC_H__INCLUDED + +#include + +#include + + +namespace dash { + +/** + * Offset and extent in a single dimension. + */ +template +struct ViewPair { + typedef typename std::make_unsigned::type SizeType; + /// Offset in dimension. + IndexType offset; + /// Extent in dimension. + SizeType extent; +}; + +/** + * Representation of a ViewPair as region specified by origin and end + * coordinates. + */ +template< + dim_t NDim, + typename IndexType = dash::default_index_t> +struct ViewRegion { + // Region origin coordinates. + std::array begin; + // Region end coordinates. + std::array end; +}; + +template< + typename IndexType = dash::default_index_t> +struct ViewRange { + // Range begin offset. + IndexType begin; + // Range end offset. + IndexType end; +}; + +template +std::ostream & operator<<( + std::ostream & os, + const ViewRange & viewrange) { + os << "dash::ViewRange<" << typeid(IndexType).name() << ">(" + << "begin:" << viewrange.begin << " " + << "end:" << viewrange.end << ")"; + return os; +} + +/** + * Equality comparison operator for ViewPair. + */ +template +static bool operator==( + const ViewPair & lhs, + const ViewPair & rhs) { + if (&lhs == &rhs) { + return true; + } + return ( + lhs.offset == rhs.offset && + lhs.extent == rhs.extent); +} + +/** + * Inequality comparison operator for ViewPair. + */ +template +static bool operator!=( + const ViewPair & lhs, + const ViewPair & rhs) { + return !(lhs == rhs); +} + +template +std::ostream & operator<<( + std::ostream & os, + const ViewPair & viewpair) { + os << "dash::ViewPair<" << typeid(IndexType).name() << ">(" + << "offset:" << viewpair.offset << " " + << "extent:" << viewpair.extent << ")"; + return os; +} + +/** + * Specifies view parameters for implementing submat, rows and cols + * + * \concept(DashCartesianSpaceConcept) + */ +template< + dim_t NDim, + typename IndexType = dash::default_index_t > +class ViewSpec +{ +private: + typedef ViewSpec + self_t; + typedef typename std::make_unsigned::type + SizeType; + typedef ViewPair + ViewPair_t; + +public: + typedef ViewRegion region_type; + typedef ViewRange range_type; + typedef std::integral_constant rank; + +public: + template + friend std::ostream& operator<<( + std::ostream & os, + const ViewSpec & viewspec); + +private: + SizeType _size = 0; + SizeType _rank = NDim; + std::array _extents = {{ }}; + std::array _offsets = {{ }}; + +public: + /** + * Default constructor, initialize with extent and offset 0 in all + * dimensions. + */ + ViewSpec() + : _size(0), + _rank(NDim) + { + for (dim_t i = 0; i < NDim; i++) { + _extents[i] = 0; + _offsets[i] = 0; + } + } + + /** + * Constructor, initialize with given extents and offset 0 in all + * dimensions. + */ + ViewSpec( + const std::array & extents) + : _size(1), + _rank(NDim), + _extents(extents) + { + for (auto i = 0; i < NDim; ++i) { + _offsets[i] = 0; + _size *= _extents[i]; + } + } + + /** + * Constructor, initialize with given extents and offsets. + */ + ViewSpec( + const std::array & offsets, + const std::array & extents) + : _size(1), + _rank(NDim), + _extents(extents), + _offsets(offsets) + { + for (auto i = 0; i < NDim; ++i) { + _size *= _extents[i]; + } + } + + /** + * Copy constructor. + */ + constexpr ViewSpec(const self_t & other) = default; + + /** + * Move constructor. + */ + constexpr ViewSpec(self_t && other) = default; + + /** + * Assignment operator. + */ + self_t & operator=(const self_t & other) = default; + + /** + * Move-assignment operator. + */ + self_t & operator=(self_t && other) = default; + + /** + * Equality comparison operator. + */ + constexpr bool operator==(const self_t & other) const + { + return (_extents == other._extents && + _offsets == other._offsets && + _rank == other._rank); + } + + /** + * Equality comparison operator. + */ + constexpr bool operator!=(const self_t & other) const + { + return !(*this == other); + } + + /** + * Change the view specification's extent in every dimension. + */ + template + void resize(SizeType arg, Args... args) + { + static_assert( + sizeof...(Args) == (NDim-1), + "Invalid number of arguments"); + std::array extents = + { arg, (SizeType)(args)... }; + resize(extents); + } + + /** + * Change the view specification's extent and offset in every dimension. + */ + void resize(const std::array & view) + { + _rank = NDim; + for (dim_t i = 0; i < NDim; i++) { + _offsets[i] = view[i].offset; + _extents[i] = view[i].extent; + } + update_size(); + } + + /** + * Change the view specification's extent in every dimension. + */ + template + void resize(const std::array & extents) + { + _rank = NDim; + for (dim_t i = 0; i < NDim; i++) { + _extents[i] = extents[i]; + } + update_size(); + } + + /** + * Change the view specification's extent and offset in the + * given dimension. + */ + void resize_dim( + dim_t dimension, + IndexType offset, + SizeType extent) + { + _offsets[dimension] = offset; + _extents[dimension] = extent; + update_size(); + } + + /** + * Slice the view in the specified dimension at the given offset. + * This is different from resizing the dimension to extent 1 + * (\c resize_dim) which does not affect the view dimensionality or + * rank. + * Slicing removes the specified dimension and reduces the view + * dimensionality by 1. + * + * All dimensions higher than the sliced dimension are projected + * downwards. + * Example: + * + * dimensions: 0 1 2 3 + * : : : : + * extents: 3 4 5 6 + * | + * slice_dim(1, 2) + * | + * v + * dimensions: 0 x 1 2 + * : : : + * extents: 3 5 6 + * + * \return A copy if this view spec as a new instance of `ViewSpec` + * with the sliced dimension removed + */ + ViewSpec + slice(dim_t dimension) + { + std::array slice_extents; + std::array slice_offsets; + for (dim_t d = dimension; d < _rank-1; d++) { + slice_offsets[d] = _offsets[d+1]; + slice_extents[d] = _extents[d+1]; + } + return ViewSpec(slice_offsets, + slice_extents); + } + + /** + * Set rank of the view spec to a dimensionality between 1 and + * \c NDim. + */ + void set_rank(dim_t dimensions) + { + DASH_ASSERT_LT( + dimensions, NDim+1, + "Maximum dimension for ViewSpec::set_rank is " << NDim); + _rank = dimensions; + update_size(); + } + + constexpr SizeType size() const + { + return _size; + } + + constexpr SizeType size(dim_t dimension) const + { + return _extents[dimension]; + } + + constexpr const std::array & extents() const + { + return _extents; + } + + constexpr SizeType extent(dim_t dim) const { + return _extents[dim]; + } + + constexpr const std::array & offsets() const + { + return _offsets; + } + + constexpr range_type range(dim_t dim) const + { + return range_type { + static_cast(_offsets[dim]), + static_cast(_offsets[dim] + _extents[dim]) }; + } + + constexpr IndexType offset(dim_t dim) const + { + return _offsets[dim]; + } + + region_type region() const + { + region_type reg; + reg.begin = _offsets; + reg.end = _offsets; + for (dim_t d = 0; d < NDim; ++d) { + reg.end[d] += static_cast(_extents[d]); + } + return reg; + } + +private: + void update_size() + { + _size = 1; + for (SizeType d = 0; d < NDim; ++d) { + _size *= _extents[d]; + } + } +}; + +template +struct is_view_region; + +template < + dim_t NDim, + typename IndexT > +struct is_view_region > +: std::integral_constant +{ }; + +template +struct rank; + +template < + dim_t NDim, + typename IndexT > +struct rank > +: std::integral_constant +{ }; + +template +std::ostream& operator<<( + std::ostream & os, + const ViewSpec & viewspec) +{ + std::ostringstream ss; + ss << "dash::ViewSpec<" << NDim << ">" + << "(offsets:"; + for (auto d = 0; d < NDim; ++d) { + if (d > 0) { + ss << ","; + } + ss << viewspec.offsets()[d]; + } + ss << " extents:"; + for (auto d = 0; d < NDim; ++d) { + if (d > 0) { + ss << ","; + } + ss << viewspec.extents()[d]; + } + ss << ")"; + return operator<<(os, ss.str()); +} + +} // namespace dash + +#endif // DASH__VIEW__VIEW_SPEC_H__INCLUDED diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index aa343913f..7f48ee45c 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -54,6 +54,24 @@ struct view_traits template struct view_traits; +template +struct is_view_region; + +template +struct is_view_region +: std::integral_constant< + bool, + view_traits::is_view::value> +{ }; + +template +struct rank; + +template +struct rank +: view_traits::rank +{ }; + template class IndexSetIdentity; From daf8cea11960ae3d2c7d91f11ed32fd956f9a0b0 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 25 Sep 2017 14:31:57 -0700 Subject: [PATCH 114/161] Fixed block views on n-dim subspaces --- dash/examples/ex.02.matrix-strides/main.cpp | 11 +++ dash/examples/ex.02.matrix-sub-views/main.cpp | 10 +-- dash/examples/ex.02.matrix-views/main.cpp | 9 +- dash/examples/ex.06.make-pattern/main.cpp | 29 +++++++ dash/examples/util.h | 13 ++- dash/include/dash/algorithm/Copy.h | 4 +- dash/include/dash/view/Expand.h | 1 + dash/include/dash/view/IndexSet.h | 51 ++++++----- dash/include/dash/view/ViewSpec.h | 86 ++++++++++++------- dash/include/dash/view/ViewTraits.h | 31 +++---- 10 files changed, 161 insertions(+), 84 deletions(-) create mode 100644 dash/examples/ex.02.matrix-strides/main.cpp create mode 100644 dash/examples/ex.06.make-pattern/main.cpp diff --git a/dash/examples/ex.02.matrix-strides/main.cpp b/dash/examples/ex.02.matrix-strides/main.cpp new file mode 100644 index 000000000..b3e62adf5 --- /dev/null +++ b/dash/examples/ex.02.matrix-strides/main.cpp @@ -0,0 +1,11 @@ + + + +int main(int argc, char * argv[]) +{ + + + + return EXIT_SUCCESS; +} + diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index ffeff62fd..c975b6ff7 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -74,11 +74,9 @@ int main(int argc, char *argv[]) for (const auto & blk : m_s_blocks) { auto m_isect = matrix_sub | intersect(blk); - print("--- matrix | sub {3,-1} {1-1} | intersect(" << - "block(" << m_s_blocks_idx[b_idx] << ")) " << - "--- block[0,0] = " << std::fixed << std::setprecision(2) << - static_cast(blk[{0,0}]) << - nview_str(m_isect) << std::endl); + print("--- matrix | sub {3,-1} {1-1} | " << + "block(" << m_s_blocks_idx[b_idx] << ") " << + nview_str(blk) << std::endl); ++b_idx; } @@ -96,7 +94,7 @@ int main(int argc, char *argv[]) "offsets: " << blk.offsets() << " " << "extents: " << blk.extents()); - print(nview_str(blk) << std::endl); +// print(nview_str(blk) << std::endl); ++b_idx; } diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index cfe2ddf90..f3ea20f68 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -129,10 +129,9 @@ int main(int argc, char *argv[]) "at unit", g_block_unit.id); DASH_LOG_DEBUG("MatrixViewsExample", "vvvvvvvvvvvvvvvvvvvvvvvvvvv"); // Block is assigned to selecte remote unit, create local copy: - auto remote_block_matrix = matrix.block(gb); + auto remote_block_matrix = dash::sub(1,5, matrix.block(gb)); - auto remote_block_view = dash::sub(1,5, - dash::blocks(matrix)[gb]); + auto remote_block_view = dash::sub(1,5, dash::blocks(matrix)[gb]); DASH_LOG_DEBUG("MatrixViewsExample", "-- type:", dash::typestr(remote_block_view)); @@ -195,9 +194,9 @@ int main(int argc, char *argv[]) dash::index(dash::local(remote_block_view)) .size()); - DASH_ASSERT(remote_block_matrix.viewspec().offsets() == + DASH_ASSERT(remote_block_matrix.offsets() == dash::index(remote_block_view).offsets()); - DASH_ASSERT(remote_block_matrix.viewspec().extents() == + DASH_ASSERT(remote_block_matrix.extents() == dash::index(remote_block_view).extents()); copy_dest_last = dash::copy(remote_block_view, diff --git a/dash/examples/ex.06.make-pattern/main.cpp b/dash/examples/ex.06.make-pattern/main.cpp new file mode 100644 index 000000000..30c9be9a0 --- /dev/null +++ b/dash/examples/ex.06.make-pattern/main.cpp @@ -0,0 +1,29 @@ + +#include + +typedef struct cli_params_t { + cli_params_t() + { } + std::array domainsize {{ 12, 12 }}; + std::array teamsize {{ 3, 4 }}; + std::array tilesize {{ 3, 4 }}; + bool blocked_display = false; + bool balance_extents = false; + bool cout = false; +} cli_params; + +run_params parse_args(int argc, char * argv[]) { + +} + +int main(int argc, char * argv[]) +{ + dash::init(argc, argv); + + + + + dash::finalize(); + return EXIT_SUCCESS; +} + diff --git a/dash/examples/util.h b/dash/examples/util.h index 5de6b8f93..71c4d7a2a 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -50,12 +50,17 @@ std::string nview_str( int prec = 2) { using value_t = typename NViewType::value_type; - auto view_nrows = nview.extents()[0]; - auto view_ncols = nview.extents()[1]; - auto nindex = dash::index(nview); + const auto view_nrows = nview.extents()[0]; + const auto view_ncols = nview.extents()[1]; + const auto nindex = dash::index(nview); std::ostringstream ss; + + ss << "\n "; + for (int c = 0; c < view_ncols; ++c) { + ss << std::setw(8 + prec) << std::left << c; + } for (int r = 0; r < view_nrows; ++r) { - ss << '\n' << " " << std::right << std::setw(2) << r << " "; + ss << '\n' << std::right << std::setw(3) << r << " "; for (int c = 0; c < view_ncols; ++c) { int offset = r * view_ncols + c; value_t val = nview[offset]; diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index ce37160d4..770dc5250 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1216,8 +1216,8 @@ template < class GlobInputRange, class GlobOutputRange, typename std::enable_if< - ( dash::view_traits::is_view::value && - dash::view_traits::is_view::value ), + ( dash::is_view::value && + dash::is_view::value ), int >::type = 0 > GlobOutputRange copy( diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index 4fd008fca..a2d6faeab 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 04acb1d7f..b24fa8602 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1643,7 +1643,7 @@ class IndexSetBlock index_type block_idx) : base_t(view) , _block_idx(block_idx) - , _size(calc_size(block_idx)) + , _size(calc_size()) { } constexpr explicit IndexSetBlock( @@ -1651,7 +1651,7 @@ class IndexSetBlock index_type block_idx) : base_t(std::move(view)) , _block_idx(block_idx) - , _size(calc_size(block_idx)) + , _size(calc_size()) { } constexpr bool is_strided() const noexcept { @@ -1666,20 +1666,14 @@ class IndexSetBlock constexpr std::array extents() const { - return ( this->is_local() - ? this->pattern().local_block(_block_idx).extents() - : this->pattern().block(_block_idx).extents() - ); + return calc_viewspec().extents(); } // ---- offsets --------------------------------------------------------- constexpr std::array offsets() const { - return ( this->is_local() - ? this->pattern().local_block(_block_idx).offsets() - : this->pattern().block(_block_idx).offsets() - ); + return calc_viewspec().offsets(); } // ---- access ---------------------------------------------------------- @@ -1699,7 +1693,7 @@ class IndexSetBlock // global coords this->pattern().coords(block_phase), // viewspec - this->pattern().local_block(_block_idx) + this->calc_viewspec() ) ) : ( // translate block phase to global index: dash::CartesianIndexSpace( @@ -1707,18 +1701,22 @@ class IndexSetBlock ).at( // in-block coords dash::CartesianIndexSpace( - this->pattern().block(_block_idx).extents() + this->extents() ).coords( block_phase >= this->pattern().block(_block_idx).size() ? block_phase - 1 : block_phase ), // block viewspec - this->pattern().block(_block_idx)) + this->pattern().block(_block_idx).intersect( + // domain viewspec + ViewSpec( + this->view_domain().offsets(), + this->view_domain().extents())) ) + ( block_phase >= this->pattern().block(_block_idx).size() ? 1 : 0) - + ) ); } @@ -1739,16 +1737,27 @@ class IndexSetBlock } private: - constexpr index_type calc_size(index_type block_idx) const { + constexpr index_type calc_size() const { + return calc_viewspec().size(); + } + + ViewSpec calc_viewspec() const { return ( view_domain_is_local - ? ( // viewspec of local block referenced by this view: - this->pattern().local_block(block_idx).size() - ) - : ( // viewspec of block referenced by this view: - this->pattern().block(block_idx).size() - ) + ? // viewspec of local block referenced by this view: + this->pattern().local_block(_block_idx).intersect( + // viewspec of domain: + ViewSpec( + this->view_domain().offsets(), + this->view_domain().extents()) ) + : // viewspec of block referenced by this view: + this->pattern().block(_block_idx).intersect( + // viewspec of domain: + ViewSpec( + this->view_domain().offsets(), + this->view_domain().extents()) ) ); } + }; // class IndexSetBlock static inline auto index() { diff --git a/dash/include/dash/view/ViewSpec.h b/dash/include/dash/view/ViewSpec.h index 749108609..df174ed1a 100644 --- a/dash/include/dash/view/ViewSpec.h +++ b/dash/include/dash/view/ViewSpec.h @@ -91,6 +91,13 @@ std::ostream & operator<<( /** * Specifies view parameters for implementing submat, rows and cols * + * TODO: Should be specified as + * ViewSpec(begin Point { 0, 2, 3 }, + * end Point { 4, 7, 9 }) + * -> offset(d) = begin(d) + * extent(d) = end(d) - begin(d) + * + * * \concept(DashCartesianSpaceConcept) */ template< @@ -101,15 +108,16 @@ class ViewSpec private: typedef ViewSpec self_t; - typedef typename std::make_unsigned::type - SizeType; typedef ViewPair ViewPair_t; public: - typedef ViewRegion region_type; - typedef ViewRange range_type; - typedef std::integral_constant rank; + typedef IndexType index_type; + typedef typename std::make_unsigned::type size_type; + typedef ViewRegion region_type; + typedef ViewRange range_type; + + typedef std::integral_constant rank; public: template @@ -118,10 +126,10 @@ class ViewSpec const ViewSpec & viewspec); private: - SizeType _size = 0; - SizeType _rank = NDim; - std::array _extents = {{ }}; - std::array _offsets = {{ }}; + size_type _size = 0; + size_type _rank = NDim; + std::array _extents = {{ }}; + std::array _offsets = {{ }}; public: /** @@ -143,7 +151,7 @@ class ViewSpec * dimensions. */ ViewSpec( - const std::array & extents) + const std::array & extents) : _size(1), _rank(NDim), _extents(extents) @@ -158,8 +166,8 @@ class ViewSpec * Constructor, initialize with given extents and offsets. */ ViewSpec( - const std::array & offsets, - const std::array & extents) + const std::array & offsets, + const std::array & extents) : _size(1), _rank(NDim), _extents(extents), @@ -212,13 +220,13 @@ class ViewSpec * Change the view specification's extent in every dimension. */ template - void resize(SizeType arg, Args... args) + void resize(size_type arg, Args... args) { static_assert( sizeof...(Args) == (NDim-1), "Invalid number of arguments"); - std::array extents = - { arg, (SizeType)(args)... }; + std::array extents = + { arg, (size_type)(args)... }; resize(extents); } @@ -254,8 +262,8 @@ class ViewSpec */ void resize_dim( dim_t dimension, - IndexType offset, - SizeType extent) + index_type offset, + size_type extent) { _offsets[dimension] = offset; _extents[dimension] = extent; @@ -288,16 +296,16 @@ class ViewSpec * \return A copy if this view spec as a new instance of `ViewSpec` * with the sliced dimension removed */ - ViewSpec + ViewSpec slice(dim_t dimension) { - std::array slice_extents; - std::array slice_offsets; + std::array slice_extents; + std::array slice_offsets; for (dim_t d = dimension; d < _rank-1; d++) { slice_offsets[d] = _offsets[d+1]; slice_extents[d] = _extents[d+1]; } - return ViewSpec(slice_offsets, + return ViewSpec(slice_offsets, slice_extents); } @@ -314,26 +322,26 @@ class ViewSpec update_size(); } - constexpr SizeType size() const + constexpr size_type size() const { return _size; } - constexpr SizeType size(dim_t dimension) const + constexpr size_type size(dim_t dimension) const { return _extents[dimension]; } - constexpr const std::array & extents() const + constexpr const std::array & extents() const { return _extents; } - constexpr SizeType extent(dim_t dim) const { + constexpr size_type extent(dim_t dim) const { return _extents[dim]; } - constexpr const std::array & offsets() const + constexpr const std::array & offsets() const { return _offsets; } @@ -341,11 +349,11 @@ class ViewSpec constexpr range_type range(dim_t dim) const { return range_type { - static_cast(_offsets[dim]), - static_cast(_offsets[dim] + _extents[dim]) }; + static_cast(_offsets[dim]), + static_cast(_offsets[dim] + _extents[dim]) }; } - constexpr IndexType offset(dim_t dim) const + constexpr index_type offset(dim_t dim) const { return _offsets[dim]; } @@ -356,21 +364,37 @@ class ViewSpec reg.begin = _offsets; reg.end = _offsets; for (dim_t d = 0; d < NDim; ++d) { - reg.end[d] += static_cast(_extents[d]); + reg.end[d] += static_cast(_extents[d]); } return reg; } + template + self_t intersect(const ViewSpec & other) { + // TODO: Implement using dash::ce::map(extents(), other.extents()) ... + auto isc_extents = extents(); + auto isc_offsets = offsets(); + for (dim_t d = 0; d < NDim_; ++d) { + auto offset_d = std::max(isc_offsets[d], other.offsets()[d]); + isc_extents[d] = std::min(isc_offsets[d] + isc_extents[d], + other.offset(d) + other.extent(d)) + - offset_d; + isc_offsets[d] = offset_d; + } + return self_t(isc_offsets, isc_extents); + } + private: void update_size() { _size = 1; - for (SizeType d = 0; d < NDim; ++d) { + for (size_type d = 0; d < NDim; ++d) { _size *= _extents[d]; } } }; + template struct is_view_region; diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index 7f48ee45c..3724d00d8 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -51,27 +51,17 @@ struct view_traits #else // DOXYGEN -template -struct view_traits; - -template -struct is_view_region; - -template -struct is_view_region -: std::integral_constant< - bool, - view_traits::is_view::value> -{ }; - template struct rank; template struct rank -: view_traits::rank +: std::integral_constant::type::rank::value> { }; +template +struct view_traits; + template class IndexSetIdentity; @@ -89,6 +79,17 @@ template struct is_view : dash::detail::has_type_index_set_type { }; +template +struct is_view_region; + +template +struct is_view_region +: std::integral_constant< + bool, + dash::is_view::value> +{ }; + + namespace detail { @@ -136,7 +137,7 @@ namespace detail { global_type >::type image_type; typedef typename dash::view_traits::origin_type origin_type; - typedef std::integral_constant rank; + typedef dash::rank rank; }; /** From aa12565fad674375fb2db4c92b2b34496c822f31 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 25 Sep 2017 18:24:19 -0700 Subject: [PATCH 115/161] Added block view .is_local_at, cleanup --- dash/examples/ex.02.matrix-sub-views/main.cpp | 44 +++++----- dash/examples/util.h | 34 +++++++- dash/include/dash/view/IndexSet.h | 21 ++++- dash/include/dash/view/Sub.h | 82 ++++++++++--------- dash/include/dash/view/ViewBlocksMod.h | 22 +++++ dash/include/dash/view/ViewMod.h | 5 +- dash/test/container/MatrixTest.cc | 2 + 7 files changed, 142 insertions(+), 68 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index c975b6ff7..8c99289b8 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -1,33 +1,25 @@ #include #include "../util.h" -using std::cout; -using std::cerr; -using std::cin; -using std::endl; -using std::vector; - -using uint = unsigned int; - int main(int argc, char *argv[]) { using namespace dash; + typedef dash::SeqTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + dash::init(&argc, &argv); - auto myid = dash::myid(); + auto myid = dash::Team::All().myid(); auto nunits = dash::size(); const size_t block_size_x = 2; const size_t block_size_y = 2; const size_t block_size = block_size_x * block_size_y; - size_t extent_x = block_size_x * nunits; - size_t extent_y = block_size_y * nunits; - - typedef dash::TilePattern<2> pattern_t; - typedef typename pattern_t::index_type index_t; - typedef float value_t; + size_t extent_x = block_size_x * (nunits + 1); + size_t extent_y = block_size_y * (nunits + 1); dash::TeamSpec<2> teamspec(dash::Team::All()); teamspec.balance_extents(); @@ -49,8 +41,7 @@ int main(int argc, char *argv[]) std::generate(matrix.lbegin(), matrix.lend(), [&]() { - auto u = dash::myid(); - return u + 0.01 * li++; + return dash::myid() + 0.01 * li++; }); dash::barrier(); @@ -58,15 +49,14 @@ int main(int argc, char *argv[]) if (myid == 0) { print("matrix:" << nview_str(matrix | sub(0,extent_y)) << '\n'); - print("matrix.local.size(): " << matrix.local.size()); auto matrix_sub = matrix | sub<0>(3, extent_y-1) | sub<1>(1, extent_x-1); - print("matrix | sub<0>(3,-1) | sub<1>(1,-1)" << + print("matrix | sub<0> | sub<1>" << nview_str(matrix_sub) << "\n\n"); - print("matrix | sub<0>(3,-1) | sub<1>(1,-1) | blocks()\n"); + print("matrix | sub<0> | sub<1> | blocks\n"); { auto m_s_blocks = matrix_sub | blocks(); auto m_s_blocks_idx = m_s_blocks | index(); @@ -74,23 +64,27 @@ int main(int argc, char *argv[]) for (const auto & blk : m_s_blocks) { auto m_isect = matrix_sub | intersect(blk); - print("--- matrix | sub {3,-1} {1-1} | " << - "block(" << m_s_blocks_idx[b_idx] << ") " << + print("block " << std::left << std::setw(2) + << m_s_blocks_idx[b_idx] << '\n' << + " " << + (blk.is_strided() ? "strided, " : "contiguous, ") << + (blk.is_local_at(myid) ? "local" : "remote") << nview_str(blk) << std::endl); ++b_idx; } } - print("matrix | sub<0>(3,-1) | sub<1>(1,-1) | local | blocks()\n"); + print("matrix | sub<0> | sub<1> | local | blocks()\n"); { +// print(nview_str(matrix_sub | local()) << std::endl); + auto m_s_l_blocks = matrix_sub | local() | blocks(); auto m_s_l_blocks_idx = m_s_l_blocks | index(); int b_idx = 0; print("--- number of blocks: " << m_s_l_blocks.size()); for (const auto & blk : m_s_l_blocks) { auto block_gidx = m_s_l_blocks_idx[b_idx]; - print("--- matrix | sub {3,-1} {1-1} | local | " << - "block(" << block_gidx << ") " << + print("--- block(" << block_gidx << ") " << "offsets: " << blk.offsets() << " " << "extents: " << blk.extents()); diff --git a/dash/examples/util.h b/dash/examples/util.h index 71c4d7a2a..ce91aaa5e 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -15,10 +15,10 @@ std::istringstream iss(mss.str()); \ std::string item; \ while (std::getline(iss, item)) { \ - oss << "[ " << dash::myid() << " ] +std::string nviewrc_str( + const NViewType & nview, + int prec = 2) +{ + using value_t = typename NViewType::value_type; + const auto view_nrows = nview.extents()[0]; + const auto view_ncols = nview.extents()[1]; + const auto nindex = dash::index(nview); + std::ostringstream ss; + ss << "\n "; for (int c = 0; c < view_ncols; ++c) { ss << std::setw(8 + prec) << std::left << c; diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index b24fa8602..f33747d4e 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1002,6 +1002,10 @@ class IndexSetLocal , _size(calc_size()) { } + constexpr bool is_local() const noexcept { + return true; + } + constexpr bool is_strided() const noexcept { return ( // Local sub range of one-dimensional range is contiguous: @@ -1654,11 +1658,26 @@ class IndexSetBlock , _size(calc_size()) { } + constexpr bool is_local() const noexcept { + return // Domain is local, block must be local: + dash::view_traits::is_local::value || + // First element is local, so block is local: + ( this->pattern().unit_at(this->first()) == + this->pattern().team().myid() ); + } + constexpr bool is_strided() const noexcept { return ( // Elements are contiguous within single block, block view // is not strided: - !dash::pattern_layout_traits::type::blocked + !dash::pattern_layout_traits::type::blocked || + // Block elements are contiguous but missing columns/rows for + // row-major/column-major storage order: + ( pattern_type::memory_order() == dash::ROW_MAJOR + ? this->extent(1) < this->pattern().blocksize(1) && + this->extent(0) > 1 + : this->extent(0) < this->pattern().blocksize(0) && + this->extent(1) > 1 ) ); } diff --git a/dash/include/dash/view/Sub.h b/dash/include/dash/view/Sub.h index c14ab6548..f439f6f8a 100644 --- a/dash/include/dash/view/Sub.h +++ b/dash/include/dash/view/Sub.h @@ -15,21 +15,6 @@ namespace dash { // ------------------------------------------------------------------------- #if 0 -/** - * Sub-section, view dimensions maintain domain dimensions. - * - * \concept{DashViewConcept} - */ -template < - dim_t SubDim = 0, - dim_t NViewDim, - class OffsetFirstT, - class OffsetFinalT > -constexpr ViewSubMod, SubDim> -sub(OffsetFirstT begin, - OffsetFinalT end) { - return ViewSubMod, SubDim>(begin, end); -} /** * Sub-section, view dimensions maintain domain dimensions. @@ -47,24 +32,9 @@ sub(const IndexRangeT & range) { } #endif -#if 0 -/** - * Sub-space projection, view reduces domain by one dimension. - * - * \concept{DashViewConcept} - */ -template < - dim_t SubDim = 0, - class OffsetT > -constexpr ViewSubMod -sub( - OffsetT offset) { - return ViewSubMod(offset); -} -#endif // ------------------------------------------------------------------------- -// View Proxies (coupled with origin memory / index space): +// View Operations (coupled with origin memory / index space): // ------------------------------------------------------------------------- template < @@ -72,19 +42,19 @@ template < class DomainT, class OffsetFirstT, class OffsetFinalT, - typename DomainValueT = typename std::decay::type > + typename DomainDecayT = typename std::decay::type > constexpr ViewSubMod< - DomainValueT, + DomainDecayT, SubDim, - dash::view_traits::rank::value > + dash::rank::value > sub(OffsetFirstT begin, OffsetFinalT end, DomainT && domain) { return ViewSubMod< - DomainValueT, + DomainDecayT, SubDim, - dash::view_traits::rank::value + dash::view_traits::rank::value >(std::forward(domain), begin, end); @@ -94,8 +64,9 @@ template < dim_t SubDim = 0, class DomainT, class OffsetT, + typename DomainDecayT = typename std::decay::type, typename std::enable_if< - (!std::is_integral::value && + (!std::is_integral::value && std::is_integral::value ), int >::type = 0 > @@ -122,6 +93,43 @@ static inline auto sub(OffsetT0 a, OffsetT1 b) { }); } +// ------------------------------------------------------------------------- +// Rectangular Region +// ------------------------------------------------------------------------- + +#if 0 +template < + class DomainT > +auto region( + DomainT && domain) { + return std::forward(domain); +} + +/** + * + * \code + * auto reg = matrix | region({ 2,6 }, { 1,5 }); + * // returns sub-matrix within rectangle (2,1), (6,5) + * \endcode + */ +template < + class DomainT, + typename IndexT = typename dash::view_traits::index_type, + dim_t NDim = dash::rank::value, + typename ... Args > +auto region( + DomainT && domain, + const std::array & dsub, + Args ... subs) { + return region( + dash::sub( + std::get<0>(dsub), + std::get<1>(dsub), + std::forward(domain)), + subs...); +} +#endif + } // namespace dash #endif // DASH__VIEW__SUB_H__INCLUDED diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 7050fd19b..ad4c1e8a9 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -173,6 +173,17 @@ class ViewBlockMod block_idx) { } + // ---- properties ------------------------------------------------------ + + constexpr bool is_strided() const noexcept { + return _index_set.is_strided(); + } + + constexpr bool is_local_at(dash::team_unit_t uid) const noexcept { + return _index_set.is_local() + && uid == _index_set.pattern().team().myid(); + } + // ---- extents --------------------------------------------------------- constexpr std::array extents() const { @@ -359,6 +370,17 @@ class ViewBlockMod block_final_gidx(this->domain(), block_idx)) { } + constexpr bool is_strided() const noexcept { + return false; // 1-dimensional blocks are contiguous + } + + constexpr bool is_local_at(dash::team_unit_t uid) const noexcept { + return // Domain is local, block must be local: + dash::view_traits::is_local::value || + // First element is local, so block is local: + _index_set.pattern().unit_at(_index_set[0]) == uid; + } + constexpr const_iterator begin() const { return const_iterator(dash::origin(*this).begin(), _index_set, 0); diff --git a/dash/include/dash/view/ViewMod.h b/dash/include/dash/view/ViewMod.h index e57fc2727..530e9fcbd 100644 --- a/dash/include/dash/view/ViewMod.h +++ b/dash/include/dash/view/ViewMod.h @@ -272,8 +272,9 @@ class ViewModBase return !(derived() == rhs); } - constexpr bool is_local() const { - return view_traits::is_local::value; + constexpr bool is_local_at(dash::team_unit_t uid) const noexcept { + return view_traits::is_local::value + && uid == dash::index(*this).pattern().team().myid(); } // ---- extents --------------------------------------------------------- diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 4b6457c02..66bfb9f82 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -738,6 +738,7 @@ TEST_F(MatrixTest, BlockCopyGlobalToGlobal) LOG_MESSAGE("Copying block"); +#if 0 // Copy block 1 of matrix_a to block 0 of matrix_b: dash::copy(block_a, block_b); @@ -754,6 +755,7 @@ TEST_F(MatrixTest, BlockCopyGlobalToGlobal) } } } +#endif } TEST_F(MatrixTest, StorageOrder) From 1b064a12fa0fe5f695cceca9fc8dc788d32c746e Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 25 Sep 2017 18:56:43 -0700 Subject: [PATCH 116/161] Cleanup --- dash/examples/ex.02.matrix-sub-views/main.cpp | 7 ++----- dash/test/container/MatrixTest.cc | 11 ++++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 8c99289b8..5de1baed2 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -62,15 +62,12 @@ int main(int argc, char *argv[]) auto m_s_blocks_idx = m_s_blocks | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { - auto m_isect = matrix_sub | intersect(blk); - print("block " << std::left << std::setw(2) << m_s_blocks_idx[b_idx] << '\n' << " " << - (blk.is_strided() ? "strided, " : "contiguous, ") << - (blk.is_local_at(myid) ? "local" : "remote") << + (blk.is_strided() ? "strided, " : "contiguous, ") << + (blk.is_local_at(myid) ? "local" : "remote") << nview_str(blk) << std::endl); - ++b_idx; } } diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 66bfb9f82..918116307 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -1119,21 +1119,21 @@ TEST_F(MatrixTest, UnderfilledBlockedPatternExtents) EXPECT_LE_U( corner[0] + matrix.local.extent(0), h ); } -TEST_F(MatrixTest, UnderfilledLocalViewSpec){ +TEST_F(MatrixTest, UnderfilledLocalViewSpec) { auto myid = dash::myid(); auto numunits = dash::Team::All().size(); dash::TeamSpec<2> teamspec( numunits, 1 ); teamspec.balance_extents(); - uint32_t w= 13; - uint32_t h= 7; + uint32_t w = 13; + uint32_t h = 7; auto distspec= dash::DistributionSpec<2>( dash::BLOCKED, dash::BLOCKED ); dash::NArray narray( dash::SizeSpec<2>( h, w ), distspec, dash::Team::All(), teamspec ); narray.barrier(); - if ( 0 == myid ) { + if (0 == myid) { LOG_MESSAGE("global extent is %lu x %lu", narray.extent(0), narray.extent(1)); } @@ -1149,6 +1149,7 @@ TEST_F(MatrixTest, UnderfilledLocalViewSpec){ ASSERT_EQ_U(el, 1); }); dash::barrier(); + // test local view std::fill(narray.local.begin(), narray.local.end(), 2); std::for_each(narray.local.begin(), narray.local.end(), @@ -1157,7 +1158,7 @@ TEST_F(MatrixTest, UnderfilledLocalViewSpec){ }); uint32_t elementsvisited = std::distance(narray.lbegin(), narray.lend()); - auto local_elements= narray.local.extent(0) * narray.local.extent(1); + auto local_elements = narray.local.extent(0) * narray.local.extent(1); ASSERT_EQ_U(elementsvisited, local_elements); ASSERT_EQ_U(elementsvisited, narray.local.size()); From 0631e7903a6d00c8a52616f9e7ffdc4aa73604f7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 25 Sep 2017 21:00:30 -0700 Subject: [PATCH 117/161] Fixing Matrix.local --- dash/include/dash/iterator/GlobViewIter.h | 2 +- dash/include/dash/iterator/LocalViewIter.h | 2 +- dash/include/dash/matrix/internal/LocalMatrixRef-inl.h | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dash/include/dash/iterator/GlobViewIter.h b/dash/include/dash/iterator/GlobViewIter.h index b0bc60d2b..ba3383872 100644 --- a/dash/include/dash/iterator/GlobViewIter.h +++ b/dash/include/dash/iterator/GlobViewIter.h @@ -694,7 +694,7 @@ class GlobViewIter /** * Unit and local offset at the iterator's position. - * Projects iterator position from its view spec to global index domain. + * Projects iterator position from its view spec to local index domain. */ inline typename pattern_type::local_index_t lpos() const { diff --git a/dash/include/dash/iterator/LocalViewIter.h b/dash/include/dash/iterator/LocalViewIter.h index ec7a07129..21eddd8ce 100644 --- a/dash/include/dash/iterator/LocalViewIter.h +++ b/dash/include/dash/iterator/LocalViewIter.h @@ -923,7 +923,7 @@ class LocalViewIter // Apply offset of view projection to view coords: for (dim_t d = 0; d < NumDimensions; ++d) { auto dim_offset = _viewspec->offset(d); - l_coords[d] += dim_offset; + l_coords[d] += dim_offset; } } else { l_coords = _pattern->local_memory_layout().coords(l_index); diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index f070284d9..773d5b335 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -32,11 +32,9 @@ ::LocalMatrixRef( { auto local_extents = mat->_pattern.local_extents(); DASH_LOG_TRACE_VAR("LocalMatrixRef(mat)", local_extents); - // Global offset to first local element is missing: - // _refview._viewspec.resize(local_extents); - std::array local_begin_coords = {{ }}; - auto local_offsets = mat->_pattern.global(local_begin_coords); - _refview._viewspec = ViewSpec_t(local_offsets, local_extents); +//std::array local_begin_coords = {{ }}; +//auto local_offsets = mat->_pattern.global(local_begin_coords); + _refview._viewspec = ViewSpec_t(local_extents); DASH_LOG_TRACE_VAR("LocalMatrixRef(mat) >", _refview._viewspec); } From d54a020c7e794871fbe951e06dbe86efc6a7701c Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 25 Sep 2017 22:26:46 -0700 Subject: [PATCH 118/161] Fixed MatrixTest.CopyRow --- dash/examples/ex.02.matrix-copy/main.cpp | 96 ++++++++++++++------- dash/examples/ex.02.matrix-strides/main.cpp | 3 +- dash/examples/ex.06.make-pattern/main.cpp | 11 +-- dash/include/dash/algorithm/Copy.h | 51 ++++++++--- dash/include/dash/iterator/LocalViewIter.h | 13 +-- dash/include/dash/view/ViewSpec.h | 15 ++-- 6 files changed, 123 insertions(+), 66 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 59faccbf7..5e7756841 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -1,5 +1,6 @@ #include +#include "../util.h" #include #include @@ -7,48 +8,83 @@ using std::cout; using std::endl; +using namespace dash; int main(int argc, char **argv) { - constexpr int elem_per_unit = 1000; + using dash::sub; + using dash::local; + using dash::index; + using dash::blocks; + + typedef dash::TilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + int blocksize_x = 2; + int blocksize_y = 3; + dash::init(&argc, &argv); - std::vector vec(100); - std::fill(vec.begin(), vec.end(), dash::myid()); + auto myid = dash::myid(); + auto nunits = dash::size(); + + dash::SizeSpec<2> sizespec((nunits * 2) * blocksize_y, + (nunits * 2) * blocksize_x); + dash::DistributionSpec<2> distspec(dash::BLOCKED, // dash::TILE(blocksize_y), + dash::BLOCKED);//dash::TILE(blocksize_x)); + dash::TeamSpec<2> teamspec(dash::Team::All()); + teamspec.balance_extents(); - dash::NArray matrix; + pattern_t pattern( + sizespec, + distspec, + teamspec + ); - dash::SizeSpec<2> sizespec(dash::size(), elem_per_unit); - dash::DistributionSpec<2> distspec(dash::BLOCKED, dash::NONE); - dash::TeamSpec<2> teamspec(dash::size(), 1); + dash::Matrix matrix(pattern); - matrix.allocate(sizespec, distspec, teamspec); + int li = 0; + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { + return dash::myid() + 0.01 * li++; + }); + + dash::barrier(); 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(dest_range.begin() + 100) - << endl; - - dash::copy(&vec[0], - &vec[0] + vec.size(), - static_cast(dest_range.begin())); + print("matrix:" << + nview_str(matrix | sub(0,matrix.extents()[0]))); + } + + dash::barrier(); + + print("matrix.local size: " << matrix.local.size()); + + for (int li = 0; li < matrix.local.size(); ++li) { + DASH_LOG_DEBUG_VAR("matrix.local", li); + + auto lit = matrix.local.begin() + li; + + DASH_LOG_DEBUG_VAR("matrix.local", lit); + print("matrix.local[" << li << "]: " << *lit); } + auto l_row = matrix.local.row(0); + print("matrix.local.row(0) " << + "size: " << l_row.size() << " " + "offsets: " << l_row.offsets() << " " + "extents: " << l_row.extents()); + + auto l_row_range = dash::make_range(l_row.begin(), l_row.end()); + print("matrix.local.row(0) range type: " << dash::typestr(l_row_range)); + print("matrix.local.row(0) range: " << l_row_range); + +//std::vector tmp(l_row.size()); +//auto copy_end = dash::copy(l_row.begin(), l_row.end(), +// tmp.data()); + matrix.barrier(); dash::finalize(); diff --git a/dash/examples/ex.02.matrix-strides/main.cpp b/dash/examples/ex.02.matrix-strides/main.cpp index b3e62adf5..ef7b11afa 100644 --- a/dash/examples/ex.02.matrix-strides/main.cpp +++ b/dash/examples/ex.02.matrix-strides/main.cpp @@ -1,11 +1,10 @@ +#include int main(int argc, char * argv[]) { - - return EXIT_SUCCESS; } diff --git a/dash/examples/ex.06.make-pattern/main.cpp b/dash/examples/ex.06.make-pattern/main.cpp index 30c9be9a0..70d4db23a 100644 --- a/dash/examples/ex.06.make-pattern/main.cpp +++ b/dash/examples/ex.06.make-pattern/main.cpp @@ -1,9 +1,9 @@ #include +typedef int extent_t; + typedef struct cli_params_t { - cli_params_t() - { } std::array domainsize {{ 12, 12 }}; std::array teamsize {{ 3, 4 }}; std::array tilesize {{ 3, 4 }}; @@ -12,13 +12,14 @@ typedef struct cli_params_t { bool cout = false; } cli_params; -run_params parse_args(int argc, char * argv[]) { - +cli_params parse_args(int argc, char * argv[]) { + cli_params params; + return params; } int main(int argc, char * argv[]) { - dash::init(argc, argv); + dash::init(&argc, &argv); diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 770dc5250..73c2bb18a 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -121,7 +121,7 @@ template < ValueType * copy_block( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { DASH_LOG_TRACE("dash::copy_block()", "in_first:", in_first.pos(), @@ -267,7 +267,7 @@ template < dash::Future copy_block_async( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { DASH_LOG_TRACE("dash::copy_block_async()", "in_first:", in_first.pos(), @@ -459,9 +459,9 @@ template < class ValueType, class GlobOutputIt > GlobOutputIt copy_block( - ValueType * in_first, - ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy_block()", "l_in_first:", in_first, @@ -495,9 +495,9 @@ template < class ValueType, class GlobOutputIt > dash::Future copy_block_async( - ValueType * in_first, - ValueType * in_last, - GlobOutputIt out_first) + ValueType * in_first, + ValueType * in_last, + GlobOutputIt out_first) { DASH_LOG_TRACE("dash::copy_block_async()", "l_in_first:", in_first, @@ -585,7 +585,7 @@ template < dash::Future copy_async( GlobInputIt in_first, GlobInputIt in_last, - ValueType * out_first) + ValueType * out_first) { const auto & team = in_first.team(); dash::util::UnitLocality uloc(team, team.myid()); @@ -1030,9 +1030,33 @@ auto copy( return out_last; } +/** + * Specialization of global to local copy for local iterators in global input + * range. + */ +template < + class ValueType, + class GlobInputIt, + typename std::enable_if< + std::is_same::value, + int >::type = 0 > +ValueType * copy( + GlobInputIt in_first, + GlobInputIt in_last, + ValueType * out_first) +{ + DASH_LOG_TRACE("dash::copy()", "blocking, local view iterator to local"); + return std::copy(static_cast(in_first), + static_cast(in_first), + out_first); +} + template < class ValueType, - class GlobInputIt > + class GlobInputIt, + typename std::enable_if< + !std::is_same::value, + int >::type = 0 > ValueType * copy( GlobInputIt in_first, GlobInputIt in_last, @@ -1044,10 +1068,9 @@ ValueType * copy( DASH_LOG_TRACE_VAR("dash::copy", in_last.dart_gptr()); DASH_LOG_TRACE_VAR("dash::copy", out_first); -//auto li_range_in_old = local_index_range(in_first, in_last); -//DASH_LOG_TRACE("dash::copy", "source index range (old):", -// "(", li_range_in_old.begin, ",", li_range_in_old.end, ")"); - auto in_range = dash::make_range(in_first, in_last); + auto in_range = dash::make_range(in_first, in_last); + DASH_LOG_TRACE("dash::copy", "source value range type:", + dash::typestr(in_range)); DASH_LOG_TRACE("dash::copy", "source value range:", in_range); DASH_LOG_TRACE("dash::copy", "source index range:", dash::index(in_range)); DASH_LOG_TRACE("dash::copy", "source range extents:", in_range.extents()); diff --git a/dash/include/dash/iterator/LocalViewIter.h b/dash/include/dash/iterator/LocalViewIter.h index 21eddd8ce..e688ca0b5 100644 --- a/dash/include/dash/iterator/LocalViewIter.h +++ b/dash/include/dash/iterator/LocalViewIter.h @@ -442,10 +442,11 @@ class LocalViewIter if (_viewspec != nullptr) { // Viewspec projection required: auto l_coords = coords(idx); - DASH_LOG_TRACE_VAR("LocalViewIter.[]", l_coords); idx = _pattern->local_memory_layout().at(l_coords); } - DASH_LOG_TRACE_VAR("LocalViewIter.[]", idx); + DASH_LOG_TRACE("LocalViewIter.[] >", + "globmem.lbegin:", _globmem->lbegin(), + "+", idx); // Global reference to element at given position: return *(_globmem->lbegin() + idx); } @@ -461,10 +462,11 @@ class LocalViewIter if (_viewspec != nullptr) { // Viewspec projection required: auto l_coords = coords(idx); - DASH_LOG_TRACE_VAR("LocalViewIter.[]", l_coords); idx = _pattern->local_memory_layout().at(); } - DASH_LOG_TRACE_VAR("LocalViewIter.[]", idx); + DASH_LOG_TRACE("LocalViewIter.[] >", + "globmem.lbegin:", _globmem->lbegin(), + "+", idx); // Global reference to element at given position: return *(_globmem->lbegin() + idx); } @@ -922,8 +924,7 @@ class LocalViewIter l_coords = index_space.coords(l_index); // Apply offset of view projection to view coords: for (dim_t d = 0; d < NumDimensions; ++d) { - auto dim_offset = _viewspec->offset(d); - l_coords[d] += dim_offset; + l_coords[d] += _viewspec->offset(d); } } else { l_coords = _pattern->local_memory_layout().coords(l_index); diff --git a/dash/include/dash/view/ViewSpec.h b/dash/include/dash/view/ViewSpec.h index df174ed1a..84ca82c3e 100644 --- a/dash/include/dash/view/ViewSpec.h +++ b/dash/include/dash/view/ViewSpec.h @@ -341,23 +341,20 @@ class ViewSpec return _extents[dim]; } - constexpr const std::array & offsets() const - { + constexpr const std::array & offsets() const { return _offsets; } - constexpr range_type range(dim_t dim) const - { + constexpr index_type offset(dim_t dim) const { + return _offsets[dim]; + } + + constexpr range_type range(dim_t dim) const { return range_type { static_cast(_offsets[dim]), static_cast(_offsets[dim] + _extents[dim]) }; } - constexpr index_type offset(dim_t dim) const - { - return _offsets[dim]; - } - region_type region() const { region_type reg; From 83a3e719d09d1930b80ed65e5b2cb46738ae7c6b Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 25 Sep 2017 22:53:01 -0700 Subject: [PATCH 119/161] Fixed typo in dash::copy --- dash/examples/ex.02.matrix-copy/main.cpp | 6 +++--- dash/include/dash/algorithm/Copy.h | 2 +- dash/test/container/MatrixTest.cc | 21 ++++++++------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 5e7756841..4291ec14a 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -81,9 +81,9 @@ int main(int argc, char **argv) print("matrix.local.row(0) range type: " << dash::typestr(l_row_range)); print("matrix.local.row(0) range: " << l_row_range); -//std::vector tmp(l_row.size()); -//auto copy_end = dash::copy(l_row.begin(), l_row.end(), -// tmp.data()); + std::vector tmp(l_row.size()); + auto copy_end = dash::copy(l_row.begin(), l_row.end(), + tmp.data()); matrix.barrier(); dash::finalize(); diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 73c2bb18a..95c3035a9 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1047,7 +1047,7 @@ ValueType * copy( { DASH_LOG_TRACE("dash::copy()", "blocking, local view iterator to local"); return std::copy(static_cast(in_first), - static_cast(in_first), + static_cast(in_last), out_first); } diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 918116307..99e7f9bdc 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -1195,6 +1195,13 @@ TEST_F(MatrixTest, MatrixLBegin) int * l_first = matrix.lbegin(); + DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", + matrix.local.block(0).offsets()); + DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", + matrix.local.block(0).extents()); + DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", + matrix.local.block(0)); + EXPECT_EQ_U(myid, static_cast(*(matrix.lbegin()))); EXPECT_EQ_U(myid, static_cast(*(matrix.local.block(0).begin()))); EXPECT_EQ_U(myid, static_cast(*(matrix.local.begin()))); @@ -1274,22 +1281,10 @@ TEST_F(MatrixTest, CopyRow) dash::barrier(); dash::test::print_matrix("Matrix<2>.local.row(0)", row, 2); - auto l_prange = dash::local_range(row.begin(), row.end()); - DASH_LOG_DEBUG_VAR("MatrixTest.CopyRow", - static_cast(l_prange.begin)); - DASH_LOG_DEBUG_VAR("MatrixTest.CopyRow", - static_cast(l_prange.end)); - auto l_irange = dash::local_index_range(row.begin(), row.end()); - DASH_LOG_DEBUG_VAR("MatrixTest.CopyRow", static_cast(l_irange.begin)); - DASH_LOG_DEBUG_VAR("MatrixTest.CopyRow", static_cast(l_irange.end)); - - EXPECT_EQ_U(row_size, l_irange.end - l_irange.begin); - EXPECT_EQ_U(row_size, l_prange.end - l_prange.begin); - EXPECT_EQ_U(1, decltype(row)::ndim()); EXPECT_EQ_U(n_lextent, row_size); - EXPECT_EQ_U(n_lextent, row.extents()[1]); + EXPECT_EQ_U(n_lextent, row.end() - row.begin()); // Check values and test for each expression: int li = 0; From d417278c0196bae2c0d8afe7935f2a2c33b91ea7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 00:51:13 -0700 Subject: [PATCH 120/161] Fixed matrix unit tests --- dash/examples/ex.02.matrix-copy/main.cpp | 6 ++--- .../dash/matrix/internal/LocalMatrixRef-inl.h | 4 ++-- dash/test/container/MatrixTest.cc | 23 +++++++++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 4291ec14a..fc809226b 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -77,9 +77,9 @@ int main(int argc, char **argv) "offsets: " << l_row.offsets() << " " "extents: " << l_row.extents()); - auto l_row_range = dash::make_range(l_row.begin(), l_row.end()); - print("matrix.local.row(0) range type: " << dash::typestr(l_row_range)); - print("matrix.local.row(0) range: " << l_row_range); +// auto l_row_range = dash::make_range(l_row.begin(), l_row.end()); +// print("matrix.local.row(0) range type: " << dash::typestr(l_row_range)); +// print("matrix.local.row(0) range: " << l_row_range); std::vector tmp(l_row.size()); auto copy_end = dash::copy(l_row.begin(), l_row.end(), diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index 773d5b335..50c2dab0e 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -109,13 +109,13 @@ ::block( DASH_LOG_TRACE("LocalMatrixRef.block()", block_lindex); const auto& pattern = _refview._mat->_pattern; // Global view of local block: - auto l_block_g_view = pattern.local_block(block_lindex); +//auto l_block_g_view = pattern.local_block(block_lindex); // Local view of local block: auto l_block_l_view = pattern.local_block_local(block_lindex); // Return a view specified by the block's viewspec: ViewT view; view._refview = MatrixRefView_t(_refview._mat); - view._refview._viewspec = l_block_g_view; + view._refview._viewspec = l_block_l_view; view._refview._l_viewspec = l_block_l_view; DASH_LOG_TRACE("LocalMatrixRef.block >", "global:", diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 99e7f9bdc..76852efe4 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -156,8 +156,12 @@ TEST_F(MatrixTest, Views) l_block_view.offset(1), ")", "extent: (", l_block_view.extent(0), ",", l_block_view.extent(1), ")"); - // Verify matrix.block(b) == matrix.local.block(lb): - ASSERT_EQ_U(g_block_view, l_block_view); + // Verify matrix.block(b) vs. matrix.local.block(lb): + ASSERT_EQ_U(l_block_view.extents(), l_block_view.extents()); + ASSERT_EQ_U(l_block_view.offsets(), l_block_view.offsets()); + + ASSERT_TRUE_U(std::equal(g_block.begin(), g_block.end(), + l_block.begin(), l_block.end())); ++lb; } } @@ -1194,6 +1198,13 @@ TEST_F(MatrixTest, MatrixLBegin) matrix.barrier(); int * l_first = matrix.lbegin(); + DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", l_first); + + int * l_matrix_first = static_cast(matrix.local.begin()); + DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", l_matrix_first); + + EXPECT_EQ_U(l_first, l_matrix_first); + EXPECT_EQ_U(myid, *l_matrix_first); DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", matrix.local.block(0).offsets()); @@ -1202,9 +1213,11 @@ TEST_F(MatrixTest, MatrixLBegin) DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", matrix.local.block(0)); - EXPECT_EQ_U(myid, static_cast(*(matrix.lbegin()))); - EXPECT_EQ_U(myid, static_cast(*(matrix.local.block(0).begin()))); - EXPECT_EQ_U(myid, static_cast(*(matrix.local.begin()))); + int * l_block_first = static_cast(matrix.local.block(0).begin()); + DASH_LOG_DEBUG_VAR("MatrixTest.MatrixLBegin", l_block_first); + + EXPECT_EQ_U(l_first, l_block_first); + EXPECT_EQ_U(myid, *l_block_first); } TEST_F(MatrixTest, DelayedPatternAllocation) From b68573b12f6025a27aaa73446bdee5e7c5b804ab Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 02:33:29 -0700 Subject: [PATCH 121/161] Intermediate, fixing matrix local block views --- dash/examples/ex.02.matrix-copy/main.cpp | 131 +++++++++++++++++------ dash/include/dash/algorithm/Copy.h | 14 ++- dash/test/algorithm/CopyTest.cc | 13 +-- 3 files changed, 118 insertions(+), 40 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index fc809226b..6c031ae24 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -10,6 +10,10 @@ using std::endl; using namespace dash; +template +void run_example(MatrixT & matrix); + + int main(int argc, char **argv) { using dash::sub; @@ -29,24 +33,53 @@ int main(int argc, char **argv) auto myid = dash::myid(); auto nunits = dash::size(); - dash::SizeSpec<2> sizespec((nunits * 2) * blocksize_y, - (nunits * 2) * blocksize_x); - dash::DistributionSpec<2> distspec(dash::BLOCKED, // dash::TILE(blocksize_y), - dash::BLOCKED);//dash::TILE(blocksize_x)); dash::TeamSpec<2> teamspec(dash::Team::All()); teamspec.balance_extents(); - pattern_t pattern( + dash::DistributionSpec<2> block_ds(dash::BLOCKED, + dash::BLOCKED); + dash::DistributionSpec<2> tiled_ds(dash::TILE(blocksize_y), + dash::TILE(blocksize_x)); + dash::SizeSpec<2> sizespec((teamspec.extent(0) * 2) * blocksize_y, + (teamspec.extent(1) * 2) * blocksize_x); + + pattern_t block_pattern( + sizespec, + block_ds, + teamspec + ); + + pattern_t tiled_pattern( sizespec, - distspec, + tiled_ds, teamspec ); - dash::Matrix matrix(pattern); + // Block-distributed Matrix: + dash::Matrix + matrix_blocked(block_pattern); + + // Block-distributed Matrix: + dash::Matrix + matrix_tiled(tiled_pattern); + +// run_example(matrix_blocked); + run_example(matrix_tiled); + + dash::finalize(); + + return 0; +} + +template +void run_example(MatrixT & matrix) { + typedef typename MatrixT::pattern_type pattern_t; + typedef typename pattern_t::index_type index_t; + typedef typename MatrixT::value_type value_t; int li = 0; - std::generate(matrix.lbegin(), - matrix.lend(), + std::generate(matrix.local.begin(), + matrix.local.end(), [&]() { return dash::myid() + 0.01 * li++; }); @@ -60,33 +93,69 @@ int main(int argc, char **argv) dash::barrier(); - print("matrix.local size: " << matrix.local.size()); + print("matrix.local size: " << matrix.local.size()); + print("matrix.local extents: " << matrix.local.extents()); + print("matrix.local offsets: " << matrix.local.offsets()); for (int li = 0; li < matrix.local.size(); ++li) { - DASH_LOG_DEBUG_VAR("matrix.local", li); - auto lit = matrix.local.begin() + li; - - DASH_LOG_DEBUG_VAR("matrix.local", lit); - print("matrix.local[" << li << "]: " << *lit); + DASH_ASSERT_EQ(*lit, *(matrix.lbegin() + li), "local value mismatch"); } - auto l_row = matrix.local.row(0); - print("matrix.local.row(0) " << - "size: " << l_row.size() << " " - "offsets: " << l_row.offsets() << " " - "extents: " << l_row.extents()); - -// auto l_row_range = dash::make_range(l_row.begin(), l_row.end()); -// print("matrix.local.row(0) range type: " << dash::typestr(l_row_range)); -// print("matrix.local.row(0) range: " << l_row_range); - - std::vector tmp(l_row.size()); - auto copy_end = dash::copy(l_row.begin(), l_row.end(), - tmp.data()); - + // Copy local row + { + auto l_row = matrix | local() | sub(0,1); // matrix.local.row(0); + DASH_LOG_DEBUG("matrix.local.row(0)", + "type:", dash::typestr(l_row)); + print("matrix.local.row(0): " << + "size: " << l_row.size() << " " << + "offsets: " << l_row.offsets() << " " << + "extents: " << l_row.extents()); + +// print("matrix.local.row(0) " << nview_str(l_row)); + +#if 0 + std::vector tmp(l_row.size()); + auto copy_end = dash::copy(l_row.begin(), l_row.end(), + tmp.data()); + print("matrix.local.row(0) copy: " << tmp); +#endif + } matrix.barrier(); - dash::finalize(); - return 0; + // Copy local block + { + auto l_blocks = matrix | local() | blocks(); + print("matrix.local.blocks(): " << + "size: " << l_blocks.size() << " " << + "offsets: " << l_blocks.offsets() << " " << + "extents: " << l_blocks.extents()); + + int l_bi = 0; + for (const auto & lb : l_blocks) { + print("matrix.local.blocks(): [" << l_bi << "]: " << + "size: " << lb.size() << " " << + "offsets: " << lb.offsets() << " " << + "extents: " << lb.extents()); + ++l_bi; + } + + auto l_block = matrix | local() | block(0); // matrix.local.block(0); + DASH_LOG_DEBUG("matrix.local.block(0)", + "type:", dash::typestr(l_block)); + print("matrix.local.block(0): " << + "size: " << l_block.size() << " " << + "offsets: " << l_block.offsets() << " " << + "extents: " << l_block.extents()); + +// print("matrix.local.block(0) " << nview_str(l_block)); +#if 0 + std::vector tmp(l_block.size()); + auto copy_end = dash::copy(l_block.begin(), l_block.end(), + tmp.data()); + print("matrix.local.block(0) copy: " << tmp); +#endif + } + matrix.barrier(); } + diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 95c3035a9..36fe7be5d 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1046,9 +1046,17 @@ ValueType * copy( ValueType * out_first) { DASH_LOG_TRACE("dash::copy()", "blocking, local view iterator to local"); - return std::copy(static_cast(in_first), - static_cast(in_last), - out_first); + DASH_LOG_TRACE_VAR("dash::copy", in_last - in_first); +// DASH_LOG_TRACE_VAR("dash::copy", in_first.viewspec().offsets()); +// DASH_LOG_TRACE_VAR("dash::copy", in_first.viewspec().extents()); +// DASH_LOG_TRACE_VAR("dash::copy", in_last.viewspec().offsets()); +// DASH_LOG_TRACE_VAR("dash::copy", in_last.viewspec().extents()); + ValueType * out_last = std::copy(static_cast(in_first), + static_cast(in_last), + out_first); + DASH_LOG_TRACE_VAR("dash::copy", out_last - out_first); + DASH_LOG_TRACE_VAR("dash::copy >", out_last); + return out_last; } template < diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index 3b18f41b7..3734f5c5a 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -305,14 +305,15 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) value_t local_block_copy[block_size]; int lb = 0; auto l_block = matrix.local.block(lb); - LOG_MESSAGE("Creating local copy of first local block"); - value_t * local_block_copy_last = - dash::copy(l_block.begin(), - l_block.end(), - local_block_copy); + DASH_LOG_DEBUG("CopyTest.Blocking2Dim", "matrix.local.block(0):", + "size:", l_block.size()); + EXPECT_EQ_U(block_size, l_block.size()); + auto local_block_copy_last = dash::copy(l_block.begin(), + l_block.end(), + local_block_copy); // Validate number of copied elements: auto num_copied = local_block_copy_last - local_block_copy; - EXPECT_EQ_U(num_copied, block_size); + EXPECT_EQ_U(block_size, num_copied); for (size_t bx = 0; bx < block_size_x; ++bx) { for (size_t by = 0; by < block_size_y; ++by) { auto l_offset = (bx * block_size_y) + by; From 5e32fa05f26401982325026928b65aad2c2b96cf Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 03:35:47 -0700 Subject: [PATCH 122/161] Fixed IndexSetBlock.rel for local domain --- dash/examples/ex.02.matrix-copy/main.cpp | 14 +++++--------- dash/include/dash/view/IndexSet.h | 17 +++++++++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 6c031ae24..873b1bf69 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -137,18 +137,14 @@ void run_example(MatrixT & matrix) { "size: " << lb.size() << " " << "offsets: " << lb.offsets() << " " << "extents: " << lb.extents()); + + DASH_LOG_DEBUG("matrix.local.block(0)", "print ..."); + print("matrix.local.blocks(): [" << l_bi << "]: " << + nview_str(lb)); + ++l_bi; } - auto l_block = matrix | local() | block(0); // matrix.local.block(0); - DASH_LOG_DEBUG("matrix.local.block(0)", - "type:", dash::typestr(l_block)); - print("matrix.local.block(0): " << - "size: " << l_block.size() << " " << - "offsets: " << l_block.offsets() << " " << - "extents: " << l_block.extents()); - -// print("matrix.local.block(0) " << nview_str(l_block)); #if 0 std::vector tmp(l_block.size()); auto copy_end = dash::copy(l_block.begin(), l_block.end(), diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index f33747d4e..0e46ae928 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1708,9 +1708,14 @@ class IndexSetBlock constexpr index_type rel(index_type block_phase) const { return ( view_domain_is_local ? ( // translate block phase to local index: - this->pattern().local_at( - // global coords - this->pattern().coords(block_phase), + this->pattern().local_at( // local coords -> local index + // phase to in-block coords + dash::CartesianIndexSpace( + this->extents() + ).coords( + block_phase >= this->pattern().block(_block_idx).size() + ? block_phase - 1 + : block_phase ), // viewspec this->calc_viewspec() ) ) @@ -1718,7 +1723,7 @@ class IndexSetBlock dash::CartesianIndexSpace( this->pattern().extents() ).at( - // in-block coords + // phase to in-block coords dash::CartesianIndexSpace( this->extents() ).coords( @@ -1762,8 +1767,8 @@ class IndexSetBlock ViewSpec calc_viewspec() const { return ( view_domain_is_local - ? // viewspec of local block referenced by this view: - this->pattern().local_block(_block_idx).intersect( + ? // local viewspec of local block referenced by this view: + this->pattern().local_block_local(_block_idx).intersect( // viewspec of domain: ViewSpec( this->view_domain().offsets(), From 9d013cdd2cf2303e53b0c784a6028e63adf48ee1 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 04:25:36 -0700 Subject: [PATCH 123/161] Fixed Local-/GlobalViewIter operator[] offsets --- dash/examples/ex.02.matrix-copy/main.cpp | 12 ++++-- dash/examples/util.h | 1 + dash/include/dash/iterator/GlobViewIter.h | 38 ++++++++++++++----- dash/include/dash/iterator/LocalViewIter.h | 34 ++++++++++++----- .../dash/matrix/internal/LocalMatrixRef-inl.h | 3 +- 5 files changed, 65 insertions(+), 23 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 873b1bf69..d18d06602 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -93,9 +93,15 @@ void run_example(MatrixT & matrix) { dash::barrier(); - print("matrix.local size: " << matrix.local.size()); - print("matrix.local extents: " << matrix.local.extents()); - print("matrix.local offsets: " << matrix.local.offsets()); + auto l_matrix = matrix | local() + | sub(0,matrix.local.extents()[0]); + + print("matrix | local size: " << l_matrix.size()); + print("matrix | local extents: " << l_matrix.extents()); + print("matrix | local offsets: " << l_matrix.offsets()); + print("matrix | local:" << nview_str(l_matrix)); + + dash::barrier(); for (int li = 0; li < matrix.local.size(); ++li) { auto lit = matrix.local.begin() + li; diff --git a/dash/examples/util.h b/dash/examples/util.h index ce91aaa5e..cc8f1680b 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -15,6 +15,7 @@ std::istringstream iss(mss.str()); \ std::string item; \ while (std::getline(iss, item)) { \ + DASH_LOG_DEBUG("print", item); \ oss << "[ U:" << dash::myid() << " ] "; \ oss << item << std::endl; \ } \ diff --git a/dash/include/dash/iterator/GlobViewIter.h b/dash/include/dash/iterator/GlobViewIter.h index ba3383872..bc08b0166 100644 --- a/dash/include/dash/iterator/GlobViewIter.h +++ b/dash/include/dash/iterator/GlobViewIter.h @@ -493,7 +493,7 @@ class GlobViewIter */ inline reference operator*() { - return this->operator[](_idx); + return this->operator[](0); } /** @@ -503,7 +503,7 @@ class GlobViewIter */ inline const_reference operator*() const { - return this->operator[](_idx); + return this->operator[](0); } /** @@ -512,22 +512,31 @@ class GlobViewIter */ reference operator[]( /// The global position of the element - index_type g_index) + index_type idx) { typedef typename pattern_type::local_index_t local_pos_t; // Global index to local index and unit: local_pos_t local_pos; + idx += _idx; + IndexType offset = 0; + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; + } if (_viewspec == nullptr) { // No viewspec mapping required: - local_pos = _pattern->local(g_index); + local_pos = _pattern->local(idx); } else { // Viewspec projection required: - auto glob_coords = coords(g_index); + auto glob_coords = coords(idx); local_pos = _pattern->local_index(glob_coords); } DASH_LOG_TRACE("GlobViewIter.[]", - "(index:", g_index, " voffset:", _view_idx_offset, ") ->", + "(index:", idx, " voffset:", _view_idx_offset, ") ->", "(unit:", local_pos.unit, " index:", local_pos.index, ")"); // Global reference to element at given position: return reference( @@ -541,22 +550,31 @@ class GlobViewIter */ const_reference operator[]( /// The global position of the element - index_type g_index) const + index_type idx) const { typedef typename pattern_type::local_index_t local_pos_t; + idx += _idx; + IndexType offset = 0; + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; + } // Global index to local index and unit: local_pos_t local_pos; if (_viewspec == nullptr) { // No viewspec mapping required: - local_pos = _pattern->local(g_index); + local_pos = _pattern->local(idx); } else { // Viewspec projection required: - auto glob_coords = coords(g_index); + auto glob_coords = coords(idx); local_pos = _pattern->local_index(glob_coords); } DASH_LOG_TRACE("GlobViewIter.[]", - "(index:", g_index, " voffset:", _view_idx_offset, ") ->", + "(index:", idx, " voffset:", _view_idx_offset, ") ->", "(unit:", local_pos.unit, " index:", local_pos.index, ")"); // Global reference to element at given position: return const_reference( diff --git a/dash/include/dash/iterator/LocalViewIter.h b/dash/include/dash/iterator/LocalViewIter.h index e688ca0b5..dcd441253 100644 --- a/dash/include/dash/iterator/LocalViewIter.h +++ b/dash/include/dash/iterator/LocalViewIter.h @@ -392,9 +392,6 @@ class LocalViewIter // which is the case for .end() iterators. idx = _max_idx; offset += _idx - _max_idx; - DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr", _max_idx); - DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr", idx); - DASH_LOG_TRACE_VAR("LocalViewIter.dart_gptr", offset); } // Global index to local index and unit: local_pos_t local_pos = lpos(); @@ -418,7 +415,7 @@ class LocalViewIter */ inline reference operator*() { - return this->operator[](_idx); + return this->operator[](0); } /** @@ -428,7 +425,7 @@ class LocalViewIter */ inline const_reference operator*() const { - return this->operator[](_idx); + return this->operator[](0); } /** @@ -439,16 +436,25 @@ class LocalViewIter /// The global position of the element index_type idx) { + DASH_LOG_TRACE_VAR("LocalViewIter.[]=()", idx); + idx += _idx; + IndexType offset = 0; + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; + } if (_viewspec != nullptr) { // Viewspec projection required: auto l_coords = coords(idx); idx = _pattern->local_memory_layout().at(l_coords); } - DASH_LOG_TRACE("LocalViewIter.[] >", + DASH_LOG_TRACE("LocalViewIter.[]= >", "globmem.lbegin:", _globmem->lbegin(), "+", idx); // Global reference to element at given position: - return *(_globmem->lbegin() + idx); + return *(_globmem->lbegin() + idx + offset); } /** @@ -459,6 +465,15 @@ class LocalViewIter /// The global position of the element index_type idx) const { + DASH_LOG_TRACE_VAR("LocalViewIter.[]()", idx); + idx += _idx; + IndexType offset = 0; + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; + } if (_viewspec != nullptr) { // Viewspec projection required: auto l_coords = coords(idx); @@ -466,9 +481,10 @@ class LocalViewIter } DASH_LOG_TRACE("LocalViewIter.[] >", "globmem.lbegin:", _globmem->lbegin(), - "+", idx); + "+ index", idx, + "+ tail", offset); // Global reference to element at given position: - return *(_globmem->lbegin() + idx); + return *(_globmem->lbegin() + idx + offset); } /** diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index 50c2dab0e..5f90562de 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -34,7 +34,8 @@ ::LocalMatrixRef( DASH_LOG_TRACE_VAR("LocalMatrixRef(mat)", local_extents); //std::array local_begin_coords = {{ }}; //auto local_offsets = mat->_pattern.global(local_begin_coords); - _refview._viewspec = ViewSpec_t(local_extents); + _refview._viewspec = ViewSpec_t(local_extents); + _refview._l_viewspec = ViewSpec_t(local_extents); DASH_LOG_TRACE_VAR("LocalMatrixRef(mat) >", _refview._viewspec); } From c76907e51ffc53726565df302f8b2f1cac9cc896 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 05:09:08 -0700 Subject: [PATCH 124/161] Fixed LocalViewIter operator[] local offsets --- dash/examples/ex.02.matrix-copy/main.cpp | 48 +++++++++++----------- dash/examples/util.h | 4 +- dash/include/dash/iterator/LocalViewIter.h | 28 ++++++++----- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index d18d06602..5ddf40421 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -78,8 +78,8 @@ void run_example(MatrixT & matrix) { typedef typename MatrixT::value_type value_t; int li = 0; - std::generate(matrix.local.begin(), - matrix.local.end(), + std::generate(matrix.lbegin(), + matrix.lend(), [&]() { return dash::myid() + 0.01 * li++; }); @@ -93,24 +93,22 @@ void run_example(MatrixT & matrix) { dash::barrier(); - auto l_matrix = matrix | local() - | sub(0,matrix.local.extents()[0]); + print("matrix.pattern local size: " << matrix.pattern().local_size()); + print("matrix.pattern local extents: " << matrix.pattern().local_extents()); - print("matrix | local size: " << l_matrix.size()); + auto l_matrix = matrix | local(); + + print("matrix | local size: " << l_matrix.size()); print("matrix | local extents: " << l_matrix.extents()); print("matrix | local offsets: " << l_matrix.offsets()); - print("matrix | local:" << nview_str(l_matrix)); + print("matrix | local:" << + nview_str(l_matrix)); dash::barrier(); - for (int li = 0; li < matrix.local.size(); ++li) { - auto lit = matrix.local.begin() + li; - DASH_ASSERT_EQ(*lit, *(matrix.lbegin() + li), "local value mismatch"); - } - // Copy local row { - auto l_row = matrix | local() | sub(0,1); // matrix.local.row(0); + auto l_row = matrix | local() | sub(0,1); DASH_LOG_DEBUG("matrix.local.row(0)", "type:", dash::typestr(l_row)); print("matrix.local.row(0): " << @@ -138,25 +136,25 @@ void run_example(MatrixT & matrix) { "extents: " << l_blocks.extents()); int l_bi = 0; + auto l_blocks_idx = l_blocks | index(); for (const auto & lb : l_blocks) { - print("matrix.local.blocks(): [" << l_bi << "]: " << - "size: " << lb.size() << " " << - "offsets: " << lb.offsets() << " " << - "extents: " << lb.extents()); + DASH_LOG_DEBUG("matrix.local.blocks()", "[", l_bi, "]", + "size:", lb.size(), + "offsets:", lb.offsets(), + "extents:", lb.extents()); - DASH_LOG_DEBUG("matrix.local.block(0)", "print ..."); - print("matrix.local.blocks(): [" << l_bi << "]: " << + print("matrix.local.block(" << l_bi << "): " << + "block[" << l_blocks_idx[l_bi] << "]" << nview_str(lb)); - +#if 0 + std::vector tmp(lb.size()); + auto copy_end = dash::copy(lb.begin(), lb.end(), + tmp.data()); + print("matrix.local.block(" << l_bi << ") copy: " << tmp); +#endif ++l_bi; } -#if 0 - std::vector tmp(l_block.size()); - auto copy_end = dash::copy(l_block.begin(), l_block.end(), - tmp.data()); - print("matrix.local.block(0) copy: " << tmp); -#endif } matrix.barrier(); } diff --git a/dash/examples/util.h b/dash/examples/util.h index cc8f1680b..5984b0416 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -60,7 +60,7 @@ std::string nview_str( ss << "\n "; for (int c = 0; c < view_ncols; ++c) { int offset = r * view_ncols + c; - value_t val = nview[offset]; + value_t val = nview.begin()[offset]; ss << std::fixed << std::setw(3) << nindex[offset] << TermColorMod(unit_term_colors[(int)val]) @@ -92,7 +92,7 @@ std::string nviewrc_str( ss << '\n' << std::right << std::setw(3) << r << " "; for (int c = 0; c < view_ncols; ++c) { int offset = r * view_ncols + c; - value_t val = nview[offset]; + value_t val = nview.begin()[offset]; ss << std::fixed << std::setw(3) << nindex[offset] << TermColorMod(unit_term_colors[(int)val]) diff --git a/dash/include/dash/iterator/LocalViewIter.h b/dash/include/dash/iterator/LocalViewIter.h index dcd441253..c5abfce2d 100644 --- a/dash/include/dash/iterator/LocalViewIter.h +++ b/dash/include/dash/iterator/LocalViewIter.h @@ -445,11 +445,10 @@ class LocalViewIter idx = _max_idx; offset += _idx - _max_idx; } - if (_viewspec != nullptr) { - // Viewspec projection required: - auto l_coords = coords(idx); - idx = _pattern->local_memory_layout().at(l_coords); - } + // Local coords at index, applies viewspec: + auto l_coords = coords(idx); + // Local index with respect to local block layout: + idx = _pattern->local_at(l_coords); DASH_LOG_TRACE("LocalViewIter.[]= >", "globmem.lbegin:", _globmem->lbegin(), "+", idx); @@ -474,11 +473,10 @@ class LocalViewIter idx = _max_idx; offset += _idx - _max_idx; } - if (_viewspec != nullptr) { - // Viewspec projection required: - auto l_coords = coords(idx); - idx = _pattern->local_memory_layout().at(); - } + // Local coords at index, applies viewspec: + auto l_coords = coords(idx); + // Local index with respect to local block layout: + idx = _pattern->local_at(l_coords); DASH_LOG_TRACE("LocalViewIter.[] >", "globmem.lbegin:", _globmem->lbegin(), "+ index", idx, @@ -514,6 +512,10 @@ class LocalViewIter idx = _max_idx; offset += _idx - _max_idx; } + // Local coords at index, applies viewspec: + auto l_coords = coords(idx); + // Local index with respect to local block layout: + idx = _pattern->local_at(l_coords); DASH_LOG_TRACE_VAR("LocalViewIter.local=", idx); DASH_LOG_TRACE_VAR("LocalViewIter.local=", offset); @@ -576,6 +578,9 @@ class LocalViewIter inline index_type gpos() const { DASH_LOG_TRACE_VAR("LocalViewIter.gpos()", _idx); + + DASH_THROW(dash::exception::NotImplemented, "LocalViewIter.gpos"); + if (_viewspec == nullptr) { // No viewspec mapping required: DASH_LOG_TRACE_VAR("LocalViewIter.gpos >", _idx); @@ -611,6 +616,9 @@ class LocalViewIter inline typename pattern_type::local_index_t lpos() const { DASH_LOG_TRACE_VAR("LocalViewIter.lpos()", _idx); + + DASH_THROW(dash::exception::NotImplemented, "LocalViewIter.lpos"); + typedef typename pattern_type::local_index_t local_pos_t; IndexType idx = _idx; From a4460c2b24e3784e5286171303499fc5122f7c37 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 05:34:10 -0700 Subject: [PATCH 125/161] Further fixes in LocalViewIter --- dash/examples/ex.02.matrix-copy/main.cpp | 4 +- dash/include/dash/iterator/LocalViewIter.h | 67 ++++++++-------------- 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 5ddf40421..85db6c728 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -146,9 +146,9 @@ void run_example(MatrixT & matrix) { print("matrix.local.block(" << l_bi << "): " << "block[" << l_blocks_idx[l_bi] << "]" << nview_str(lb)); -#if 0 +#if 1 std::vector tmp(lb.size()); - auto copy_end = dash::copy(lb.begin(), lb.end(), + auto copy_end = dash::copy(lb, tmp.data()); print("matrix.local.block(" << l_bi << ") copy: " << tmp); #endif diff --git a/dash/include/dash/iterator/LocalViewIter.h b/dash/include/dash/iterator/LocalViewIter.h index c5abfce2d..59216923b 100644 --- a/dash/include/dash/iterator/LocalViewIter.h +++ b/dash/include/dash/iterator/LocalViewIter.h @@ -579,34 +579,24 @@ class LocalViewIter { DASH_LOG_TRACE_VAR("LocalViewIter.gpos()", _idx); - DASH_THROW(dash::exception::NotImplemented, "LocalViewIter.gpos"); - - if (_viewspec == nullptr) { - // No viewspec mapping required: - DASH_LOG_TRACE_VAR("LocalViewIter.gpos >", _idx); - return _idx; - } else { - IndexType idx = _idx; - IndexType offset = 0; - DASH_LOG_TRACE_VAR("LocalViewIter.gpos", *_viewspec); - DASH_LOG_TRACE_VAR("LocalViewIter.gpos", _max_idx); - // Convert iterator position (_idx) to local index and unit. - if (_idx > _max_idx) { - // Global iterator pointing past the range indexed by the pattern - // which is the case for .end() iterators. - idx = _max_idx; - offset = _idx - _max_idx; - } - // Viewspec projection required: - auto g_coords = coords(idx); - DASH_LOG_TRACE_VAR("LocalViewIter.gpos", _idx); - DASH_LOG_TRACE_VAR("LocalViewIter.gpos", g_coords); - auto g_idx = _pattern->memory_layout().at(g_coords); - DASH_LOG_TRACE_VAR("LocalViewIter.gpos", g_idx); - g_idx += offset; - DASH_LOG_TRACE_VAR("LocalViewIter.gpos >", g_idx); - return g_idx; + IndexType idx = _idx; + IndexType offset = 0; + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", _max_idx); + // Convert iterator position (_idx) to local index and unit. + if (_idx > _max_idx) { + // Global iterator pointing past the range indexed by the pattern + // which is the case for .end() iterators. + idx = _max_idx; + offset += _idx - _max_idx; } + // Local coords at index, applies viewspec: + auto l_coords = coords(idx); + // Global index with respect to local block layout: + IndexType g_idx = _pattern->global_index(_myid, l_coords); + DASH_LOG_TRACE_VAR("LocalViewIter.gpos", g_idx); + g_idx += offset; + DASH_LOG_TRACE_VAR("LocalViewIter.gpos >", g_idx); + return g_idx; } /** @@ -617,8 +607,6 @@ class LocalViewIter { DASH_LOG_TRACE_VAR("LocalViewIter.lpos()", _idx); - DASH_THROW(dash::exception::NotImplemented, "LocalViewIter.lpos"); - typedef typename pattern_type::local_index_t local_pos_t; IndexType idx = _idx; @@ -629,22 +617,15 @@ class LocalViewIter // which is the case for .end() iterators. idx = _max_idx; offset = _idx - _max_idx; - DASH_LOG_TRACE_VAR("LocalViewIter.lpos", _max_idx); - DASH_LOG_TRACE_VAR("LocalViewIter.lpos", idx); - DASH_LOG_TRACE_VAR("LocalViewIter.lpos", offset); } - // Global index to local index and unit: + // Local coords at index, applies viewspec: + auto l_coords = coords(idx); + // Local index with respect to local block layout: + idx = _pattern->local_at(l_coords); + local_pos_t local_pos; - if (_viewspec == nullptr) { - // No viewspec mapping required: - local_pos = _pattern->local(idx); - } else { - // Viewspec projection required: - DASH_LOG_TRACE_VAR("LocalViewIter.lpos", *_viewspec); - auto glob_coords = coords(idx); - local_pos = _pattern->local_index(glob_coords); - } - local_pos.index += offset; + local_pos.unit = _myid; + local_pos.index = idx + offset; DASH_LOG_TRACE("LocalViewIter.lpos >", "unit:", local_pos.unit, "local index:", local_pos.index); From 81842958e9b7d052303e7ab1f7de8db6f1432541 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 06:26:09 -0700 Subject: [PATCH 126/161] Fixed IndexSetBlock.rel for local views --- dash/examples/ex.02.matrix-copy/main.cpp | 4 +++- dash/include/dash/view/IndexSet.h | 28 ++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 85db6c728..89f3949f3 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -135,8 +135,10 @@ void run_example(MatrixT & matrix) { "offsets: " << l_blocks.offsets() << " " << "extents: " << l_blocks.extents()); - int l_bi = 0; auto l_blocks_idx = l_blocks | index(); +// print("matrix | local | blocks() | index:" << nview_str(l_blocks_idx)); + + int l_bi = 0; for (const auto & lb : l_blocks) { DASH_LOG_DEBUG("matrix.local.blocks()", "[", l_bi, "]", "size:", lb.size(), diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index 0e46ae928..d2a1d057e 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1708,17 +1708,41 @@ class IndexSetBlock constexpr index_type rel(index_type block_phase) const { return ( view_domain_is_local ? ( // translate block phase to local index: +#if 0 // uses iteration order for local index: this->pattern().local_at( // local coords -> local index // phase to in-block coords dash::CartesianIndexSpace( this->extents() ).coords( - block_phase >= this->pattern().block(_block_idx).size() + block_phase >= this->pattern().local_block(_block_idx).size() ? block_phase - 1 : block_phase ), // viewspec this->calc_viewspec() - ) ) + ) +#else // uses canonical order for local index: + dash::CartesianIndexSpace( + this->pattern().local_extents() + ).at( + // phase to in-block coords + dash::CartesianIndexSpace( + this->extents() + ).coords( + block_phase >= this->pattern().local_block(_block_idx).size() + ? block_phase - 1 + : block_phase ), + // block viewspec + this->pattern().local_block_local(_block_idx).intersect( + // domain viewspec + ViewSpec( + this->view_domain().offsets(), + this->view_domain().extents())) + ) + ( + block_phase >= this->pattern().local_block(_block_idx).size() + ? 1 + : 0) +#endif + ) : ( // translate block phase to global index: dash::CartesianIndexSpace( this->pattern().extents() From 1b929afbd9968e44882b9dd88c13f1d58d7961b7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 06:43:43 -0700 Subject: [PATCH 127/161] Cleanup in example ex.02.matrix-copy --- dash/examples/ex.02.matrix-copy/main.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-copy/main.cpp index 89f3949f3..eee32a95f 100644 --- a/dash/examples/ex.02.matrix-copy/main.cpp +++ b/dash/examples/ex.02.matrix-copy/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char **argv) dash::Matrix matrix_tiled(tiled_pattern); -// run_example(matrix_blocked); + run_example(matrix_blocked); run_example(matrix_tiled); dash::finalize(); @@ -89,20 +89,19 @@ void run_example(MatrixT & matrix) { if (dash::myid() == 0) { print("matrix:" << nview_str(matrix | sub(0,matrix.extents()[0]))); + + std::vector tmp(6); + auto copy_end = std::copy(matrix.begin() + 3, + matrix.begin() + 9, + tmp.data()); + print("matrix.begin()[3...9]: " << tmp); } dash::barrier(); - print("matrix.pattern local size: " << matrix.pattern().local_size()); - print("matrix.pattern local extents: " << matrix.pattern().local_extents()); - auto l_matrix = matrix | local(); - print("matrix | local size: " << l_matrix.size()); - print("matrix | local extents: " << l_matrix.extents()); - print("matrix | local offsets: " << l_matrix.offsets()); - print("matrix | local:" << - nview_str(l_matrix)); + print("matrix | local:" << nview_str(l_matrix)); dash::barrier(); @@ -136,7 +135,6 @@ void run_example(MatrixT & matrix) { "extents: " << l_blocks.extents()); auto l_blocks_idx = l_blocks | index(); -// print("matrix | local | blocks() | index:" << nview_str(l_blocks_idx)); int l_bi = 0; for (const auto & lb : l_blocks) { @@ -148,12 +146,12 @@ void run_example(MatrixT & matrix) { print("matrix.local.block(" << l_bi << "): " << "block[" << l_blocks_idx[l_bi] << "]" << nview_str(lb)); -#if 1 + std::vector tmp(lb.size()); auto copy_end = dash::copy(lb, tmp.data()); print("matrix.local.block(" << l_bi << ") copy: " << tmp); -#endif + ++l_bi; } From 7043632b8a43c310ea3cab8a21d4e70273bfd64d Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 10:21:14 -0700 Subject: [PATCH 128/161] Fixing n-dim local sub-views --- dash/examples/ex.02.matrix-views/main.cpp | 13 ------------- dash/include/dash/view/IndexSet.h | 14 -------------- 2 files changed, 27 deletions(-) diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index f3ea20f68..9034f4c4b 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -90,19 +90,6 @@ int main(int argc, char *argv[]) dash::typestr(sreg_block.begin())); DASH_LOG_DEBUG("MatrixViewsExample", nview_str(sreg_block)); - - auto block_rg = dash::make_range(reg_block.begin(), - reg_block.end()); - auto block_srg = dash::sub<0>(1,2, block_rg); - - DASH_LOG_DEBUG("MatrixViewsExample", "------------------------------", - nview_str(block_rg)); - DASH_LOG_DEBUG("MatrixViewsExample", "block range origin iterator:", - dash::typestr(dash::origin(block_srg).begin())); - // DASH_LOG_DEBUG("MatrixViewsExample", "block range origin:", - // nview_str(dash::origin(block_srg))); - // DASH_LOG_DEBUG("MatrixViewsExample", - // nview_str(block_srg)); } } dash::barrier(); diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index d2a1d057e..cb508ec7f 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1708,19 +1708,6 @@ class IndexSetBlock constexpr index_type rel(index_type block_phase) const { return ( view_domain_is_local ? ( // translate block phase to local index: -#if 0 // uses iteration order for local index: - this->pattern().local_at( // local coords -> local index - // phase to in-block coords - dash::CartesianIndexSpace( - this->extents() - ).coords( - block_phase >= this->pattern().local_block(_block_idx).size() - ? block_phase - 1 - : block_phase ), - // viewspec - this->calc_viewspec() - ) -#else // uses canonical order for local index: dash::CartesianIndexSpace( this->pattern().local_extents() ).at( @@ -1741,7 +1728,6 @@ class IndexSetBlock block_phase >= this->pattern().local_block(_block_idx).size() ? 1 : 0) -#endif ) : ( // translate block phase to global index: dash::CartesianIndexSpace( From f2d8197d0346f923ba9f5ae20cb91afb9497d605 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 10:32:24 -0700 Subject: [PATCH 129/161] Renamed example --- .../{ex.02.matrix-copy => ex.02.matrix-local-views}/main.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dash/examples/{ex.02.matrix-copy => ex.02.matrix-local-views}/main.cpp (100%) diff --git a/dash/examples/ex.02.matrix-copy/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp similarity index 100% rename from dash/examples/ex.02.matrix-copy/main.cpp rename to dash/examples/ex.02.matrix-local-views/main.cpp From f8a5d6f56bb7188b3fa2a4ef58628649445c0cfb Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 26 Sep 2017 10:32:43 -0700 Subject: [PATCH 130/161] Fixed macro usage in dart_communication --- dart-impl/mpi/src/dart_communication.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dart-impl/mpi/src/dart_communication.c b/dart-impl/mpi/src/dart_communication.c index ef5d4032e..e45b0d639 100644 --- a/dart-impl/mpi/src/dart_communication.c +++ b/dart-impl/mpi/src/dart_communication.c @@ -1194,7 +1194,7 @@ dart_ret_t dart_wait( (unsigned long)handle->win); if (handle->num_reqs > 0) { DART_LOG_DEBUG("dart_wait: -- MPI_Wait"); - DART_LOG_DEBUG( + CHECK_MPI_RET( MPI_Waitall(handle->num_reqs, handle->reqs, MPI_STATUS_IGNORE), "MPI_Waitall"); @@ -1236,8 +1236,8 @@ dart_ret_t dart_waitall_local( if (handles[i] != DART_HANDLE_NULL) { for (uint8_t j = 0; j < handles[i]->num_reqs; ++j) { if (handles[i]->reqs[j] != MPI_REQUEST_NULL){ - DART_LOG_TRACE("dart_waitall_local: -- handle[%"PRIu64"]: %p)", - i, (void*)handles[i]->reqs[j]); + DART_LOG_TRACE("dart_waitall_local: -- handle[%"PRIu64"]: 0x%x)", + i, handles[i]->reqs[j]); DART_LOG_TRACE("dart_waitall_local: handle[%"PRIu64"]->dest: %d", i, handles[i]->dest); mpi_req[r_n] = handles[i]->reqs[j]; @@ -1312,9 +1312,9 @@ dart_ret_t dart_waitall( if (handles[i] != DART_HANDLE_NULL) { for (uint8_t j = 0; j < handles[i]->num_reqs; ++j) { if (handles[i]->reqs[j] != MPI_REQUEST_NULL){ - DART_LOG_DEBUG("dart_waitall: -- handle[%zu](%p): " + DART_LOG_DEBUG("dart_waitall: -- handle[%zu](0x%x): " "dest:%d win:%"PRIu64, - i, (void*)handles[i]->reqs[0], + i, handles[i]->reqs[0], handles[i]->dest, (unsigned long)handles[i]->win); mpi_req[r_n] = handles[i]->reqs[j]; From a2cf66f23a23e62d34982071508824447e71d5c0 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 27 Sep 2017 05:50:53 -0700 Subject: [PATCH 131/161] Adding examples, fixes in ViewBlocksMod, LocalMatrixRef --- .../examples/ex.02.matrix-copy-views/main.cpp | 88 ++++++++ .../ex.02.matrix-local-views/main.cpp | 85 +++++-- dash/examples/ex.02.matrix-sub-views/main.cpp | 1 - dash/examples/ex.02.matrix-views/main.cpp | 8 + dash/examples/ex.06.make-pattern/main.cpp | 66 ++++-- .../ex.06.pattern-block-visualizer/main.cpp | 41 +--- dash/examples/ex.xx.tmp/main.cpp | 11 + dash/examples/pattern_params.h | 208 ++++++++++++++++++ dash/examples/util.h | 41 ++++ .../dash/matrix/internal/LocalMatrixRef-inl.h | 31 ++- dash/include/dash/view/ViewBlocksMod.h | 16 ++ 11 files changed, 510 insertions(+), 86 deletions(-) create mode 100644 dash/examples/ex.02.matrix-copy-views/main.cpp create mode 100644 dash/examples/ex.xx.tmp/main.cpp create mode 100644 dash/examples/pattern_params.h diff --git a/dash/examples/ex.02.matrix-copy-views/main.cpp b/dash/examples/ex.02.matrix-copy-views/main.cpp new file mode 100644 index 000000000..aaff7e07a --- /dev/null +++ b/dash/examples/ex.02.matrix-copy-views/main.cpp @@ -0,0 +1,88 @@ +#include +#include "../util.h" + + +int main(int argc, char *argv[]) +{ + using namespace dash; + + typedef dash::SeqTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + dash::init(&argc, &argv); + + auto myid = dash::Team::All().myid(); + auto nunits = dash::size(); + + const size_t block_size_x = 2; + const size_t block_size_y = 2; + const size_t block_size = block_size_x * block_size_y; + size_t extent_x = block_size_x * (nunits + 1); + size_t extent_y = block_size_y * (nunits + 1); + + dash::TeamSpec<2> teamspec(dash::Team::All()); + teamspec.balance_extents(); + + pattern_t pattern( + dash::SizeSpec<2>( + extent_y, + extent_x), + dash::DistributionSpec<2>( + dash::TILE(block_size_y), + dash::TILE(block_size_x)), + teamspec + ); + + dash::Matrix + matrix_a(pattern); + + dash::Matrix + matrix_b(pattern); + + int li; + + li = 0; + std::generate(matrix_a.lbegin(), + matrix_a.lend(), + [&]() { + return dash::myid() + 0.01 * li++; + }); + li = 0; + std::generate(matrix_b.lbegin(), + matrix_b.lend(), + [&]() { + return dash::myid() + 0.01 * li++; + }); + dash::barrier(); + + if (myid == 0) { + print("matrix_a:" << + nview_str(matrix_a | sub(0,extent_y)) << '\n'); + print("matrix_b:" << + nview_str(matrix_b | sub(0,extent_y)) << '\n'); + + print("matrix number of blocks:" <<(matrix_b | blocks()).size()); + } + dash::barrier(); + + index_t n_lblocks = (matrix_b | local() | blocks()).size(); + print("matrix number of local blocks:" <<(matrix_b | blocks()).size()); + + + index_t dst_block = dash::myid() + 1; + + auto copy_end = dash::copy(matrix_a | local() | block(1), + matrix_b | block(dst_block)); + + if (myid == 0) { + print("matrix:" << + nview_str(matrix_b | sub(0,extent_y)) << '\n'); + + print("matrix number of blocks:" <<(matrix_b | blocks()).size()); + } + + + dash::finalize(); + return EXIT_SUCCESS; +} diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index eee32a95f..b3a3a939d 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -1,6 +1,7 @@ #include #include "../util.h" +#include "../pattern_params.h" #include #include @@ -26,13 +27,76 @@ int main(int argc, char **argv) typedef float value_t; int blocksize_x = 2; - int blocksize_y = 3; + int blocksize_y = 2; dash::init(&argc, &argv); auto myid = dash::myid(); auto nunits = dash::size(); + auto params = parse_args(argc, argv); + + if (dash::myid() == 0) { + print_params(params); + + try { + dash::SizeSpec<2, extent_t> sizespec(params.size[0], params.size[1]); + dash::TeamSpec<2, index_t> teamspec(params.units[0], params.units[1]); + + if(params.balance_extents) { + teamspec.balance_extents(); + } + if (params.tile[0] < 0 && params.tile[1] < 0) { + auto max_team_extent = std::max(teamspec.extent(0), + teamspec.extent(1)); + params.tile[0] = sizespec.extent(0) / max_team_extent; + params.tile[1] = sizespec.extent(1) / max_team_extent; + } + if (params.type == "summa") { + auto pattern = make_summa_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + dash::Matrix + matrix(pattern); + run_example(matrix); + } else if (params.type == "block") { + auto pattern = make_block_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + dash::Matrix + matrix(pattern); + run_example(matrix); + } else if (params.type == "tile") { + auto pattern = make_tile_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + dash::Matrix + matrix(pattern); + run_example(matrix); + } else if (params.type == "shift") { + auto pattern = make_shift_tile_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + dash::Matrix + matrix(pattern); + run_example(matrix); + } else if (params.type == "seq") { + auto pattern = make_seq_tile_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + dash::Matrix + matrix(pattern); + run_example(matrix); + } else { + print_usage(argv); + exit(EXIT_FAILURE); + } + } catch (std::exception & excep) { + std::cerr << excep.what() << std::endl; + } + } + +#if 0 dash::TeamSpec<2> teamspec(dash::Team::All()); teamspec.balance_extents(); @@ -65,7 +129,7 @@ int main(int argc, char **argv) run_example(matrix_blocked); run_example(matrix_tiled); - +#endif dash::finalize(); return 0; @@ -107,22 +171,11 @@ void run_example(MatrixT & matrix) { // Copy local row { - auto l_row = matrix | local() | sub(0,1); - DASH_LOG_DEBUG("matrix.local.row(0)", + auto l_row = matrix | sub(0, matrix.extent(0)) | local() | sub(1,2); + DASH_LOG_DEBUG("matrix.local.row(1)", "type:", dash::typestr(l_row)); - print("matrix.local.row(0): " << - "size: " << l_row.size() << " " << - "offsets: " << l_row.offsets() << " " << - "extents: " << l_row.extents()); - -// print("matrix.local.row(0) " << nview_str(l_row)); -#if 0 - std::vector tmp(l_row.size()); - auto copy_end = dash::copy(l_row.begin(), l_row.end(), - tmp.data()); - print("matrix.local.row(0) copy: " << tmp); -#endif + print("matrix.local.row(1) " << nview_str(l_row)); } matrix.barrier(); diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 5de1baed2..20dda755c 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -91,7 +91,6 @@ int main(int argc, char *argv[]) } } } - dash::barrier(); dash::finalize(); return EXIT_SUCCESS; diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index 9034f4c4b..d98734042 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -9,6 +9,12 @@ using std::vector; using uint = unsigned int; +template +auto transform_in_view(MatrixT & mat, ViewMods && vmods) { + print("transform_in_view: " << nview_str(mat | vmods)); + return 0; +} + int main(int argc, char *argv[]) { @@ -65,6 +71,8 @@ int main(int argc, char *argv[]) print("matrix:" << nview_str(dash::sub(0, matrix.extents()[0], matrix))); + transform_in_view(matrix, sub<0>(2,4) | sub<1>(2,6)); + auto matrix_region = dash::size() > 1 ? dash::sub<0>( 2, matrix.extents()[0] - 2, diff --git a/dash/examples/ex.06.make-pattern/main.cpp b/dash/examples/ex.06.make-pattern/main.cpp index 70d4db23a..53814d554 100644 --- a/dash/examples/ex.06.make-pattern/main.cpp +++ b/dash/examples/ex.06.make-pattern/main.cpp @@ -1,29 +1,61 @@ #include +#include "../util.h" +#include "../pattern_params.h" -typedef int extent_t; +using namespace dash; -typedef struct cli_params_t { - std::array domainsize {{ 12, 12 }}; - std::array teamsize {{ 3, 4 }}; - std::array tilesize {{ 3, 4 }}; - bool blocked_display = false; - bool balance_extents = false; - bool cout = false; -} cli_params; - -cli_params parse_args(int argc, char * argv[]) { - cli_params params; - return params; -} int main(int argc, char * argv[]) { dash::init(&argc, &argv); - - - + auto params = parse_args(argc, argv); + + if (dash::myid() == 0) { + print_params(params); + + try { + dash::SizeSpec<2, extent_t> sizespec(params.size[0], params.size[1]); + dash::TeamSpec<2, index_t> teamspec(params.units[0], params.units[1]); + + if(params.balance_extents) { + teamspec.balance_extents(); + } + if (params.tile[0] < 0 && params.tile[1] < 0) { + auto max_team_extent = std::max(teamspec.extent(0), + teamspec.extent(1)); + params.tile[0] = sizespec.extent(0) / max_team_extent; + params.tile[1] = sizespec.extent(1) / max_team_extent; + } + if (params.type == "summa") { + auto pattern = make_summa_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + } else if (params.type == "block") { + auto pattern = make_block_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + } else if (params.type == "tile") { + auto pattern = make_tile_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + } else if (params.type == "shift") { + auto pattern = make_shift_tile_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + } else if (params.type == "seq") { + auto pattern = make_seq_tile_pattern(params, sizespec, teamspec); + std::cout << "Pattern type:\n " + << pattern_to_string(pattern) << std::endl; + } else { + print_usage(argv); + exit(EXIT_FAILURE); + } + } catch (std::exception & excep) { + std::cerr << excep.what() << std::endl; + } + } dash::finalize(); return EXIT_SUCCESS; } diff --git a/dash/examples/ex.06.pattern-block-visualizer/main.cpp b/dash/examples/ex.06.pattern-block-visualizer/main.cpp index c91e3116e..e4eb046e4 100644 --- a/dash/examples/ex.06.pattern-block-visualizer/main.cpp +++ b/dash/examples/ex.06.pattern-block-visualizer/main.cpp @@ -23,6 +23,8 @@ // needed for basename() #include +#include "../util.h" + using std::cout; using std::cerr; @@ -66,6 +68,7 @@ void print_usage(char **argv); static cli_params parse_args(int argc, char * argv[]); + static void print_params(const cli_params & params); @@ -214,9 +217,10 @@ int main(int argc, char* argv[]) dash::init(&argc, &argv); auto params = parse_args(argc, argv); - print_params(params); if (dash::myid() == 0) { + print_params(params); + try { dash::SizeSpec<2, extent_t> sizespec(params.size_y, params.size_x); dash::TeamSpec<2, index_t> teamspec(params.units_y, params.units_x); @@ -360,41 +364,6 @@ void print_params(const cli_params & params) << endl; } -/** - * Create string describing of pattern instance. - */ -template -static -std::string pattern_to_string( - const PatternType & pattern) -{ - typedef typename PatternType::index_type index_t; - - dim_t ndim = pattern.ndim(); - - std::string storage_order = pattern.memory_order() == ROW_MAJOR - ? "ROW_MAJOR" - : "COL_MAJOR"; - - std::array blocksize; - blocksize[0] = pattern.blocksize(0); - blocksize[1] = pattern.blocksize(1); - - std::ostringstream ss; - ss << "dash::" - << PatternType::PatternName - << "<" - << ndim << "," - << storage_order << "," - << typeid(index_t).name() - << ">(" << endl - << " SizeSpec: " << pattern.sizespec().extents() << "," << endl - << " TeamSpec: " << pattern.teamspec().extents() << "," << endl - << " BlockSpec: " << pattern.blockspec().extents() << "," << endl - << " BlockSize: " << blocksize << " )"; - - return ss.str(); -} /** * Create filename describing of pattern instance. diff --git a/dash/examples/ex.xx.tmp/main.cpp b/dash/examples/ex.xx.tmp/main.cpp new file mode 100644 index 000000000..65e5a1a81 --- /dev/null +++ b/dash/examples/ex.xx.tmp/main.cpp @@ -0,0 +1,11 @@ + +#include +#include + + +int main(int argc, char * argv[]) { + + return EXIT_SUCCESS; +}; + + diff --git a/dash/examples/pattern_params.h b/dash/examples/pattern_params.h new file mode 100644 index 000000000..855872ddf --- /dev/null +++ b/dash/examples/pattern_params.h @@ -0,0 +1,208 @@ +#ifndef DASH__EXAMPLES__PATTERN_PARAMS_H__INCLUDED +#define DASH__EXAMPLES__PATTERN_PARAMS_H__INCLUDED + +typedef dash::default_extent_t extent_t; +typedef dash::default_index_t index_t; + +typedef struct cli_params_t { + std::string type = "seq"; + std::array size {{ 12, 12 }}; + std::array units {{ 3, 4 }}; + std::array tile {{ 3, 4 }}; + bool blocked_display = false; + bool balance_extents = false; + bool cout = false; +} cli_params; + +void print_usage(char **argv); +cli_params parse_args(int argc, char * argv[]); +void print_params(const cli_params & params); + + +cli_params default_params; + +cli_params parse_args(int argc, char * argv[]) +{ + cli_params params = default_params; + + for (auto i = 1; i < argc; i += 3) { + std::string flag = argv[i]; + if (flag == "-h") { + print_usage(argv); + exit(EXIT_SUCCESS); + } + if (flag == "-s") { + params.type = argv[i+1]; + i -= 1; + } else if (flag == "-n") { + params.size = { static_cast(atoi(argv[i+1])), + static_cast(atoi(argv[i+2])) }; + } else if (flag == "-u") { + params.units = { static_cast(atoi(argv[i+1])), + static_cast(atoi(argv[i+2])) }; + } else if (flag == "-t") { + params.tile = { static_cast(atoi(argv[i+1])), + static_cast(atoi(argv[i+2])) }; + } else if (flag == "-e") { + params.balance_extents = true; + i -= 2; + } else { + print_usage(argv); + exit(EXIT_FAILURE); + } + } + + return params; +} + +void print_usage(char **argv) +{ + if (dash::myid() == 0) { + std::cerr << "Usage: \n" + << basename(argv[0]) << " " + << "-h | " + << "[-s pattern] " + << "[-n size_spec] " + << "[-u unit_spec] " + << "[-t tile_spec] " + << "[-p] " + << "\n\n"; + std::cerr << "-s pattern: [summa|block|tile|seq|shift]\n" + << "-n size_spec: [ " + << default_params.size[0] << " " << default_params.size[1] << " ]\n" + << "-u unit_spec: [ " + << default_params.units[0] << " " << default_params.units[1] << " ]\n" + << "-t tile_spec: [ automatically determined ]\n" + << "-p : print to stdout instead of stderr\n" + << "-h : print help and exit" + << std::endl; + } +} + +void print_params(const cli_params & params) +{ + int w_size = std::log10(std::max(params.size[0], params.size[1])); + int w_units = std::log10(std::max(params.units[0], params.units[1])); + int w_tile = std::log10(std::max(params.tile[0], params.tile[1])); + int w = std::max({ w_size, w_units, w_tile }) + 1; + + std::cerr << "Parameters:\n" + << " type (-s): " << params.type + << '\n' + << " size (-n ): ( " + << std::fixed << std::setw(w) << params.size[0] << ", " + << std::fixed << std::setw(w) << params.size[1] << " )" + << '\n' + << " team (-u ): ( " + << std::fixed << std::setw(w) << params.units[0] << ", " + << std::fixed << std::setw(w) << params.units[1] << " )" + << '\n' + << " balance extents (-e): " + << (params.balance_extents ? "yes" : "no") + << '\n' + << " tile (-t ): ( " + << std::fixed << std::setw(w) << params.tile[0] << ", " + << std::fixed << std::setw(w) << params.tile[1] << " )" + << '\n' + << std::endl; +} + +dash::TilePattern<2, dash::ROW_MAJOR, index_t> +make_summa_pattern( + const cli_params & params, + const dash::SizeSpec<2, extent_t> & sizespec, + const dash::TeamSpec<2, index_t> & teamspec) +{ + auto pattern = dash::make_pattern< + dash::summa_pattern_partitioning_constraints, + dash::summa_pattern_mapping_constraints, + dash::summa_pattern_layout_constraints >( + sizespec, + teamspec); + + if (params.tile[1] >= 0 || params.tile[0] >= 0) { + // change tile sizes of deduced pattern: + typedef decltype(pattern) pattern_t; + pattern_t custom_pattern(sizespec, + dash::DistributionSpec<2>( + params.tile[0] > 0 + ? dash::TILE(params.tile[0]) + : dash::NONE, + params.tile[1] > 0 + ? dash::TILE(params.tile[1]) + : dash::NONE), + teamspec); + pattern = custom_pattern; + } + return pattern; +} + +dash::ShiftTilePattern<2, dash::ROW_MAJOR, index_t> +make_shift_tile_pattern( + const cli_params & params, + const dash::SizeSpec<2, extent_t> & sizespec, + const dash::TeamSpec<2, index_t> & teamspec) +{ + // Example: -n 1680 1680 -u 28 1 -t 60 60 + typedef dash::ShiftTilePattern<2> pattern_t; + pattern_t pattern(sizespec, + dash::DistributionSpec<2>( + dash::TILE(params.tile[0]), + dash::TILE(params.tile[1])), + teamspec); + return pattern; +} + +dash::SeqTilePattern<2, dash::ROW_MAJOR, index_t> +make_seq_tile_pattern( + const cli_params & params, + const dash::SizeSpec<2, extent_t> & sizespec, + const dash::TeamSpec<2, index_t> & teamspec) +{ + // Example: -n 30 30 -u 4 1 -t 10 10 + typedef dash::SeqTilePattern<2> pattern_t; + pattern_t pattern(sizespec, + dash::DistributionSpec<2>( + dash::TILE(params.tile[0]), + dash::TILE(params.tile[1])), + teamspec); + return pattern; +} + +dash::TilePattern<2, dash::ROW_MAJOR, index_t> +make_tile_pattern( + const cli_params & params, + const dash::SizeSpec<2, extent_t> & sizespec, + const dash::TeamSpec<2, index_t> & teamspec) +{ + // Example: -n 30 30 -u 4 1 -t 10 10 + typedef dash::TilePattern<2> pattern_t; + pattern_t pattern(sizespec, + dash::DistributionSpec<2>( + dash::TILE(params.tile[0]), + dash::TILE(params.tile[1])), + teamspec); + return pattern; +} + +dash::Pattern<2, dash::ROW_MAJOR, index_t> +make_block_pattern( + const cli_params & params, + const dash::SizeSpec<2, extent_t> & sizespec, + const dash::TeamSpec<2, index_t> & teamspec) +{ + // Example: -n 30 30 -u 4 1 -t 10 10 + typedef dash::Pattern<2> pattern_t; + pattern_t pattern(sizespec, + dash::DistributionSpec<2>( + (params.tile[0] > 0 + ? dash::BLOCKCYCLIC(params.tile[0]) + : dash::NONE), + (params.tile[1] > 0 + ? dash::BLOCKCYCLIC(params.tile[1]) + : dash::NONE)), + teamspec); + return pattern; +} + +#endif // DASH__EXAMPLES__PATTERN_PARAMS_H__INCLUDED diff --git a/dash/examples/util.h b/dash/examples/util.h index 5984b0416..fd0d96a55 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -2,9 +2,14 @@ #define DASH__EXAMPLES__UTIL_H__INCLUDED #include + +#include #include +#include #include #include +#include +#include #define print(stream_expr__) \ @@ -105,4 +110,40 @@ std::string nviewrc_str( return ss.str(); } +/** + * Create string describing of pattern instance. + */ +template +static +std::string pattern_to_string( + const PatternType & pattern) +{ + typedef typename PatternType::index_type index_t; + + dash::dim_t ndim = pattern.ndim(); + + std::string storage_order = pattern.memory_order() == dash::ROW_MAJOR + ? "ROW_MAJOR" + : "COL_MAJOR"; + + std::array blocksize; + blocksize[0] = pattern.blocksize(0); + blocksize[1] = pattern.blocksize(1); + + std::ostringstream ss; + ss << "dash::" + << PatternType::PatternName + << "<" + << ndim << "," + << storage_order << "," + << typeid(index_t).name() + << ">(\n" + << " SizeSpec: " << pattern.sizespec().extents() << ",\n" + << " TeamSpec: " << pattern.teamspec().extents() << ",\n" + << " BlockSpec: " << pattern.blockspec().extents() << ",\n" + << " BlockSize: " << blocksize << " )"; + + return ss.str(); +} + #endif // DASH__EXAMPLES__UTIL_H__INCLUDED diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index 5f90562de..fea93c3e0 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -34,7 +34,6 @@ ::LocalMatrixRef( DASH_LOG_TRACE_VAR("LocalMatrixRef(mat)", local_extents); //std::array local_begin_coords = {{ }}; //auto local_offsets = mat->_pattern.global(local_begin_coords); - _refview._viewspec = ViewSpec_t(local_extents); _refview._l_viewspec = ViewSpec_t(local_extents); DASH_LOG_TRACE_VAR("LocalMatrixRef(mat) >", _refview._viewspec); } @@ -110,13 +109,13 @@ ::block( DASH_LOG_TRACE("LocalMatrixRef.block()", block_lindex); const auto& pattern = _refview._mat->_pattern; // Global view of local block: -//auto l_block_g_view = pattern.local_block(block_lindex); + auto l_block_g_view = pattern.local_block(block_lindex); // Local view of local block: auto l_block_l_view = pattern.local_block_local(block_lindex); // Return a view specified by the block's viewspec: ViewT view; view._refview = MatrixRefView_t(_refview._mat); - view._refview._viewspec = l_block_l_view; + view._refview._viewspec = l_block_g_view; view._refview._l_viewspec = l_block_l_view; DASH_LOG_TRACE("LocalMatrixRef.block >", "global:", @@ -158,7 +157,7 @@ ::extent( (NumDim - 1), "got ", dim); assert(false); } - return _refview._viewspec.extent(dim); + return _refview._l_viewspec.extent(dim); } template @@ -166,7 +165,7 @@ constexpr std::array LocalMatrixRef ::extents() const noexcept { - return _refview._viewspec.extents(); + return _refview._l_viewspec.extents(); } template @@ -181,7 +180,7 @@ ::offset( (NumDim - 1), "got ", dim); assert(false); } - return _refview._viewspec.offset(dim); + return _refview._l_viewspec.offset(dim); } template @@ -189,7 +188,7 @@ constexpr std::array LocalMatrixRef ::offsets() const noexcept { - return _refview._viewspec.offsets(); + return _refview._l_viewspec.offsets(); } template @@ -237,7 +236,7 @@ ::begin() noexcept return iterator( _refview._mat->_glob_mem, _refview._mat->_pattern, - _refview._viewspec, + _refview._l_viewspec, // iterator position in view index space 0, // view index start offset @@ -255,7 +254,7 @@ ::begin() const noexcept return const_iterator( _refview._mat->_glob_mem, _refview._mat->_pattern, - _refview._viewspec, + _refview._l_viewspec, // iterator position in view index space 0, // view index start offset @@ -318,7 +317,7 @@ typename LocalMatrixRef::size_type constexpr LocalMatrixRef ::size() const noexcept { - return _refview._viewspec.size(); + return _refview._l_viewspec.size(); } template @@ -594,13 +593,13 @@ ::sub( "Wrong sub-dimension"); LocalMatrixRef ref; ::std::fill(ref._refview._coord.begin(), ref._refview._coord.end(), 0); - ref._refview._viewspec = _refview._viewspec; - ref._refview._viewspec.resize_dim( + ref._refview._l_viewspec = _refview._l_viewspec; + ref._refview._l_viewspec.resize_dim( SubDimension, offset, extent); DASH_LOG_TRACE_VAR("LocalMatrixRef.sub >", - ref._refview._viewspec.size()); + ref._refview._l_viewspec.size()); ref._refview._mat = _refview._mat; return ref; } @@ -621,13 +620,13 @@ ::sub( "Wrong sub-dimension"); LocalMatrixRef ref; ::std::fill(ref._refview._coord.begin(), ref._refview._coord.end(), 0); - ref._refview._viewspec = _refview._viewspec; - ref._refview._viewspec.resize_dim( + ref._refview._l_viewspec = _refview._l_viewspec; + ref._refview._l_viewspec.resize_dim( SubDimension, offset, extent); DASH_LOG_TRACE_VAR("LocalMatrixRef.sub >", - ref._refview._viewspec.size()); + ref._refview._l_viewspec.size()); ref._refview._mat = _refview._mat; return ref; } diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index ad4c1e8a9..2fc2d63bd 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -249,6 +249,11 @@ class ViewBlockMod _index_set, offset)); } + reference operator[](int offset) { + return *(iterator(dash::origin(*this).begin(), + _index_set, offset)); + } + constexpr const_reference operator[]( const std::array< typename self_t::index_set_type::index_type, @@ -260,6 +265,17 @@ class ViewBlockMod dash::linearize(*this, coords))); } + reference operator[]( + const std::array< + typename self_t::index_set_type::index_type, + self_t::rank::value + > & coords) { + return *(iterator(dash::origin(*this).begin(), + _index_set, + // offset: + dash::linearize(*this, coords))); + } + constexpr const index_set_type & index_set() const { return _index_set; } From 4ea390e2bf3bb1bad61bd02e892327f29e604566 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 27 Sep 2017 07:40:00 -0700 Subject: [PATCH 132/161] Extending examples, fixed viewspecs in local matrix --- .../examples/ex.02.matrix-copy-views/main.cpp | 4 +- .../ex.02.matrix-local-views/main.cpp | 93 ++++++++----------- dash/include/dash/algorithm/Copy.h | 28 +++--- dash/include/dash/view/ViewBlocksMod.h | 7 ++ 4 files changed, 64 insertions(+), 68 deletions(-) diff --git a/dash/examples/ex.02.matrix-copy-views/main.cpp b/dash/examples/ex.02.matrix-copy-views/main.cpp index aaff7e07a..5da3e2faa 100644 --- a/dash/examples/ex.02.matrix-copy-views/main.cpp +++ b/dash/examples/ex.02.matrix-copy-views/main.cpp @@ -72,8 +72,8 @@ int main(int argc, char *argv[]) index_t dst_block = dash::myid() + 1; - auto copy_end = dash::copy(matrix_a | local() | block(1), - matrix_b | block(dst_block)); +// auto copy_end = dash::copy(matrix_a | local() | block(1), +// matrix_b | block(dst_block)); if (myid == 0) { print("matrix:" << diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index b3a3a939d..090c0257d 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -14,6 +14,18 @@ using namespace dash; template void run_example(MatrixT & matrix); +#define RUN_EXAMPLE(pattern_type__) do { \ + auto pattern = make_ ## pattern_type__ ## _pattern( \ + params, sizespec, teamspec); \ + std::cout << "Pattern:\n " \ + << pattern_to_string(pattern) << std::endl; \ + dash::Matrix \ + matrix(pattern); \ + std::cout << "Matrix:\n " \ + << typestr(matrix) << std::endl; \ + run_example(matrix); \ +} while(0) + int main(int argc, char **argv) { @@ -38,62 +50,33 @@ int main(int argc, char **argv) if (dash::myid() == 0) { print_params(params); + } - try { - dash::SizeSpec<2, extent_t> sizespec(params.size[0], params.size[1]); - dash::TeamSpec<2, index_t> teamspec(params.units[0], params.units[1]); - - if(params.balance_extents) { - teamspec.balance_extents(); - } - if (params.tile[0] < 0 && params.tile[1] < 0) { - auto max_team_extent = std::max(teamspec.extent(0), - teamspec.extent(1)); - params.tile[0] = sizespec.extent(0) / max_team_extent; - params.tile[1] = sizespec.extent(1) / max_team_extent; - } - if (params.type == "summa") { - auto pattern = make_summa_pattern(params, sizespec, teamspec); - std::cout << "Pattern type:\n " - << pattern_to_string(pattern) << std::endl; - dash::Matrix - matrix(pattern); - run_example(matrix); - } else if (params.type == "block") { - auto pattern = make_block_pattern(params, sizespec, teamspec); - std::cout << "Pattern type:\n " - << pattern_to_string(pattern) << std::endl; - dash::Matrix - matrix(pattern); - run_example(matrix); - } else if (params.type == "tile") { - auto pattern = make_tile_pattern(params, sizespec, teamspec); - std::cout << "Pattern type:\n " - << pattern_to_string(pattern) << std::endl; - dash::Matrix - matrix(pattern); - run_example(matrix); - } else if (params.type == "shift") { - auto pattern = make_shift_tile_pattern(params, sizespec, teamspec); - std::cout << "Pattern type:\n " - << pattern_to_string(pattern) << std::endl; - dash::Matrix - matrix(pattern); - run_example(matrix); - } else if (params.type == "seq") { - auto pattern = make_seq_tile_pattern(params, sizespec, teamspec); - std::cout << "Pattern type:\n " - << pattern_to_string(pattern) << std::endl; - dash::Matrix - matrix(pattern); - run_example(matrix); - } else { - print_usage(argv); - exit(EXIT_FAILURE); - } - } catch (std::exception & excep) { - std::cerr << excep.what() << std::endl; - } + dash::SizeSpec<2, extent_t> sizespec(params.size[0], params.size[1]); + dash::TeamSpec<2, index_t> teamspec(params.units[0], params.units[1]); + + if(params.balance_extents) { + teamspec.balance_extents(); + } + if (params.tile[0] < 0 && params.tile[1] < 0) { + auto max_team_extent = std::max(teamspec.extent(0), + teamspec.extent(1)); + params.tile[0] = sizespec.extent(0) / max_team_extent; + params.tile[1] = sizespec.extent(1) / max_team_extent; + } + if (params.type == "summa") { + RUN_EXAMPLE(summa); + } else if (params.type == "block") { + RUN_EXAMPLE(block); + } else if (params.type == "tile") { + RUN_EXAMPLE(tile); + } else if (params.type == "shift") { + RUN_EXAMPLE(shift_tile); + } else if (params.type == "seq") { + RUN_EXAMPLE(seq_tile); + } else { + print_usage(argv); + exit(EXIT_FAILURE); } #if 0 diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 36fe7be5d..7c799008e 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -1038,22 +1038,24 @@ template < class ValueType, class GlobInputIt, typename std::enable_if< - std::is_same::value, + std::is_pointer::value, int >::type = 0 > ValueType * copy( GlobInputIt in_first, GlobInputIt in_last, ValueType * out_first) { + typedef typename GlobInputIt::pointer pointer_t; + DASH_LOG_TRACE("dash::copy()", "blocking, local view iterator to local"); DASH_LOG_TRACE_VAR("dash::copy", in_last - in_first); // DASH_LOG_TRACE_VAR("dash::copy", in_first.viewspec().offsets()); // DASH_LOG_TRACE_VAR("dash::copy", in_first.viewspec().extents()); // DASH_LOG_TRACE_VAR("dash::copy", in_last.viewspec().offsets()); // DASH_LOG_TRACE_VAR("dash::copy", in_last.viewspec().extents()); - ValueType * out_last = std::copy(static_cast(in_first), - static_cast(in_last), - out_first); + auto out_last = std::copy(static_cast(in_first.local()), + static_cast(in_last.local()), + out_first); DASH_LOG_TRACE_VAR("dash::copy", out_last - out_first); DASH_LOG_TRACE_VAR("dash::copy >", out_last); return out_last; @@ -1243,17 +1245,20 @@ GlobOutputIt copy( * * \ingroup DashAlgorithms */ + template < - class GlobInputRange, - class GlobOutputRange, + typename GlobInputRange, + typename GlobOutputRange, typename std::enable_if< ( dash::is_view::value && dash::is_view::value ), - int >::type = 0 -> -GlobOutputRange copy( - GlobInputRange in_g_range, - GlobOutputRange out_g_range) + int >::type = 0 > +GlobOutputRange +// dash::IteratorRange< +// typename OutputRange::iterator, +// typename OutputRange::iterator > +copy(GlobInputRange && in_g_range, + GlobOutputRange out_g_range) { DASH_LOG_TRACE("dash::copy()", "blocking, global to global"); @@ -1406,6 +1411,7 @@ GlobOutputIt copy( } + // ====================================================================== // Other Specializations // ====================================================================== diff --git a/dash/include/dash/view/ViewBlocksMod.h b/dash/include/dash/view/ViewBlocksMod.h index 2fc2d63bd..caad3a1c7 100644 --- a/dash/include/dash/view/ViewBlocksMod.h +++ b/dash/include/dash/view/ViewBlocksMod.h @@ -755,6 +755,13 @@ static inline auto blocks() { }); } +static inline auto block(int bi) { + return dash::make_pipeable( + [=](auto && x) { + return blocks(std::forward(x))[bi]; + }); +} + } // namespace dash #endif // DASH__VIEW__VIEW_BLOCKS_MOD_H__INCLUDED From fb919faa58c47a49b957b04e37820e43e4f9fb6a Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 27 Sep 2017 08:30:49 -0700 Subject: [PATCH 133/161] Extending examples --- dash/examples/ex.02.matrix-sub-views/main.cpp | 25 +++++++++++++------ dash/examples/pattern_params.h | 6 ++--- .../dash/matrix/internal/LocalMatrixRef-inl.h | 13 +++++----- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 20dda755c..16646543c 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -1,6 +1,14 @@ #include #include "../util.h" +#include +#include + +#define STEP(stream_m__) do { \ + std::cin.ignore(); \ + print(stream_m__); \ +} while(0) + int main(int argc, char *argv[]) { @@ -50,28 +58,30 @@ int main(int argc, char *argv[]) print("matrix:" << nview_str(matrix | sub(0,extent_y)) << '\n'); + STEP("sub<0>(3,-1) | sub<1>(1,-1)"); + auto matrix_sub = matrix | sub<0>(3, extent_y-1) | sub<1>(1, extent_x-1); - print("matrix | sub<0> | sub<1>" << - nview_str(matrix_sub) << "\n\n"); + print(nview_str(matrix_sub) << "\n\n"); - print("matrix | sub<0> | sub<1> | blocks\n"); + STEP("sub<0>(3,-1) | sub<1>(1,-1) | blocks()"); { auto m_s_blocks = matrix_sub | blocks(); auto m_s_blocks_idx = m_s_blocks | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { - print("block " << std::left << std::setw(2) - << m_s_blocks_idx[b_idx] << '\n' << - " " << + STEP("block " << std::left << std::setw(2) + << m_s_blocks_idx[b_idx] << '\n'); + print(" " << (blk.is_strided() ? "strided, " : "contiguous, ") << (blk.is_local_at(myid) ? "local" : "remote") << nview_str(blk) << std::endl); ++b_idx; } } - print("matrix | sub<0> | sub<1> | local | blocks()\n"); + + STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()"); { // print(nview_str(matrix_sub | local()) << std::endl); @@ -80,6 +90,7 @@ int main(int argc, char *argv[]) int b_idx = 0; print("--- number of blocks: " << m_s_l_blocks.size()); for (const auto & blk : m_s_l_blocks) { + STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()[b_idx]"); auto block_gidx = m_s_l_blocks_idx[b_idx]; print("--- block(" << block_gidx << ") " << "offsets: " << blk.offsets() << " " << diff --git a/dash/examples/pattern_params.h b/dash/examples/pattern_params.h index 855872ddf..7ab0cd591 100644 --- a/dash/examples/pattern_params.h +++ b/dash/examples/pattern_params.h @@ -5,10 +5,10 @@ typedef dash::default_extent_t extent_t; typedef dash::default_index_t index_t; typedef struct cli_params_t { - std::string type = "seq"; + std::string type = "tile"; std::array size {{ 12, 12 }}; - std::array units {{ 3, 4 }}; - std::array tile {{ 3, 4 }}; + std::array units {{ 2, 2 }}; + std::array tile {{ 3, 4 }}; bool blocked_display = false; bool balance_extents = false; bool cout = false; diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index fea93c3e0..9a01a10cc 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -34,6 +34,7 @@ ::LocalMatrixRef( DASH_LOG_TRACE_VAR("LocalMatrixRef(mat)", local_extents); //std::array local_begin_coords = {{ }}; //auto local_offsets = mat->_pattern.global(local_begin_coords); + _refview._viewspec = ViewSpec_t(local_extents); _refview._l_viewspec = ViewSpec_t(local_extents); DASH_LOG_TRACE_VAR("LocalMatrixRef(mat) >", _refview._viewspec); } @@ -593,13 +594,13 @@ ::sub( "Wrong sub-dimension"); LocalMatrixRef ref; ::std::fill(ref._refview._coord.begin(), ref._refview._coord.end(), 0); - ref._refview._l_viewspec = _refview._l_viewspec; - ref._refview._l_viewspec.resize_dim( + ref._refview._viewspec = _refview._viewspec; + ref._refview._viewspec.resize_dim( SubDimension, offset, extent); DASH_LOG_TRACE_VAR("LocalMatrixRef.sub >", - ref._refview._l_viewspec.size()); + ref._refview._viewspec.size()); ref._refview._mat = _refview._mat; return ref; } @@ -620,13 +621,13 @@ ::sub( "Wrong sub-dimension"); LocalMatrixRef ref; ::std::fill(ref._refview._coord.begin(), ref._refview._coord.end(), 0); - ref._refview._l_viewspec = _refview._l_viewspec; - ref._refview._l_viewspec.resize_dim( + ref._refview._viewspec = _refview._viewspec; + ref._refview._viewspec.resize_dim( SubDimension, offset, extent); DASH_LOG_TRACE_VAR("LocalMatrixRef.sub >", - ref._refview._l_viewspec.size()); + ref._refview._viewspec.size()); ref._refview._mat = _refview._mat; return ref; } From 81b88a916658de6e38ebebe7524b7caf80886902 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 27 Sep 2017 10:15:39 -0700 Subject: [PATCH 134/161] Fixing matrix | sub | local --- dart-impl/base/CMakeLists.txt | 9 ++++++ dart-impl/mpi/CMakeLists.txt | 9 ++++++ dash/CMakeLists.txt | 11 ++++++- dash/examples/ex.02.matrix-sub-views/main.cpp | 23 +++++++++----- dash/examples/ex.02.matrix-views/main.cpp | 30 ++++++++++++------- dash/examples/util.h | 5 ++++ dash/include/dash/view/Expand.h | 16 ++++++++++ 7 files changed, 83 insertions(+), 20 deletions(-) diff --git a/dart-impl/base/CMakeLists.txt b/dart-impl/base/CMakeLists.txt index 87c43a23b..3d8abe4d5 100644 --- a/dart-impl/base/CMakeLists.txt +++ b/dart-impl/base/CMakeLists.txt @@ -9,6 +9,8 @@ file(GLOB_RECURSE DASH_DART_BASE_HEADERS "include/*.h") set(DASH_DART_IF_INCLUDE_DIR ${DASH_DART_IF_INCLUDE_DIR} PARENT_SCOPE) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} + PARENT_SCOPE) set(ENABLE_DART_LOGGING ${ENABLE_DART_LOGGING} PARENT_SCOPE) set(ENABLE_UNIFIED_MEMORY_MODEL ${ENABLE_UNIFIED_MEMORY_MODEL} @@ -107,6 +109,13 @@ add_library( ${DASH_DART_BASE_SOURCES} # sources ${DASH_DART_BASE_HEADERS} # headers ) +if (${BUILD_SHARED_LIBS}) + add_library( + ${DASH_DART_BASE_LIBRARY} SHARED # library name + ${DASH_DART_BASE_SOURCES} # sources + ${DASH_DART_BASE_HEADERS} # headers + ) +endif() # Link dependencies target_link_libraries( diff --git a/dart-impl/mpi/CMakeLists.txt b/dart-impl/mpi/CMakeLists.txt index 9c5884a9b..049457068 100644 --- a/dart-impl/mpi/CMakeLists.txt +++ b/dart-impl/mpi/CMakeLists.txt @@ -19,6 +19,8 @@ file(GLOB_RECURSE DASH_DART_IMPL_MPI_HEADERS "include/*.h") # Load global build settings set(DASH_DART_IF_INCLUDE_DIR ${DASH_DART_IF_INCLUDE_DIR} PARENT_SCOPE) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} + PARENT_SCOPE) set(ENABLE_DART_LOGGING ${ENABLE_DART_LOGGING} PARENT_SCOPE) set(ENABLE_UNIFIED_MEMORY_MODEL ${ENABLE_UNIFIED_MEMORY_MODEL} @@ -195,6 +197,13 @@ add_library( ${DASH_DART_IMPL_MPI_SOURCES} # sources ${DASH_DART_IMPL_MPI_HEADERS} # headers ) +if (${BUILD_SHARED_LIBS}) + add_library( + ${DASH_DART_IMPL_MPI_LIBRARY} SHARED # library name + ${DASH_DART_IMPL_MPI_SOURCES} # sources + ${DASH_DART_IMPL_MPI_HEADERS} # headers + ) +endif() # Link dependencies target_link_libraries( ${DASH_DART_IMPL_MPI_LIBRARY} diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt index 0813f6dfd..a5dd73844 100644 --- a/dash/CMakeLists.txt +++ b/dash/CMakeLists.txt @@ -9,6 +9,8 @@ set(BUILD_EXAMPLES ${BUILD_EXAMPLES} PARENT_SCOPE) set(BUILD_TESTS ${BUILD_TESTS} PARENT_SCOPE) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} + PARENT_SCOPE) set(BUILD_COVERAGE_TESTS ${BUILD_COVERAGE_TESTS} PARENT_SCOPE) set(ENABLE_LOGGING ${ENABLE_LOGGING} @@ -279,10 +281,17 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) # Library compilation sources add_library( - ${DASH_LIBRARY} # library name + ${DASH_LIBRARY} # library name ${DASH_LIBRARY_SOURCES} # sources ${DASH_LIBRARY_HEADERS} # headers ) + if (${BUILD_SHARED_LIBS}) + add_library( + ${DASH_LIBRARY} SHARED # library name + ${DASH_LIBRARY_SOURCES} # sources + ${DASH_LIBRARY_HEADERS} # headers + ) + endif() target_link_libraries( ${DASH_LIBRARY} # library name ${DASH_LINK_DART_LIBRARY} # dependency: DART lib diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 16646543c..4c9c0a038 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -4,11 +4,6 @@ #include #include -#define STEP(stream_m__) do { \ - std::cin.ignore(); \ - print(stream_m__); \ -} while(0) - int main(int argc, char *argv[]) { @@ -83,12 +78,24 @@ int main(int argc, char *argv[]) STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()"); { -// print(nview_str(matrix_sub | local()) << std::endl); + print("matrix | sub | local:" << + nview_str(matrix_sub | local())); + print("matrix | sub | local: type: " << + dash::typestr(matrix_sub | local())); + print("matrix | sub | local: strided: " << + (matrix_sub | local() | index()).is_strided()); auto m_s_l_blocks = matrix_sub | local() | blocks(); auto m_s_l_blocks_idx = m_s_l_blocks | index(); + print("matrix | sub | local | blocks: \n" << + "size: " << m_s_l_blocks.size()); + + print("type:" << dash::typestr(m_s_l_blocks)); + print("origin type: " << dash::typestr( + dash::origin(m_s_l_blocks)) + << std::endl); int b_idx = 0; - print("--- number of blocks: " << m_s_l_blocks.size()); + for (const auto & blk : m_s_l_blocks) { STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()[b_idx]"); auto block_gidx = m_s_l_blocks_idx[b_idx]; @@ -96,7 +103,7 @@ int main(int argc, char *argv[]) "offsets: " << blk.offsets() << " " << "extents: " << blk.extents()); -// print(nview_str(blk) << std::endl); + print(nview_str(blk) << std::endl); ++b_idx; } diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index d98734042..93bbe0844 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -89,15 +89,22 @@ int main(int argc, char *argv[]) nview_str(matrix_region)); auto matrix_reg_blocks = dash::blocks(matrix_region); + int bi = 0; for (const auto & reg_block : matrix_reg_blocks) { - auto sreg_block = dash::sub<0>(1,2, reg_block); - - DASH_LOG_DEBUG("MatrixViewsExample", "==============================", - nview_str(reg_block)); - DASH_LOG_DEBUG("MatrixViewsExample", - dash::typestr(sreg_block.begin())); - DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(sreg_block)); + print("matrix | sub | sub | block[" << bi << "] " << + "extents: " << reg_block.extents() << " " << + "offsets: " << reg_block.offsets()); + print(nview_str(reg_block)); + + // auto sreg_block = reg_block | dash::intersect( + // ViewSpec<2>({ 1,2 })); + // if (!sreg_block) { continue; } + // DASH_LOG_DEBUG("MatrixViewsExample", sreg_block.size()); + // DASH_LOG_DEBUG("MatrixViewsExample", + // dash::typestr(sreg_block.begin())); + // DASH_LOG_DEBUG("MatrixViewsExample", + // nview_str(sreg_block)); + ++bi; } } dash::barrier(); @@ -108,6 +115,8 @@ int main(int argc, char *argv[]) value_t * copy_dest_begin = local_copy.data(); value_t * copy_dest_last = local_copy.data(); + print("Number of blocks: " << num_blocks_total); + for (size_t gb = 0; gb < num_blocks_total; ++gb) { // View of block at global block index gb: auto g_block_view = pattern.block(gb); @@ -119,9 +128,8 @@ int main(int argc, char *argv[]) (dash::Team::All().myid().id + 1) % nunits); if (g_block_unit == remote_unit_id) { DASH_LOG_DEBUG("MatrixViewsExample", "==========================="); - DASH_LOG_DEBUG("MatrixViewsExample", - "block gidx", gb, - "at unit", g_block_unit.id); + print("--- block gidx " << gb << " at unit " << g_block_unit.id); + DASH_LOG_DEBUG("MatrixViewsExample", "vvvvvvvvvvvvvvvvvvvvvvvvvvv"); // Block is assigned to selecte remote unit, create local copy: auto remote_block_matrix = dash::sub(1,5, matrix.block(gb)); diff --git a/dash/examples/util.h b/dash/examples/util.h index fd0d96a55..5d4d68534 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -27,6 +27,11 @@ std::cout << oss.str(); \ } while(0) +#define STEP(stream_m__) do { \ + std::cin.ignore(); \ + print(stream_m__); \ +} while(0) + using namespace dash::internal::logging; diff --git a/dash/include/dash/view/Expand.h b/dash/include/dash/view/Expand.h index a2d6faeab..e786e2b53 100644 --- a/dash/include/dash/view/Expand.h +++ b/dash/include/dash/view/Expand.h @@ -149,6 +149,22 @@ static inline auto expand(OffsetT0 a, OffsetT1 b) { }); } +template < + dim_t SubDim = 0, + class OffsetT0, + class OffsetT1, + typename std::enable_if< + ( std::is_integral::value && + std::is_integral::value ), + int + >::type = 0 > +static inline auto stretch(OffsetT0 a, OffsetT1 b) { + return dash::make_pipeable( + [=](auto && x) { + return expand(a,b, std::forward(x)); + }); +} + template < dim_t SubDim = 0, class OffsetT, From 2d7d283c6253d9ebdfd581ec035fd4e8fec654ac Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 27 Sep 2017 12:53:07 -0700 Subject: [PATCH 135/161] Extending examples --- dash/examples/ex.02.matrix-sub-views/main.cpp | 32 +++-- dash/examples/ex.02.matrix-views/main.cpp | 30 ++-- dash/include/dash/view/IndexSet.h | 129 ++++++++++-------- 3 files changed, 115 insertions(+), 76 deletions(-) diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 16646543c..05313302c 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -4,11 +4,6 @@ #include #include -#define STEP(stream_m__) do { \ - std::cin.ignore(); \ - print(stream_m__); \ -} while(0) - int main(int argc, char *argv[]) { @@ -83,12 +78,33 @@ int main(int argc, char *argv[]) STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()"); { -// print(nview_str(matrix_sub | local()) << std::endl); + print("matrix | sub | local:" << + nview_str(matrix_sub | local())); + print("matrix | sub | local: is_local: " << + (matrix_sub | local() | index()).is_local()); + print("matrix | sub | local: type: " << + dash::typestr(matrix_sub | local())); + print("matrix | sub | local: is_strided: " << + (matrix_sub | local() | index()).is_strided()); + print("matrix | sub | local: is_sub: " << + (matrix_sub | local() | index()).is_sub()); + print("matrix | sub | local: domain is_sub: " << + dash::domain(matrix_sub | local() | index()).is_sub()); + print("matrix | sub | local: index set: " << + (matrix_sub | local() | index()).first() << "," << + (matrix_sub | local() | index()).last()); auto m_s_l_blocks = matrix_sub | local() | blocks(); auto m_s_l_blocks_idx = m_s_l_blocks | index(); + print("matrix | sub | local | blocks: \n" << + "size: " << m_s_l_blocks.size()); + + print("type:" << dash::typestr(m_s_l_blocks)); + print("origin type: " << dash::typestr( + dash::origin(m_s_l_blocks)) + << std::endl); int b_idx = 0; - print("--- number of blocks: " << m_s_l_blocks.size()); + for (const auto & blk : m_s_l_blocks) { STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()[b_idx]"); auto block_gidx = m_s_l_blocks_idx[b_idx]; @@ -96,7 +112,7 @@ int main(int argc, char *argv[]) "offsets: " << blk.offsets() << " " << "extents: " << blk.extents()); -// print(nview_str(blk) << std::endl); + print(nview_str(blk) << std::endl); ++b_idx; } diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index d98734042..f22474292 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -89,15 +89,22 @@ int main(int argc, char *argv[]) nview_str(matrix_region)); auto matrix_reg_blocks = dash::blocks(matrix_region); + int bi = 0; for (const auto & reg_block : matrix_reg_blocks) { - auto sreg_block = dash::sub<0>(1,2, reg_block); - - DASH_LOG_DEBUG("MatrixViewsExample", "==============================", - nview_str(reg_block)); - DASH_LOG_DEBUG("MatrixViewsExample", - dash::typestr(sreg_block.begin())); - DASH_LOG_DEBUG("MatrixViewsExample", - nview_str(sreg_block)); + print("matrix | sub | sub | block[" << bi << "] " << + "extents: " << reg_block.extents() << " " << + "offsets: " << reg_block.offsets()); + print(nview_str(reg_block) << '\n'); + + // auto sreg_block = reg_block | dash::intersect( + // ViewSpec<2>({ 1,2 })); + // if (!sreg_block) { continue; } + // DASH_LOG_DEBUG("MatrixViewsExample", sreg_block.size()); + // DASH_LOG_DEBUG("MatrixViewsExample", + // dash::typestr(sreg_block.begin())); + // DASH_LOG_DEBUG("MatrixViewsExample", + // nview_str(sreg_block)); + ++bi; } } dash::barrier(); @@ -108,6 +115,8 @@ int main(int argc, char *argv[]) value_t * copy_dest_begin = local_copy.data(); value_t * copy_dest_last = local_copy.data(); + print("Number of blocks: " << num_blocks_total); + for (size_t gb = 0; gb < num_blocks_total; ++gb) { // View of block at global block index gb: auto g_block_view = pattern.block(gb); @@ -119,9 +128,8 @@ int main(int argc, char *argv[]) (dash::Team::All().myid().id + 1) % nunits); if (g_block_unit == remote_unit_id) { DASH_LOG_DEBUG("MatrixViewsExample", "==========================="); - DASH_LOG_DEBUG("MatrixViewsExample", - "block gidx", gb, - "at unit", g_block_unit.id); + print("--- block gidx " << gb << " at unit " << g_block_unit.id); + DASH_LOG_DEBUG("MatrixViewsExample", "vvvvvvvvvvvvvvvvvvvvvvvvvvv"); // Block is assigned to selecte remote unit, create local copy: auto remote_block_matrix = dash::sub(1,5, matrix.block(gb)); diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index cb508ec7f..c307468eb 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -506,11 +506,13 @@ class IndexSetBase } constexpr bool is_sub() const noexcept { + // TODO: must not be defined depending on size as size() might + // use is_sub() itself return ( this->is_local() ? derived().size() < this->pattern().local_size() : derived().size() < this->pattern().size() - ); + ) || dash::domain(derived()).is_sub(); } constexpr bool is_strided() const noexcept { @@ -809,6 +811,13 @@ class IndexSetSub , _domain_end_idx(end_idx) { } +#if 0 + constexpr bool is_sub() const noexcept { + return true; // not necessarily true, sub<0, extent> should return + // false despite of index set type + } +#endif + // ---- extents --------------------------------------------------------- template @@ -1127,7 +1136,7 @@ class IndexSetLocal // blocked (not blockcyclic) distribution: single local // element space with contiguous global index range ? ( this->ndim() == 1 - // one-dimensional, simple intersect: + // one-dimensional, simple intersect: ? this->index_range_size( this->index_range_intersect( // local range in global index space: @@ -1137,7 +1146,7 @@ class IndexSetLocal { this->domain().first(), this->domain().last() } )) + 1 - // multi-dimensional, size calculation requires view spec: + // multi-dimensional, size calculation requires view spec: : ( this->pattern().block_at( this->pattern().coords(this->domain().first())) == this->pattern().block_at( @@ -1153,61 +1162,67 @@ class IndexSetLocal ) // strided, e.g. blockcyclic distribution: local element space // chunked in global index range - : this->index_range_size( - this->index_range_g2l( - this->pattern(), - // intersection of local range and domain range: - this->index_range_intersect( - // local range in global index space: - { - this->pattern().lbegin(), - ( this->pattern().lend() < this->domain().last() - // domain range contains end of local range: - ? this->pattern().lend() - 1 - // domain range ends in local range, determine last - // local index contained in domain from last local - // block contained in domain range: - // - // gbi: 0 1 2 3 4 5 - // lbi: 0 0 1 1 2 2 - // : : - // [ | |xxxx| |xxxx| | |xxxx] - // '---------------------' - // - // --> domain.end.gbi = 4 ------------. - // domain.end.lbi = 2 -. | - // | | - // v | - // local.lblock(lbi = 2).gbi = 5 | - // | | - // ! 5 > domain.end.gbi = 4 <-----'-' - // --> local.lblock(lbi = 1) - // - // Resolve global index past the last element: - // - : ( domain_block_gidx_last() - >= local_block_gidx_last() - // Last local block is included in domain: - ? this->pattern().block( - local_block_gidx_last() - ).range(0).end - 1 - // Domain ends before last local block: - : local_block_gidx_at_block_lidx( - domain_block_lidx_last()) - > domain_block_gidx_last() - ? this->pattern().local_block( - domain_block_lidx_last() - 1 + : ( this->ndim() == 1 + ? this->index_range_size( + this->index_range_g2l( + this->pattern(), + // intersection of local range and domain range: + this->index_range_intersect( + // local range in global index space: + { + this->pattern().lbegin(), + ( this->pattern().lend() < this->domain().last() + // domain range contains end of local range: + ? this->pattern().lend() - 1 + // domain range ends in local range, determine last + // local index contained in domain from last local + // block contained in domain range: + // + // gbi: 0 1 2 3 4 5 + // lbi: 0 0 1 1 2 2 + // : : + // [ | |xxxx| |xxxx| | |xxxx] + // '---------------------' + // + // --> domain.end.gbi = 4 ------------. + // domain.end.lbi = 2 -. | + // | | + // v | + // local.lblock(lbi = 2).gbi = 5 | + // | | + // ! 5 > domain.end.gbi = 4 <-----'-' + // --> local.lblock(lbi = 1) + // + // Resolve global index past the last element: + // + : ( domain_block_gidx_last() + >= local_block_gidx_last() + // Last local block is included in domain: + ? this->pattern().block( + local_block_gidx_last() ).range(0).end - 1 - : this->pattern().local_block( - domain_block_lidx_last() - ).range(0).end - 1 ) - ) - }, - // domain range in global index space; - { this->domain().first(), - this->domain().last() - }) - )) + 1 + // Domain ends before last local block: + : local_block_gidx_at_block_lidx( + domain_block_lidx_last()) + > domain_block_gidx_last() + ? this->pattern().local_block( + domain_block_lidx_last() - 1 + ).range(0).end - 1 + : this->pattern().local_block( + domain_block_lidx_last() + ).range(0).end - 1 ) + ) + }, + // domain range in global index space; + { this->domain().first(), + this->domain().last() + }) + )) + 1 + // ndim != 1, multi-dimensional + : ( + 6 + ) + ) ) // domain.is_sub() ); } From 3a5b9e970c9352ef4ef3538a4cc17df18f447e20 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 29 Sep 2017 00:12:34 -0700 Subject: [PATCH 136/161] Cleanup in examples --- .../ex.02.matrix-local-views/main.cpp | 26 ++++++------------- dash/examples/util.h | 4 ++- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index 090c0257d..2aad2b390 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -64,6 +64,7 @@ int main(int argc, char **argv) params.tile[0] = sizespec.extent(0) / max_team_extent; params.tile[1] = sizespec.extent(1) / max_team_extent; } + if (params.type == "summa") { RUN_EXAMPLE(summa); } else if (params.type == "block") { @@ -141,31 +142,21 @@ void run_example(MatrixT & matrix) { auto copy_end = std::copy(matrix.begin() + 3, matrix.begin() + 9, tmp.data()); - print("matrix.begin()[3...9]: " << tmp); + STEP("matrix.begin()[3...9]: " << tmp); } dash::barrier(); auto l_matrix = matrix | local(); - print("matrix | local:" << nview_str(l_matrix)); + STEP("matrix | local():" << nview_str(l_matrix)); dash::barrier(); - // Copy local row - { - auto l_row = matrix | sub(0, matrix.extent(0)) | local() | sub(1,2); - DASH_LOG_DEBUG("matrix.local.row(1)", - "type:", dash::typestr(l_row)); - - print("matrix.local.row(1) " << nview_str(l_row)); - } - matrix.barrier(); - // Copy local block { auto l_blocks = matrix | local() | blocks(); - print("matrix.local.blocks(): " << + STEP("matrix | local() | blocks(): " << "size: " << l_blocks.size() << " " << "offsets: " << l_blocks.offsets() << " " << "extents: " << l_blocks.extents()); @@ -174,24 +165,23 @@ void run_example(MatrixT & matrix) { int l_bi = 0; for (const auto & lb : l_blocks) { - DASH_LOG_DEBUG("matrix.local.blocks()", "[", l_bi, "]", + DASH_LOG_DEBUG("matrix | local() | blocks()", "[", l_bi, "]", "size:", lb.size(), "offsets:", lb.offsets(), "extents:", lb.extents()); - print("matrix.local.block(" << l_bi << "): " << + STEP("-- matrix | local() | block(" << l_bi << "): " << "block[" << l_blocks_idx[l_bi] << "]" << nview_str(lb)); std::vector tmp(lb.size()); auto copy_end = dash::copy(lb, tmp.data()); - print("matrix.local.block(" << l_bi << ") copy: " << tmp); + STEP(" matrix | local() | block(" << l_bi << ") copy: " << tmp); ++l_bi; } - + dash::barrier(); } - matrix.barrier(); } diff --git a/dash/examples/util.h b/dash/examples/util.h index 5d4d68534..1ebe84480 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -28,7 +28,9 @@ } while(0) #define STEP(stream_m__) do { \ - std::cin.ignore(); \ + if (dash::myid() == 0) { \ + std::cin.ignore(); \ + } \ print(stream_m__); \ } while(0) From 0ab4cb7dc2633859aee3ba9d86ab8a0961934aa8 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 29 Sep 2017 00:44:55 -0700 Subject: [PATCH 137/161] Cleanup in examples --- .../ex.02.matrix-local-views/main.cpp | 27 +++++++++++++------ dash/examples/pattern_params.h | 17 +++++++----- dash/examples/util.h | 5 ++-- dash/include/dash/internal/StreamConversion.h | 1 + 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index 2aad2b390..3c5ba578c 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -38,15 +38,21 @@ int main(int argc, char **argv) typedef typename pattern_t::index_type index_t; typedef float value_t; - int blocksize_x = 2; - int blocksize_y = 2; - dash::init(&argc, &argv); auto myid = dash::myid(); auto nunits = dash::size(); - auto params = parse_args(argc, argv); + cli_params defaults = default_params; + defaults.type = "tile"; + defaults.size = {{ 12, 12 }}; + defaults.tile = {{ 2, 2 }}; + defaults.units = {{ 1, static_cast(nunits) }}; + defaults.blocked_display = false; + defaults.balance_extents = false; + defaults.cout = false; + + auto params = parse_args(argc, argv, defaults); if (dash::myid() == 0) { print_params(params); @@ -81,6 +87,9 @@ int main(int argc, char **argv) } #if 0 + int blocksize_x = 2; + int blocksize_y = 2; + dash::TeamSpec<2> teamspec(dash::Team::All()); teamspec.balance_extents(); @@ -142,7 +151,7 @@ void run_example(MatrixT & matrix) { auto copy_end = std::copy(matrix.begin() + 3, matrix.begin() + 9, tmp.data()); - STEP("matrix.begin()[3...9]: " << tmp); + STEP("matrix.begin()[3...9]: " << range_str(tmp, 2)); } dash::barrier(); @@ -175,9 +184,11 @@ void run_example(MatrixT & matrix) { nview_str(lb)); std::vector tmp(lb.size()); - auto copy_end = dash::copy(lb, - tmp.data()); - STEP(" matrix | local() | block(" << l_bi << ") copy: " << tmp); + auto copy_end = std::copy(lb.begin(), + lb.end(), + tmp.data()); + STEP(" matrix | local() | block(" << l_bi << ") copy: " << + range_str(tmp, 2)); ++l_bi; } diff --git a/dash/examples/pattern_params.h b/dash/examples/pattern_params.h index 7ab0cd591..3645b34c6 100644 --- a/dash/examples/pattern_params.h +++ b/dash/examples/pattern_params.h @@ -7,23 +7,23 @@ typedef dash::default_index_t index_t; typedef struct cli_params_t { std::string type = "tile"; std::array size {{ 12, 12 }}; - std::array units {{ 2, 2 }}; std::array tile {{ 3, 4 }}; + std::array units; bool blocked_display = false; bool balance_extents = false; bool cout = false; } cli_params; +cli_params default_params; + void print_usage(char **argv); cli_params parse_args(int argc, char * argv[]); void print_params(const cli_params & params); -cli_params default_params; - -cli_params parse_args(int argc, char * argv[]) +cli_params parse_args(int argc, char * argv[], const cli_params & defaults) { - cli_params params = default_params; + cli_params params = defaults; for (auto i = 1; i < argc; i += 3) { std::string flag = argv[i]; @@ -43,7 +43,7 @@ cli_params parse_args(int argc, char * argv[]) } else if (flag == "-t") { params.tile = { static_cast(atoi(argv[i+1])), static_cast(atoi(argv[i+2])) }; - } else if (flag == "-e") { + } else if (flag == "-b") { params.balance_extents = true; i -= 2; } else { @@ -51,10 +51,13 @@ cli_params parse_args(int argc, char * argv[]) exit(EXIT_FAILURE); } } - return params; } +cli_params parse_args(int argc, char * argv[]) { + return parse_args(argc, argv, default_params); +} + void print_usage(char **argv) { if (dash::myid() == 0) { diff --git a/dash/examples/util.h b/dash/examples/util.h index 1ebe84480..a5d4f9c01 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -43,11 +43,10 @@ static std::string range_str( int prec = 2) { typedef typename ValueRange::value_type value_t; std::ostringstream ss; - auto idx = dash::index(vrange); - int i = 0; + int i = 0; for (const auto & v : vrange) { const value_t val = v; - ss << std::setw(3) << *(dash::begin(idx) + i) << "|" + ss << std::setw(2 + prec) << std::right << std::fixed << std::setprecision(prec) << TermColorMod(unit_term_colors[(int)val]) << val diff --git a/dash/include/dash/internal/StreamConversion.h b/dash/include/dash/internal/StreamConversion.h index bf39d5ee5..a23034ae2 100644 --- a/dash/include/dash/internal/StreamConversion.h +++ b/dash/include/dash/internal/StreamConversion.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace dash { From 0900d1dcbb55c50eb19b9388ae477d91d1ca635b Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 29 Sep 2017 02:04:53 -0700 Subject: [PATCH 138/161] Cleanup in examples --- .../examples/ex.02.matrix-halo-views/main.cpp | 65 ++++++++----------- .../ex.02.matrix-local-views/main.cpp | 61 ++++------------- dash/examples/ex.02.matrix-views/main.cpp | 9 ++- 3 files changed, 44 insertions(+), 91 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 1f2cfaaf1..20918db51 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -26,52 +26,38 @@ int main(int argc, char *argv[]) const size_t block_size_x = 2; const size_t block_size_y = 2; - const size_t block_size = block_size_x * block_size_y; - size_t num_local_blocks_x = 1; - size_t num_local_blocks_y = 2; - size_t num_blocks_x = nunits * num_local_blocks_x; - size_t num_blocks_y = nunits * num_local_blocks_y; - size_t num_blocks_total = num_blocks_x * num_blocks_y; + size_t num_blocks_x = nunits - 1; + size_t num_blocks_y = nunits; size_t extent_x = block_size_x * num_blocks_x; size_t extent_y = block_size_y * num_blocks_y; - size_t num_elem_total = extent_x * extent_y; - // Assuming balanced mapping: - size_t num_elem_per_unit = num_elem_total / nunits; - size_t num_blocks_per_unit = num_elem_per_unit / block_size; - typedef dash::ShiftTilePattern<2> pattern_t; + typedef dash::TilePattern<2> pattern_t; typedef typename pattern_t::index_type index_t; typedef float value_t; + dash::TeamSpec<2> teamspec(dash::Team::All()); + teamspec.balance_extents(); + pattern_t pattern( dash::SizeSpec<2>( extent_y, extent_x), dash::DistributionSpec<2>( dash::TILE(block_size_y), - dash::TILE(block_size_x)) + dash::TILE(block_size_x)), + teamspec ); dash::Matrix matrix(pattern); // Initialize matrix values: - for (size_t lb = 0; lb < num_blocks_per_unit; ++lb) { - auto lblock = matrix.local.block(lb); - auto lblock_view = lblock.begin().viewspec(); - auto lblock_extents = lblock_view.extents(); - auto lblock_offsets = lblock_view.offsets(); - dash__unused(lblock_offsets); - for (auto bx = 0; bx < static_cast(lblock_extents[0]); ++bx) { - for (auto by = 0; by < static_cast(lblock_extents[1]); ++by) { - // Phase coordinates (bx,by) to global coordinates (gx,gy): - value_t value = static_cast(dash::myid().id) - + 0.01 * lb - + 0.0001 * (bx * lblock_extents[0] + by); - lblock[bx][by] = value; - } - } - } + int li = 0; + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { + return dash::myid() + 0.01 * li++; + }); dash::barrier(); if (myid == 0) { @@ -86,7 +72,7 @@ int main(int argc, char *argv[]) auto b_extents = m_block.extents(); // matrix block view: - print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "]:" << + STEP("\n-- matrix | block[" << matrix_b_idx[b_idx] << "]:" << "\n " << "offsets: " << b_offsets[0] << "," << b_offsets[1] << " " << "extents: " << b_extents[0] << "," << b_extents[1] << @@ -98,32 +84,33 @@ int main(int argc, char *argv[]) auto bh_offsets = b_halo.offsets(); auto bh_extents = b_halo.extents(); - print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + STEP(" matrix | block[" << matrix_b_idx[b_idx] << "] | " << "expand({ -1,1 }, { -1,1 }):" << "\n " << "offsets: " << bh_offsets[0] << "," << bh_offsets[1] << " " << "extents: " << bh_extents[0] << "," << bh_extents[1] << nview_str(b_halo, 4)); +#if 0 + auto bh_blocks = b_halo | dash::blocks(); + for (const auto & bh_block : bh_blocks) { + STEP(" -- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + "expand({ -1,1 }, { -1,1 }) | block(n)" << + nview_str(bh_block, 4)); + } +#endif + // matrix shifted block halo: auto b_halo_s = b_halo | shift<1>(1); auto bhs_offsets = b_halo_s.offsets(); auto bhs_extents = b_halo_s.extents(); - print("\n-- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + STEP(" matrix | block[" << matrix_b_idx[b_idx] << "] | " << "expand({ -1,1 }, { -1,1 }) | shift(1):" << "\n " << "offsets: " << bhs_offsets[0] << "," << bhs_offsets[1] << " " << "extents: " << bhs_extents[0] << "," << bhs_extents[1] << nview_str(b_halo_s, 4)); -#if 0 - auto bh_blocks = b_halo | dash::blocks(); - for (const auto & bh_block : bh_blocks) { - print("matrix | block[" << matrix_b_idx[b_idx] << "] | " << - "expand({ -1,1 }, { -1,1 }) | block(n)" << - nview_str(bh_block, 4)); - } -#endif ++b_idx; } } diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index 3c5ba578c..89d1b0b9c 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char **argv) cli_params defaults = default_params; defaults.type = "tile"; - defaults.size = {{ 12, 12 }}; + defaults.size = {{ 8, 8 }}; defaults.tile = {{ 2, 2 }}; defaults.units = {{ 1, static_cast(nunits) }}; defaults.blocked_display = false; @@ -58,8 +58,10 @@ int main(int argc, char **argv) print_params(params); } - dash::SizeSpec<2, extent_t> sizespec(params.size[0], params.size[1]); - dash::TeamSpec<2, index_t> teamspec(params.units[0], params.units[1]); + dash::SizeSpec<2, extent_t> sizespec(params.size[0], + params.size[1]); + dash::TeamSpec<2, index_t> teamspec(params.units[0], + params.units[1]); if(params.balance_extents) { teamspec.balance_extents(); @@ -86,45 +88,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } -#if 0 - int blocksize_x = 2; - int blocksize_y = 2; - - dash::TeamSpec<2> teamspec(dash::Team::All()); - teamspec.balance_extents(); - - dash::DistributionSpec<2> block_ds(dash::BLOCKED, - dash::BLOCKED); - dash::DistributionSpec<2> tiled_ds(dash::TILE(blocksize_y), - dash::TILE(blocksize_x)); - dash::SizeSpec<2> sizespec((teamspec.extent(0) * 2) * blocksize_y, - (teamspec.extent(1) * 2) * blocksize_x); - - pattern_t block_pattern( - sizespec, - block_ds, - teamspec - ); - - pattern_t tiled_pattern( - sizespec, - tiled_ds, - teamspec - ); - - // Block-distributed Matrix: - dash::Matrix - matrix_blocked(block_pattern); - - // Block-distributed Matrix: - dash::Matrix - matrix_tiled(tiled_pattern); - - run_example(matrix_blocked); - run_example(matrix_tiled); -#endif dash::finalize(); - return 0; } @@ -147,11 +111,11 @@ void run_example(MatrixT & matrix) { print("matrix:" << nview_str(matrix | sub(0,matrix.extents()[0]))); - std::vector tmp(6); - auto copy_end = std::copy(matrix.begin() + 3, - matrix.begin() + 9, + std::vector tmp(10); + auto copy_end = std::copy(matrix.begin() + 11, + matrix.begin() + 21, tmp.data()); - STEP("matrix.begin()[3...9]: " << range_str(tmp, 2)); + STEP("matrix.begin()[11...20]: " << range_str(tmp, 2)); } dash::barrier(); @@ -170,8 +134,6 @@ void run_example(MatrixT & matrix) { "offsets: " << l_blocks.offsets() << " " << "extents: " << l_blocks.extents()); - auto l_blocks_idx = l_blocks | index(); - int l_bi = 0; for (const auto & lb : l_blocks) { DASH_LOG_DEBUG("matrix | local() | blocks()", "[", l_bi, "]", @@ -179,15 +141,14 @@ void run_example(MatrixT & matrix) { "offsets:", lb.offsets(), "extents:", lb.extents()); - STEP("-- matrix | local() | block(" << l_bi << "): " << - "block[" << l_blocks_idx[l_bi] << "]" << + STEP("-- matrix | local() | blocks()[" << l_bi << "]: " << nview_str(lb)); std::vector tmp(lb.size()); auto copy_end = std::copy(lb.begin(), lb.end(), tmp.data()); - STEP(" matrix | local() | block(" << l_bi << ") copy: " << + STEP(" matrix | local() | blocks()[" << l_bi << "] copy: " << range_str(tmp, 2)); ++l_bi; diff --git a/dash/examples/ex.02.matrix-views/main.cpp b/dash/examples/ex.02.matrix-views/main.cpp index f22474292..fa176032f 100644 --- a/dash/examples/ex.02.matrix-views/main.cpp +++ b/dash/examples/ex.02.matrix-views/main.cpp @@ -7,6 +7,8 @@ using std::cin; using std::endl; using std::vector; +using namespace dash; + using uint = unsigned int; template @@ -18,7 +20,10 @@ auto transform_in_view(MatrixT & mat, ViewMods && vmods) { int main(int argc, char *argv[]) { - using namespace dash; + using dash::sub; + using dash::local; + using dash::index; + using dash::blocks; dash::init(&argc, &argv); @@ -88,7 +93,7 @@ int main(int argc, char *argv[]) print("matrix | sub<0>(2,-2) | sub<1>(2,-3) \n" << nview_str(matrix_region)); - auto matrix_reg_blocks = dash::blocks(matrix_region); + auto matrix_reg_blocks = matrix_region | blocks(); int bi = 0; for (const auto & reg_block : matrix_reg_blocks) { print("matrix | sub | sub | block[" << bi << "] " << From 8de7bf65a282ce1ec8406f3ba34639a43d654418 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 29 Sep 2017 02:09:37 -0700 Subject: [PATCH 139/161] Cleanup in examples --- .../examples/ex.02.matrix-halo-views/main.cpp | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index 20918db51..cb8db1155 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) if (myid == 0) { auto matrix_view = dash::sub(0, matrix.extents()[0], matrix); - print("matrix" << nview_str(matrix_view, 4)); + print("matrix" << nview_str(matrix_view, 2)); auto matrix_blocks = dash::blocks(matrix); auto matrix_b_idx = matrix_blocks | dash::index(); @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) "\n " << "offsets: " << b_offsets[0] << "," << b_offsets[1] << " " << "extents: " << b_extents[0] << "," << b_extents[1] << - nview_str(m_block, 4)); + nview_str(m_block, 2)); // matrix block halo view: auto b_halo = m_block | dash::expand<0>(-1, 1) @@ -89,16 +89,7 @@ int main(int argc, char *argv[]) "\n " << "offsets: " << bh_offsets[0] << "," << bh_offsets[1] << " " << "extents: " << bh_extents[0] << "," << bh_extents[1] << - nview_str(b_halo, 4)); - -#if 0 - auto bh_blocks = b_halo | dash::blocks(); - for (const auto & bh_block : bh_blocks) { - STEP(" -- matrix | block[" << matrix_b_idx[b_idx] << "] | " << - "expand({ -1,1 }, { -1,1 }) | block(n)" << - nview_str(bh_block, 4)); - } -#endif + nview_str(b_halo, 2)); // matrix shifted block halo: auto b_halo_s = b_halo | shift<1>(1); @@ -106,11 +97,17 @@ int main(int argc, char *argv[]) auto bhs_offsets = b_halo_s.offsets(); auto bhs_extents = b_halo_s.extents(); STEP(" matrix | block[" << matrix_b_idx[b_idx] << "] | " << - "expand({ -1,1 }, { -1,1 }) | shift(1):" << + "expand({ -1,1 }, { -1,1 }) | shift<1>(1):" << "\n " << "offsets: " << bhs_offsets[0] << "," << bhs_offsets[1] << " " << "extents: " << bhs_extents[0] << "," << bhs_extents[1] << - nview_str(b_halo_s, 4)); + nview_str(b_halo_s, 2)); + + auto bhs_blocks = b_halo_s | dash::blocks(); + STEP(" -- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + "expand({ -1,1 }, { -1,1 }) | shift<1>(1) | block(0)" << + nview_str(bhs_blocks[0], 2)); + ++b_idx; } } From 285dea4dc84d0c35feff10d2f8282fac156e92f6 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 29 Sep 2017 02:39:41 -0700 Subject: [PATCH 140/161] Cleanup in examples --- dash/examples/ex.02.array-views/main.cpp | 44 +++++++++++-------- .../examples/ex.02.matrix-halo-views/main.cpp | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index 77614194d..ffed80c36 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) dash::init(&argc, &argv); - int elem_per_unit = 5; + int elem_per_unit = 3; int elem_additional = 2; int array_size = dash::size() * elem_per_unit + std::min(elem_additional, dash::size()); @@ -46,28 +46,34 @@ int main(int argc, char *argv[]) initialize_array(a); if (dash::myid() == 0) { - print("a: " << range_str(a)); + print("a: " << range_str(a)); - auto sb_array = a | sub(1, a.size()-1) | blocks(); - for (const auto & b : sb_array) { - print("a | sub | block: " << range_str(b)); - } + STEP("- a | sub"); + auto s_array = a | sub(1, a.size()-2); + print(" a | sub: " << range_str(s_array)); - auto slb_array = a | sub(1, a.size()-1) | local() | blocks(); - for (const auto & b : slb_array) { - print("a | sub | local | block: " << range_str(b)); + STEP("- a | sub | blocks"); + auto sb_array = a | sub(1, a.size()-2) | blocks(); + for (const auto & b : sb_array) { + print(" a | sub | blocks: " << range_str(b)); } } dash::barrier(); auto l_array = a | local(); - print("a | local: " << range_str(l_array)); + STEP("- a | local: " << range_str(l_array)); dash::barrier(); - auto sl_array = a | sub(1, a.size()-1) | local(); - print("a | sub | local: " << range_str(sl_array)); + auto sl_array = a | sub(1, a.size()-2) | local(); + STEP("- a | sub | local: " << range_str(sl_array)); dash::barrier(); + STEP("- a | sub | local | blocks"); + auto slb_array = a | sub(1, a.size()-2) | local() | blocks(); + for (const auto & b : slb_array) { + print(" a | sub | local | blocks:" << range_str(b)); + } + auto copy_num_elem = a.size() / 2; auto copy_dest_begin_idx = a.size() / 4 - 1; auto copy_dest_end_idx = copy_dest_begin_idx + copy_num_elem; @@ -77,13 +83,13 @@ int main(int argc, char *argv[]) std::transform(buf.begin(), buf.end(), buf.begin(), [&](const double & a) { - return a + 6; + return a + 6 + (0.01 * ++buf_i); }); a.barrier(); if (dash::myid() == 0) { - print("copy target index range: " + STEP("copy to index range " << "[" << copy_dest_begin_idx << "," << copy_dest_end_idx << ")"); @@ -96,12 +102,12 @@ int main(int argc, char *argv[]) // Printing temporaries from view expressions instead of // named values for testing: - print("target index set: " << dash::index(dest_range)); - print("target block set: " << dash::index(dash::blocks(dest_range))); - print("copy target range: " << range_str(dest_range)); + STEP("target index set: " << dash::index(dest_range)); + STEP("target block set: " << dash::index(dash::blocks(dest_range))); + STEP("copy target range: " << range_str(dest_range)); for (const auto & block : dest_blocks) { - print("copy to block: " << range_str(block)); + print("copy to block: " << range_str(block)); } // copy local buffer to global array @@ -112,7 +118,7 @@ int main(int argc, char *argv[]) } a.barrier(); - print("modified array: " << range_str(a)); + print("modified array: " << range_str(a)); } dash::finalize(); diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index cb8db1155..b37d069e9 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) nview_str(b_halo_s, 2)); auto bhs_blocks = b_halo_s | dash::blocks(); - STEP(" -- matrix | block[" << matrix_b_idx[b_idx] << "] | " << + STEP(" matrix | block[" << matrix_b_idx[b_idx] << "] | " << "expand({ -1,1 }, { -1,1 }) | shift<1>(1) | block(0)" << nview_str(bhs_blocks[0], 2)); From d3de7459058b276db0e1ad8cbe8385d99ece5a01 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Tue, 3 Oct 2017 01:21:04 +0200 Subject: [PATCH 141/161] Fixes for SuperMIC --- config/supermic.cmake | 4 +++- config/supermuc.cmake | 2 +- dash/CMakeLists.txt | 8 ++++---- dash/test/algorithm/CopyTest.cc | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/config/supermic.cmake b/config/supermic.cmake index caa7db4b5..f7fd151cd 100644 --- a/config/supermic.cmake +++ b/config/supermic.cmake @@ -6,7 +6,7 @@ # export CC=`which mpiicc` # export CXX=`which mpiicc` # -set(ENV{CXX} mpiicc) +set(ENV{CXX} mpiicpc) set(ENV{CC} mpiicc) set(DASH_ENV_HOST_SYSTEM_ID "supermic" CACHE STRING @@ -21,11 +21,13 @@ set(CC_ENV_SETUP_FLAGS "${CC_ENV_SETUP_FLAGS} -qopenmp -mmic -mkl") set(CC_ENV_SETUP_FLAGS "${CC_ENV_SETUP_FLAGS} -mt_mpi") set(CC_ENV_SETUP_FLAGS "${CC_ENV_SETUP_FLAGS} -qopt-streaming-stores always") set(CC_ENV_SETUP_FLAGS "${CC_ENV_SETUP_FLAGS} -qopt-prefetch-distance=64,8") +set(CC_ENV_SETUP_FLAGS "${CC_ENV_SETUP_FLAGS} -Wl,-rpath,$ENV{MIC_LD_LIBRARY_PATH}") set(CXX_ENV_SETUP_FLAGS "${CXX_ENV_SETUP_FLAGS} -qopenmp -mmic -mkl") set(CXX_ENV_SETUP_FLAGS "${CXX_ENV_SETUP_FLAGS} -mt_mpi") set(CXX_ENV_SETUP_FLAGS "${CXX_ENV_SETUP_FLAGS} -qopt-streaming-stores always") set(CXX_ENV_SETUP_FLAGS "${CXX_ENV_SETUP_FLAGS} -qopt-prefetch-distance=64,8") +set(CXX_ENV_SETUP_FLAGS "${CXX_ENV_SETUP_FLAGS} -Wl,-rpath,$ENV{MIC_LD_LIBRARY_PATH}") set(MKLROOT $ENV{MKLROOT}) diff --git a/config/supermuc.cmake b/config/supermuc.cmake index 8c055b82d..c5db7839c 100644 --- a/config/supermuc.cmake +++ b/config/supermuc.cmake @@ -6,7 +6,7 @@ # export CC=`which icc` # export CXX=`which icc` # -set(ENV{CXX} mpiicc) +set(ENV{CXX} mpiicpc) set(ENV{CC} mpiicc) set(DASH_ENV_HOST_SYSTEM_ID "supermuc" CACHE STRING diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt index 28d07de2f..4d85b381f 100644 --- a/dash/CMakeLists.txt +++ b/dash/CMakeLists.txt @@ -321,7 +321,7 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) # cmake packaging if(${CMAKE_VERSION} VERSION_GREATER 3.0.0 ) include(CMakePackageConfigHelpers) - + target_include_directories("${DASH_LIBRARY}" PUBLIC $ PUBLIC ${ADDITIONAL_INCLUDES}) @@ -340,13 +340,13 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) DESTINATION cmake) if(${CMAKE_VERSION} VERSION_GREATER 3.0.0 ) - configure_package_config_file( + configure_package_config_file( "dash-config.cmake.in" "${DASH_LIBRARY}-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake") - # install custom config - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${DASH_LIBRARY}-config.cmake" + # install custom config + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${DASH_LIBRARY}-config.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake") endif() diff --git a/dash/test/algorithm/CopyTest.cc b/dash/test/algorithm/CopyTest.cc index c27b60f70..5599056f7 100644 --- a/dash/test/algorithm/CopyTest.cc +++ b/dash/test/algorithm/CopyTest.cc @@ -167,7 +167,7 @@ TEST_F(CopyTest, Blocking2DimGlobalToLocalBlock) auto g_block_view = pattern.block(gb); // Unit assigned to block at global block index gb: auto g_block_unit = pattern.unit_at( - std::array {0,0}, + std::array {{ 0,0 }}, g_block_view); LOG_MESSAGE("Block %zu: assigned to unit %d", gb, g_block_unit.id); if (g_block_unit == remote_unit_id) { @@ -693,7 +693,7 @@ TEST_F(CopyTest, AsyncGlobalToLocalTiles) dash::test::print_pattern_mapping( "matrix.a", pattern, 3, [](const pattern_t & _pattern, int _x, int _y) -> dart_unit_t { - return _pattern.unit_at(std::array {_x, _y}); + return _pattern.unit_at(std::array {{ _x, _y }}); }); dash::test::print_matrix("matrix.a", matrix_a, 2); } From dd591ab7cadabc9b0467adc62fe7f1c648462b2a Mon Sep 17 00:00:00 2001 From: Daniel Diefenthaler Date: Tue, 3 Oct 2017 13:22:49 +0200 Subject: [PATCH 142/161] clean-up of root directory, build-scripts in build-tools --- .syntastic_c | 11 -- .syntastic_cpp | 14 --- .../build.analyze.sh | 0 build.cov.sh => build-tools/build.cov.sh | 0 build.debug.sh => build-tools/build.debug.sh | 0 build.dev.sh => build-tools/build.dev.sh | 0 build.mic.sh => build-tools/build.mic.sh | 0 .../build.minimal.sh | 0 build.nasty.sh => build-tools/build.nasty.sh | 0 build-tools/build.sh | 101 +++++++++++++++++ build.sh | 102 +----------------- 11 files changed, 102 insertions(+), 126 deletions(-) delete mode 100644 .syntastic_c delete mode 100644 .syntastic_cpp rename build.analyze.sh => build-tools/build.analyze.sh (100%) rename build.cov.sh => build-tools/build.cov.sh (100%) rename build.debug.sh => build-tools/build.debug.sh (100%) rename build.dev.sh => build-tools/build.dev.sh (100%) rename build.mic.sh => build-tools/build.mic.sh (100%) rename build.minimal.sh => build-tools/build.minimal.sh (100%) rename build.nasty.sh => build-tools/build.nasty.sh (100%) create mode 100755 build-tools/build.sh mode change 100755 => 120000 build.sh diff --git a/.syntastic_c b/.syntastic_c deleted file mode 100644 index 160629d1d..000000000 --- a/.syntastic_c +++ /dev/null @@ -1,11 +0,0 @@ --I./dart-impl/base/include --I./dart-impl/mpi/include --I./dart-impl/shmem/include --I./dart-if/v3.2/include --I/opt/openmpi-1.8/include --std=c99 --Wall --Wextra --pedantic --Wno-unused-function - diff --git a/.syntastic_cpp b/.syntastic_cpp deleted file mode 100644 index 3b82ce45e..000000000 --- a/.syntastic_cpp +++ /dev/null @@ -1,14 +0,0 @@ --I./dash/include --I./dart-impl/mpi/include --I./dart-impl/base/include --I./dart-if/v3.2/include --I/opt/openmpi-1.8/include --I/home/fuchst/opt/gtest/include --std=c++11 --Wall --Wextra --pedantic --Wno-unused-function --Wno-unused-variable --Wno-missing-braces - diff --git a/build.analyze.sh b/build-tools/build.analyze.sh similarity index 100% rename from build.analyze.sh rename to build-tools/build.analyze.sh diff --git a/build.cov.sh b/build-tools/build.cov.sh similarity index 100% rename from build.cov.sh rename to build-tools/build.cov.sh diff --git a/build.debug.sh b/build-tools/build.debug.sh similarity index 100% rename from build.debug.sh rename to build-tools/build.debug.sh diff --git a/build.dev.sh b/build-tools/build.dev.sh similarity index 100% rename from build.dev.sh rename to build-tools/build.dev.sh diff --git a/build.mic.sh b/build-tools/build.mic.sh similarity index 100% rename from build.mic.sh rename to build-tools/build.mic.sh diff --git a/build.minimal.sh b/build-tools/build.minimal.sh similarity index 100% rename from build.minimal.sh rename to build-tools/build.minimal.sh diff --git a/build.nasty.sh b/build-tools/build.nasty.sh similarity index 100% rename from build.nasty.sh rename to build-tools/build.nasty.sh diff --git a/build-tools/build.sh b/build-tools/build.sh new file mode 100755 index 000000000..06355aef2 --- /dev/null +++ b/build-tools/build.sh @@ -0,0 +1,101 @@ +#!/bin/sh + +BUILD_DIR=./build + +FORCE_BUILD=false +if [ "$1" = "-f" ]; then + FORCE_BUILD=true +fi + +await_confirm() { + if ! $FORCE_BUILD; then + echo "" + echo " To build using these settings, hit ENTER" + read confirm + fi +} + +exit_message() { + echo "--------------------------------------------------------" + echo "Done. To install DASH, run make install in $BUILD_DIR" +} + +if [ "${PAPI_HOME}" = "" ]; then + PAPI_HOME=$PAPI_BASE +fi + +# To specify a build configuration for a specific system, use: +# +# -DENVIRONMENT_TYPE= \ +# +# For available types, see the files in folder ./config. +# To specify a custom build configuration, use: +# +# -DENVIRONMENT_CONFIG_PATH= \ +# + +# To use an existing installation of gtest instead of downloading the sources +# from the google test subversion repository, use: +# +# -DGTEST_LIBRARY_PATH=${HOME}/gtest \ +# -DGTEST_INCLUDE_PATH=${HOME}/gtest/include \ +# + +# To build with MKL support, set environment variables MKLROOT and INTELROOT. +# + +# To enable IPM runtime support, use: +# +# -DIPM_PREFIX= \ + +# For likwid support, ensure that the likwid development headers are +# installed. + +# Configure with default release build settings: +mkdir -p $BUILD_DIR +rm -Rf $BUILD_DIR/* +(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_GENERIC=OFF \ + -DENVIRONMENT_TYPE=default \ + -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \ + -DDART_IMPLEMENTATIONS=mpi \ + -DENABLE_THREADSUPPORT=ON \ + -DENABLE_DEV_COMPILER_WARNINGS=OFF \ + -DENABLE_EXT_COMPILER_WARNINGS=OFF \ + -DENABLE_LT_OPTIMIZATION=OFF \ + -DENABLE_ASSERTIONS=ON \ + \ + -DENABLE_SHARED_WINDOWS=ON \ + -DENABLE_DYNAMIC_WINDOWS=ON \ + -DENABLE_UNIFIED_MEMORY_MODEL=ON \ + -DENABLE_DEFAULT_INDEX_TYPE_LONG=ON \ + \ + -DENABLE_LOGGING=OFF \ + -DENABLE_TRACE_LOGGING=OFF \ + -DENABLE_DART_LOGGING=OFF \ + \ + -DENABLE_LIBNUMA=ON \ + -DENABLE_LIKWID=OFF \ + -DENABLE_HWLOC=ON \ + -DENABLE_PAPI=ON \ + -DENABLE_MKL=ON \ + -DENABLE_BLAS=ON \ + -DENABLE_LAPACK=ON \ + -DENABLE_SCALAPACK=ON \ + -DENABLE_PLASMA=ON \ + -DENABLE_HDF5=ON \ + \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTS=ON \ + -DBUILD_DOCS=ON \ + \ + -DIPM_PREFIX=${IPM_HOME} \ + -DPAPI_PREFIX=${PAPI_HOME} \ + \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + ../ && \ + await_confirm && \ + make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ +exit_message + diff --git a/build.sh b/build.sh deleted file mode 100755 index 06355aef2..000000000 --- a/build.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/sh - -BUILD_DIR=./build - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi - -# To specify a build configuration for a specific system, use: -# -# -DENVIRONMENT_TYPE= \ -# -# For available types, see the files in folder ./config. -# To specify a custom build configuration, use: -# -# -DENVIRONMENT_CONFIG_PATH= \ -# - -# To use an existing installation of gtest instead of downloading the sources -# from the google test subversion repository, use: -# -# -DGTEST_LIBRARY_PATH=${HOME}/gtest \ -# -DGTEST_INCLUDE_PATH=${HOME}/gtest/include \ -# - -# To build with MKL support, set environment variables MKLROOT and INTELROOT. -# - -# To enable IPM runtime support, use: -# -# -DIPM_PREFIX= \ - -# For likwid support, ensure that the likwid development headers are -# installed. - -# Configure with default release build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_GENERIC=OFF \ - -DENVIRONMENT_TYPE=default \ - -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \ - -DDART_IMPLEMENTATIONS=mpi \ - -DENABLE_THREADSUPPORT=ON \ - -DENABLE_DEV_COMPILER_WARNINGS=OFF \ - -DENABLE_EXT_COMPILER_WARNINGS=OFF \ - -DENABLE_LT_OPTIMIZATION=OFF \ - -DENABLE_ASSERTIONS=ON \ - \ - -DENABLE_SHARED_WINDOWS=ON \ - -DENABLE_DYNAMIC_WINDOWS=ON \ - -DENABLE_UNIFIED_MEMORY_MODEL=ON \ - -DENABLE_DEFAULT_INDEX_TYPE_LONG=ON \ - \ - -DENABLE_LOGGING=OFF \ - -DENABLE_TRACE_LOGGING=OFF \ - -DENABLE_DART_LOGGING=OFF \ - \ - -DENABLE_LIBNUMA=ON \ - -DENABLE_LIKWID=OFF \ - -DENABLE_HWLOC=ON \ - -DENABLE_PAPI=ON \ - -DENABLE_MKL=ON \ - -DENABLE_BLAS=ON \ - -DENABLE_LAPACK=ON \ - -DENABLE_SCALAPACK=ON \ - -DENABLE_PLASMA=ON \ - -DENABLE_HDF5=ON \ - \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_TESTS=ON \ - -DBUILD_DOCS=ON \ - \ - -DIPM_PREFIX=${IPM_HOME} \ - -DPAPI_PREFIX=${PAPI_HOME} \ - \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ - await_confirm && \ - make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ -exit_message - diff --git a/build.sh b/build.sh new file mode 120000 index 000000000..1aee1d51f --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +build-tools/build.sh \ No newline at end of file From 056a43653da4ab59a5bd0a2f7ec93d47f1c0705e Mon Sep 17 00:00:00 2001 From: Daniel Diefenthaler Date: Tue, 3 Oct 2017 19:39:38 +0200 Subject: [PATCH 143/161] made build scripts independant of working directory --- build-tools/build.analyze.sh | 13 ++++++++++++- build-tools/build.cov.sh | 13 ++++++++++++- build-tools/build.debug.sh | 13 ++++++++++++- build-tools/build.dev.sh | 13 ++++++++++++- build-tools/build.mic.sh | 13 ++++++++++++- build-tools/build.minimal.sh | 13 ++++++++++++- build-tools/build.nasty.sh | 13 ++++++++++++- build-tools/build.sh | 13 ++++++++++++- 8 files changed, 96 insertions(+), 8 deletions(-) diff --git a/build-tools/build.analyze.sh b/build-tools/build.analyze.sh index f5ba3d8da..4ca041f32 100755 --- a/build-tools/build.analyze.sh +++ b/build-tools/build.analyze.sh @@ -6,7 +6,18 @@ # export CCC_CC=clang-3.8 # export CCC_CXX=clang++3.8 -BUILD_DIR=./build.analyze +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build.analyze REPORT_DIR=report # relative to BUILD_DIR BUILD_WRAPPER="${SCANBUILD_BIN}"; diff --git a/build-tools/build.cov.sh b/build-tools/build.cov.sh index 19c72ed04..c53586411 100755 --- a/build-tools/build.cov.sh +++ b/build-tools/build.cov.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build.cov +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build.cov FORCE_BUILD=false if [ "$1" = "-f" ]; then diff --git a/build-tools/build.debug.sh b/build-tools/build.debug.sh index 3a737a295..b1f01334a 100755 --- a/build-tools/build.debug.sh +++ b/build-tools/build.debug.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build.dev +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build.dev FORCE_BUILD=false if [ "$1" = "-f" ]; then diff --git a/build-tools/build.dev.sh b/build-tools/build.dev.sh index 1d793d56f..fa910a969 100755 --- a/build-tools/build.dev.sh +++ b/build-tools/build.dev.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build.dev +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build.dev FORCE_BUILD=false if [ "$1" = "-f" ]; then diff --git a/build-tools/build.mic.sh b/build-tools/build.mic.sh index 0ed0ab666..59c7ff68a 100755 --- a/build-tools/build.mic.sh +++ b/build-tools/build.mic.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build.mic +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build.mic FORCE_BUILD=false if [ "$1" = "-f" ]; then diff --git a/build-tools/build.minimal.sh b/build-tools/build.minimal.sh index 90f5ae48c..c1260b0c9 100755 --- a/build-tools/build.minimal.sh +++ b/build-tools/build.minimal.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build FORCE_BUILD=false if [ "$1" = "-f" ]; then diff --git a/build-tools/build.nasty.sh b/build-tools/build.nasty.sh index 81cbb9b58..a3b25fb8b 100755 --- a/build-tools/build.nasty.sh +++ b/build-tools/build.nasty.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build.nasty +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build.nasty FORCE_BUILD=false if [ "$1" = "-f" ]; then diff --git a/build-tools/build.sh b/build-tools/build.sh index 06355aef2..bb1e3ee92 100755 --- a/build-tools/build.sh +++ b/build-tools/build.sh @@ -1,6 +1,17 @@ #!/bin/sh -BUILD_DIR=./build +SCRIPT=$0 +while [ -h $SCRIPT ] +do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE +done + +cd $(dirname $SCRIPT)/.. +DASHDIR=$(pwd -P) + +BUILD_DIR=$DASHDIR/build FORCE_BUILD=false if [ "$1" = "-f" ]; then From 96614c72a846bfcc6c3f3e59114ffa5fd0cc511a Mon Sep 17 00:00:00 2001 From: Daniel Diefenthaler Date: Fri, 6 Oct 2017 00:01:39 +0200 Subject: [PATCH 144/161] unified build scripts, parameter can be used to change build type --- build-tools/build.analyze.sh | 103 ++++++++++----------------- build-tools/build.cov.sh | 63 ++++++----------- build-tools/build.debug.sh | 62 +++++----------- build-tools/build.default.sh | 88 +++++++++++++++++++++++ build-tools/build.dev.sh | 62 +++++----------- build-tools/build.mic.sh | 63 ++++++----------- build-tools/build.minimal.sh | 63 ++++++----------- build-tools/build.nasty.sh | 62 +++++----------- build-tools/build.sh | 133 +++++++++++++---------------------- 9 files changed, 290 insertions(+), 409 deletions(-) create mode 100755 build-tools/build.default.sh diff --git a/build-tools/build.analyze.sh b/build-tools/build.analyze.sh index 4ca041f32..eed8fff61 100755 --- a/build-tools/build.analyze.sh +++ b/build-tools/build.analyze.sh @@ -1,4 +1,7 @@ #!/bin/sh + +if ! [ -z ${SOURCING+x} ]; then + # This script runs scan-build to perform a static code analysis # https://clang-analyzer.llvm.org/scan-build.html # @@ -6,23 +9,6 @@ # export CCC_CC=clang-3.8 # export CCC_CXX=clang++3.8 -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build.analyze -REPORT_DIR=report # relative to BUILD_DIR -BUILD_WRAPPER="${SCANBUILD_BIN}"; - - - ## !! NOTE !! # # See documentation of scan-build for details on recommended build @@ -32,44 +18,6 @@ BUILD_WRAPPER="${SCANBUILD_BIN}"; # ## - - -# try to find build wrapper -if [ "$BUILD_WRAPPER" = "" ]; then - BUILD_WRAPPER="scan-build" -fi -if [ "$SCANBUILD_OPTS" = "" ]; then - SCANBUILD_OPTS="-analyze-headers -plist-html" -fi -SCANBUILD_OPTS="-o $REPORT_DIR ${SCANBUILD_OPTS}" -SCANBUILD_OPTS="--force-analyze-debug-code -v ${SCANBUILD_OPTS}" - -which $BUILD_WRAPPER || - (echo "This build requires $BUILD_WRAPPER. Set env. var SCANBUILD_BIN" \ - & exit 1); - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build and analyze using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi - # To specify a build configuration for a specific system, use: # # -DENVIRONMENT_TYPE= \ @@ -97,11 +45,30 @@ fi # For likwid support, ensure that the likwid development headers are # installed. -# Configure with default release build settings: -rm -Rf $BUILD_DIR/* -mkdir -p $BUILD_DIR/$REPORT_DIR -(cd $BUILD_DIR && $BUILD_WRAPPER $SCANBUILD_OPTS \ - cmake3 -DCMAKE_BUILD_TYPE=Debug \ + +BUILD_DIR=build.analyze +REPORT_DIR=report # relative to BUILD_DIR +BUILD_WRAPPER="${SCANBUILD_BIN}"; + +# try to find build wrapper +if [ "$BUILD_WRAPPER" = "" ]; then + BUILD_WRAPPER="scan-build" +fi +if [ "$SCANBUILD_OPTS" = "" ]; then + SCANBUILD_OPTS="-analyze-headers -plist-html" +fi +SCANBUILD_OPTS="-o $REPORT_DIR ${SCANBUILD_OPTS}" +SCANBUILD_OPTS="--force-analyze-debug-code -v ${SCANBUILD_OPTS}" + +which $BUILD_WRAPPER || + (echo "This build requires $BUILD_WRAPPER. Set env. var SCANBUILD_BIN" \ + & exit 1); + +# custom cmake command +CMAKE_COMMAND="$BUILD_WRAPPER $SCANBUILD_OPTS cmake3" + +# default release build settings: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Debug \ -DENVIRONMENT_TYPE=default \ -DENABLE_COMPTIME_RED=OFF \ \ @@ -141,10 +108,14 @@ mkdir -p $BUILD_DIR/$REPORT_DIR -DIPM_PREFIX=${IPM_HOME} \ -DPAPI_PREFIX=${PAPI_HOME} \ \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ - await_confirm && \ - $BUILD_WRAPPER $SCANBUILD_OPTS make) && \ - (cp $BUILD_DIR/compile_commands.json .) && \ -exit_message + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + +# the make command used +MAKE_COMMAND="$BUILD_WRAPPER $SCANBUILD_OPTS make" + +else + + $(dirname $0)/build.sh analyze $@ + +fi diff --git a/build-tools/build.cov.sh b/build-tools/build.cov.sh index c53586411..2337114e9 100755 --- a/build-tools/build.cov.sh +++ b/build-tools/build.cov.sh @@ -1,39 +1,6 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build.cov - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To run code coverage measurement, run make coverage in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +if ! [ -z ${SOURCING+x} ]; then # To specify a build configuration for a specific system, use: # @@ -62,10 +29,14 @@ fi # For likwid support, ensure that the likwid development headers are # installed. -# Configure with default release build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Debug \ +# relative to $ROOTDIR of dash +BUILD_DIR=$DASHDIR/build.cov + +# custom cmake command +CMAKE_COMMAND="cmake" + +# default release build settings: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Debug \ -DENVIRONMENT_TYPE=default \ -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \ -DDART_IMPLEMENTATIONS=mpi \ @@ -100,8 +71,14 @@ rm -Rf $BUILD_DIR/* -DBUILD_DOCS=OFF \ \ -DIPM_PREFIX=${IPM_HOME} \ - -DPAPI_PREFIX=${PAPI_HOME} \ - ../ && \ - await_confirm && \ - make -j 4) && \ -exit_message + -DPAPI_PREFIX=${PAPI_HOME}" + +# the mak e command used +MAKE_COMMAND="make -j 4" + +else + + $(dirname $0)/build.sh cov $@ + +fi + diff --git a/build-tools/build.debug.sh b/build-tools/build.debug.sh index b1f01334a..c706d4201 100755 --- a/build-tools/build.debug.sh +++ b/build-tools/build.debug.sh @@ -1,39 +1,6 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build.dev - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +if ! [ -z ${SOURCING+x} ]; then # To specify a build configuration for a specific system, use: # @@ -64,10 +31,14 @@ fi # For likwid support, ensure that the likwid development headers are # installed. -# Configure with default debug build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Debug \ +# relative to $ROOTDIR of dash +BUILD_DIR=build.dev + +# custom cmake command +CMAKE_COMMAND="cmake" + +# default debug build settings: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Debug \ -DENVIRONMENT_TYPE=default \ -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0-dev/ \ -DDART_IMPLEMENTATIONS=mpi \ @@ -104,9 +75,14 @@ rm -Rf $BUILD_DIR/* -DIPM_PREFIX=${IPM_HOME} \ -DPAPI_PREFIX=${PAPI_HOME} \ \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ - await_confirm && \ - make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ -exit_message + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + +# the make command used +MAKE_COMMAND="make -j 4" + +else + + $(dirname $0)/build.sh debug $@ + +fi diff --git a/build-tools/build.default.sh b/build-tools/build.default.sh new file mode 100755 index 000000000..6e3d7575a --- /dev/null +++ b/build-tools/build.default.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +if ! [ -z ${SOURCING+x} ]; then + +# To specify a build configuration for a specific system, use: +# +# -DENVIRONMENT_TYPE= \ +# +# For available types, see the files in folder ./config. +# To specify a custom build configuration, use: +# +# -DENVIRONMENT_CONFIG_PATH= \ +# + +# To use an existing installation of gtest instead of downloading the sources +# from the google test subversion repository, use: +# +# -DGTEST_LIBRARY_PATH=${HOME}/gtest \ +# -DGTEST_INCLUDE_PATH=${HOME}/gtest/include \ +# + +# To build with MKL support, set environment variables MKLROOT and INTELROOT. +# + +# To enable IPM runtime support, use: +# +# -DIPM_PREFIX= \ + +# For likwid support, ensure that the likwid development headers are +# installed. + +# relative to $ROOTDIR of dash +BUILD_DIR=build + +# custom cmake command +CMAKE_COMMAND="cmake" + +# default release build settings: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_GENERIC=OFF \ + -DENVIRONMENT_TYPE=default \ + -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \ + -DDART_IMPLEMENTATIONS=mpi \ + -DENABLE_THREADSUPPORT=ON \ + -DENABLE_DEV_COMPILER_WARNINGS=OFF \ + -DENABLE_EXT_COMPILER_WARNINGS=OFF \ + -DENABLE_LT_OPTIMIZATION=OFF \ + -DENABLE_ASSERTIONS=ON \ + \ + -DENABLE_SHARED_WINDOWS=ON \ + -DENABLE_DYNAMIC_WINDOWS=ON \ + -DENABLE_UNIFIED_MEMORY_MODEL=ON \ + -DENABLE_DEFAULT_INDEX_TYPE_LONG=ON \ + \ + -DENABLE_LOGGING=OFF \ + -DENABLE_TRACE_LOGGING=OFF \ + -DENABLE_DART_LOGGING=OFF \ + \ + -DENABLE_LIBNUMA=ON \ + -DENABLE_LIKWID=OFF \ + -DENABLE_HWLOC=ON \ + -DENABLE_PAPI=ON \ + -DENABLE_MKL=ON \ + -DENABLE_BLAS=ON \ + -DENABLE_LAPACK=ON \ + -DENABLE_SCALAPACK=ON \ + -DENABLE_PLASMA=ON \ + -DENABLE_HDF5=ON \ + \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTS=ON \ + -DBUILD_DOCS=ON \ + \ + -DIPM_PREFIX=${IPM_HOME} \ + -DPAPI_PREFIX=${PAPI_HOME} \ + \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + +# the make command used +MAKE_COMMAND="make -j 4" + +else + + $(dirname $0)/build.sh $@ + +fi + diff --git a/build-tools/build.dev.sh b/build-tools/build.dev.sh index fa910a969..f4df6291e 100755 --- a/build-tools/build.dev.sh +++ b/build-tools/build.dev.sh @@ -1,39 +1,6 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build.dev - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +if ! [ -z ${SOURCING+x} ]; then # To specify a build configuration for a specific system, use: # @@ -64,10 +31,14 @@ fi # For likwid support, ensure that the likwid development headers are # installed. -# Configure with default developer build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Debug \ +# relative to $ROOTDIR of dash +BUILD_DIR=build.dev + +# custom cmake command +CMAKE_COMMAND="cmake" + +# default developer build settings: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Debug \ -DENVIRONMENT_TYPE=default \ -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0-dev/ \ -DDART_IMPLEMENTATIONS=mpi \ @@ -104,9 +75,14 @@ rm -Rf $BUILD_DIR/* -DIPM_PREFIX=${IPM_HOME} \ -DPAPI_PREFIX=${PAPI_HOME} \ \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ - await_confirm && \ - make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ -exit_message + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + +# the make command used +MAKE_COMMAND="make -j 4" + +else + + $(dirname $0)/build.sh dev $@ + +fi diff --git a/build-tools/build.mic.sh b/build-tools/build.mic.sh index 59c7ff68a..cde5c8a21 100755 --- a/build-tools/build.mic.sh +++ b/build-tools/build.mic.sh @@ -1,39 +1,6 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build.mic - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "------------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +if ! [ -z ${SOURCING+x} ]; then # To use an existing installation of gtest instead of downloading the sources # from the google test subversion repository, use: @@ -52,10 +19,14 @@ fi # To build with MKL support, set environment variables MKLROOT and INTELROOT. -# Configure with default release build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ +# relative to $ROOTDIR of dash +BUILD_DIR=build.mic + +# custom cmake command +CMAKE_COMMAND="cmake" + +# default release build settings for supermic environment: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Release \ -DENVIRONMENT_TYPE=supermic \ -DCMAKE_C_COMPILER=mpiicc \ -DCMAKE_CXX_COMPILER=mpiicc \ @@ -91,8 +62,14 @@ rm -Rf $BUILD_DIR/* -DBUILD_DOCS=OFF \ \ -DPAPI_PREFIX=${PAPI_HOME} \ - -DIPM_PREFIX=${IPM_BASE} \ - ../ && \ - await_confirm && \ - make -j 5) && \ -exit_message + -DIPM_PREFIX=${IPM_BASE}" + +# the make command used +MAKE_COMMAND="make -j 5" + +else + + $(dirname $0)/build.sh mic $@ + +fi + diff --git a/build-tools/build.minimal.sh b/build-tools/build.minimal.sh index c1260b0c9..9c4d6f34d 100755 --- a/build-tools/build.minimal.sh +++ b/build-tools/build.minimal.sh @@ -1,39 +1,6 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +if ! [ -z ${SOURCING+x} ]; then # To specify a build configuration for a specific system, use: # @@ -56,10 +23,14 @@ fi # # -DIPM_PREFIX= \ -# Configure with default release build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ +# relative to $ROOTDIR of dash +BUILD_DIR=build + +# custom cmake command +CMAKE_COMMAND="cmake" + +# minimal release build settings: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Release \ -DENVIRONMENT_TYPE=default \ -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \ -DDART_IMPLEMENTATIONS=mpi \ @@ -96,8 +67,14 @@ rm -Rf $BUILD_DIR/* -DIPM_PREFIX=${IPM_HOME} \ -DPAPI_PREFIX=${PAPI_HOME} \ \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ - await_confirm && \ - make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ -exit_message + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + +# the make command used +MAKE_COMMAND="make -j 4" + +else + + $(dirname $0)/build.sh minimal $@ + +fi + diff --git a/build-tools/build.nasty.sh b/build-tools/build.nasty.sh index a3b25fb8b..90f70d832 100755 --- a/build-tools/build.nasty.sh +++ b/build-tools/build.nasty.sh @@ -1,39 +1,6 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) - -BUILD_DIR=$DASHDIR/build.nasty - -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi - -await_confirm() { - if ! $FORCE_BUILD; then - echo "" - echo " To build using these settings, hit ENTER" - read confirm - fi -} - -exit_message() { - echo "--------------------------------------------------------" - echo "Done. To install DASH, run make install in $BUILD_DIR" -} - -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +if ! [ -z ${SOURCING+x} ]; then # To specify a build configuration for a specific system, use: # @@ -69,10 +36,14 @@ fi # # !!!!!!!!!!!!!!!!!!!!! DO NOT ENABLE IN PRODUCTION !!!!!!!!!!!!!!!!!!!!!!!! -# Configure with default release build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ +# relative to $ROOTDIR of dash +BUILD_DIR=build.nasty + +# custom cmake command +CMAKE_COMMAND="cmake" + +# default release build settings with nasty mpi: +CMAKE_OPTIONS=" -DCMAKE_BUILD_TYPE=Release \ -DENVIRONMENT_TYPE=default \ -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0-nasty \ -DDART_IMPLEMENTATIONS=mpi \ @@ -111,9 +82,14 @@ rm -Rf $BUILD_DIR/* -DIPM_PREFIX=${IPM_HOME} \ -DPAPI_PREFIX=${PAPI_HOME} \ \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ - await_confirm && \ - make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ -exit_message + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + +# the make command used +MAKE_COMMAND="make -j 4" + +else + + $(dirname $0)/build.sh nasty $@ + +fi diff --git a/build-tools/build.sh b/build-tools/build.sh index bb1e3ee92..29a632232 100755 --- a/build-tools/build.sh +++ b/build-tools/build.sh @@ -1,22 +1,25 @@ #!/bin/sh -SCRIPT=$0 -while [ -h $SCRIPT ] -do - BASE=$(dirname $SCRIPT) - SCRIPT=$(readlink $SCRIPT) - cd $BASE -done - -cd $(dirname $SCRIPT)/.. -DASHDIR=$(pwd -P) +# traverse symlinks of the script and find the original scriptdir +find_scriptdir() { + ( + SCRIPT=$1 + while [ -h $SCRIPT ] + do + BASE=$(dirname $SCRIPT) + SCRIPT=$(readlink $SCRIPT) + cd $BASE + done -BUILD_DIR=$DASHDIR/build + cd $(dirname $SCRIPT) && pwd -P + ) +} -FORCE_BUILD=false -if [ "$1" = "-f" ]; then - FORCE_BUILD=true -fi +# find the root of the project +# when given the scriptdir as parameter +find_rootdir() { + ( cd $1/.. && pwd -P ) +} await_confirm() { if ! $FORCE_BUILD; then @@ -31,82 +34,42 @@ exit_message() { echo "Done. To install DASH, run make install in $BUILD_DIR" } -if [ "${PAPI_HOME}" = "" ]; then - PAPI_HOME=$PAPI_BASE -fi +SCRIPTDIR=$(find_scriptdir $0) +ROOTDIR=$(find_rootdir $SCRIPTDIR) -# To specify a build configuration for a specific system, use: -# -# -DENVIRONMENT_TYPE= \ -# -# For available types, see the files in folder ./config. -# To specify a custom build configuration, use: -# -# -DENVIRONMENT_CONFIG_PATH= \ -# +SOURCING=true +# load default options +. $SCRIPTDIR/build.default.sh -# To use an existing installation of gtest instead of downloading the sources -# from the google test subversion repository, use: -# -# -DGTEST_LIBRARY_PATH=${HOME}/gtest \ -# -DGTEST_INCLUDE_PATH=${HOME}/gtest/include \ -# +FORCE_BUILD=false +# go through parameters +while [ $# -gt 0 ]; do + if [ "$1" = "-f" ]; then + FORCE_BUILD=true + fi -# To build with MKL support, set environment variables MKLROOT and INTELROOT. -# + # load options from seperate file(s) + if [ -x $SCRIPTDIR/build.$1.sh ]; then + . $SCRIPTDIR/build.$1.sh + fi + if [ -x $SCRIPTDIR/my.build.$1.sh ]; then + . $SCRIPTDIR/my.build.$1.sh + fi -# To enable IPM runtime support, use: -# -# -DIPM_PREFIX= \ + shift +done -# For likwid support, ensure that the likwid development headers are -# installed. -# Configure with default release build settings: -mkdir -p $BUILD_DIR -rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_GENERIC=OFF \ - -DENVIRONMENT_TYPE=default \ - -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \ - -DDART_IMPLEMENTATIONS=mpi \ - -DENABLE_THREADSUPPORT=ON \ - -DENABLE_DEV_COMPILER_WARNINGS=OFF \ - -DENABLE_EXT_COMPILER_WARNINGS=OFF \ - -DENABLE_LT_OPTIMIZATION=OFF \ - -DENABLE_ASSERTIONS=ON \ - \ - -DENABLE_SHARED_WINDOWS=ON \ - -DENABLE_DYNAMIC_WINDOWS=ON \ - -DENABLE_UNIFIED_MEMORY_MODEL=ON \ - -DENABLE_DEFAULT_INDEX_TYPE_LONG=ON \ - \ - -DENABLE_LOGGING=OFF \ - -DENABLE_TRACE_LOGGING=OFF \ - -DENABLE_DART_LOGGING=OFF \ - \ - -DENABLE_LIBNUMA=ON \ - -DENABLE_LIKWID=OFF \ - -DENABLE_HWLOC=ON \ - -DENABLE_PAPI=ON \ - -DENABLE_MKL=ON \ - -DENABLE_BLAS=ON \ - -DENABLE_LAPACK=ON \ - -DENABLE_SCALAPACK=ON \ - -DENABLE_PLASMA=ON \ - -DENABLE_HDF5=ON \ - \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_TESTS=ON \ - -DBUILD_DOCS=ON \ - \ - -DIPM_PREFIX=${IPM_HOME} \ - -DPAPI_PREFIX=${PAPI_HOME} \ - \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ../ && \ +if [ "${PAPI_HOME}" = "" ]; then + PAPI_HOME=$PAPI_BASE +fi + +# Configure with build settings loaded previously: +mkdir -p $ROOTDIR/$BUILD_DIR +rm -Rf $ROOTDIR/$BUILD_DIR/* +(cd $ROOTDIR/$BUILD_DIR && cmake $CMAKE_OPTIONS \ + $ROOTDIR && \ await_confirm && \ - make -j 4) && (cp $BUILD_DIR/compile_commands.json .) && \ + $MAKE_COMMAND) && \ exit_message From d2b3211e81844ebb796a522ae32e38ee90dd9857 Mon Sep 17 00:00:00 2001 From: Daniel Diefenthaler Date: Fri, 6 Oct 2017 00:24:27 +0200 Subject: [PATCH 145/161] minor fix to use specified cmake command --- build-tools/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-tools/build.sh b/build-tools/build.sh index 29a632232..f36d20bd3 100755 --- a/build-tools/build.sh +++ b/build-tools/build.sh @@ -67,8 +67,8 @@ fi # Configure with build settings loaded previously: mkdir -p $ROOTDIR/$BUILD_DIR rm -Rf $ROOTDIR/$BUILD_DIR/* -(cd $ROOTDIR/$BUILD_DIR && cmake $CMAKE_OPTIONS \ - $ROOTDIR && \ +(cd $ROOTDIR/$BUILD_DIR && $CMAKE_COMMAND $CMAKE_OPTIONS \ + $ROOTDIR && \ await_confirm && \ $MAKE_COMMAND) && \ exit_message From 944b275030533ec4ece87d1e79a4cbf22b946651 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 7 Oct 2017 01:40:17 +0200 Subject: [PATCH 146/161] Adding matrix view tests --- dash/include/dash/View.h | 1 + dash/include/dash/view/IndexSet.h | 35 +++++----- dash/test/view/MatrixViewTest.cc | 111 ++++++++++++++++++++++++++++++ dash/test/view/MatrixViewTest.h | 22 ++++++ dash/test/view/NViewTest.cc | 65 +---------------- dash/test/view/ViewTestBase.h | 103 +++++++++++++++++++++++++++ 6 files changed, 257 insertions(+), 80 deletions(-) create mode 100644 dash/test/view/MatrixViewTest.cc create mode 100644 dash/test/view/MatrixViewTest.h create mode 100644 dash/test/view/ViewTestBase.h diff --git a/dash/include/dash/View.h b/dash/include/dash/View.h index cec32a03c..50d84dac6 100644 --- a/dash/include/dash/View.h +++ b/dash/include/dash/View.h @@ -117,5 +117,6 @@ #include #include +#include #endif // DASH__VIEW_H__INCLUDED diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index cb508ec7f..09274d9e0 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -532,7 +532,7 @@ class IndexSetBase pat_mapping_traits::diagonal; } - // ---- extents --------------------------------------------------------- + // ---- extents -------------------------------------------------------- constexpr std::array extents() const { @@ -548,7 +548,7 @@ class IndexSetBase return derived().extents()[shape_dim]; } - // ---- offsets --------------------------------------------------------- + // ---- offsets -------------------------------------------------------- constexpr std::array offsets() const { @@ -564,7 +564,21 @@ class IndexSetBase return derived().offsets()[shape_dim]; } - // ---- access ---------------------------------------------------------- + // ---- size ----------------------------------------------------------- + + constexpr bool empty() const noexcept { + return derived().size() == 0; + } + + constexpr bool operator!() const noexcept { + return derived().empty(); + } + + constexpr explicit operator bool() const noexcept { + return !derived().empty(); + } + + // ---- access --------------------------------------------------------- constexpr index_type rel(index_type image_index) const { return image_index; @@ -1076,18 +1090,6 @@ class IndexSetLocal // ---- size ------------------------------------------------------------ - constexpr bool empty() const noexcept { - return size() == 0; - } - - constexpr bool operator!() const noexcept { - return empty(); - } - - constexpr explicit operator bool() const noexcept { - return !empty(); - } - constexpr size_type size(dim_t sub_dim) const noexcept { return _size; } @@ -1227,7 +1229,8 @@ class IndexSetLocal this->pattern().coords( this->pattern().lend() - 1)); } - constexpr index_type local_block_gidx_at_block_lidx(index_type lbi) const { + constexpr index_type local_block_gidx_at_block_lidx( + index_type lbi) const { return this->pattern().block_at( this->pattern().coords( this->pattern().local_block(lbi).offset(0))); diff --git a/dash/test/view/MatrixViewTest.cc b/dash/test/view/MatrixViewTest.cc new file mode 100644 index 000000000..748cb0adc --- /dev/null +++ b/dash/test/view/MatrixViewTest.cc @@ -0,0 +1,111 @@ + +#include "MatrixViewTest.h" +#include "ViewTestBase.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include + + +using dash::test::range_str; +using dash::test::print_nview; +using dash::test::region_values; + +TEST_F(MatrixViewTest, GlobalSubLocalBlocks) +{ + using namespace dash; + + typedef dash::SeqTilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; + + auto myid = dash::Team::All().myid(); + auto nunits = dash::size(); + + const size_t block_size_x = 2; + const size_t block_size_y = 2; + const size_t block_size = block_size_x * block_size_y; + size_t extent_x = block_size_x * (nunits + 1); + size_t extent_y = block_size_y * (nunits + 1); + + dash::TeamSpec<2> teamspec(dash::Team::All()); + teamspec.balance_extents(); + + pattern_t pattern( + dash::SizeSpec<2>( + extent_y, + extent_x), + dash::DistributionSpec<2>( + dash::TILE(block_size_y), + dash::TILE(block_size_x)), + teamspec + ); + + dash::Matrix + matrix(pattern); + + int li = 0; + std::generate(matrix.lbegin(), + matrix.lend(), + [&]() { + return dash::myid() + 0.01 * li++; + }); + + dash::barrier(); + + // -------------------------------------------------------------------- + // matrix | sub + // + auto matrix_sub = matrix | sub<0>(3, extent_y-1) + | sub<1>(1, extent_x-1); + + EXPECT_EQ_U(matrix.extent(0) - 4, matrix_sub.extent(0)); + EXPECT_EQ_U(matrix.extent(1) - 2, matrix_sub.extent(1)); + + // -------------------------------------------------------------------- + // matrix | sub | blocks + // + { + auto m_s_blocks = matrix_sub | blocks(); + auto m_s_blocks_idx = m_s_blocks | index(); + int b_idx = 0; + for (const auto & blk : m_s_blocks) { + auto blk_gidx = m_s_blocks_idx[b_idx]; + auto blk_glob_viewspec = matrix.pattern().block(blk_gidx); + bool blk_is_local_expected = matrix.pattern().unit_at( + blk_glob_viewspec.offsets() + ) == myid; + bool blk_is_strid_expected = !test::is_contiguous_ix(blk | index()); + + EXPECT_EQ_U(blk_is_local_expected, blk.is_local_at(myid)); + EXPECT_EQ_U(blk_is_strid_expected, blk.is_strided()); + ++b_idx; + } + } + + // -------------------------------------------------------------------- + // matrix | sub | local | blocks + // + return; + { + auto m_s_l_blocks = matrix_sub | local() | blocks(); + auto m_s_l_blocks_idx = m_s_l_blocks | index(); + int b_idx = 0; + for (const auto & blk : m_s_l_blocks) { + auto blk_gidx = m_s_l_blocks_idx[b_idx]; + auto blk_glob_viewspec = matrix.pattern().block(blk_gidx); + bool blk_is_local_expected = true; + bool blk_is_strid_expected = !test::is_contiguous_ix(blk | index()); + + ++b_idx; + } + } +} + diff --git a/dash/test/view/MatrixViewTest.h b/dash/test/view/MatrixViewTest.h new file mode 100644 index 000000000..ffba02f11 --- /dev/null +++ b/dash/test/view/MatrixViewTest.h @@ -0,0 +1,22 @@ +#ifndef DASH__TEST__MATRIX_VIEW_TEST_H__INCLUDED +#define DASH__TEST__MATRIX_VIEW_TEST_H__INCLUDED + +#include "ViewTestBase.h" + +/** + * Test fixture for the DASH View concept + */ +class MatrixViewTest : public dash::test::ViewTestBase { +protected: + + MatrixViewTest() { + LOG_MESSAGE(">>> Test suite: MatrixViewTest"); + } + + virtual ~MatrixViewTest() { + LOG_MESSAGE("<<< Closing test suite: MatrixViewTest"); + } + +}; + +#endif // DASH__TEST__MATRIX_VIEW_TEST_H__INCLUDED diff --git a/dash/test/view/NViewTest.cc b/dash/test/view/NViewTest.cc index 7e0e443fa..29d8a7ffb 100644 --- a/dash/test/view/NViewTest.cc +++ b/dash/test/view/NViewTest.cc @@ -1,5 +1,6 @@ #include "NViewTest.h" +#include "ViewTestBase.h" #include @@ -11,72 +12,8 @@ #include #include -#include -#include -namespace dash { -namespace test { - - template - void initialize_matrix(MatrixT & matrix) { - if (dash::myid() == 0) { - for(size_t i = 0; i < matrix.extent(0); ++i) { - for(size_t k = 0; k < matrix.extent(1); ++k) { - matrix[i][k] = (i + 1) * 0.100 + (k + 1) * 0.001; - } - } - } - matrix.barrier(); - - for(size_t i = 0; i < matrix.local_size(); ++i) { - matrix.lbegin()[i] += dash::myid(); - } - matrix.barrier(); - } - - template - void print_nview( - const std::string & name, - const NViewType & nview) { - using value_t = typename NViewType::value_type; - auto view_nrows = nview.extents()[0]; - auto view_ncols = nview.extents()[1]; - auto nindex = dash::index(nview); - for (int r = 0; r < view_nrows; ++r) { - std::ostringstream row_ss; - for (int c = 0; c < view_ncols; ++c) { - int offset = r * view_ncols + c; - row_ss << std::fixed << std::setw(2) - << nindex[offset] - << ":" - << std::fixed << std::setprecision(3) - << static_cast(nview[offset]) - << " "; - } - DASH_LOG_DEBUG("NViewTest.print_nview", - name, "[", r, "]", row_ss.str()); - } - } - - template - std::vector - region_values(const NViewType & view, const dash::ViewSpec<2> & vs) { - auto nvalues = vs.size(); - using value_t = typename NViewType::value_type; - std::vector values; - values.reserve(nvalues); - dash::CartesianIndexSpace<2> cart(view.extents()); - for (int i = 0; i < nvalues; i++) { - auto coords = cart.coords(i, vs); - auto index = cart.at(coords); - values.push_back(static_cast(view.begin()[index])); - } - return values; - } -} -} - using dash::test::range_str; TEST_F(NViewTest, ViewTraits) diff --git a/dash/test/view/ViewTestBase.h b/dash/test/view/ViewTestBase.h new file mode 100644 index 000000000..3baf4b0a7 --- /dev/null +++ b/dash/test/view/ViewTestBase.h @@ -0,0 +1,103 @@ +#ifndef DASH__TEST__VIEW__VIEW_TEST_BASE_H__INCLUDED +#define DASH__TEST__VIEW__VIEW_TEST_BASE_H__INCLUDED + +#include "../TestBase.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +namespace dash { +namespace test { + +template +void initialize_matrix(MatrixT & matrix) { + if (dash::myid() == 0) { + for(size_t i = 0; i < matrix.extent(0); ++i) { + for(size_t k = 0; k < matrix.extent(1); ++k) { + matrix[i][k] = (i + 1) * 0.100 + (k + 1) * 0.001; + } + } + } + matrix.barrier(); + + for(size_t i = 0; i < matrix.local_size(); ++i) { + matrix.lbegin()[i] += dash::myid(); + } + matrix.barrier(); +} + +template +void print_nview( + const std::string & name, + const NViewType & nview) { + using value_t = typename NViewType::value_type; + auto view_nrows = nview.extents()[0]; + auto view_ncols = nview.extents()[1]; + auto nindex = dash::index(nview); + for (int r = 0; r < view_nrows; ++r) { + std::ostringstream row_ss; + for (int c = 0; c < view_ncols; ++c) { + int offset = r * view_ncols + c; + row_ss << std::fixed << std::setw(2) + << nindex[offset] + << ":" + << std::fixed << std::setprecision(3) + << static_cast(nview[offset]) + << " "; + } + DASH_LOG_DEBUG("NViewTest.print_nview", + name, "[", r, "]", row_ss.str()); + } +} + +template +std::vector +region_values(const NViewType & view, const dash::ViewSpec<2> & vs) { + auto nvalues = vs.size(); + using value_t = typename NViewType::value_type; + std::vector values; + values.reserve(nvalues); + dash::CartesianIndexSpace<2> cart(view.extents()); + for (int i = 0; i < nvalues; i++) { + auto coords = cart.coords(i, vs); + auto index = cart.at(coords); + values.push_back(static_cast(view.begin()[index])); + } + return values; +} + +template +bool is_contiguous_ix(const RangeT & rng) { + if (!rng) { return true; } + auto ix_prev = *dash::begin(rng); + for (const auto & ix : rng) { + if (ix > ix_prev) { return false; } + } + return true; +} + +using dash::sub; +using dash::block; +using dash::blocks; +using dash::local; +using dash::index; +using dash::expand; +using dash::shift; + +class ViewTestBase : public dash::test::TestBase { +protected: +}; + +} // namespace test +} // namespace dash + +#endif // DASH__TEST__VIEW__VIEW_TEST_BASE_H__INCLUDED From 57f8a355eb6b0a20bf515cb4f063d0dbc2bbe110 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 7 Oct 2017 02:04:49 +0200 Subject: [PATCH 147/161] Adding matrix view tests --- dash/test/view/MatrixViewTest.cc | 25 ++++++++++++++++++++++--- dash/test/view/ViewTestBase.h | 5 +++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/dash/test/view/MatrixViewTest.cc b/dash/test/view/MatrixViewTest.cc index 748cb0adc..b0e4a3f60 100644 --- a/dash/test/view/MatrixViewTest.cc +++ b/dash/test/view/MatrixViewTest.cc @@ -82,10 +82,29 @@ TEST_F(MatrixViewTest, GlobalSubLocalBlocks) bool blk_is_local_expected = matrix.pattern().unit_at( blk_glob_viewspec.offsets() ) == myid; + bool blk_is_local_actual = blk.is_local_at(myid); bool blk_is_strid_expected = !test::is_contiguous_ix(blk | index()); - - EXPECT_EQ_U(blk_is_local_expected, blk.is_local_at(myid)); - EXPECT_EQ_U(blk_is_strid_expected, blk.is_strided()); + bool blk_is_strid_actual = blk.is_strided(); + + DASH_LOG_DEBUG("MatrixViewTest.GlobalSubLocalBlocks", + "block view idx:", b_idx, "-> block gidx:", blk_gidx, + ":", range_str(blk)); + DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", + blk_is_local_expected); + DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", + blk_is_local_actual); + DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", + blk_is_strid_expected); + DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", + blk_is_strid_actual); + + if (!blk || !(blk | index())) { + EXPECT_EQ_U(blk.size(), 0); + EXPECT_EQ_U((blk | index()).size(), 0); + } else { + EXPECT_EQ_U(blk_is_local_expected, blk.is_local_at(myid)); + EXPECT_EQ_U(blk_is_strid_expected, blk.is_strided()); + } ++b_idx; } } diff --git a/dash/test/view/ViewTestBase.h b/dash/test/view/ViewTestBase.h index 3baf4b0a7..fff1d1aff 100644 --- a/dash/test/view/ViewTestBase.h +++ b/dash/test/view/ViewTestBase.h @@ -78,9 +78,10 @@ region_values(const NViewType & view, const dash::ViewSpec<2> & vs) { template bool is_contiguous_ix(const RangeT & rng) { if (!rng) { return true; } - auto ix_prev = *dash::begin(rng); + auto ix_prev = rng.first(); for (const auto & ix : rng) { - if (ix > ix_prev) { return false; } + if (ix < ix_prev || ix == ix_prev && ix != rng.first()) { return false; } + ix_prev = ix; } return true; } From 14cfcc6e3e8c18fd54e06e92e550bfa727a9584c Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 7 Oct 2017 02:16:10 +0200 Subject: [PATCH 148/161] Adding matrix view tests --- dash/test/view/ViewTestBase.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dash/test/view/ViewTestBase.h b/dash/test/view/ViewTestBase.h index fff1d1aff..837c272cb 100644 --- a/dash/test/view/ViewTestBase.h +++ b/dash/test/view/ViewTestBase.h @@ -77,10 +77,11 @@ region_values(const NViewType & view, const dash::ViewSpec<2> & vs) { template bool is_contiguous_ix(const RangeT & rng) { - if (!rng) { return true; } + if (!rng || rng.size() == 1) { return true; } auto ix_prev = rng.first(); for (const auto & ix : rng) { - if (ix < ix_prev || ix == ix_prev && ix != rng.first()) { return false; } + if ((ix != ix_prev+1) && + !(ix == ix_prev && ix == rng.first())) { return false; } ix_prev = ix; } return true; From 5f23f012027be0e222c7808aad1650ceac124246 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 7 Oct 2017 02:19:19 +0200 Subject: [PATCH 149/161] Adding matrix view tests --- dash/test/view/MatrixViewTest.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dash/test/view/MatrixViewTest.cc b/dash/test/view/MatrixViewTest.cc index b0e4a3f60..fe3c0018c 100644 --- a/dash/test/view/MatrixViewTest.cc +++ b/dash/test/view/MatrixViewTest.cc @@ -83,7 +83,8 @@ TEST_F(MatrixViewTest, GlobalSubLocalBlocks) blk_glob_viewspec.offsets() ) == myid; bool blk_is_local_actual = blk.is_local_at(myid); - bool blk_is_strid_expected = !test::is_contiguous_ix(blk | index()); + bool blk_is_strid_expected = blk.extent(1) < block_size_x && + blk.extent(0) > 1; bool blk_is_strid_actual = blk.is_strided(); DASH_LOG_DEBUG("MatrixViewTest.GlobalSubLocalBlocks", From 2571daf996379e5545acd615f62fa5883ccbd481 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Sat, 7 Oct 2017 02:49:14 +0200 Subject: [PATCH 150/161] Adding matrix view tests --- dash/test/view/MatrixViewTest.cc | 37 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/dash/test/view/MatrixViewTest.cc b/dash/test/view/MatrixViewTest.cc index fe3c0018c..c8b83241e 100644 --- a/dash/test/view/MatrixViewTest.cc +++ b/dash/test/view/MatrixViewTest.cc @@ -75,6 +75,9 @@ TEST_F(MatrixViewTest, GlobalSubLocalBlocks) { auto m_s_blocks = matrix_sub | blocks(); auto m_s_blocks_idx = m_s_blocks | index(); + std::vector m_s_b_values; + std::vector m_s_values; + int b_idx = 0; for (const auto & blk : m_s_blocks) { auto blk_gidx = m_s_blocks_idx[b_idx]; @@ -90,14 +93,6 @@ TEST_F(MatrixViewTest, GlobalSubLocalBlocks) DASH_LOG_DEBUG("MatrixViewTest.GlobalSubLocalBlocks", "block view idx:", b_idx, "-> block gidx:", blk_gidx, ":", range_str(blk)); - DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", - blk_is_local_expected); - DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", - blk_is_local_actual); - DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", - blk_is_strid_expected); - DASH_LOG_DEBUG_VAR("MatrixViewTest.GlobalSubLocalBlocks", - blk_is_strid_actual); if (!blk || !(blk | index())) { EXPECT_EQ_U(blk.size(), 0); @@ -105,9 +100,35 @@ TEST_F(MatrixViewTest, GlobalSubLocalBlocks) } else { EXPECT_EQ_U(blk_is_local_expected, blk.is_local_at(myid)); EXPECT_EQ_U(blk_is_strid_expected, blk.is_strided()); + + std::copy(blk.begin(), blk.end(), + std::back_inserter(m_s_b_values)); } ++b_idx; } + + // Block-wise element order differs from element order in sub-matrix + // which is canonical. Copy, sort and intersect both ranges to test + // equality: + + std::copy(matrix_sub.begin(), matrix_sub.end(), + std::back_inserter(m_s_values)); + + DASH_LOG_DEBUG("MatrixViewTest.GlobalSubLocalBlocks", + "matrix_sub:", (m_s_values)); + DASH_LOG_DEBUG("MatrixViewTest.GlobalSubLocalBlocks", + "copied from blocks:", (m_s_b_values)); + + std::sort(m_s_values.begin(), m_s_values.end()); + std::sort(m_s_b_values.begin(), m_s_b_values.end()); + + std::vector m_s_isect; + std::set_difference(m_s_values.begin(), m_s_values.end(), + m_s_b_values.begin(), m_s_b_values.end(), + std::back_inserter(m_s_isect)); + DASH_LOG_DEBUG("MatrixViewTest.GlobalSubLocalBlocks", + "intersection:", (m_s_isect)); + EXPECT_EQ_U(0, m_s_isect.size()); } // -------------------------------------------------------------------- From 9fddf12ddb6574f74b5f1ac82c3e686dab6d7a83 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 11 Oct 2017 00:56:37 +0200 Subject: [PATCH 151/161] Cleanup in examples --- dash/examples/bench.05.array-range/main.cpp | 18 +++---- dash/examples/ex.02.array-views/main.cpp | 13 +++-- .../examples/ex.02.matrix-halo-views/main.cpp | 10 ++-- .../ex.02.matrix-local-views/main.cpp | 26 ++++++---- dash/examples/ex.02.matrix-sub-views/main.cpp | 48 ++----------------- dash/examples/ex.xx.tmp/main.cpp | 11 ----- dash/include/dash/Range.h | 18 +++++++ dash/include/dash/view/IndexSet.h | 8 ++-- dash/include/dash/view/ViewTraits.h | 16 +++++++ 9 files changed, 81 insertions(+), 87 deletions(-) delete mode 100644 dash/examples/ex.xx.tmp/main.cpp diff --git a/dash/examples/bench.05.array-range/main.cpp b/dash/examples/bench.05.array-range/main.cpp index 0baea2715..1efe5d200 100644 --- a/dash/examples/bench.05.array-range/main.cpp +++ b/dash/examples/bench.05.array-range/main.cpp @@ -72,15 +72,15 @@ int main(int argc, char* argv[]) { std::deque> tests; tests.push_back({0 , 0}); // this prints the header - tests.push_back({4 , 1000000}); - tests.push_back({16 , 100000}); - tests.push_back({64 , 100000}); - tests.push_back({256 , 10000}); - tests.push_back({1024 , 10000}); - tests.push_back({4096 , 1000}); - tests.push_back({4*4096 , 5000}); - tests.push_back({16*4096 , 1000}); - tests.push_back({64*4096 , 500}); + tests.push_back({4 , 10000000}); + tests.push_back({16 , 1000000}); + tests.push_back({64 , 1000000}); + tests.push_back({256 , 100000}); + tests.push_back({1024 , 100000}); + tests.push_back({4096 , 10000}); + tests.push_back({4*4096 , 50000}); + tests.push_back({16*4096 , 10000}); + tests.push_back({64*4096 , 5000}); for (auto test: tests) { perform_test(test.first, test.second); diff --git a/dash/examples/ex.02.array-views/main.cpp b/dash/examples/ex.02.array-views/main.cpp index ffed80c36..e439d53ea 100644 --- a/dash/examples/ex.02.array-views/main.cpp +++ b/dash/examples/ex.02.array-views/main.cpp @@ -36,17 +36,18 @@ int main(int argc, char *argv[]) dash::init(&argc, &argv); - int elem_per_unit = 3; int elem_additional = 2; + int block_size = 2; + int elem_per_unit = block_size * 2; int array_size = dash::size() * elem_per_unit + std::min(elem_additional, dash::size()); { - dash::Array a(array_size, dash::BLOCKCYCLIC(2)); + dash::Array a(array_size, dash::BLOCKCYCLIC(block_size)); initialize_array(a); if (dash::myid() == 0) { - print("a: " << range_str(a)); + print("a: " << range_str(a)); STEP("- a | sub"); auto s_array = a | sub(1, a.size()-2); @@ -70,8 +71,12 @@ int main(int argc, char *argv[]) STEP("- a | sub | local | blocks"); auto slb_array = a | sub(1, a.size()-2) | local() | blocks(); + auto slb_arr_i = slb_array | index(); + int i = 0; for (const auto & b : slb_array) { - print(" a | sub | local | blocks:" << range_str(b)); + print(" a | sub | local | block(" << slb_arr_i[i] << "): " << + range_str(b)); + ++i; } auto copy_num_elem = a.size() / 2; diff --git a/dash/examples/ex.02.matrix-halo-views/main.cpp b/dash/examples/ex.02.matrix-halo-views/main.cpp index b37d069e9..25ed8c4a1 100644 --- a/dash/examples/ex.02.matrix-halo-views/main.cpp +++ b/dash/examples/ex.02.matrix-halo-views/main.cpp @@ -31,9 +31,9 @@ int main(int argc, char *argv[]) size_t extent_x = block_size_x * num_blocks_x; size_t extent_y = block_size_y * num_blocks_y; - typedef dash::TilePattern<2> pattern_t; - typedef typename pattern_t::index_type index_t; - typedef float value_t; + typedef dash::TilePattern<2> pattern_t; + typedef typename pattern_t::index_type index_t; + typedef float value_t; dash::TeamSpec<2> teamspec(dash::Team::All()); teamspec.balance_extents(); @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) auto matrix_view = dash::sub(0, matrix.extents()[0], matrix); print("matrix" << nview_str(matrix_view, 2)); - auto matrix_blocks = dash::blocks(matrix); + auto matrix_blocks = matrix | dash::blocks(); auto matrix_b_idx = matrix_blocks | dash::index(); int b_idx = 0; for (const auto & m_block : matrix_blocks) { @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) auto bhs_blocks = b_halo_s | dash::blocks(); STEP(" matrix | block[" << matrix_b_idx[b_idx] << "] | " << - "expand({ -1,1 }, { -1,1 }) | shift<1>(1) | block(0)" << + "expand({ -1,1 }, { -1,1 }) | shift<1>(1) | block[0]" << nview_str(bhs_blocks[0], 2)); ++b_idx; diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index 89d1b0b9c..72ca55f28 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -17,12 +17,13 @@ void run_example(MatrixT & matrix); #define RUN_EXAMPLE(pattern_type__) do { \ auto pattern = make_ ## pattern_type__ ## _pattern( \ params, sizespec, teamspec); \ - std::cout << "Pattern:\n " \ - << pattern_to_string(pattern) << std::endl; \ + if (dash::myid() == 0) { \ + std::cout << "Pattern:\n " \ + << pattern_to_string(pattern) \ + << std::endl; \ + } \ dash::Matrix \ matrix(pattern); \ - std::cout << "Matrix:\n " \ - << typestr(matrix) << std::endl; \ run_example(matrix); \ } while(0) @@ -44,9 +45,9 @@ int main(int argc, char **argv) auto nunits = dash::size(); cli_params defaults = default_params; - defaults.type = "tile"; - defaults.size = {{ 8, 8 }}; - defaults.tile = {{ 2, 2 }}; + defaults.type = "seq"; + defaults.size = {{ 8, 6 }}; + defaults.tile = {{ 0, 0 }}; defaults.units = {{ 1, static_cast(nunits) }}; defaults.blocked_display = false; defaults.balance_extents = false; @@ -66,7 +67,7 @@ int main(int argc, char **argv) if(params.balance_extents) { teamspec.balance_extents(); } - if (params.tile[0] < 0 && params.tile[1] < 0) { + if (params.tile[0] == 0 && params.tile[1] == 0) { auto max_team_extent = std::max(teamspec.extent(0), teamspec.extent(1)); params.tile[0] = sizespec.extent(0) / max_team_extent; @@ -122,6 +123,11 @@ void run_example(MatrixT & matrix) { auto l_matrix = matrix | local(); + STEP("matrix | local() | index():" << dash::typestr(l_matrix)); + + return; + + STEP("matrix | local() | index():" << dash::typestr(l_matrix | index())); STEP("matrix | local():" << nview_str(l_matrix)); dash::barrier(); @@ -129,7 +135,7 @@ void run_example(MatrixT & matrix) { // Copy local block { auto l_blocks = matrix | local() | blocks(); - STEP("matrix | local() | blocks(): " << + STEP("-- matrix | local() | blocks(): " << "size: " << l_blocks.size() << " " << "offsets: " << l_blocks.offsets() << " " << "extents: " << l_blocks.extents()); @@ -141,7 +147,7 @@ void run_example(MatrixT & matrix) { "offsets:", lb.offsets(), "extents:", lb.extents()); - STEP("-- matrix | local() | blocks()[" << l_bi << "]: " << + STEP(" matrix | local() | blocks()[" << l_bi << "]: " << nview_str(lb)); std::vector tmp(lb.size()); diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 05313302c..0f3ecbd6c 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -53,21 +53,21 @@ int main(int argc, char *argv[]) print("matrix:" << nview_str(matrix | sub(0,extent_y)) << '\n'); - STEP("sub<0>(3,-1) | sub<1>(1,-1)"); + STEP("mat | sub<0>(3,-1) | sub<1>(1,-1)"); auto matrix_sub = matrix | sub<0>(3, extent_y-1) | sub<1>(1, extent_x-1); print(nview_str(matrix_sub) << "\n\n"); - STEP("sub<0>(3,-1) | sub<1>(1,-1) | blocks()"); + STEP("mat | sub<0>(3,-1) | sub<1>(1,-1) | blocks()"); { auto m_s_blocks = matrix_sub | blocks(); auto m_s_blocks_idx = m_s_blocks | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { STEP("block " << std::left << std::setw(2) - << m_s_blocks_idx[b_idx] << '\n'); + << (blk | index()) << '\n'); print(" " << (blk.is_strided() ? "strided, " : "contiguous, ") << (blk.is_local_at(myid) ? "local" : "remote") << @@ -75,48 +75,6 @@ int main(int argc, char *argv[]) ++b_idx; } } - - STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()"); - { - print("matrix | sub | local:" << - nview_str(matrix_sub | local())); - print("matrix | sub | local: is_local: " << - (matrix_sub | local() | index()).is_local()); - print("matrix | sub | local: type: " << - dash::typestr(matrix_sub | local())); - print("matrix | sub | local: is_strided: " << - (matrix_sub | local() | index()).is_strided()); - print("matrix | sub | local: is_sub: " << - (matrix_sub | local() | index()).is_sub()); - print("matrix | sub | local: domain is_sub: " << - dash::domain(matrix_sub | local() | index()).is_sub()); - print("matrix | sub | local: index set: " << - (matrix_sub | local() | index()).first() << "," << - (matrix_sub | local() | index()).last()); - - auto m_s_l_blocks = matrix_sub | local() | blocks(); - auto m_s_l_blocks_idx = m_s_l_blocks | index(); - print("matrix | sub | local | blocks: \n" << - "size: " << m_s_l_blocks.size()); - - print("type:" << dash::typestr(m_s_l_blocks)); - print("origin type: " << dash::typestr( - dash::origin(m_s_l_blocks)) - << std::endl); - int b_idx = 0; - - for (const auto & blk : m_s_l_blocks) { - STEP("sub<0>(3,-1) | sub<1>(1,-1) | local() | blocks()[b_idx]"); - auto block_gidx = m_s_l_blocks_idx[b_idx]; - print("--- block(" << block_gidx << ") " << - "offsets: " << blk.offsets() << " " << - "extents: " << blk.extents()); - - print(nview_str(blk) << std::endl); - - ++b_idx; - } - } } dash::finalize(); diff --git a/dash/examples/ex.xx.tmp/main.cpp b/dash/examples/ex.xx.tmp/main.cpp deleted file mode 100644 index 65e5a1a81..000000000 --- a/dash/examples/ex.xx.tmp/main.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -#include -#include - - -int main(int argc, char * argv[]) { - - return EXIT_SUCCESS; -}; - - diff --git a/dash/include/dash/Range.h b/dash/include/dash/Range.h index a62b8303c..b017d9bb5 100644 --- a/dash/include/dash/Range.h +++ b/dash/include/dash/Range.h @@ -173,6 +173,15 @@ constexpr auto begin(RangeType && range) return std::forward(range).begin(); } +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto lbegin(RangeType && range) + -> decltype(std::forward(range).begin()) { + return std::forward(range).lbegin(); +} + /** * \concept{DashRangeConcept} */ @@ -182,6 +191,15 @@ constexpr auto begin(const RangeType & range) return range.begin(); } +/** + * \concept{DashRangeConcept} + */ +template +constexpr auto lend(RangeType && range) + -> decltype(std::forward(range).end()) { + return std::forward(range).lend(); +} + /** * \concept{DashRangeConcept} */ diff --git a/dash/include/dash/view/IndexSet.h b/dash/include/dash/view/IndexSet.h index c307468eb..57a6c9a4c 100644 --- a/dash/include/dash/view/IndexSet.h +++ b/dash/include/dash/view/IndexSet.h @@ -1220,7 +1220,7 @@ class IndexSetLocal )) + 1 // ndim != 1, multi-dimensional : ( - 6 + 100 ) ) ) // domain.is_sub() @@ -1730,7 +1730,8 @@ class IndexSetBlock dash::CartesianIndexSpace( this->extents() ).coords( - block_phase >= this->pattern().local_block(_block_idx).size() + block_phase >= this->pattern() + .local_block(_block_idx).size() ? block_phase - 1 : block_phase ), // block viewspec @@ -1740,7 +1741,8 @@ class IndexSetBlock this->view_domain().offsets(), this->view_domain().extents())) ) + ( - block_phase >= this->pattern().local_block(_block_idx).size() + block_phase >= this->pattern() + .local_block(_block_idx).size() ? 1 : 0) ) diff --git a/dash/include/dash/view/ViewTraits.h b/dash/include/dash/view/ViewTraits.h index 3724d00d8..9ccf24abd 100644 --- a/dash/include/dash/view/ViewTraits.h +++ b/dash/include/dash/view/ViewTraits.h @@ -89,6 +89,22 @@ struct is_view_region dash::is_view::value> { }; +template +struct is_local_view +: std::integral_constant< + bool, + ( dash::is_view::value && + dash::view_traits::is_local::value ) > +{ }; + +template +struct is_global_view +: std::integral_constant< + bool, + ( dash::is_view::value && + !dash::view_traits::is_local::value ) > +{ }; + namespace detail { From 345e008580a9d6b24b070980e03e50263da114f7 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 11 Oct 2017 01:44:04 +0200 Subject: [PATCH 152/161] Fixes for clang c++14 compliance --- dash/include/dash/Types.h | 6 +++++- dash/include/dash/pattern/BlockPattern1D.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dash/include/dash/Types.h b/dash/include/dash/Types.h index f057cf5aa..9925838e5 100644 --- a/dash/include/dash/Types.h +++ b/dash/include/dash/Types.h @@ -231,7 +231,11 @@ struct is_container_compatible : // std::is_trivially_copyable. && std::is_trivially_copyable::value #elif defined(__GNUG__) && __GNUC__ < 5 - && std::has_trivial_copy_constructor::value + // deprecated in C++14 + // && std::has_trivial_copy_constructor::value + && std::is_trivially_copy_constructible::value + // no test for assignment as const element type is + // allowed #endif > { }; diff --git a/dash/include/dash/pattern/BlockPattern1D.h b/dash/include/dash/pattern/BlockPattern1D.h index e5f4f3b00..fa0743d08 100644 --- a/dash/include/dash/pattern/BlockPattern1D.h +++ b/dash/include/dash/pattern/BlockPattern1D.h @@ -1201,7 +1201,7 @@ class BlockPattern<1, Arrangement, IndexType> constexpr std::array initialize_local_range(SizeType l_size) const { return (l_size == 0) - ? std::array {{ 0, 0 }} + ? std::array {{ }} : std::array {{ global(0), global(l_size - 1) + 1 From 3e1f92fcb5cbc671cb23f40105a528d9ce159154 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 11 Oct 2017 01:52:58 +0200 Subject: [PATCH 153/161] Fixes for clang --- dash/examples/ex.06.pattern-block-visualizer/main.cpp | 1 + dash/examples/util.h | 3 +++ dash/include/dash/pattern/internal/PatternLogging.h | 1 + 3 files changed, 5 insertions(+) diff --git a/dash/examples/ex.06.pattern-block-visualizer/main.cpp b/dash/examples/ex.06.pattern-block-visualizer/main.cpp index e4eb046e4..8d7d6ad7f 100644 --- a/dash/examples/ex.06.pattern-block-visualizer/main.cpp +++ b/dash/examples/ex.06.pattern-block-visualizer/main.cpp @@ -19,6 +19,7 @@ #include #include +#include // needed for basename() #include diff --git a/dash/examples/util.h b/dash/examples/util.h index a5d4f9c01..2248dbe6c 100644 --- a/dash/examples/util.h +++ b/dash/examples/util.h @@ -3,6 +3,8 @@ #include +#include + #include #include #include @@ -35,6 +37,7 @@ } while(0) +using namespace dash; using namespace dash::internal::logging; template diff --git a/dash/include/dash/pattern/internal/PatternLogging.h b/dash/include/dash/pattern/internal/PatternLogging.h index c86f363fc..06e9408c9 100644 --- a/dash/include/dash/pattern/internal/PatternLogging.h +++ b/dash/include/dash/pattern/internal/PatternLogging.h @@ -3,6 +3,7 @@ #include #include +#include #include #include From 3d0e030f71f2c0aaee58e81a3cd4031a7a7a7863 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 11 Oct 2017 03:18:57 +0200 Subject: [PATCH 154/161] Specify C++ standard version via CMake built-in option --- CMakeExt/CompilerFlags.cmake | 17 +++++------------ CMakeLists.txt | 20 ++++++++++++-------- dash/CMakeLists.txt | 20 +++++++++++--------- dash/examples/bench.05.array-range/main.cpp | 6 +++--- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/CMakeExt/CompilerFlags.cmake b/CMakeExt/CompilerFlags.cmake index a20726a27..1e83e3d0e 100644 --- a/CMakeExt/CompilerFlags.cmake +++ b/CMakeExt/CompilerFlags.cmake @@ -5,11 +5,11 @@ # -rdynamic Instructs the linker to add all symbols, not only used ones, # to the dynamic symbol table +set(CMAKE_CXX_STANDARD ${DASH_CXX_STANDARD}) -find_package(OpenMP) +find_package(OpenMP) -set(CPP_STD_VERSION 14) # The following warning options are intentionally not enabled: # @@ -138,8 +138,6 @@ endif() # Set C++ compiler flags: if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") # using Clang - set (CXX_STD_FLAG "--std=c++${CPP_STD_VERSION}" - CACHE STRING "C++ compiler std flag") set (CXX_GDB_FLAG "-g" CACHE STRING "C++ compiler (clang++) debug symbols flag") set (CXX_OMP_FLAG ${OpenMP_CXX_FLAGS}) @@ -151,8 +149,6 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") # using GCC - set (CXX_STD_FLAG "-std=c++${CPP_STD_VERSION}" - CACHE STRING "C++ compiler std flag") set (CXX_GDB_FLAG "-ggdb3 -rdynamic" CACHE STRING "C++ compiler GDB debug symbols flag") set (CXX_OMP_FLAG ${OpenMP_CXX_FLAGS}) @@ -167,8 +163,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") # using Intel C++ - set (CXX_STD_FLAG "-std=c++${CPP_STD_VERSION}" - CACHE STRING "C++ compiler std flag") set (CXX_OMP_FLAG ${OpenMP_CXX_FLAGS}) set (CC_OMP_FLAG ${OpenMP_CC_FLAGS}) if(ENABLE_LT_OPTIMIZATION) @@ -178,16 +172,15 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") set (CC_REPORT_FLAG "-qopt-report=4 -qopt-report-phase ipo") endif() - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.0.0") message(FATAL_ERROR "Insufficient Intel compiler version (< 15.0.0)") endif() elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Cray") # Cray compiler not supported for C++ - message(FATAL_ERROR, - "Cray compiler does not support C++${CPP_STD_VERSION} features and is only " - "eligible for building DART.") + message(WARNING, + "Cray compiler does not support C++11/14 features and is " + "only eligible for building DART.") endif() # Set C compiler flags: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b04b49ec..3c01359a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,9 @@ else() endif() ## Build options +set(DASH_CXX_STANDARD "14" + CACHE STRING "C++ standard version for DASH") + option(BUILD_TESTS "Whether tests should be built" on) option(BUILD_COVERAGE_TESTS @@ -116,14 +119,6 @@ include(${CMAKE_SOURCE_DIR}/CMakeExt/Doxygen.cmake) include(${CMAKE_SOURCE_DIR}/CMakeExt/Platform.cmake) include(${CMAKE_SOURCE_DIR}/CMakeExt/Environment.cmake) -if (ENABLE_THREADSUPPORT) - include(${CMAKE_SOURCE_DIR}/CMakeExt/Threading.cmake) -endif() - -if (ENABLE_COMPTIME_RED) - include(${CMAKE_SOURCE_DIR}/CMakeExt/cotire.cmake) -endif() - # Load build modules to locate libraries after environment setup # has been loaded: include(${CMAKE_SOURCE_DIR}/CMakeExt/MPI.cmake) @@ -212,6 +207,14 @@ set(DASH_DART_BASE_INCLUDE_DIR ## Set compiler flags (depend on CMake options) include(${CMAKE_SOURCE_DIR}/CMakeExt/CompilerFlags.cmake) +if (ENABLE_THREADSUPPORT) + include(${CMAKE_SOURCE_DIR}/CMakeExt/Threading.cmake) +endif() + +if (ENABLE_COMPTIME_RED) + include(${CMAKE_SOURCE_DIR}/CMakeExt/cotire.cmake) +endif() + ## Build results output directories (/bin, /lib, /doc) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin) @@ -298,6 +301,7 @@ message(INFO "Enabled DART backends: (DART_IMPLEMENTATIONS) " ${DART_IMPLEMENTATIONS}) message(INFO "C compiler id: ${CMAKE_C_COMPILER_ID}") message(INFO "C++ compiler id: ${CMAKE_CXX_COMPILER_ID}") +message(INFO "C++ standard version: ${CMAKE_CXX_STANDARD}") if (MPI_FOUND) message(INFO "MPI implementation: " ${MPI_IMPL_ID}) endif() diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt index 2afa14d87..875ec3e50 100644 --- a/dash/CMakeLists.txt +++ b/dash/CMakeLists.txt @@ -43,7 +43,7 @@ set(ENABLE_PAPI ${ENABLE_PAPI} PARENT_SCOPE) set(ENABLE_COMPTIME_RED ${ENABLE_COMPTIME_RED} PARENT_SCOPE) -set(CPP_STD_VERSION ${CPP_STD_VERSION} +set(DASH_CXX_STANDARD ${DASH_CXX_STANDARD} PARENT_SCOPE) @@ -316,7 +316,7 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) ) set_target_properties( ${DASH_LIBRARY} PROPERTIES - CXX_STANDARD ${CPP_STD_VERSION} + CXX_STANDARD ${DASH_CXX_STANDARD} ) if(ENABLE_COMPTIME_RED) @@ -325,8 +325,9 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) set_target_properties( ${DASH_LIBRARY} PROPERTIES - CXX_STANDARD_REQUIRED ${CPP_STD_VERSION} + CXX_STANDARD_REQUIRED ON ) + include_directories( ${ADDITIONAL_INCLUDES} ) @@ -361,8 +362,9 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake") # install custom config - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${DASH_LIBRARY}-config.cmake" - DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake") + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${DASH_LIBRARY}-config.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake") endif() # Examples @@ -418,11 +420,11 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST}) ) set_target_properties( ${exampletarget} PROPERTIES - CXX_STANDARD ${CPP_STD_VERSION} + CXX_STANDARD ${DASH_CXX_STANDARD} ) set_target_properties( ${exampletarget} PROPERTIES - CXX_STANDARD_REQUIRED ${CPP_STD_VERSION} + CXX_STANDARD_REQUIRED ON ) # Installation @@ -479,7 +481,7 @@ include(${CMAKE_SOURCE_DIR}/CMakeExt/GoogleTest.cmake) ) set_target_properties( ${DASH_TEST} PROPERTIES - CXX_STANDARD ${CPP_STD_VERSION} + CXX_STANDARD ${DASH_CXX_STANDARD} ) if(ENABLE_COMPTIME_RED) @@ -488,7 +490,7 @@ include(${CMAKE_SOURCE_DIR}/CMakeExt/GoogleTest.cmake) set_target_properties( ${DASH_TEST} PROPERTIES - CXX_STANDARD_REQUIRED ${CPP_STD_VERSION} + CXX_STANDARD_REQUIRED ON ) # Installation diff --git a/dash/examples/bench.05.array-range/main.cpp b/dash/examples/bench.05.array-range/main.cpp index 1efe5d200..66086314d 100644 --- a/dash/examples/bench.05.array-range/main.cpp +++ b/dash/examples/bench.05.array-range/main.cpp @@ -78,9 +78,9 @@ int main(int argc, char* argv[]) { tests.push_back({256 , 100000}); tests.push_back({1024 , 100000}); tests.push_back({4096 , 10000}); - tests.push_back({4*4096 , 50000}); - tests.push_back({16*4096 , 10000}); - tests.push_back({64*4096 , 5000}); + tests.push_back({4*4096 , 2500}); + tests.push_back({16*4096 , 1000}); + tests.push_back({64*4096 , 250}); for (auto test: tests) { perform_test(test.first, test.second); From 829422c177720744ee406f5aa7e3b0c28f1345e0 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 11 Oct 2017 03:31:40 +0200 Subject: [PATCH 155/161] Specify C++ standard version via CMake built-in option --- CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c01359a1..aa2447743 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,10 +242,19 @@ message(EMPH "Install prefix: (INSTALL_PREFIX) " ${CMAKE_INSTALL_PREFIX}) message(EMPH "Build type: (CMAKE_BUILD_TYPE) " ${CMAKE_BUILD_TYPE}) +message(EMPH "C compiler: (CMAKE_C_COMPILER) " + ${CMAKE_C_COMPILER_ID}) +message(EMPH "C++ compiler: (CMAKE_CXX_COMPILER) " + ${CMAKE_CXX_COMPILER_ID}) +message(EMPH "C++ standard version: (DASH_CXX_STANDARD) " + ${CMAKE_CXX_STANDARD}) message(EMPH "Generic build: (BUILD_GENERIC) " ${BUILD_GENERIC}) message(EMPH "Build shared libraries: (BUILD_SHARED_LIBS) " ${BUILD_SHARED_LIBS}) +if (MPI_FOUND) + message(EMPH "MPI implementation: " ${MPI_IMPL_ID}) +endif() message(INFO "Host system identifier: (ENVIRONMENT_TYPE) " ${DASH_ENV_HOST_SYSTEM_ID}) @@ -299,12 +308,6 @@ message(INFO "HDF5 support: (ENABLE_HDF5) " ${ENABLE_HDF5}) message(INFO "Enabled DART backends: (DART_IMPLEMENTATIONS) " ${DART_IMPLEMENTATIONS}) -message(INFO "C compiler id: ${CMAKE_C_COMPILER_ID}") -message(INFO "C++ compiler id: ${CMAKE_CXX_COMPILER_ID}") -message(INFO "C++ standard version: ${CMAKE_CXX_STANDARD}") -if (MPI_FOUND) - message(INFO "MPI implementation: " ${MPI_IMPL_ID}) -endif() if (ENABLE_PAPI) if (PAPI_FOUND) From e95cb75d8f363ba2752d5ad1670063153eafac65 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 16 Oct 2017 21:25:53 +0200 Subject: [PATCH 156/161] Intermediate --- CMakeLists.txt | 3 +++ dash/examples/ex.02.matrix-local-views/main.cpp | 2 -- dash/examples/ex.02.matrix-sub-views/main.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa2447743..19d08cbad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ endif(POLICY CMP0004) if(POLICY CMP0016) cmake_policy(SET CMP0016 OLD) endif(POLICY CMP0016) +if(POLICY CMP0058) + cmake_policy(SET CMP0058 OLD) +endif(POLICY CMP0058) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") set(DEFAULT_COMPTIME_RED on) diff --git a/dash/examples/ex.02.matrix-local-views/main.cpp b/dash/examples/ex.02.matrix-local-views/main.cpp index 72ca55f28..b0a991016 100644 --- a/dash/examples/ex.02.matrix-local-views/main.cpp +++ b/dash/examples/ex.02.matrix-local-views/main.cpp @@ -125,8 +125,6 @@ void run_example(MatrixT & matrix) { STEP("matrix | local() | index():" << dash::typestr(l_matrix)); - return; - STEP("matrix | local() | index():" << dash::typestr(l_matrix | index())); STEP("matrix | local():" << nview_str(l_matrix)); diff --git a/dash/examples/ex.02.matrix-sub-views/main.cpp b/dash/examples/ex.02.matrix-sub-views/main.cpp index 0f3ecbd6c..22ef3d673 100644 --- a/dash/examples/ex.02.matrix-sub-views/main.cpp +++ b/dash/examples/ex.02.matrix-sub-views/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) STEP("mat | sub<0>(3,-1) | sub<1>(1,-1) | blocks()"); { auto m_s_blocks = matrix_sub | blocks(); - auto m_s_blocks_idx = m_s_blocks | index(); + auto m_s_blocks_idx = matrix_sub | blocks() | index(); int b_idx = 0; for (const auto & blk : m_s_blocks) { STEP("block " << std::left << std::setw(2) From 0c0961f6fcb21f662c49ee597e39d1afd7444828 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 14 Dec 2017 04:19:44 +0100 Subject: [PATCH 157/161] Fixed build errors from incomplete merge --- dash/include/dash/Types.h | 72 ++++++++++++++++----------------- dash/include/dash/view/Domain.h | 10 ----- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/dash/include/dash/Types.h b/dash/include/dash/Types.h index 5286b94ff..889c6e1bb 100644 --- a/dash/include/dash/Types.h +++ b/dash/include/dash/Types.h @@ -84,61 +84,78 @@ struct Extent { ::std::array sizes; }; +#ifdef DOXYGEN -namespace internal { +/** + * Type trait for mapping to DART data types. + */ +template +struct dart_datatype { + static constexpr const dart_datatype_t value; +}; + +/** + * Type trait for mapping to punned DART data type for reduce operations. + */ +template +struct dart_punned_datatype { + static constexpr const dart_datatype_t value; +}; + +#else template -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_UNDEFINED; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_BYTE; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_BYTE; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_SHORT; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_SHORT; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_INT; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_UINT; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_FLOAT; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_LONG; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_ULONG; }; template<> -struct dart_datatype_ { +struct dart_datatype { static constexpr const dart_datatype_t value = DART_TYPE_DOUBLE; }; @@ -148,6 +165,7 @@ struct dart_datatype : dart_datatype { }; template struct dart_datatype : dart_datatype { }; + namespace internal { template @@ -177,34 +195,16 @@ struct dart_pun_datatype_size<8> } // namespace internal -#ifdef DOXYGEN - -/** - * Type trait for mapping to punned DART data type for reduce operations. - */ -template -struct dart_punned_datatype { - static constexpr const dart_datatype_t value; -}; - -#else - template struct dart_punned_datatype { -private: - typedef typename std::remove_const< - typename std::remove_reference::type - >::type - TDec; -public: static constexpr const dart_datatype_t value = std::conditional< // only use type punning if T is not a DART // data type: - dash::dart_datatype::value + dash::dart_datatype::value == DART_TYPE_UNDEFINED, - internal::dart_pun_datatype_size, - dash::dart_datatype + internal::dart_pun_datatype_size, + dash::dart_datatype >::type::value; }; @@ -224,11 +224,7 @@ struct is_container_compatible : // std::is_trivially_copyable. && std::is_trivially_copyable::value #elif defined(__GNUG__) && __GNUC__ < 5 - // deprecated in C++14 - // && std::has_trivial_copy_constructor::value - && std::is_trivially_copy_constructible::value - // no test for assignment as const element type is - // allowed + && std::has_trivial_copy_constructor::value #endif > { }; diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index 20a892fcb..281dd6d80 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -9,16 +9,6 @@ namespace dash { -namespace detail { - /** - * Definition of type trait \c dash::detail::has_type_domain_type - * with static member \c value indicating whether type \c T provides - * dependent type \c domain_type. - */ - DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_type); -} - - // ----------------------------------------------------------------------- // Forward-declarations From c67bde2a6d197969bc7d3df672e0c81b75572227 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Thu, 14 Dec 2017 04:30:28 +0100 Subject: [PATCH 158/161] Fixed build errors from incomplete merge --- dash/test/container/MatrixTest.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 01059a2a4..1f0cb1574 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include From ead6e729217be7e375d61e0019e089be630b7963 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 21 Mar 2018 14:11:28 +0100 Subject: [PATCH 159/161] Fixing build after merge --- dash/include/dash/GlobRef.h | 9 -- dash/include/dash/Iterator.h | 21 ---- dash/include/dash/algorithm/Copy.h | 48 +------- dash/include/dash/iterator/IteratorTraits.h | 128 +++++++++++++------- dash/include/dash/view/Domain.h | 9 +- 5 files changed, 91 insertions(+), 124 deletions(-) diff --git a/dash/include/dash/GlobRef.h b/dash/include/dash/GlobRef.h index 6f7affc4a..b6798db81 100644 --- a/dash/include/dash/GlobRef.h +++ b/dash/include/dash/GlobRef.h @@ -188,15 +188,6 @@ class GlobRef return !(*this == value); } - /** - * Implicit cast to const. - */ - template::value,void>> - operator GlobRef () const { - return GlobRef(_gptr); - } - /** * Explicit cast to non-const */ diff --git a/dash/include/dash/Iterator.h b/dash/include/dash/Iterator.h index 545007acf..2725e5fe5 100644 --- a/dash/include/dash/Iterator.h +++ b/dash/include/dash/Iterator.h @@ -57,30 +57,9 @@ namespace detail { DASH__META__DEFINE_TRAIT__HAS_TYPE(const_reference); DASH__META__DEFINE_TRAIT__HAS_TYPE(pointer); DASH__META__DEFINE_TRAIT__HAS_TYPE(const_pointer); - - DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_iterator); } -template -struct iterator_traits -: public std::iterator_traits { - using is_local - = typename std::integral_constant::value - >; - using is_view_iterator - = typename dash::detail::has_type_domain_iterator; -}; - -template -struct iterator_traits -: public std::iterator_traits { - using is_local = typename std::integral_constant; - using is_view_iterator = std::integral_constant; -}; - - /** * * \concept{DashIteratorConcept} diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 5529dfb3e..fa4ca1bd4 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -233,21 +233,18 @@ ValueType * copy_block( "left:", total_elem_left); auto dest_ptr = out_first + num_elem_copied; auto src_gptr = cur_in_first.dart_gptr(); -<<<<<<< HEAD dash::dart_storage ds(num_copy_elem); if (dart_get_blocking( dest_ptr, src_gptr, ds.nelem, + ds.dtype, ds.dtype) != DART_OK) { DASH_LOG_ERROR("dash::copy_block", "dart_get failed"); DASH_THROW( dash::exception::RuntimeError, "dart_get failed"); } -======= - dash::internal::get_blocking(src_gptr, dest_ptr, num_copy_elem); ->>>>>>> db6cbb6f9f3b5ee1a21ae9fc7bbc549503c75b21 num_elem_copied += num_copy_elem; } } @@ -332,16 +329,6 @@ dash::Future copy_block_async( "left:", total_elem_left); auto cur_in_first = g_in_first + num_elem_copied; auto cur_out_first = out_first + num_elem_copied; -<<<<<<< HEAD -======= -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - dash::internal::get( - cur_in_first.dart_gptr(), - cur_out_first, - num_copy_elem); - req_handles.push_back(in_first.dart_gptr()); -#else ->>>>>>> db6cbb6f9f3b5ee1a21ae9fc7bbc549503c75b21 dart_handle_t get_handle; dash::internal::get_handle( cur_in_first.dart_gptr(), @@ -398,16 +385,6 @@ dash::Future copy_block_async( "left:", total_elem_left); auto src_gptr = cur_in_first.dart_gptr(); auto dest_ptr = out_first + num_elem_copied; -<<<<<<< HEAD -======= -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - dash::internal::get( - src_gptr, - dest_ptr, - num_copy_elem); - req_handles.push_back(src_gptr); -#else ->>>>>>> db6cbb6f9f3b5ee1a21ae9fc7bbc549503c75b21 dart_handle_t get_handle; dash::internal::get_handle( src_gptr, @@ -518,26 +495,17 @@ dash::Future copy_block_async( auto num_copy_elem = std::distance(in_first, in_last); auto src_ptr = in_first; auto dest_gptr = out_first.dart_gptr(); -<<<<<<< HEAD dart_handle_t put_handle; dash::dart_storage ds(num_copy_elem); + DASH_ASSERT_RETURNS( dart_put_handle( -======= -#ifdef DASH__ALGORITHM__COPY__USE_FLUSH - dash::internal::put( - dest_gptr, - src_ptr, - num_copy_elem); - req_handles.push_back(dest_gptr); -#else - dart_handle_t put_handle; - dash::internal::put_handle( ->>>>>>> db6cbb6f9f3b5ee1a21ae9fc7bbc549503c75b21 dest_gptr, src_ptr, num_copy_elem - &put_handle); + &put_handle), + DART_OK); + if (put_handle != DART_HANDLE_NULL) { req_handles.push_back(put_handle); } @@ -899,15 +867,9 @@ auto copy( bool use_memcpy = ((in_last - in_first) * sizeof(ValueType)) <= l2_line_size; -<<<<<<< HEAD // Instead of testing in_first.local() and in_last.local(), this test // for a local-only range only requires one call to in_first.local() // which increases throughput by ~10% for local ranges. -======= - // Instead of testing in_first.local() and in_last.local(), this test for - // a local-only range only requires one call to in_first.local() which - // increases throughput by ~10% for local ranges. ->>>>>>> db6cbb6f9f3b5ee1a21ae9fc7bbc549503c75b21 if (num_local_elem == total_copy_elem) { // Entire input range is local: DASH_LOG_TRACE("dash::copy:range", "entire input range is local"); diff --git a/dash/include/dash/iterator/IteratorTraits.h b/dash/include/dash/iterator/IteratorTraits.h index d071e6f95..dc6471425 100644 --- a/dash/include/dash/iterator/IteratorTraits.h +++ b/dash/include/dash/iterator/IteratorTraits.h @@ -9,64 +9,104 @@ #include #include + namespace dash { namespace detail { -template -struct is_global_iterator : std::false_type { -}; + /** + * Definition of type trait \c dash::detail::has_type_domain_iterator + * with static member \c value indicating whether type \c T provides + * dependent type \c domain_iterator. + */ + DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_iterator); -template < - typename ElementType, - class PatternType, - class GlobMemType, - class PointerType, - class ReferenceType> -struct is_global_iterator> : std::true_type { -}; -template < - typename ElementType, - class PatternType, - class GlobMemType, - class PointerType, - class ReferenceType> -struct is_global_iterator> : std::true_type { -}; + template + struct is_global_iterator : std::false_type { + }; -/// iterator traits index_type + template < + typename ElementType, + class PatternType, + class GlobMemType, + class PointerType, + class ReferenceType> + struct is_global_iterator> : std::true_type { + }; -DASH__META__DEFINE_TRAIT__HAS_TYPE(index_type) + template < + typename ElementType, + class PatternType, + class GlobMemType, + class PointerType, + class ReferenceType> + struct is_global_iterator> : std::true_type { + }; -template ::value> -struct iterator_traits_index_type { - typedef typename _Iter::index_type type; -}; + /// iterator traits index_type -template -struct iterator_traits_index_type<_Iter, false> { - typedef dash::default_index_t type; -}; + DASH__META__DEFINE_TRAIT__HAS_TYPE(index_type) + + template ::value> + struct iterator_traits_index_type { + typedef typename _Iter::index_type type; + }; + + template + struct iterator_traits_index_type<_Iter, false> { + typedef dash::default_index_t type; + }; } // namespace detail -template -struct iterator_traits : std::iterator_traits { - using is_global_iterator = typename detail::is_global_iterator; - using index_type = - typename detail::iterator_traits_index_type::type; + +template +struct iterator_traits +: public std::iterator_traits { + + using is_global_iterator + = typename detail::is_global_iterator; + + using is_view_iterator + = typename dash::detail::has_type_domain_iterator; + + using index_type + = typename detail::iterator_traits_index_type::type; + + using is_local + = typename std::integral_constant::value + >; +}; + +template +struct iterator_traits +: public std::iterator_traits { + + using is_global_iterator + = typename detail::is_global_iterator; + + using is_view_iterator + = std::integral_constant; + + using index_type + = typename detail::iterator_traits_index_type::type; + + using is_local + = typename std::integral_constant; }; } // namespace dash + #endif diff --git a/dash/include/dash/view/Domain.h b/dash/include/dash/view/Domain.h index edd6e9bb9..a912c3fc3 100644 --- a/dash/include/dash/view/Domain.h +++ b/dash/include/dash/view/Domain.h @@ -10,19 +10,14 @@ namespace dash { namespace detail { - /** - * Definition of type trait \c dash::detail::has_type_domain_iterator - * with static member \c value indicating whether type \c T provides - * dependent type \c domain_iterator. - */ -//DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_iterator); /** * Definition of type trait \c dash::detail::has_type_domain_type * with static member \c value indicating whether type \c T provides * dependent type \c domain_type. */ - DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_type) + DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_type); + } // ----------------------------------------------------------------------- From f5bcd078c047d215739adb3f5fe8c38a3db34772 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 21 Mar 2018 14:54:45 +0100 Subject: [PATCH 160/161] Rollback of pathological concept changes on development branch after merge --- dash/include/dash/Array.h | 94 ++----- dash/include/dash/GlobAsyncRef.h | 95 ++----- dash/include/dash/GlobRef.h | 109 +++----- dash/include/dash/atomic/GlobAtomicRef.h | 333 +++++++---------------- dash/include/dash/iterator/GlobIter.h | 46 +++- 5 files changed, 217 insertions(+), 460 deletions(-) diff --git a/dash/include/dash/Array.h b/dash/include/dash/Array.h index 29b602d7d..1c9813ca9 100644 --- a/dash/include/dash/Array.h +++ b/dash/include/dash/Array.h @@ -286,8 +286,8 @@ class AsyncArrayRef typedef T * pointer; typedef const T * const_pointer; - typedef GlobAsyncRef async_reference; - typedef typename GlobAsyncRef::const_type const_async_reference; + typedef GlobAsyncRef< T> async_reference; + typedef GlobAsyncRef const_async_reference; public: typedef std::integral_constant @@ -363,7 +363,7 @@ class AsyncArrayRef * Subscript operator, access to local array element at given position. */ constexpr const_async_reference operator[](const size_type n) const { - return const_async_reference( + return async_reference( (*(_array->begin() + n)).dart_gptr()); } @@ -660,8 +660,8 @@ class Array typedef std::reverse_iterator< iterator> reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - typedef GlobRef reference; - typedef typename GlobRef::const_type const_reference; + typedef GlobRef< value_type> reference; + typedef GlobRef const_reference; typedef GlobIter< value_type, PatternType> pointer; typedef GlobIter const_pointer; @@ -718,6 +718,8 @@ class Array private: /// Team containing all units interacting with the array dash::Team * m_team = nullptr; + /// DART id of the unit that created the array + team_unit_t m_myid; /// Element distribution pattern PatternType m_pattern; /// Global memory allocation and -access @@ -736,10 +738,18 @@ class Array ElementType * m_lbegin = nullptr; /// Native pointer past last local element in the array ElementType * m_lend = nullptr; - /// DART id of the unit that created the array - team_unit_t m_myid; - /// Whether or not the array was actually allocated - bool m_registered = false; + +public: +/* + Check requirements on element type + is_trivially_copyable is not implemented presently, and is_trivial + is too strict (e.g. fails on std::pair). + + static_assert(std::is_trivially_copyable::value, + "Element type must be trivially copyable"); + static_assert(std::is_trivial::value, + "Element type must be trivially copyable"); +*/ public: /** @@ -892,30 +902,7 @@ class Array * The pattern has to be movable or copyable * The underlying memory does not have to be movable (it might). */ - Array(self_t && other) - : local(this), - async(this), - m_team(other.m_team), - m_myid(other.m_myid), - m_pattern(std::move(other.m_pattern)), - m_globmem(std::move(other.m_globmem)), - m_begin(other.m_begin), - m_end(other.m_end), - m_size(other.m_size), - m_lsize(other.m_lsize), - m_lcapacity(other.m_lcapacity), - m_lbegin(other.m_lbegin), - m_lend(other.m_lend) { - - other.m_globmem = nullptr; - other.m_lbegin = nullptr; - other.m_lend = nullptr; - // Register deallocator of this array instance at the team - // instance that has been used to initialized it: - m_team->register_deallocator( - this, std::bind(&Array::deallocate, this)); - m_registered = true; - } + Array(self_t && other) = default; /** * Assignment operator is deleted to prevent unintentional copies of @@ -944,38 +931,7 @@ class Array * The pattern has to be movable or copyable * The underlying memory does not have to be movable (it might). */ - self_t & operator=(self_t && other) { - - if (this == &other) return *this; - - deallocate(); - - this->m_begin = other.m_begin; - this->m_end = other.m_end; - this->m_globmem = std::move(other.m_globmem); - this->m_lbegin = other.m_lbegin; - this->m_lcapacity = other.m_lcapacity; - this->m_lend = other.m_lend; - this->m_lsize = other.m_lsize; - this->m_myid = other.m_myid; - this->m_pattern = std::move(other.m_pattern); - this->m_size = other.m_size; - this->m_team = other.m_team; - - other.m_globmem = nullptr; - other.m_lbegin = nullptr; - other.m_lend = nullptr; - - // Re-register deallocator of this array instance at the team - // instance that has been used to initialized it: - if (this->m_globmem != nullptr) { - m_team->register_deallocator( - this, std::bind(&Array::deallocate, this)); - m_registered = true; - } - - return *this; - } + self_t & operator=(self_t && other) = default; /** * Destructor, deallocates array elements. @@ -1374,10 +1330,8 @@ class Array } // Remove this function from team deallocator list to avoid // double-free: - if (m_registered) { - m_team->unregister_deallocator( - this, std::bind(&Array::deallocate, this)); - } + m_team->unregister_deallocator( + this, std::bind(&Array::deallocate, this)); // Actual destruction of the array instance: DASH_LOG_TRACE_VAR("Array.deallocate()", m_globmem.get()); if (m_globmem != nullptr) { @@ -1427,7 +1381,6 @@ class Array // instance that has been used to initialized it: m_team->register_deallocator( this, std::bind(&Array::deallocate, this)); - m_registered = true; // Assure all units are synchronized after allocation, otherwise // other units might start working on the array before allocation // completed at all units: @@ -1478,7 +1431,6 @@ class Array // instance that has been used to initialized it: m_team->register_deallocator( this, std::bind(&Array::deallocate, this)); - m_registered = true; // Assure all units are synchronized after allocation, otherwise // other units might start working on the array before allocation // completed at all units: diff --git a/dash/include/dash/GlobAsyncRef.h b/dash/include/dash/GlobAsyncRef.h index f1570bd7a..d80137093 100644 --- a/dash/include/dash/GlobAsyncRef.h +++ b/dash/include/dash/GlobAsyncRef.h @@ -9,20 +9,6 @@ namespace dash { - -template -struct add_const_from_type -{ - using type = TargetT; -}; - -template -struct add_const_from_type -{ - using type = typename std::add_const::type; -}; - - /** * Global value reference for asynchronous / non-blocking operations. * @@ -60,20 +46,24 @@ class GlobAsyncRef friend class GlobAsyncRef; public: - using value_type = T; - using const_value_type = typename std::add_const::type; - using nonconst_value_type = typename std::remove_const::type; - using self_t = GlobAsyncRef; - using const_type = GlobAsyncRef; - using nonconst_type = GlobAsyncRef; + typedef GlobAsyncRef + self_t; + + typedef T value_type; + + typedef typename std::remove_const::type + nonconst_value_type; + + typedef typename std::add_const::type + const_value_type; private: /// Pointer to referenced element in global memory dart_gptr_t _gptr; /// Temporary value required for non-blocking put - mutable nonconst_value_type _value; + nonconst_value_type _value; /// DART handle for asynchronous transfers - mutable dart_handle_t _handle = DART_HANDLE_NULL; + dart_handle_t _handle = DART_HANDLE_NULL; private: @@ -117,13 +107,14 @@ class GlobAsyncRef { } /** - * Conctructor, creates an GlobRefAsync object referencing an element in - * global memory. + * Constructor, creates an GlobRef object referencing an element in global + * memory. */ + template explicit GlobAsyncRef( /// Pointer to referenced object in global memory - const GlobRef & gref) - : GlobAsyncRef(gref.dart_gptr()) + const GlobConstPtr & gptr) + : GlobAsyncRef(gptr.dart_gptr()) { } /** @@ -132,31 +123,9 @@ class GlobAsyncRef */ explicit GlobAsyncRef( /// Pointer to referenced object in global memory - const GlobRef & gref) + const GlobRef & gref) : GlobAsyncRef(gref.dart_gptr()) - { - static_assert(std::is_same::value, - "Cannot create GlobAsyncRef from GlobRef!"); - } - - /** - * Implicit conversion to const. - */ - template::value,void>> - operator GlobAsyncRef() { - return GlobAsyncRef(_gptr); - } - - /** - * Excpliti conversion to non-const. - */ - template::value,void>> - explicit - operator GlobAsyncRef() { - return GlobAsyncRef(_gptr); - } + { } /** * Like native references, global reference types cannot be copied. @@ -190,28 +159,24 @@ class GlobAsyncRef * specified offset */ template - GlobAsyncRef::type> - member(size_t offs) const { - return GlobAsyncRef::type>(*this, offs); + GlobAsyncRef member(size_t offs) const { + return GlobAsyncRef(*this, offs); } /** * Get the member via pointer to member */ template - GlobAsyncRef::type> - member( + GlobAsyncRef member( const MEMTYPE P::*mem) const { size_t offs = (size_t) &( reinterpret_cast(0)->*mem); - return member::type>(offs); + return member(offs); } /** * Swap values with synchronous reads and asynchronous writes. */ friend void swap(self_t & a, self_t & b) { - static_assert(std::is_same::value, - "Cannot swap GlobAsyncRef!"); nonconst_value_type temp = a->get(); a = b->get(); b = temp; @@ -254,9 +219,7 @@ class GlobAsyncRef * This operation is guaranteed to be complete after a call to \ref flush * and the pointer \c tptr should not be reused before completion. */ - void set(const_value_type* tptr) const { - static_assert(std::is_same::value, - "Cannot modify value through GlobAsyncRef!"); + void set(const_value_type* tptr) { DASH_LOG_TRACE_VAR("GlobAsyncRef.set()", *tptr); DASH_LOG_TRACE_VAR("GlobAsyncRef.set()", _gptr); dash::internal::put(_gptr, tptr, 1); @@ -268,9 +231,7 @@ class GlobAsyncRef * This operation is guaranteed to be complete after a call to \ref flush, * but the value referenced by \c new_value can be re-used immediately. */ - void set(const_value_type& new_value) const { - static_assert(std::is_same::value, - "Cannot modify value through GlobAsyncRef!"); + void set(const_value_type& new_value) { DASH_LOG_TRACE_VAR("GlobAsyncRef.set()", new_value); DASH_LOG_TRACE_VAR("GlobAsyncRef.set()", _gptr); _value = new_value; @@ -289,8 +250,8 @@ class GlobAsyncRef * This operation is guaranteed to be complete after a call to \ref flush, * but the value referenced by \c new_value can be re-used immediately. */ - const self_t & - operator=(const_value_type & new_value) const + self_t & + operator=(const_value_type & new_value) { set(new_value); return *this; @@ -315,7 +276,7 @@ class GlobAsyncRef /** * Flush all pending asynchronous operations on this asynchronous reference. */ - void flush() const + void flush() { DASH_ASSERT_RETURNS( dart_flush(_gptr), diff --git a/dash/include/dash/GlobRef.h b/dash/include/dash/GlobRef.h index b6798db81..2f22c03e5 100644 --- a/dash/include/dash/GlobRef.h +++ b/dash/include/dash/GlobRef.h @@ -38,13 +38,21 @@ class GlobRef typename ElementT > friend class GlobRef; + typedef typename std::remove_const::type + nonconst_value_type; + + typedef typename std::add_const::type + const_value_type; public: - using value_type = T; - using const_value_type = typename std::add_const::type; - using nonconst_value_type = typename std::remove_const::type; - using self_t = GlobRef; - using const_type = GlobRef; + typedef T value_type; + + typedef GlobRef const_type; +private: + typedef GlobRef + self_t; + typedef GlobRef + self_const_t; private: dart_gptr_t _gptr; @@ -132,7 +140,7 @@ class GlobRef /** * Value-assignment operator. */ - const self_t & operator=(const value_type& val) const { + self_t & operator=(const T val) { set(val); return *this; } @@ -140,7 +148,7 @@ class GlobRef /** * Assignment operator. */ - const self_t & operator=(const self_t & other) const + self_t & operator=(const self_t & other) { set(static_cast(other)); return *this; @@ -150,7 +158,7 @@ class GlobRef * Assignment operator. */ template - const self_t & operator=(GlobRefOrElementT && other) const + self_t & operator=(GlobRefOrElementT && other) { set(std::forward(other)); return *this; @@ -188,21 +196,7 @@ class GlobRef return !(*this == value); } - /** - * Explicit cast to non-const - */ - template::value,void>> - explicit - operator GlobRef () const { - return GlobRef(_gptr); - } - - void - set(const value_type & val) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); - + void set(const_value_type & val) { DASH_LOG_TRACE_VAR("GlobRef.set()", val); DASH_LOG_TRACE_VAR("GlobRef.set", _gptr); // TODO: Clarify if dart-call can be avoided if @@ -231,28 +225,19 @@ class GlobRef dash::internal::get_blocking(_gptr, &tref, 1); } - void - put(const_value_type& tref) const { - static_assert(std::is_same::value, - "Cannot assign to GlobRef!"); + void put(const_value_type& tref) { DASH_LOG_TRACE("GlobRef.put(T&)", "explicit put of provided ref"); DASH_LOG_TRACE_VAR("GlobRef.T()", _gptr); dash::internal::put_blocking(_gptr, &tref, 1); } - void - put(const_value_type* tptr) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + void put(const_value_type* tptr) { DASH_LOG_TRACE("GlobRef.put(T*)", "explicit put of provided ptr"); DASH_LOG_TRACE_VAR("GlobRef.T()", _gptr); dash::internal::put_blocking(_gptr, tptr, 1); } - const self_t & - operator+=(const nonconst_value_type& ref) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator+=(const nonconst_value_type& ref) { #if 0 // TODO: Alternative implementation, possibly more efficient: T add_val = ref; @@ -273,78 +258,54 @@ class GlobRef return *this; } - const self_t & - operator-=(const nonconst_value_type& ref) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator-=(const nonconst_value_type& ref) { nonconst_value_type val = operator nonconst_value_type(); val -= ref; operator=(val); return *this; } - const self_t & - operator++() const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator++() { nonconst_value_type val = operator nonconst_value_type(); operator=(++val); return *this; } - nonconst_value_type - operator++(int) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + nonconst_value_type operator++(int) { nonconst_value_type val = operator nonconst_value_type(); nonconst_value_type res = val++; operator=(val); return res; } - const self_t & - operator--() const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator--() { nonconst_value_type val = operator nonconst_value_type(); operator=(--val); return *this; } - nonconst_value_type - operator--(int) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + nonconst_value_type operator--(int) { nonconst_value_type val = operator nonconst_value_type(); nonconst_value_type res = val--; operator=(val); return res; } - const self_t & - operator*=(const_value_type& ref) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator*=(const_value_type& ref) { nonconst_value_type val = operator nonconst_value_type(); val *= ref; operator=(val); return *this; } - const self_t & - operator/=(const_value_type& ref) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator/=(const_value_type& ref) { nonconst_value_type val = operator nonconst_value_type(); val /= ref; operator=(val); return *this; } - const self_t & - operator^=(const_value_type& ref) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + self_t & operator^=(const_value_type& ref) { nonconst_value_type val = operator nonconst_value_type(); val ^= ref; operator=(val); @@ -383,33 +344,29 @@ class GlobRef * specified offset */ template - GlobRef::type> - member(size_t offs) const { + GlobRef member(size_t offs) const { dart_gptr_t dartptr = _gptr; DASH_ASSERT_RETURNS( dart_gptr_incaddr(&dartptr, offs), DART_OK); - return GlobRef::type>(dartptr); + return GlobRef(dartptr); } /** * Get the member via pointer to member */ template - GlobRef::type> - member( + GlobRef member( const MEMTYPE P::*mem) const { // TODO: Thaaaat ... looks hacky. size_t offs = (size_t) &( reinterpret_cast(0)->*mem); - return member::type>(offs); + return member(offs); } /** * specialization which swappes the values of two global references */ - inline void swap(dash::GlobRef & b) const{ - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); + inline void swap(dash::GlobRef & b){ T tmp = static_cast(*this); *this = b; b = tmp; diff --git a/dash/include/dash/atomic/GlobAtomicRef.h b/dash/include/dash/atomic/GlobAtomicRef.h index e29cab720..1312d69d3 100644 --- a/dash/include/dash/atomic/GlobAtomicRef.h +++ b/dash/include/dash/atomic/GlobAtomicRef.h @@ -12,129 +12,105 @@ namespace dash { template class Atomic; +template +class Shared; + /** -* Specialization for atomic values. All atomic operations are -* \c const as the \c GlobRef does not own the atomic values. -*/ + * Specialization for atomic values. All atomic operations are + * \c const as the \c GlobRef does not own the atomic values. + */ template class GlobRef> { -/* Notes on type compatibility: -* -* - The general support of atomic operations on values of type T is -* checked in `dash::Atomic` and is not verified here. -* - Whether arithmetic operations (like `fetch_add`) are supported -* for values of type T is implicitly tested in the DASH operation -* types (like `dash::plus`) and is not verified here. -* -*/ - -template -friend std::ostream & operator<<( -std::ostream & os, -const GlobRef & gref); - -public: -using value_type = T; -using const_value_type = typename std::add_const::type; -using nonconst_value_type = typename std::remove_const::type; -using atomic_t = dash::Atomic; -using const_atomic_t = typename dash::Atomic; -using nonconst_atomic_t = typename dash::Atomic; -using self_t = GlobRef; -using const_type = GlobRef; -using nonconst_type = GlobRef>; + /* Notes on type compatibility: + * + * - The general support of atomic operations on values of type T is + * checked in `dash::Atomic` and is not verified here. + * - Whether arithmetic operations (like `fetch_add`) are supported + * for values of type T is implicitly tested in the DASH operation + * types (like `dash::plus`) and is not verified here. + * + */ -private: -dart_gptr_t _gptr; + template + friend std::ostream & operator<<( + std::ostream & os, + const GlobRef & gref); public: -/** -* Reference semantics forbid declaration without definition. -*/ -GlobRef() = delete; - -/** -* Constructor, creates an GlobRef object referencing an element in global -* memory. -*/ -template -explicit GlobRef( -/// Pointer to referenced object in global memory -GlobPtr & gptr) -: GlobRef(gptr.dart_gptr()) -{ } + typedef T + value_type; + typedef GlobRef> + const_type; -/** -* Constructor, creates an GlobRef object referencing an element in global -* memory. -*/ -template -GlobRef( -/// Pointer to referenced object in global memory -const GlobPtr & gptr) -: GlobRef(gptr.dart_gptr()) -{ -static_assert(std::is_same::value, - "Cannot create GlobRef> from GlobPtr>!"); -} - -template -GlobRef( -/// Pointer to referenced object in global memory -const GlobPtr & gptr) -: GlobRef(gptr.dart_gptr()) -{ } - - -/** -* Constructor, creates an GlobRef object referencing an element in global -* memory. -*/ -explicit GlobRef(dart_gptr_t dart_gptr) -: _gptr(dart_gptr) -{ -DASH_LOG_TRACE_VAR("GlobRef(dart_gptr_t)", dart_gptr); -} +private: + typedef dash::Atomic atomic_t; + typedef GlobRef self_t; -/** -* Like native references, global reference types cannot be copied. -* -* Default definition of copy constructor would conflict with semantics -* of \c operator=(const self_t &). -*/ -GlobRef(const self_t & other) = delete; +private: + dart_gptr_t _gptr; -/** -* Unlike native reference types, global reference types are moveable. -*/ -GlobRef(self_t && other) = default; +public: + /** + * Default constructor, creates an GlobRef object referencing an element in + * global memory. + */ + GlobRef() + : _gptr(DART_GPTR_NULL) { + } -self_t & operator=(const self_t & other) = delete; + /** + * Constructor, creates an GlobRef object referencing an element in global + * memory. + */ + template + explicit GlobRef( + /// Pointer to referenced object in global memory + GlobPtr & gptr) + : GlobRef(gptr.dart_gptr()) + { } -operator T() const { -return load(); -} + /** + * Constructor, creates an GlobRef object referencing an element in global + * memory. + */ + template + GlobRef( + /// Pointer to referenced object in global memory + const GlobPtr & gptr) + : GlobRef(gptr.dart_gptr()) + { } /** - * Implicit conversion to const type. + * Constructor, creates an GlobRef object referencing an element in global + * memory. */ - template::value,void>> - operator const_type() const { - return const_type(_gptr); + explicit GlobRef(dart_gptr_t dart_gptr) + : _gptr(dart_gptr) + { + DASH_LOG_TRACE_VAR("GlobRef(dart_gptr_t)", dart_gptr); } /** - * Explicit conversion to non-const type. + * Copy constructor. */ - template::value,void>> - explicit - operator nonconst_type() const { - return nonconst_type(_gptr); + GlobRef( + /// GlobRef instance to copy. + const GlobRef & other) + : _gptr(other._gptr) + { } + + self_t & operator=(const self_t & other) = delete; + + operator T() const { + return load(); } + operator GlobPtr() const { + DASH_LOG_TRACE("GlobRef.GlobPtr()", "conversion operator"); + DASH_LOG_TRACE_VAR("GlobRef.T()", _gptr); + return GlobPtr(_gptr); + } dart_gptr_t dart_gptr() const { return _gptr; @@ -145,22 +121,13 @@ return load(); * the calling unit's local memory. */ bool is_local() const { - return dash::internal::is_local(_gptr); + return GlobPtr(_gptr).is_local(); } - /** - * atomically assigns value - * - * \return The assigned value. - * - * \note This operator does not return a reference but a copy of the value - * in order to ensure atomicity. This is consistent with the C++ std::atomic - * \c operator=, see - * http://en.cppreference.com/w/cpp/atomic/atomic/operator%3D. - */ - T operator=(const T & value) const { + /// atomically assigns value + GlobRef operator=(const T & value) const { store(value); - return value; + return *this; } /** @@ -168,11 +135,6 @@ return load(); */ void set(const T & value) const { - static_assert(dash::dart_punned_datatype::value != DART_TYPE_UNDEFINED, - "Basic type or type smaller than 64bit required for " - "atomic set!"); - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef>!"); DASH_LOG_DEBUG_VAR("GlobRef.store()", value); DASH_LOG_TRACE_VAR("GlobRef.store", _gptr); dart_ret_t ret = dart_accumulate( @@ -190,19 +152,16 @@ return load(); * Set the value of the shared atomic variable. */ inline void store(const T & value) const { - set(value); + exchange(value); } /// atomically fetches value T get() const { - static_assert(dash::dart_punned_datatype::value != DART_TYPE_UNDEFINED, - "Basic type or type smaller than 64bit required for " - "atomic get!"); DASH_LOG_DEBUG("GlobRef.load()"); DASH_LOG_TRACE_VAR("GlobRef.load", _gptr); - nonconst_value_type nothing; - nonconst_value_type result; + value_type nothing; + value_type result; dart_ret_t ret = dart_fetch_and_op( _gptr, reinterpret_cast(¬hing), @@ -216,7 +175,7 @@ return load(); } /** - * Get the value of the shared atomic variable. + * Set the value of the shared atomic variable. */ inline T load() const { return get(); @@ -227,22 +186,13 @@ return load(); */ template void op( - /// Binary operation to be performed on global atomic variable BinaryOp binary_op, - /// Value to be used in binary op on global atomic variable. + /// Value to be added to global atomic variable. const T & value) const { - static_assert(dash::dart_punned_datatype::value != DART_TYPE_UNDEFINED, - "Basic type or type smaller than 64bit required for " - "atomic operation!"); - static_assert(dash::dart_datatype::value != DART_TYPE_UNDEFINED || - binary_op.op_kind() != dash::internal::OpKind::ARITHMETIC, - "Atomic arithmetic operations only valid on basic types"); - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef>!"); DASH_LOG_DEBUG_VAR("GlobRef.op()", value); DASH_LOG_TRACE_VAR("GlobRef.op", _gptr); - nonconst_value_type acc = value; + value_type acc = value; DASH_LOG_TRACE("GlobRef.op", "dart_accumulate"); dart_ret_t ret = dart_accumulate( _gptr, @@ -267,18 +217,10 @@ return load(); /// Value to be added to global atomic variable. const T & value) const { - static_assert(dash::dart_punned_datatype::value != DART_TYPE_UNDEFINED, - "Basic type or type smaller than 64bit required for " - "atomic fetch_op!"); - static_assert(dash::dart_datatype::value != DART_TYPE_UNDEFINED || - binary_op.op_kind() != dash::internal::OpKind::ARITHMETIC, - "Atomic arithmetic operations only valid on basic types!"); - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef>!"); DASH_LOG_DEBUG_VAR("GlobRef.fetch_op()", value); DASH_LOG_TRACE_VAR("GlobRef.fetch_op", _gptr); DASH_LOG_TRACE_VAR("GlobRef.fetch_op", typeid(value).name()); - nonconst_value_type res; + value_type res; dart_ret_t ret = dart_fetch_and_op( _gptr, reinterpret_cast(&value), @@ -307,19 +249,12 @@ return load(); * \see \c dash::atomic::compare_exchange */ bool compare_exchange(const T & expected, const T & desired) const { - static_assert(dash::dart_punned_datatype::value != DART_TYPE_UNDEFINED, - "Integral type or type smaller than 64bit required for " - "compare_exchange!"); - static_assert(!std::is_floating_point::value, - "compare_exchange not available for floating point!"); - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); DASH_LOG_DEBUG_VAR("GlobRef.compare_exchange()", desired); DASH_LOG_TRACE_VAR("GlobRef.compare_exchange", _gptr); DASH_LOG_TRACE_VAR("GlobRef.compare_exchange", expected); DASH_LOG_TRACE_VAR( "GlobRef.compare_exchange", typeid(desired).name()); - nonconst_value_type result; + value_type result; dart_ret_t ret = dart_compare_and_swap( _gptr, reinterpret_cast(&desired), @@ -339,8 +274,6 @@ return load(); */ void add(const T & value) const { - static_assert(std::is_same::value, - "Cannot modify value referenced by GlobRef!"); op(dash::plus(), value); } @@ -350,7 +283,7 @@ return load(); * \return The value of the referenced shared variable before the * operation. */ - T fetch_add ( + T fetch_add( /// Value to be added to global atomic variable. const T & value) const { @@ -379,104 +312,32 @@ return load(); return fetch_op(dash::plus(), -value); } - /** - * DASH specific variant which is faster than \c fetch_multiply - * but does not return value - */ - void multiply(const T & value) const - { - op(dash::multiply(), value); - } - - /** - * Atomic fetch-and-multiply operation on the referenced shared value. - * - * \return The value of the referenced shared variable before the - * operation. - */ - T fetch_multiply( - /// Value to be added to global atomic variable. - const T & value) const - { - return fetch_op(dash::multiply(), value); - } - - /** - * prefix atomically increment value by one - * - * \return The value of the referenced shared variable after the - * operation. - * - * \note This operator does not return a reference but a copy of the value - * in order to ensure atomicity. This is consistent with the C++ std::atomic - * \c operator++, see - * http://en.cppreference.com/w/cpp/atomic/atomic/operator_arith. - */ + /// prefix atomically increment value by one T operator++ () const { return fetch_add(1) + 1; } - /** - * postfix atomically increment value by one - * - * \return The value of the referenced shared variable before the - * operation. - */ + /// postfix atomically increment value by one T operator++ (int) const { return fetch_add(1); } - /** - * prefix atomically decrement value by one - * - * \return The value of the referenced shared variable after the - * operation. - * - * \note This operator does not return a reference but a copy of the value - * in order to ensure atomicity. This is consistent with the C++ std::atomic - * \c operator--, see - * http://en.cppreference.com/w/cpp/atomic/atomic/operator_arith. - */ + /// prefix atomically decrement value by one T operator-- () const { return fetch_sub(1) - 1; } - /** - * postfix atomically decrement value by one - * - * \return The value of the referenced shared variable before the - * operation. - */ + /// postfix atomically decrement value by one T operator-- (int) const { return fetch_sub(1); } - /** - * atomically increment value by ref - * - * \return The value of the referenced shared variable after the - * operation. - * - * \note This operator does not return a reference but a copy of the value - * in order to ensure atomicity. This is consistent with the C++ std::atomic - * \c operator+=, see - * http://en.cppreference.com/w/cpp/atomic/atomic/operator_arith2. - */ + /// atomically increment value by ref T operator+=(const T & value) const { return fetch_add(value) + value; } - /** - * atomically decrement value by ref - * - * \return The value of the referenced shared variable after the - * operation. - * - * Note that this operator does not return a reference but a copy of the value - * in order to ensure atomicity. This is consistent with the C++ std::atomic - * \c operator-=, see - * http://en.cppreference.com/w/cpp/atomic/atomic/operator_arith2. - */ + /// atomically decrement value by ref T operator-=(const T & value) const { return fetch_sub(value) - value; } diff --git a/dash/include/dash/iterator/GlobIter.h b/dash/include/dash/iterator/GlobIter.h index 930dfce53..ac2b73c91 100644 --- a/dash/include/dash/iterator/GlobIter.h +++ b/dash/include/dash/iterator/GlobIter.h @@ -147,12 +147,23 @@ class GlobIter index_type _idx = 0; /// Maximum position allowed for this iterator. index_type _max_idx = 0; + /// Unit id of the active unit + team_unit_t _myid = DART_UNDEFINED_TEAM_UNIT_ID; /// Pointer to first element in local memory local_pointer _lbegin = nullptr; public: - - constexpr GlobIter() = default; + /** + * Default constructor. + */ + constexpr GlobIter() + : _globmem(nullptr), + _pattern(nullptr), + _idx(0), + _max_idx(0), + _myid(dash::Team::All().myid()), + _lbegin(nullptr) + { } /** * Constructor, creates a global iterator on global memory following @@ -160,12 +171,13 @@ class GlobIter */ constexpr GlobIter( GlobMemType * gmem, - const PatternType & pat, - index_type position = 0) + const PatternType & pat, + index_type position = 0) : _globmem(gmem), _pattern(&pat), _idx(position), _max_idx(pat.size() - 1), + _myid(pat.team().myid()), _lbegin(_globmem->lbegin()) { } @@ -178,14 +190,18 @@ class GlobIter * Templated copy constructor. */ template < + class T_, + class P_, + class GM_, class Ptr_, class Ref_ > constexpr GlobIter( - const GlobIter & other) + const GlobIter & other) : _globmem(other._globmem) , _pattern(other._pattern) , _idx (other._idx) , _max_idx(other._max_idx) + , _myid (other._myid) , _lbegin (other._lbegin) { } @@ -198,14 +214,18 @@ class GlobIter * Templated move constructor. */ template < + class T_, + class P_, + class GM_, class Ptr_, class Ref_ > constexpr GlobIter( - GlobIter && other) + GlobIter && other) : _globmem(other._globmem) , _pattern(other._pattern) , _idx (other._idx) , _max_idx(other._max_idx) + , _myid (other._myid) , _lbegin (other._lbegin) { } @@ -219,15 +239,18 @@ class GlobIter */ template < typename T_, + class P_, + class GM_, class Ptr_, class Ref_ > self_t & operator=( - const GlobIter & other) + const GlobIter & other) { _globmem = other._globmem; _pattern = other._pattern; _idx = other._idx; _max_idx = other._max_idx; + _myid = other._myid; _lbegin = other._lbegin; return *this; } @@ -242,15 +265,18 @@ class GlobIter */ template < typename T_, + class P_, + class GM_, class Ptr_, class Ref_ > self_t & operator=( - GlobIter && other) + GlobIter && other) { _globmem = other._globmem; _pattern = other._pattern; _idx = other._idx; _max_idx = other._max_idx; + _myid = other._myid; _lbegin = other._lbegin; // no ownership to transfer return *this; @@ -440,7 +466,7 @@ class GlobIter */ constexpr bool is_local() const { - return (_globmem->team().myid() == lpos().unit); + return (_myid == lpos().unit); } /** @@ -476,7 +502,7 @@ class GlobIter local_pos_t local_pos = _pattern->local(idx); DASH_LOG_TRACE_VAR("GlobIter.local= >", local_pos.unit); DASH_LOG_TRACE_VAR("GlobIter.local= >", local_pos.index); - if (_globmem->team().myid() != local_pos.unit) { + if (_myid != local_pos.unit) { // Iterator position does not point to local element return nullptr; } From 3dab95811e3d0b00f0946dacd546ebfe37c73843 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Wed, 21 Mar 2018 16:52:39 +0100 Subject: [PATCH 161/161] Outlining pattern concept separation --- dash/test/PatternExprTest.cc | 179 +++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 dash/test/PatternExprTest.cc diff --git a/dash/test/PatternExprTest.cc b/dash/test/PatternExprTest.cc new file mode 100644 index 000000000..46270039b --- /dev/null +++ b/dash/test/PatternExprTest.cc @@ -0,0 +1,179 @@ + +#include + +#include +#include + +/* + * General findings and assumptions: + * + * 0) Patterns are domain-specific views and may differ from view + * expressions in: + * - design criteria + * - semantics + * - valid expressions (= algebra) + * + * Therefore, for example: + * - nviews do not depend on anything but the existence of a + * canonical index space (d'uh) + * - patterns are restricted to specific mapping + * signatures (smarter but less generic than nviews) and depend + * on concrete concepts such as Unit, Team, Locality, ... + * + * !! nviews are a pure-mathematical concoction, patterns are + * abstract algorithmic building blocks. + * + * + * I) Conceptional differences between nviews and pattern views: + * -- nview operations first and foremost must provide a zero-cost + * operation abstraction + * ( -> efficient to pipe, pass, invoke, confabulate, mogrify) + * + * some_origin | foo() | bar() | index() + * ... should not copy a darn thing. + * + * !! this is not a priority for patterns: + * - pattern instantiation may be "expensive" compared to views + * - pattern dereferentiation aka index access like + * + * pattern | global(34) | local() + * or + * pattern | global(34) | unit() + * + * - pattern expression modifiers (global, local, unit_at, ...) + * possibly have different semantics than view modifiers of + * the same name (but please should not). + * + * + * + * + * C) Advantages from switching to Pattern Views: + * + * -- With status quo pattern (class template) definitions, domain + * decomposition specified by a pattern object is immutable after + * its instantiation + * >> With pattern views, data space mappings can be modified just like + * nviews + * + * + * N) Some Wisenheimer words: + * + * - index: some numeric reference (scalar or n-dim point) to an + * element position + * - offset: a scalar index + * - point: an n-dim index + * + */ + + + +/*------------------------------------------------------------------------- + * pattern/PatternExpressionDefs.h + * + * + * Want: + * + * template< + * dim_t NumDimensions, + * MemArrange Arrangement = ROW_MAJOR, + * typename IndexType = dash::default_index_t + * > + * using BlockPattern = decltype(view_expr); + * + * template <...> + * struct pattern_mapping_properties { + * typedef pattern_mapping_properties< + * // Number of blocks assigned to a unit may differ. + * pattern_mapping_tag::unbalanced + * > mapping_properties; + * } + * + */ + +TEST_T(PatternExprTest, BlockCyclicPatternExpression) +{ + BlockPattern<1, dash::ROW_MAJOR, ssize_t> block_pat( + nlocal * nunits, + dash::DistributionSpec<1>(dash::BLOCKED)); + + dash::Array array(nlocal * nunits); + + // + +} + + + +/*-- snip ---------------------------------------------------------------- */ + + +// Need adapter from current pattern constructor interface to view +// expressions +BlockPattern(size_spec, dist_spec, team) +{ +//> size_spec: 100 * nunits +//> dist_spec: dash::BLOCKED + + // View object configured without any modifiers, comparable to + // dash::origin or dash::identity: + // + auto pat_id = make_pattern_id_view(size_spec); + + // mapping signatures: + // + // (1,2) + // + // gidx <--> (uidx, lidx) + // gidx <--> goffs + // ... + // Xidx <--> Xoffs + // + // ... with X as model of one of: + // + // - block index + // - element index + // - unit index + // ... + // whatev + // + // - Chaining mappings of X* index spaces allow for hierarchical + // patterns: + // + // global space block space sub-block space ... + // (Aidx, uidx) -> (Bidx, uidx) -> (Pidx, Bidx) ... + // + + // Provides: + // - (coord-like) <-> (offset-like) + pat_blk = pat_id | chunk() + // Now provides: + // + (index-like) <-> (chunk range) + // ... + // that is, the following expressions are valid: + // + // pat_blk[2] -> chunk + // with chunk ~> nview + // Therefore: + // + // pat_blk[2].extents() + // pat_blk[2].offsets() + // pat_blk[4] | index() -> block index (THIS is the block index) + // + // pat_unit_offs = pat_blk | cycle(nunits) | index() + // // = offset of unit in team spec, so + // // team_spec[unit_offs] -> unit_id + // + + + +} + +/*-- snip ---------------------------------------------------------------- */ + + + + + + + +