From 7d8a9bfe09f0421f5d875d2c253cf67091a76c09 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Wed, 10 Jul 2019 18:08:40 +0200 Subject: [PATCH] Fix local_size() in some patterns and improve short-cut detection --- dash/include/dash/pattern/BlockPattern.h | 4 +- dash/include/dash/pattern/BlockPattern1D.h | 21 ++--------- dash/include/dash/pattern/SeqTilePattern.h | 2 +- dash/include/dash/pattern/TilePattern.h | 2 +- dash/include/dash/pattern/TilePattern1D.h | 20 ++++++---- dash/test/container/MatrixTest.cc | 44 ++++++++++++++++++++++ 6 files changed, 63 insertions(+), 30 deletions(-) diff --git a/dash/include/dash/pattern/BlockPattern.h b/dash/include/dash/pattern/BlockPattern.h index 1838727b7..b55203a24 100644 --- a/dash/include/dash/pattern/BlockPattern.h +++ b/dash/include/dash/pattern/BlockPattern.h @@ -1204,9 +1204,9 @@ class BlockPattern constexpr SizeType local_size( team_unit_t unit = UNDEFINED_TEAM_UNIT_ID) const noexcept { - return (unit == UNDEFINED_TEAM_UNIT_ID) + return (unit == UNDEFINED_TEAM_UNIT_ID || _team->myid() == unit) ? _local_memory_layout.size() - : initialize_local_extents(unit).size(); + : LocalMemoryLayout_t(initialize_local_extents(unit)).size(); } /** diff --git a/dash/include/dash/pattern/BlockPattern1D.h b/dash/include/dash/pattern/BlockPattern1D.h index a49818f93..205e0132e 100644 --- a/dash/include/dash/pattern/BlockPattern1D.h +++ b/dash/include/dash/pattern/BlockPattern1D.h @@ -939,26 +939,11 @@ class BlockPattern<1, Arrangement, IndexType> * * \see DashPatternConcept */ - constexpr SizeType local_size(team_unit_t unit) const + constexpr SizeType local_size(team_unit_t unit = UNDEFINED_TEAM_UNIT_ID) const { - return (unit == _team->myid().id) + return (UNDEFINED_TEAM_UNIT_ID == unit || unit == _team->myid().id) ? _local_size - : initialize_local_extent(unit); - } - - /** - * The actual number of elements in this pattern that are local to the - * calling unit in total. - * - * \see blocksize() - * \see local_extent() - * \see local_capacity() - * - * \see DashPatternConcept - */ - constexpr SizeType local_size() const noexcept - { - return _local_size; + : LocalMemoryLayout_t(initialize_local_extent(unit)).size(); } /** diff --git a/dash/include/dash/pattern/SeqTilePattern.h b/dash/include/dash/pattern/SeqTilePattern.h index c659aa628..0cd0f585f 100644 --- a/dash/include/dash/pattern/SeqTilePattern.h +++ b/dash/include/dash/pattern/SeqTilePattern.h @@ -1329,7 +1329,7 @@ class SeqTilePattern * \see DashPatternConcept */ SizeType local_size(team_unit_t unit = UNDEFINED_TEAM_UNIT_ID) const { - if (unit == DART_UNDEFINED_UNIT_ID) { + if (unit == DART_UNDEFINED_UNIT_ID || _team->myid() == unit) { return _local_memory_layout.size(); } // Non-local query, requires to construct local memory layout of diff --git a/dash/include/dash/pattern/TilePattern.h b/dash/include/dash/pattern/TilePattern.h index dec8c493d..538ade070 100644 --- a/dash/include/dash/pattern/TilePattern.h +++ b/dash/include/dash/pattern/TilePattern.h @@ -1348,7 +1348,7 @@ class TilePattern * \see DashPatternConcept */ SizeType local_size(team_unit_t unit = UNDEFINED_TEAM_UNIT_ID) const { - if (unit == UNDEFINED_TEAM_UNIT_ID) { + if (unit == UNDEFINED_TEAM_UNIT_ID || _team->myid() == unit) { return _local_memory_layout.size(); } // Non-local query, requires to construct local memory layout of diff --git a/dash/include/dash/pattern/TilePattern1D.h b/dash/include/dash/pattern/TilePattern1D.h index ec8eae14b..c1f95ef2a 100644 --- a/dash/include/dash/pattern/TilePattern1D.h +++ b/dash/include/dash/pattern/TilePattern1D.h @@ -224,7 +224,7 @@ class TilePattern<1, Arrangement, IndexType> _blocksize, _nunits)), _local_size( - initialize_local_extent(_team->myid())), + initialize_local_extents(_team->myid())), _local_memory_layout(std::array {{ _local_size }}), _nlblocks(initialize_num_local_blocks( _blocksize, @@ -276,7 +276,7 @@ class TilePattern<1, Arrangement, IndexType> , _nunits(_team->size()) , _blocksize(initialize_blocksize(_size, _distspec, _nunits)) , _nblocks(initialize_num_blocks(_size, _blocksize, _nunits)) - , _local_size(initialize_local_extent(_team->myid())) + , _local_size(initialize_local_extents(_team->myid())) , _local_memory_layout(std::array{{_local_size}}) , _nlblocks(initialize_num_local_blocks(_blocksize, _local_size)) , _local_capacity(initialize_local_capacity()) @@ -888,7 +888,7 @@ class TilePattern<1, Arrangement, IndexType> /** * The actual number of elements in this pattern that are local to the - * calling unit in total. + * specified (or calling) unit in total. * * \see blocksize() * \see local_extent() @@ -896,10 +896,14 @@ class TilePattern<1, Arrangement, IndexType> * * \see DashPatternConcept */ - constexpr SizeType local_size() const { - return _local_size; + SizeType local_size(team_unit_t unit = UNDEFINED_TEAM_UNIT_ID) const { + if (unit == DART_UNDEFINED_UNIT_ID || _team->myid() == unit) { + return _local_memory_layout.size(); + } + // Non-local query, requires to construct local memory layout of + // remote unit: + return LocalMemoryLayout_t(initialize_local_extents(unit)).size(); } - /** * The number of units to which this pattern's elements are mapped. * @@ -1031,7 +1035,7 @@ class TilePattern<1, Arrangement, IndexType> _blocksize, _nunits)), _local_size( - initialize_local_extent(_team->myid())), + initialize_local_extents(_team->myid())), _local_memory_layout(std::array {{ _local_size }}), _nlblocks(initialize_num_local_blocks( _blocksize, @@ -1136,7 +1140,7 @@ class TilePattern<1, Arrangement, IndexType> /** * Resolve extents of local memory layout for a specified unit. */ - SizeType initialize_local_extent( + SizeType initialize_local_extents( team_unit_t unit) const { DASH_LOG_DEBUG_VAR("TilePattern<1>.init_local_extent()", unit); DASH_LOG_DEBUG_VAR("TilePattern<1>.init_local_extent()", _nunits); diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index 2dcde9139..6f023d19d 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -1676,3 +1676,47 @@ TEST_F(MatrixTest, LocalDiagonal){ ASSERT_EQ_U(value_sub, unit); } } + +template +static void +test_pattern_local_size(dash::Distribution dist) +{ + using TeamSpecT = dash::TeamSpec<2>; + using MatrixT = dash::NArray; + using SizeSpecT = dash::SizeSpec<2>; + using DistSpecT = dash::DistributionSpec<2>; + + auto size_spec = SizeSpecT(4*dash::size(), 4*::dash::size()); + auto dist_spec = DistSpecT(dist, dist); + + auto& team_all = dash::Team::All(); + TeamSpecT team_all_spec(team_all.size(), 1); + team_all_spec.balance_extents(); + MatrixT matrix(size_spec, dist_spec, team_all, team_all_spec); + + ASSERT_EQ_U(matrix.local.size(), matrix.pattern().local_size()); + + size_t size = 0; + for (dash::team_unit_t unit{0}; unit < dash::size(); ++unit) { + size += matrix.pattern().local_size(unit); + } + ASSERT_EQ_U(size, matrix.size()); + +} + +TEST_F(MatrixTest, BlockPatternLocalSize){ + test_pattern_local_size>(dash::BLOCKED); +} + +TEST_F(MatrixTest, TilePatternLocalSize){ + test_pattern_local_size>(dash::BLOCKED); + test_pattern_local_size>(dash::TILE(4)); +} + +TEST_F(MatrixTest, ShiftTilePatternLocalSize){ + test_pattern_local_size>(dash::TILE(4)); +} + +TEST_F(MatrixTest, SeqTilePatternLocalSize){ + test_pattern_local_size>(dash::TILE(4)); +}