Skip to content

Commit

Permalink
Bug 125 array team (#135)
Browse files Browse the repository at this point in the history
* added test case for team-aware array allocation

* removed explicit usage of unit id in array.lbegin

* added unit test for GlobMem lbegin using teams

* reverted changes from PR #133 as GlobMem requires absolute unit ids

* renamed unit id parameters in GlobMem to differentiate between realtive and global unit ids

* skip team unit tests if team is already splitted
  • Loading branch information
fmoessbauer authored and ddiefenthaler committed Nov 22, 2016
1 parent 5deffc7 commit 94ff4cb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
4 changes: 2 additions & 2 deletions dash/include/dash/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ class Array
m_begin = iterator(m_globmem, m_pattern);
m_end = iterator(m_begin) + m_size;
// Local iterators:
m_lbegin = m_globmem->lbegin(m_myid);
m_lbegin = m_globmem->lbegin();
// More efficient than using m_globmem->lend as this a second mapping
// of the local memory segment:
m_lend = m_lbegin + m_lsize;
Expand Down Expand Up @@ -1204,7 +1204,7 @@ class Array
m_begin = iterator(m_globmem, pattern);
m_end = iterator(m_begin) + m_size;
// Local iterators:
m_lbegin = m_globmem->lbegin(m_myid);
m_lbegin = m_globmem->lbegin();
// More efficient than using m_globmem->lend as this a second mapping
// of the local memory segment:
m_lend = m_lbegin + pattern.local_size();
Expand Down
25 changes: 14 additions & 11 deletions dash/include/dash/GlobMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ class GlobMem
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

_lbegin = lbegin(team.myid());
_lend = lend(team.myid());
// Use id's of team all
_lbegin = lbegin(dash::myid());
_lend = lend(dash::myid());
DASH_LOG_TRACE("GlobMem(nlocal,team) >");
}

Expand Down Expand Up @@ -158,8 +159,8 @@ class GlobMem
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

_lbegin = lbegin(team.myid());
_lend = lend(team.myid());
_lbegin = lbegin(dash::myid());
_lend = lend(dash::myid());
// Initialize allocated local elements with specified values:
auto copy_end = std::copy(local_elements.begin(),
local_elements.end(),
Expand All @@ -175,7 +176,7 @@ class GlobMem
// TODO: Should depend on allocator trait
// dash::allocator_traits<Alloc>::is_collective()
DASH_LOG_DEBUG("GlobMem(lvals,team)", "barrier");
barrier();
team.barrier();
}

DASH_LOG_DEBUG("GlobMem(lvals,team) >",
Expand Down Expand Up @@ -244,15 +245,16 @@ class GlobMem
/**
* Native pointer of the initial address of the local memory of
* a unit.
* \param global_unit_id id of unit in \c dash::Team::All()
*/
const ElementType * lbegin(
dart_unit_t unit_id) const
dart_unit_t global_unit_id) const
{
void *addr;
DASH_LOG_TRACE_VAR("GlobMem.lbegin const()", unit_id);
DASH_LOG_TRACE_VAR("GlobMem.lbegin const()", global_unit_id);
dart_gptr_t gptr = _begptr;
DASH_ASSERT_RETURNS(
dart_gptr_setunit(&gptr, unit_id),
dart_gptr_setunit(&gptr, global_unit_id),
DART_OK);
DASH_ASSERT_RETURNS(
dart_gptr_getaddr(gptr, &addr),
Expand All @@ -264,17 +266,18 @@ class GlobMem
/**
* Native pointer of the initial address of the local memory of
* a unit.
* \param global_unit_id id of unit in \c dash::Team::All()
*/
ElementType * lbegin(
dart_unit_t unit_id)
dart_unit_t global_unit_id)
{
void *addr;
DASH_LOG_TRACE_VAR("GlobMem.lbegin()", unit_id);
DASH_LOG_TRACE_VAR("GlobMem.lbegin()", global_unit_id);
dart_gptr_t gptr = _begptr;
DASH_LOG_TRACE_VAR("GlobMem.lbegin",
GlobPtr<ElementType>((dart_gptr_t)gptr));
DASH_ASSERT_RETURNS(
dart_gptr_setunit(&gptr, unit_id),
dart_gptr_setunit(&gptr, global_unit_id),
DART_OK);
DASH_ASSERT_RETURNS(
dart_gptr_getaddr(gptr, &addr),
Expand Down
20 changes: 20 additions & 0 deletions dash/test/ArrayTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,24 @@ TEST_F(ArrayTest, ConstructorNelemInitializerList)
}
}

TEST_F(ArrayTest, TeamSplit)
{
auto & team_all = dash::Team::All();
auto ext_x = team_all.size();

if(team_all.size() < 2){
SKIP_TEST();
}
if(!team_all.is_leaf()){
LOG_MESSAGE("team is already splitted. Skip test");
SKIP_TEST();
}

auto & myteam = team_all.split(2);
auto array_a = dash::Array<double>(ext_x, myteam);

array_a.barrier();
// Check if array is allocated
ASSERT_NE_U(array_a.lbegin(), nullptr);
team_all.barrier();
}
7 changes: 6 additions & 1 deletion dash/test/GlobMemTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ TEST_F(GlobMemTest, LocalBegin)
{
auto target_local_elements = { 1, 2, 3, 4 };

if(!dash::Team::All().is_leaf()){
LOG_MESSAGE("team is already splitted. Skip test");
SKIP_TEST();
}

auto & sub_team = dash::size() < 4
? dash::Team::All()
: dash::Team::All().split(2);
Expand All @@ -37,5 +42,5 @@ TEST_F(GlobMemTest, LocalBegin)
for (int l = 0; l < target_local_elements.size(); l++) {
EXPECT_EQ_U(*(target_local_elements.begin() + l), target.lbegin()[l]);
}
EXPECT_NE_U(target.lbegin(), nullptr);
}

5 changes: 5 additions & 0 deletions dash/test/TeamTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ TEST_F(TeamTest, SplitTeamSync)
if(team_all.size() < 2){
SKIP_TEST();
}
if(!team_all.is_leaf()){
LOG_MESSAGE("team is already splitted. Skip test");
SKIP_TEST();
}

LOG_MESSAGE("team_all contains %d units", team_all.size());

auto & team_core = team_all.split(2);
Expand Down

0 comments on commit 94ff4cb

Please sign in to comment.