Skip to content

Commit

Permalink
Merge pull request #6550 from STEllAR-GROUP/partitioned_vector
Browse files Browse the repository at this point in the history
Partitioned vector updates
  • Loading branch information
hkaiser authored Jan 22, 2025
2 parents ef4f92e + d245144 commit 3a2b72a
Show file tree
Hide file tree
Showing 91 changed files with 2,363 additions and 1,424 deletions.
2 changes: 1 addition & 1 deletion .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 Down
3 changes: 1 addition & 2 deletions .github/workflows/macos_debug_fetch_hwloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
- name: Install dependencies
run: |
brew install --overwrite python-tk && \
brew install --overwrite boost gperftools ninja autoconf automake && \
autoreconf -f -i \
brew install --overwrite boost gperftools ninja autoconf automake libtool && \
brew upgrade cmake
- name: Configure
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion cmake/HPX_SetupHwloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else()
execute_process(
COMMAND
sh -c
"cd ${FETCHCONTENT_BASE_DIR}/hwloc-src && ./configure --prefix=${FETCHCONTENT_BASE_DIR}/hwloc-installed && make -j && make install"
"cd ${FETCHCONTENT_BASE_DIR}/hwloc-src && autoreconf -f -i && ./configure --prefix=${FETCHCONTENT_BASE_DIR}/hwloc-installed && make -j && make install"
)
endif()
set(HWLOC_ROOT "${FETCHCONTENT_BASE_DIR}/hwloc-installed")
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 @@ -9,16 +9,14 @@
#include <hpx/config/export_definitions.hpp>

#if defined(HPX_PARTITIONED_VECTOR_MODULE_EXPORTS)
# define HPX_PARTITIONED_VECTOR_EXPORT HPX_SYMBOL_EXPORT
#define HPX_PARTITIONED_VECTOR_EXPORT HPX_SYMBOL_EXPORT
#else
# define HPX_PARTITIONED_VECTOR_EXPORT HPX_SYMBOL_IMPORT
#define HPX_PARTITIONED_VECTOR_EXPORT HPX_SYMBOL_IMPORT
#endif

#if defined(HPX_GCC_VERSION) && !defined(HPX_CLANG_VERSION)
#define HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT HPX_PARTITIONED_VECTOR_EXPORT
#define HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT \
HPX_PARTITIONED_VECTOR_EXPORT
#else
#define HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
#endif



Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2014 Anuj R. Sharma
// Copyright (c) 2014-2017 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 @@ -9,11 +9,12 @@

#pragma once

/// \brief The partitioned_vector_partition as the hpx component is defined here.
/// \brief The partitioned_vector_partition as the hpx component is defined
/// here.
///
/// The partitioned_vector_partition is the wrapper to the stl vector class except all API's
/// are defined as component action. All the API's in stubs classes are
/// asynchronous API which return the futures.
/// The partitioned_vector_partition is the wrapper to the stl vector class
/// except all APIs are defined as component action. All the APIs in stubs
/// classes are asynchronous API which return the futures.

#include <hpx/config.hpp>
#include <hpx/actions/transfer_action.hpp>
Expand All @@ -23,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 @@ -38,27 +40,49 @@

#include <hpx/config/warnings_prefix.hpp>

namespace hpx { namespace server {
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 contain 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
: public components::locking_hook<
components::component_base<partitioned_vector<T, Data>>>
{
public:
typedef Data data_type;
using data_type = std::decay_t<Data>;

typedef typename data_type::allocator_type allocator_type;
typedef typename data_type::size_type size_type;
typedef typename data_type::iterator iterator_type;
typedef typename data_type::const_iterator const_iterator_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;

typedef components::locking_hook<
components::component_base<partitioned_vector<T, Data>>>
base_type;
using base_type = components::locking_hook<
components::component_base<partitioned_vector<T, Data>>>;

data_type partitioned_vector_partition_;

Expand All @@ -70,17 +94,20 @@ namespace hpx { namespace 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 @@ -110,7 +137,7 @@ namespace hpx { namespace server {
const_iterator_type cend() const;

///////////////////////////////////////////////////////////////////////
// Capacity Related API's in the server class
// Capacity Related APIs in the server class
///////////////////////////////////////////////////////////////////////

/// Returns the number of elements
Expand Down Expand Up @@ -143,17 +170,16 @@ namespace hpx { namespace server {
/// partitioned_vector_partition capacity, the function causes the
/// partitioned_vector_partition to
/// reallocate its storage increasing its capacity to n (or greater).
/// In other cases the partitioned_vector_partition capacity does not
/// got affected.
/// It does not change the partitioned_vector_partition size.
/// In other cases the partitioned_vector_partition capacity is not
/// affected. It does not change the partitioned_vector_partition size.
///
/// \param n minimum capacity of partitioned_vector_partition
///
///
void reserve(size_type n);

///////////////////////////////////////////////////////////////////////
// Element access API's
// Element access APIs
///////////////////////////////////////////////////////////////////////

/// Return the element at the position \a pos in the
Expand Down Expand Up @@ -196,7 +222,7 @@ namespace hpx { namespace server {
T back() const;

///////////////////////////////////////////////////////////////////////
// Modifiers API's in server class
// Modifiers APIs in server class
///////////////////////////////////////////////////////////////////////

/// Assigns new contents to the partitioned_vector_partition, replacing
Expand Down Expand Up @@ -240,8 +266,7 @@ namespace hpx { namespace server {
///
/// \param val The value to be copied
///
void set_values(
std::vector<size_type> const& pos, std::vector<T> const& val);
void set_values(std::vector<size_type> const& pos, std::vector<T> val);

/// Remove all elements from the vector leaving the
/// partitioned_vector_partition with size 0.
Expand Down Expand Up @@ -274,13 +299,31 @@ namespace hpx { namespace 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
} // 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,34 +350,35 @@ namespace hpx { namespace 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 {

template <typename T, typename Data>
class partitioned_vector_partition
: public components::client_base<partitioned_vector_partition<T, Data>,
server::partitioned_vector<T, Data>>
{
private:
typedef hpx::server::partitioned_vector<T, Data> server_type;
typedef hpx::components::client_base<
partitioned_vector_partition<T, Data>,
server::partitioned_vector<T, Data>>
base_type;
using server_type = hpx::server::partitioned_vector<T, Data>;
using base_type =
hpx::components::client_base<partitioned_vector_partition<T, Data>,
server::partitioned_vector<T, Data>>;

public:
partitioned_vector_partition() = default;

explicit partitioned_vector_partition(id_type const& gid);
explicit partitioned_vector_partition(
id_type const& gid, bool make_unmanaged = false);

explicit partitioned_vector_partition(
hpx::shared_future<id_type> const& gid);
Expand All @@ -343,7 +387,7 @@ namespace hpx {
std::shared_ptr<server::partitioned_vector<T, Data>> get_ptr() const;

///////////////////////////////////////////////////////////////////////
// Capacity related API's in partitioned_vector_partition client class
// Capacity related APIs in partitioned_vector_partition client class

/// Asynchronously return the size of the partitioned_vector_partition
/// component.
Expand Down Expand Up @@ -415,7 +459,7 @@ namespace hpx {
// this->base_type::reserve_async(this->get_id(), n).get();
// }

// Element Access API's in Client class
// Element Access APIs in Client class

/// Returns the value at position \a pos in the partitioned_vector_partition
/// component.
Expand Down Expand Up @@ -478,7 +522,7 @@ namespace hpx {
// return back_async().get();
// }

// Modifiers API's in client class
// Modifiers APIs in client class
// void assign(std::size_t n, T const& val)
// {
// HPX_ASSERT(this->get_id());
Expand Down Expand Up @@ -556,14 +600,11 @@ namespace hpx {
/// Returns a copy of the data owned by the partitioned_vector_partition
/// component.
///
/// \return This returns the data as an hpx::future
/// \return This returns the data as a hpx::future
///
hpx::future<typename server_type::data_type> get_copied_data() const;

/// Updates the data owned by the partition_vector
/// component.
///
/// \return This returns the data of the partition_vector
/// Updates the data owned by the partition_vector component.
///
void set_data(
launch::sync_policy, typename server_type::data_type&& other) const;
Expand All @@ -575,6 +616,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 3a2b72a

Please sign in to comment.