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 13, 2024
1 parent 41643da commit 56fd46b
Show file tree
Hide file tree
Showing 44 changed files with 1,454 additions and 583 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: [hpx-users@stellar-group.org](email:hpx-users@stellar-group.org), [hpx-devel@stellar-group.org](email:hpx-devel@stellar-group.org)
* 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: [hpx-users@stellar-group.org](email:hpx-users@stellar-group.org), [hpx-devel@stellar-group.org](email:hpx-devel@stellar-group.org)
* 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 [hpx-devel@stellar-group.org](email:hpx-devel@stellar-group.org)
Expand Down
6 changes: 6 additions & 0 deletions cmake/HPX_SetupNanobench.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Copyright (c) 2024 Hartmut Kaiser
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

include(FetchContent)

fetchcontent_declare(
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,21 @@ 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,
traits::create_mode = traits::create_mode::resize);

/// 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 +301,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 +352,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 +605,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 +619,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
Loading

0 comments on commit 56fd46b

Please sign in to comment.