Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local_size() in some patterns and improve short-cut detection #655

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dash/include/dash/pattern/BlockPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
21 changes: 3 additions & 18 deletions dash/include/dash/pattern/BlockPattern1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion dash/include/dash/pattern/SeqTilePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dash/include/dash/pattern/TilePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions dash/include/dash/pattern/TilePattern1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SizeType, 1> {{ _local_size }}),
_nlblocks(initialize_num_local_blocks(
_blocksize,
Expand Down Expand Up @@ -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<SizeType, 1>{{_local_size}})
, _nlblocks(initialize_num_local_blocks(_blocksize, _local_size))
, _local_capacity(initialize_local_capacity())
Expand Down Expand Up @@ -913,18 +913,22 @@ 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()
* \see local_capacity()
*
* \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.
*
Expand Down Expand Up @@ -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<SizeType, 1> {{ _local_size }}),
_nlblocks(initialize_num_local_blocks(
_blocksize,
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions dash/test/container/MatrixTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1676,3 +1676,47 @@ TEST_F(MatrixTest, LocalDiagonal){
ASSERT_EQ_U(value_sub, unit);
}
}

template<typename PatternT>
static void
test_pattern_local_size(dash::Distribution dist)
{
using TeamSpecT = dash::TeamSpec<2>;
using MatrixT = dash::NArray<double, 2, dash::default_index_t, PatternT>;
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<typename dash::BlockPattern<2>>(dash::BLOCKED);
}

TEST_F(MatrixTest, TilePatternLocalSize){
test_pattern_local_size<typename dash::TilePattern<2>>(dash::BLOCKED);
test_pattern_local_size<typename dash::TilePattern<2>>(dash::TILE(4));
}

TEST_F(MatrixTest, ShiftTilePatternLocalSize){
test_pattern_local_size<typename dash::ShiftTilePattern<2>>(dash::TILE(4));
}

TEST_F(MatrixTest, SeqTilePatternLocalSize){
test_pattern_local_size<typename dash::SeqTilePattern<2>>(dash::TILE(4));
}