Skip to content

Commit

Permalink
Merge pull request #2794 from STEllAR-GROUP/fixing_partitioned_vector…
Browse files Browse the repository at this point in the history
…_iteration

Fixing test for partitioned_vector iteration
  • Loading branch information
hkaiser committed Aug 2, 2017
2 parents 68bd40c + 864ba9d commit 838e557
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
Expand Up @@ -1626,53 +1626,41 @@ namespace hpx
// Return local segment iterator
local_segment_iterator segment_begin(std::uint32_t id)
{
// local_segement_iterators are only valid on the locality where
// the data lives
HPX_ASSERT(id == hpx::get_locality_id());
return local_segment_iterator(partitions_.begin(),
partitions_.end(), id);
}

const_local_segment_iterator segment_begin(std::uint32_t id) const
{
// local_segement_iterators are only valid on the locality where
// the data lives
HPX_ASSERT(id == hpx::get_locality_id());
return const_local_segment_iterator(partitions_.cbegin(),
partitions_.cend(), id);
}

const_local_segment_iterator segment_cbegin(std::uint32_t id) const
{
// local_segement_iterators are only valid on the locality where
// the data lives
HPX_ASSERT(id == hpx::get_locality_id());
return const_local_segment_iterator(partitions_.cbegin(),
partitions_.cend(), id);
}

local_segment_iterator segment_end(std::uint32_t id)
{
// local_segement_iterators are only valid on the locality where
// the data lives
HPX_ASSERT(id == hpx::get_locality_id());
return local_segment_iterator(partitions_.end());
local_segment_iterator it = segment_begin(id);
it.unsatisfy_predicate();
return it;
}

const_local_segment_iterator segment_end(std::uint32_t id) const
{
// local_segement_iterators are only valid on the locality where
// the data lives
HPX_ASSERT(id == hpx::get_locality_id());
return const_local_segment_iterator(partitions_.cend());
const_local_segment_iterator it = segment_begin(id);
it.unsatisfy_predicate();
return it;
}

const_local_segment_iterator segment_cend(std::uint32_t id) const
{
// local_segement_iterators are only valid on the locality where
// the data lives
HPX_ASSERT(id == hpx::get_locality_id());
return const_local_segment_iterator(partitions_.cend());
const_local_segment_iterator it = segment_cbegin(id);
it.unsatisfy_predicate();
return it;
}

///////////////////////////////////////////////////////////////////////
Expand Down
Expand Up @@ -633,6 +633,18 @@ namespace hpx
return !data_ || this->base() == end_;
}

// increment until predicate is not satisfied any more
void unsatisfy_predicate()
{
while (this->base() != end_ && predicate_(*this->base()))
++(this->base_reference());

if (this->base() != end_)
data_ = this->base()->local_data_;
else
data_.reset();
}

private:
friend class hpx::util::iterator_core_access;

Expand All @@ -645,7 +657,11 @@ namespace hpx
void increment()
{
++(this->base_reference());
satisfy_predicate();

if (this->base() != end_)
data_ = this->base()->local_data_;
else
data_.reset();
}

void satisfy_predicate()
Expand Down
Expand Up @@ -176,7 +176,6 @@ void test_segmented_iteration(hpx::partitioned_vector<T>& v, std::size_t size,
HPX_TEST_EQ(count, size);

// test segmented iteration over localities
count = 0;
seg_count = 0;
for (hpx::id_type const& loc : hpx::find_all_localities())
{
Expand All @@ -185,17 +184,19 @@ void test_segmented_iteration(hpx::partitioned_vector<T>& v, std::size_t size,
for (local_segment_iterator seg_it = v.segment_begin(locality_id);
seg_it != seg_end; ++seg_it, ++seg_count)
{
// local raw iterators are valid locally only
if (loc != hpx::find_here())
continue;

local_raw_iterator loc_end = traits::end(seg_it);
for (local_raw_iterator lit = traits::begin(seg_it);
lit != loc_end; ++lit, ++count)
{
}
}
}
HPX_TEST_EQ(count, size);
HPX_TEST_EQ(seg_count, parts);

count = 0;
seg_count = 0;
for (hpx::id_type const& loc : hpx::find_all_localities())
{
Expand All @@ -204,14 +205,17 @@ void test_segmented_iteration(hpx::partitioned_vector<T>& v, std::size_t size,
for (const_local_segment_iterator seg_cit = v.segment_cbegin(locality_id);
seg_cit != seg_cend; ++seg_cit, ++seg_count)
{
// local raw iterators are valid locally only
if (loc != hpx::find_here())
continue;

const_local_raw_iterator loc_cend = const_traits::end(seg_cit);
for (const_local_raw_iterator lcit = const_traits::begin(seg_cit);
lcit != loc_cend; ++lcit, ++count)
{
}
}
}
HPX_TEST_EQ(count, size);
HPX_TEST_EQ(seg_count, parts);

// test iterator composition
Expand Down

0 comments on commit 838e557

Please sign in to comment.