Skip to content

Commit

Permalink
Cleaning up partitioned vector and segmented algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Sep 27, 2024
1 parent ce61055 commit 41643da
Show file tree
Hide file tree
Showing 33 changed files with 605 additions and 672 deletions.
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 @@ -38,27 +39,27 @@

#include <hpx/config/warnings_prefix.hpp>

namespace hpx { namespace server {
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 = 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 = typename data_type::allocator_type;
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 Down Expand Up @@ -110,7 +111,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 +144,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 +196,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 @@ -275,7 +275,7 @@ namespace hpx { namespace server {
HPX_DEFINE_COMPONENT_DIRECT_ACTION(partitioned_vector, get_copied_data)
HPX_DEFINE_COMPONENT_DIRECT_ACTION(partitioned_vector, set_data)
};
}} // namespace hpx::server
} // namespace hpx::server

///////////////////////////////////////////////////////////////////////////////
#define HPX_REGISTER_PARTITIONED_VECTOR_DECLARATION(...) \
Expand Down Expand Up @@ -319,17 +319,16 @@ namespace hpx { namespace server {
/**/

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;
Expand All @@ -343,7 +342,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 +414,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 +477,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,7 +555,7 @@ 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2014 Anuj R. Sharma
// 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 @@ -10,16 +10,11 @@
#include <hpx/config.hpp>
#include <hpx/assert.hpp>
#include <hpx/async_base/launch_policy.hpp>
#include <hpx/components/client_base.hpp>
#include <hpx/components/get_ptr.hpp>
#include <hpx/components_base/server/component.hpp>
#include <hpx/components_base/server/component_base.hpp>
#include <hpx/components_base/server/locking_hook.hpp>
#include <hpx/preprocessor/cat.hpp>
#include <hpx/preprocessor/expand.hpp>
#include <hpx/preprocessor/nargs.hpp>
#include <hpx/runtime_components/component_factory.hpp>
#include <hpx/type_support/unused.hpp>

#include <hpx/components/containers/partitioned_vector/partitioned_vector_decl.hpp>

Expand All @@ -30,7 +25,8 @@
#include <utility>
#include <vector>

namespace hpx { namespace server {
namespace hpx::server {

///////////////////////////////////////////////////////////////////////////
template <typename T, typename Data>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
Expand Down Expand Up @@ -270,7 +266,7 @@ namespace hpx { namespace server {
{
partitioned_vector_partition_.clear();
}
}} // namespace hpx::server
} // namespace hpx::server

///////////////////////////////////////////////////////////////////////////////
#define HPX_REGISTER_PARTITIONED_VECTOR(...) \
Expand Down Expand Up @@ -317,6 +313,7 @@ namespace hpx { namespace server {
/**/

namespace hpx {

template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
partitioned_vector_partition<T, Data>::partitioned_vector_partition(
Expand Down Expand Up @@ -374,16 +371,14 @@ namespace hpx {
template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<void>
partitioned_vector_partition<T, Data>::resize_async(
std::size_t n, T const& val /*= T()*/)
[[maybe_unused]] std::size_t n, [[maybe_unused]] T const& val /*= T()*/)
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::resize_action>(
this->get_id(), n, val);
#else
HPX_ASSERT(false);
HPX_UNUSED(n);
HPX_UNUSED(val);
return hpx::make_ready_future();
#endif
}
Expand All @@ -398,15 +393,15 @@ namespace hpx {

template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<T>
partitioned_vector_partition<T, Data>::get_value(std::size_t pos) const
partitioned_vector_partition<T, Data>::get_value(
[[maybe_unused]] std::size_t pos) const
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::get_value_action>(
this->get_id(), pos);
#else
HPX_ASSERT(false);
HPX_UNUSED(pos);
return hpx::future<T>{};
#endif
}
Expand All @@ -422,15 +417,14 @@ namespace hpx {
template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<std::vector<T>>
partitioned_vector_partition<T, Data>::get_values(
std::vector<std::size_t> const& pos) const
[[maybe_unused]] std::vector<std::size_t> const& pos) const
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::get_values_action>(
this->get_id(), pos);
#else
HPX_ASSERT(false);
HPX_UNUSED(pos);
return hpx::make_ready_future(std::vector<T>{});
#endif
}
Expand All @@ -453,33 +447,30 @@ namespace hpx {

template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<void>
partitioned_vector_partition<T, Data>::set_value(std::size_t pos, T&& val)
partitioned_vector_partition<T, Data>::set_value(
[[maybe_unused]] std::size_t pos, [[maybe_unused]] T&& val)
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_value_action>(
this->get_id(), pos, HPX_MOVE(val));
#else
HPX_ASSERT(false);
HPX_UNUSED(pos);
HPX_UNUSED(val);
return hpx::make_ready_future();
#endif
}

template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<void>
partitioned_vector_partition<T, Data>::set_value(
std::size_t pos, T const& val)
[[maybe_unused]] std::size_t pos, [[maybe_unused]] T const& val)
{
#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);
#else
HPX_ASSERT(false);
HPX_UNUSED(pos);
HPX_UNUSED(val);
return hpx::make_ready_future();
#endif
}
Expand All @@ -495,25 +486,24 @@ namespace hpx {
template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<void>
partitioned_vector_partition<T, Data>::set_values(
std::vector<std::size_t> const& pos, std::vector<T> const& val)
[[maybe_unused]] std::vector<std::size_t> const& pos,
[[maybe_unused]] std::vector<T> const& val)
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_values_action>(
this->get_id(), pos, val);
#else
HPX_ASSERT(false);
HPX_UNUSED(pos);
HPX_UNUSED(val);
return hpx::make_ready_future();
#endif
}

template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT
typename partitioned_vector_partition<T, Data>::server_type::data_type
partitioned_vector_partition<T, Data>::get_copied_data(
launch::sync_policy) const
partitioned_vector_partition<T, Data>::get_copied_data(
launch::sync_policy) const
{
return get_copied_data().get();
}
Expand Down Expand Up @@ -545,15 +535,14 @@ namespace hpx {
template <typename T, typename Data /*= std::vector<T> */>
HPX_PARTITIONED_VECTOR_SPECIALIZATION_EXPORT hpx::future<void>
partitioned_vector_partition<T, Data>::set_data(
typename server_type::data_type&& other) const
[[maybe_unused]] typename server_type::data_type&& other) const
{
#if !defined(HPX_COMPUTE_DEVICE_CODE)
HPX_ASSERT(this->get_id());
return hpx::async<typename server_type::set_data_action>(
this->get_id(), HPX_MOVE(other));
#else
HPX_ASSERT(false);
HPX_UNUSED(other);
return hpx::make_ready_future();
#endif
}
Expand Down
Loading

0 comments on commit 41643da

Please sign in to comment.