Skip to content

Commit

Permalink
Some other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
atrantan committed Jul 10, 2017
1 parent 0cb8f8a commit bbde6b3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
54 changes: 34 additions & 20 deletions hpx/components/containers/coarray/coarray.hpp
Expand Up @@ -60,6 +60,9 @@ namespace hpx
using iterator =
typename std::array<std::size_t,N>::iterator;

using const_iterator =
typename std::array<std::size_t,N>::const_iterator;

template<typename ... I>
coarray_sizes(I... i)
: sizes_({{i...}})
Expand Down Expand Up @@ -95,19 +98,14 @@ namespace hpx
return sizes_.end();
}

template<typename View, typename Iterator, std::size_t ... I>
void update_view(
View & v,
std::size_t num_images,
hpx::util::detail::pack_c<std::size_t, I...>,
hpx::lcos::spmd_block const & block,
Iterator && begin,
Iterator && last) const
const_iterator begin() const
{
return sizes_.cbegin();
}

const_iterator end() const
{
v = View(block,
std::forward<Iterator>(begin),
std::forward<Iterator>(last),
{(sizes_[I]!= std::size_t(-1) ? sizes_[I] : num_images)...});
return sizes_.cend();
}

private:
Expand Down Expand Up @@ -136,11 +134,11 @@ namespace hpx
std::size_t num_segments,
std::size_t unroll)
{
using iterator = typename
std::vector<hpx::naming::id_type>::iterator;
using iterator = typename
std::vector<hpx::naming::id_type>::iterator;

using const_iterator = typename
std::vector<hpx::naming::id_type>::const_iterator;
using const_iterator = typename
std::vector<hpx::naming::id_type>::const_iterator;

std::vector<hpx::naming::id_type> out(num_segments);

Expand All @@ -158,6 +156,23 @@ namespace hpx
return out;
}

template<typename Iterator, std::size_t ... I>
base_type update_view(
hpx::detail::coarray_sizes<N> const & cosizes,
std::size_t num_images,
hpx::util::detail::pack_c<std::size_t, I...>,
hpx::lcos::spmd_block const & block,
Iterator && begin,
Iterator && last) const
{
return base_type(
block,
std::forward<Iterator>(begin),
std::forward<Iterator>(last),
{(cosizes.begin()[I]!= std::size_t(-1)
? cosizes.begin()[I] : num_images)...});
}

public:
explicit coarray(
hpx::lcos::spmd_block const & block,
Expand All @@ -175,7 +190,7 @@ namespace hpx
{
std::size_t num_segments = N > 0 ? 1 : 0;

for(std::size_t i : cosizes)
for(std::size_t const & i : cosizes)
{
num_segments *= (i != std::size_t(-1) ? i : num_images);
}
Expand All @@ -198,9 +213,8 @@ namespace hpx
else
vector_.connect_to(hpx::launch::sync, name + "_hpx_coarray");

cosizes.update_view(
view, num_images, indices(),
block, vector_.begin(), vector_.end());
view = update_view(cosizes,
num_images, indices(), block, vector_.begin(), vector_.end());
}

template<typename... I,
Expand Down
Expand Up @@ -109,7 +109,7 @@ namespace hpx { namespace detail

// Note: Put operation. Race condition may occur, be sure that
// operator=() is called by only one thread at a time.
view_element && operator=(Data && other)
void operator=(Data && other)
{
if ( is_data_here() )
{
Expand All @@ -124,13 +124,11 @@ namespace hpx { namespace detail
{
this->set_data(hpx::launch::sync, std::move(other) );
}

return std::move(*this);
}

// Note: Put operation. Race condition may occur, be sure that
// operator=() is called by only one thread at a time.
view_element && operator=(Data const & other)
void operator=(Data const & other)
{
if ( is_data_here() )
{
Expand All @@ -145,12 +143,10 @@ namespace hpx { namespace detail
{
this->set_data(hpx::launch::sync, Data(other) );
}

return std::move(*this);
}

// Note: Put operation. Free of race conditions.
view_element && operator=(view_element<T,Data> && other)
void operator=(view_element<T,Data> && other)
{
if(other.is_owned_by_current_thread())
{
Expand All @@ -168,8 +164,6 @@ namespace hpx { namespace detail
else
this->set_data(hpx::launch::sync, other.const_data() );
}

return std::move(*this);
}

T operator[](std::size_t i) const
Expand Down

0 comments on commit bbde6b3

Please sign in to comment.