diff --git a/dash/include/dash/pattern/BlockPattern.h b/dash/include/dash/pattern/BlockPattern.h index 74f792279..360b80011 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 3d69b8ef8..e54bc3af8 100644 --- a/dash/include/dash/pattern/BlockPattern1D.h +++ b/dash/include/dash/pattern/BlockPattern1D.h @@ -965,26 +965,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 a188e0661..2f3b9984b 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 9d75d623f..70b3141d6 100644 --- a/dash/include/dash/pattern/TilePattern.h +++ b/dash/include/dash/pattern/TilePattern.h @@ -1349,7 +1349,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 e6a324a57..ce55be1f7 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()) @@ -913,7 +913,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() @@ -921,10 +921,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. * @@ -1049,7 +1053,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, @@ -1154,7 +1158,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 363dc727b..247865aaf 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)); +}