Skip to content

Commit

Permalink
Enable variable partition sizes for partitioned_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Oct 5, 2024
1 parent 41643da commit 3f0f0bb
Show file tree
Hide file tree
Showing 36 changed files with 1,039 additions and 453 deletions.
10 changes: 5 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Copyright (c) 2014-2022 Hartmut Kaiser -->
<!-- Copyright (c) 2014-2024 Hartmut Kaiser -->
<!-- -->
<!-- SPDX-License-Identifier: BSL-1.0 -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
Expand All @@ -19,10 +19,10 @@ i.e. pull requests.

The easiest ways to get in contact with us are listed here:

* Mailing list: [[email protected]](email:[email protected]), [[email protected]](email:[email protected])
* IRC channel: #ste||ar on Libra.Chat
* Blog: [hpx.stellar-group.org](hpx.stellar-group.org)
* More options: See our [support page](https://github.com/STEllAR-GROUP/hpx/blob/master/.github/SUPPORT.md)
* Mailing list: [[email protected]](email:[email protected]), [[email protected]](email:[email protected])
* Discord server: [#ste||ar](https://discord.gg/Tn9QuzVjvy)
* Blog: [hpx.stellar-group.org](hpx.stellar-group.org)
* More options: See our [support page](https://github.com/STEllAR-GROUP/hpx/blob/master/.github/SUPPORT.md)

The basic approach is to find something fun you want to fix, hack it up, and
send a `git diff` as a mail attachment to [[email protected]](email:[email protected])
Expand Down
2 changes: 1 addition & 1 deletion components/containers/partitioned_vector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ set(partitioned_vector_headers
hpx/components/containers/partitioned_vector/partitioned_vector_segmented_iterator.hpp
hpx/components/containers/partitioned_vector/partitioned_vector_view.hpp
hpx/components/containers/partitioned_vector/partitioned_vector_view_iterator.hpp
hpx/components/containers/partitioned_vector/serialization/partitioned_vector.hpp
hpx/include/partitioned_vector.hpp
hpx/include/partitioned_vector_predef.hpp
hpx/include/partitioned_vector_view.hpp
hpx/runtime/serialization/partitioned_vector.hpp
)

set(partitioned_vector_sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <hpx/components/client_base.hpp>
#include <hpx/components_base/server/component_base.hpp>
#include <hpx/components_base/server/locking_hook.hpp>
#include <hpx/functional/invoke_result.hpp>
#include <hpx/preprocessor/cat.hpp>
#include <hpx/preprocessor/expand.hpp>
#include <hpx/preprocessor/nargs.hpp>
Expand All @@ -39,11 +40,33 @@

#include <hpx/config/warnings_prefix.hpp>

namespace hpx::detail {

HPX_HAS_XXX_TRAIT_DEF(allocator_type);

template <typename T, typename Data, typename Enable = void>
struct extract_allocator_type
{
using type = std::allocator<T>;
};

template <typename T, typename Data>
struct extract_allocator_type<T, Data,
std::enable_if_t<has_allocator_type_v<Data>>>
{
using type = typename Data::allocator_type;
};

template <typename T, typename Data>
using extract_allocator_type_t =
typename extract_allocator_type<T, Data>::type;
} // namespace hpx::detail

namespace hpx::server {

/// \brief This is the basic wrapper class for stl vector.
///
/// This contains the implementation of the partitioned_vector_partition's
/// This contains the implementation of the partitioned_vector partition's
/// component functionality.
template <typename T, typename Data>
class partitioned_vector
Expand All @@ -53,7 +76,7 @@ namespace hpx::server {
public:
using data_type = Data;

using allocator_type = typename data_type::allocator_type;
using allocator_type = hpx::detail::extract_allocator_type_t<T, Data>;
using size_type = typename data_type::size_type;
using iterator_type = typename data_type::iterator;
using const_iterator_type = typename data_type::const_iterator;
Expand All @@ -71,17 +94,20 @@ namespace hpx::server {
/// size 0.
partitioned_vector();

explicit partitioned_vector(size_type partition_size);
explicit partitioned_vector(
std::size_t partnum, std::vector<size_type> const& partition_sizes);

/// Constructor which create and initialize partitioned_vector_partition
/// with all elements as \a val.
///
/// param partition_size The size of vector
/// param val Default value for the elements in partitioned_vector_partition
///
partitioned_vector(size_type partition_size, T const& val);
partitioned_vector(std::size_t partnum,
std::vector<size_type> const& partition_sizes, T const& val);

partitioned_vector(size_type partition_size, T const& val,
partitioned_vector(std::size_t partnum,
std::vector<size_type> const& partition_sizes, T const& val,
allocator_type const& alloc);

// support components::copy
Expand Down Expand Up @@ -274,13 +300,31 @@ namespace hpx::server {
// HPX_DEFINE_COMPONENT_ACTION(partitioned_vector_partition, clear)
HPX_DEFINE_COMPONENT_DIRECT_ACTION(partitioned_vector, get_copied_data)
HPX_DEFINE_COMPONENT_DIRECT_ACTION(partitioned_vector, set_data)

/// Invoke given function on given element
///
/// \return This returns whatever the given function invocation returns
template <typename F, typename... Ts>
util::invoke_result_t<F, T, Ts...> apply(
std::size_t pos, F f, Ts... ts);

template <typename F, typename... Ts>
struct apply_action
: hpx::actions::make_action_t<
decltype(&partitioned_vector::apply<F, Ts...>),
&partitioned_vector::apply<F, Ts...>, apply_action<F, Ts...>>
{
};
};
} // namespace hpx::server

///////////////////////////////////////////////////////////////////////////////
#if 0
#define HPX_REGISTER_PARTITIONED_VECTOR_DECLARATION(...)
#else
#define HPX_REGISTER_PARTITIONED_VECTOR_DECLARATION(...) \
HPX_REGISTER_VECTOR_DECLARATION_(__VA_ARGS__) \
/**/
/**/
#define HPX_REGISTER_VECTOR_DECLARATION_(...) \
HPX_PP_EXPAND(HPX_PP_CAT(HPX_REGISTER_VECTOR_DECLARATION_, \
HPX_PP_NARGS(__VA_ARGS__))(__VA_ARGS__)) \
Expand All @@ -307,16 +351,17 @@ namespace hpx::server {

#define HPX_REGISTER_VECTOR_DECLARATION_1(type) \
HPX_REGISTER_VECTOR_DECLARATION_2(type, std::vector<type>) \
/**/
/**/
#define HPX_REGISTER_VECTOR_DECLARATION_2(type, data) \
HPX_REGISTER_VECTOR_DECLARATION_3(type, data, type) \
/**/
/**/
#define HPX_REGISTER_VECTOR_DECLARATION_3(type, data, name) \
typedef ::hpx::server::partitioned_vector<type, data> HPX_PP_CAT( \
__partitioned_vector_, HPX_PP_CAT(type, name)); \
HPX_REGISTER_VECTOR_DECLARATION_IMPL( \
HPX_PP_CAT(__partitioned_vector_, HPX_PP_CAT(type, name)), name) \
/**/
#endif

namespace hpx {

Expand Down Expand Up @@ -559,8 +604,7 @@ namespace hpx {
///
hpx::future<typename server_type::data_type> get_copied_data() const;

/// Updates the data owned by the partition_vector
/// component.
/// Updates the data owned by the partition_vector component.
///
/// \return This returns the data of the partition_vector
///
Expand All @@ -574,6 +618,13 @@ namespace hpx {
///
hpx::future<void> set_data(
typename server_type::data_type&& other) const;

/// Invoke given function on given element
///
/// \return This returns whatever the given function invocation returns
template <typename F, typename... Ts>
hpx::future<util::invoke_result_t<F, T, Ts...>> apply(
std::size_t pos, F&& f, Ts&&... ts);
};
} // namespace hpx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@ namespace hpx::server {

template <typename T, typename Data>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
partitioned_vector<T, Data>::partitioned_vector(size_type partition_size)
: partitioned_vector_partition_(partition_size)
partitioned_vector<T, Data>::partitioned_vector(
std::size_t partnum, std::vector<size_type> const& partition_sizes)
: partitioned_vector_partition_(partition_sizes[partnum])
{
}

template <typename T, typename Data>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
partitioned_vector<T, Data>::partitioned_vector(
size_type partition_size, T const& val)
: partitioned_vector_partition_(partition_size, val)
partitioned_vector<T, Data>::partitioned_vector(std::size_t partnum,
std::vector<size_type> const& partition_sizes, T const& val)
: partitioned_vector_partition_(partition_sizes[partnum], val)
{
}

template <typename T, typename Data>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
partitioned_vector<T, Data>::partitioned_vector(
size_type partition_size, T const& val, allocator_type const& alloc)
: partitioned_vector_partition_(partition_size, val, alloc)
partitioned_vector<T, Data>::partitioned_vector(std::size_t partnum,
std::vector<size_type> const& partition_sizes, T const& val,
allocator_type const& alloc)
: partitioned_vector_partition_(partition_sizes[partnum], val, alloc)
{
}

Expand Down Expand Up @@ -266,12 +268,20 @@ namespace hpx::server {
{
partitioned_vector_partition_.clear();
}

template <typename T, typename Data>
template <typename F, typename... Ts>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
util::invoke_result_t<F, T, Ts...>
partitioned_vector<T, Data>::apply(std::size_t pos, F f, Ts... ts)
{
return HPX_INVOKE(
HPX_MOVE(f), partitioned_vector_partition_[pos], HPX_MOVE(ts)...);
}
} // namespace hpx::server

///////////////////////////////////////////////////////////////////////////////
#define HPX_REGISTER_PARTITIONED_VECTOR(...) \
HPX_REGISTER_VECTOR_(__VA_ARGS__) \
/**/
#define HPX_REGISTER_PARTITIONED_VECTOR(...) HPX_REGISTER_VECTOR_(__VA_ARGS__)
#define HPX_REGISTER_VECTOR_(...) \
HPX_PP_EXPAND(HPX_PP_CAT(HPX_REGISTER_VECTOR_, HPX_PP_NARGS(__VA_ARGS__))( \
__VA_ARGS__)) \
Expand All @@ -294,23 +304,38 @@ namespace hpx::server {
HPX_PP_CAT(__vector_get_copied_data_action_, name)) \
HPX_REGISTER_ACTION( \
type::set_data_action, HPX_PP_CAT(__vector_set_data_action_, name)) \
/**/

#define HPX_REGISTER_VECTOR_COMPONENT_IMPL(type, name) \
typedef ::hpx::components::component<type> HPX_PP_CAT(__vector_, name); \
HPX_REGISTER_COMPONENT(HPX_PP_CAT(__vector_, name)) \
/**/

#define HPX_REGISTER_VECTOR_1(type) \
HPX_REGISTER_VECTOR_3( \
type, std::vector<type>, HPX_PP_CAT(std_vector_, type)) \
/**/
/**/
#define HPX_REGISTER_VECTOR_2(type, data) \
HPX_REGISTER_VECTOR_3(type, data, HPX_PP_CAT(type, data)) \
/**/
/**/

#if 0
#define HPX_REGISTER_VECTOR_3(type, data, name) \
typedef ::hpx::server::partitioned_vector<type, data> HPX_PP_CAT( \
__partitioned_vector_, HPX_PP_CAT(type, name)); \
HPX_REGISTER_VECTOR_COMPONENT_IMPL( \
HPX_PP_CAT(__partitioned_vector_, HPX_PP_CAT(type, name)), name) \
/**/
#else
#define HPX_REGISTER_VECTOR_3(type, data, name) \
typedef ::hpx::server::partitioned_vector<type, data> HPX_PP_CAT( \
__partitioned_vector_, HPX_PP_CAT(type, name)); \
HPX_REGISTER_VECTOR_IMPL( \
HPX_PP_CAT(__partitioned_vector_, HPX_PP_CAT(type, name)), name) \
HPX_REGISTER_VECTOR_COMPONENT_IMPL( \
HPX_PP_CAT(__partitioned_vector_, HPX_PP_CAT(type, name)), name) \
/**/
#endif

namespace hpx {

Expand Down Expand Up @@ -346,7 +371,7 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::size_action>(this->get_id());
return hpx::async(typename server_type::size_action(), this->get_id());
#else
HPX_ASSERT(false);
return hpx::make_ready_future(std::size_t{});
Expand Down Expand Up @@ -375,8 +400,8 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::resize_action>(
this->get_id(), n, val);
return hpx::async(
typename server_type::resize_action(), this->get_id(), n, val);
#else
HPX_ASSERT(false);
return hpx::make_ready_future();
Expand All @@ -398,8 +423,8 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::get_value_action>(
this->get_id(), pos);
return hpx::async(
typename server_type::get_value_action(), this->get_id(), pos);
#else
HPX_ASSERT(false);
return hpx::future<T>{};
Expand All @@ -421,8 +446,8 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::get_values_action>(
this->get_id(), pos);
return hpx::async(
typename server_type::get_values_action(), this->get_id(), pos);
#else
HPX_ASSERT(false);
return hpx::make_ready_future(std::vector<T>{});
Expand Down Expand Up @@ -452,7 +477,7 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_value_action>(
return hpx::async(typename server_type::set_value_action(),
this->get_id(), pos, HPX_MOVE(val));
#else
HPX_ASSERT(false);
Expand All @@ -467,8 +492,8 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_value_action>(
this->get_id(), pos, val);
return hpx::async(
typename server_type::set_value_action(), this->get_id(), pos, val);
#else
HPX_ASSERT(false);
return hpx::make_ready_future();
Expand All @@ -491,7 +516,7 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_values_action>(
return hpx::async(typename server_type::set_values_action(),
this->get_id(), pos, val);
#else
HPX_ASSERT(false);
Expand All @@ -515,8 +540,8 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::get_copied_data_action>(
this->get_id());
return hpx::async(
typename server_type::get_copied_data_action(), this->get_id());
#else
HPX_ASSERT(false);
return hpx::make_ready_future(typename partitioned_vector_partition<T,
Expand All @@ -539,11 +564,30 @@ namespace hpx {
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_data_action>(
return hpx::async(typename server_type::set_data_action(),
this->get_id(), HPX_MOVE(other));
#else
HPX_ASSERT(false);
return hpx::make_ready_future();
#endif
}

template <typename T, typename Data /*= std::vector<T> */>
template <typename F, typename... Ts>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
hpx::future<util::invoke_result_t<F, T, Ts...>>
partitioned_vector_partition<T, Data>::apply(
[[maybe_unused]] std::size_t pos, [[maybe_unused]] F&& f,
[[maybe_unused]] Ts&&... ts)
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async(
typename server_type::template apply_action<F, Ts...>(),
this->get_id(), pos, HPX_FORWARD(F, f), HPX_FORWARD(Ts, ts)...);
#else
HPX_ASSERT(false);
return hpx::make_ready_future(util::invoke_result_t<F&&, Ts&&...>());
#endif
}
} // namespace hpx
Loading

0 comments on commit 3f0f0bb

Please sign in to comment.