Skip to content

Commit

Permalink
Fixing return type calculation for bulk_then_execute.
Browse files Browse the repository at this point in the history
- flyby: added util::functional::unwrap[_n|_all]
- some restructuring required by circular #include dependencies
  • Loading branch information
hkaiser committed Feb 28, 2018
1 parent 9cdd6bc commit 7b7c183
Show file tree
Hide file tree
Showing 56 changed files with 982 additions and 436 deletions.
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Expand Up @@ -143,7 +143,7 @@ set(doxygen_dependencies
"${PROJECT_SOURCE_DIR}/hpx/performance_counters/manage_counter_type.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime_fwd.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/applier_fwd.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/basename_registration.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/basename_registration_fwd.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/find_here.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/find_localities.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/get_colocation_id.hpp"
Expand Down
2 changes: 1 addition & 1 deletion hpx/apply.hpp
Expand Up @@ -7,11 +7,11 @@
#define HPX_APPLY_APR_16_20012_0943AM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/runtime/applier/apply.hpp>
#include <hpx/runtime/applier/apply_continue.hpp>
#include <hpx/runtime/threads/thread_executor.hpp>
#include <hpx/runtime/threads/thread_helpers.hpp>
#include <hpx/runtime_fwd.hpp>
#include <hpx/traits/is_executor.hpp>
#include <hpx/traits/is_launch_policy.hpp>
#include <hpx/util/bind_action.hpp>
Expand Down
2 changes: 1 addition & 1 deletion hpx/compute/cuda/target_distribution_policy.hpp
Expand Up @@ -12,7 +12,7 @@

#if defined(HPX_HAVE_CUDA)

#include <hpx/dataflow.hpp>
#include <hpx/lcos/dataflow.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/runtime/components/stubs/stub_base.hpp>
#include <hpx/runtime/serialization/base_object.hpp>
Expand Down
2 changes: 1 addition & 1 deletion hpx/compute/host/target_distribution_policy.hpp
Expand Up @@ -10,7 +10,7 @@

#include <hpx/config.hpp>

#include <hpx/dataflow.hpp>
#include <hpx/lcos/dataflow.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/runtime/components/stubs/stub_base.hpp>
#include <hpx/runtime/serialization/base_object.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/dataflow.hpp
Expand Up @@ -6,6 +6,7 @@
#ifndef HPX_DATAFLOW_HPP
#define HPX_DATAFLOW_HPP

#include <hpx/lcos/future.hpp>
#include <hpx/lcos/dataflow.hpp>
#include <hpx/lcos/local/dataflow.hpp>

Expand Down
3 changes: 3 additions & 0 deletions hpx/hpx.hpp
Expand Up @@ -6,6 +6,9 @@
#if !defined(HPX_MAR_24_2008_1118AM)
#define HPX_MAR_24_2008_1118AM

#include <hpx/apply.hpp>
#include <hpx/async.hpp>
#include <hpx/dataflow.hpp>
#include <hpx/exception.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/performance_counters.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/lcos/broadcast.hpp
Expand Up @@ -135,6 +135,7 @@ namespace hpx { namespace lcos
#define HPX_LCOS_BROADCAST_HPP

#include <hpx/config.hpp>
#include <hpx/apply.hpp>
#include <hpx/lcos/detail/async_colocated.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/lcos/when_all.hpp>
Expand Down
12 changes: 8 additions & 4 deletions hpx/lcos/dataflow.hpp
@@ -1,18 +1,21 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2007-2018 Hartmut Kaiser
//
// 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)

// hpxinspect:nodeprecatedinclude:boost/ref.hpp
// hpxinspect:nodeprecatedname:boost::reference_wrapper

#include <hpx/config.hpp>

// Intentionally #include future.hpp outside of the guards as it may #include
// dataflow.hpp itself
#include <hpx/lcos/future.hpp>

#ifndef HPX_LCOS_DATAFLOW_HPP
#define HPX_LCOS_DATAFLOW_HPP

#include <hpx/config.hpp>
#include <hpx/apply.hpp>
#include <hpx/lcos/detail/future_transforms.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/runtime/get_worker_thread_num.hpp>
#include <hpx/runtime/launch_policy.hpp>
#include <hpx/traits/acquire_future.hpp>
Expand All @@ -36,6 +39,7 @@
#include <hpx/parallel/executors/v1/executor_traits.hpp>
#endif
#include <hpx/parallel/executors/execution.hpp>
#include <hpx/parallel/executors/parallel_executor.hpp>

#include <boost/intrusive_ptr.hpp>
#include <boost/ref.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/lcos/detail/future_transforms.hpp
Expand Up @@ -6,6 +6,7 @@
#ifndef HPX_LCOS_DETAIL_FUTURE_TRANSFORMS_HPP
#define HPX_LCOS_DETAIL_FUTURE_TRANSFORMS_HPP

#include <hpx/lcos/detail/future_traits.hpp>
#include <hpx/lcos_fwd.hpp>
#include <hpx/traits/acquire_future.hpp>
#include <hpx/traits/acquire_shared_state.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/lcos/future.hpp
Expand Up @@ -37,6 +37,7 @@
#include <hpx/util/invoke.hpp>
#include <hpx/util/lazy_enable_if.hpp>
#include <hpx/util/result_of.hpp>
#include <hpx/util/serialize_exception.hpp>
#include <hpx/util/steady_clock.hpp>
#include <hpx/util/void_guard.hpp>

Expand Down
26 changes: 26 additions & 0 deletions hpx/lcos/when_all_fwd.hpp
@@ -0,0 +1,26 @@
// Copyright (c) 2018 Hartmut Kaiser
//
// 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)

#if !defined(HPX_LCOS_WHEN_ALL_FWD_HPP)
#define HPX_LCOS_WHEN_ALL_FWD_HPP

#include <hpx/config.hpp>
#include <hpx/lcos_fwd.hpp>

#include <vector>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace lcos
{
// special forwarding function to break #include dependencies
HPX_API_EXPORT hpx::future<void> when_all_fwd(
std::vector<hpx::future<void>>&);

HPX_API_EXPORT hpx::future<void> when_all_fwd(
std::vector<hpx::future<void>>&&);
}}

#endif

1 change: 1 addition & 0 deletions hpx/parallel/executors/default_executor.hpp
Expand Up @@ -9,6 +9,7 @@
#define HPX_PARALLEL_EXECUTORS_DEFAULT_EXECUTOR_AUG_24_2015_0624PM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/parallel/executors/thread_execution_information.hpp>
Expand Down
38 changes: 28 additions & 10 deletions hpx/parallel/executors/execution.hpp
Expand Up @@ -13,9 +13,11 @@
#include <hpx/parallel/executors/execution_fwd.hpp>

#include <hpx/exception_list.hpp>
#include <hpx/lcos/dataflow.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/lcos/wait_all.hpp>
#include <hpx/traits/detail/wrap_int.hpp>
#include <hpx/traits/executor_traits.hpp>
#include <hpx/traits/future_access.hpp>
#include <hpx/traits/future_then_result.hpp>
#include <hpx/traits/future_traits.hpp>
Expand Down Expand Up @@ -1133,6 +1135,7 @@ namespace hpx { namespace parallel { namespace execution
typedef typename bulk_then_execute_result<
F, Shape, Future, Ts...
>::type result_type;

typedef typename hpx::traits::detail::shared_state_ptr<
result_type
>::type shared_state_type;
Expand Down Expand Up @@ -1304,15 +1307,17 @@ namespace hpx { namespace parallel { namespace execution
Future&& predecessor, Ts &&... ts)
-> typename hpx::traits::executor_future<
Executor,
typename then_bulk_function_result<
typename bulk_then_execute_result<
F, Shape, Future, Ts...
>::type
>::type
{
// result_of_t<F(Shape::value_type, Future)>
typedef typename then_bulk_function_result<
F, Shape, Future, Ts...
>::type func_result_type;

// std::vector<future<func_result_type>>
typedef std::vector<typename hpx::traits::executor_future<
Executor, func_result_type, Ts...
>::type> result_type;
Expand All @@ -1321,18 +1326,33 @@ namespace hpx { namespace parallel { namespace execution
exec, std::forward<F>(f), shape,
hpx::util::make_tuple(std::forward<Ts>(ts)...));

// void or std::vector<func_result_type>
typedef typename bulk_then_execute_result<
F, Shape, Future, Ts...
>::type vector_result_type;

// future<vector_result_type>
typedef typename hpx::traits::executor_future<
Executor, vector_result_type
>::type result_future_type;

typedef typename hpx::traits::detail::shared_state_ptr<
result_type
result_future_type
>::type shared_state_type;

typedef typename std::decay<Future>::type future_type;

shared_state_type p =
lcos::detail::make_continuation_exec<result_type>(
lcos::detail::make_continuation_exec<result_future_type>(
std::forward<Future>(predecessor),
std::forward<BulkExecutor>(exec), std::move(func));

typedef typename hpx::traits::executor_future<
Executor, result_type
>::type result_future_type;
std::forward<BulkExecutor>(exec),
[HPX_CAPTURE_MOVE(func)](future_type&& predecessor) mutable
-> result_future_type
{
return hpx::dataflow(
hpx::util::functional::unwrap{},
func(std::move(predecessor)));
});

return hpx::traits::future_access<result_future_type>::create(
std::move(p));
Expand Down Expand Up @@ -1376,7 +1396,5 @@ namespace hpx { namespace parallel { namespace execution
/// \endcond
}}}



#endif

4 changes: 2 additions & 2 deletions hpx/parallel/executors/parallel_executor.hpp
Expand Up @@ -11,7 +11,7 @@
#include <hpx/config.hpp>
#include <hpx/async_launch_policy_dispatch.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/lcos/when_all.hpp>
#include <hpx/lcos/when_all_fwd.hpp>
#include <hpx/parallel/algorithms/detail/predicates.hpp>
#include <hpx/parallel/executors/post_policy_dispatch.hpp>
#include <hpx/parallel/executors/static_chunk_size.hpp>
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace hpx { namespace parallel { namespace execution

HPX_ASSERT(size == 0);

return hpx::when_all(tasks);
return hpx::lcos::when_all_fwd(std::move(tasks));
}

// spawn all tasks sequentially
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/executors/pool_executor.hpp
Expand Up @@ -9,6 +9,7 @@
#define HPX_PARALLEL_EXECUTORS_POOL_EXECUTOR_FEB_17_2018_0327PM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/parallel/executors/thread_execution_information.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/executors/service_executors.hpp
Expand Up @@ -9,6 +9,7 @@
#define HPX_PARALLEL_EXECUTORS_SERVICE_EXECUTORS_MAY_15_2015_0548PM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/parallel/executors/static_chunk_size.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/runtime/threads/executors/service_executors.hpp>
Expand Down
2 changes: 1 addition & 1 deletion hpx/parallel/executors/static_chunk_size.hpp
Expand Up @@ -12,7 +12,7 @@
#include <hpx/runtime/serialization/serialize.hpp>
#include <hpx/traits/is_executor_parameters.hpp>

#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/execution_parameters_fwd.hpp>

#include <cstddef>
#include <type_traits>
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/executors/this_thread_executors.hpp
Expand Up @@ -7,6 +7,7 @@
#define HPX_PARALLEL_EXECUTORS_THIS_THREAD_EXECUTORS_JUL_16_2015_0809PM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/parallel/executors/thread_execution_information.hpp>
Expand Down
24 changes: 20 additions & 4 deletions hpx/parallel/executors/thread_execution.hpp
Expand Up @@ -9,6 +9,7 @@
#define HPX_PARALLEL_EXECUTORS_THREAD_EXECUTION_JAN_03_2017_1145AM

#include <hpx/config.hpp>
#include <hpx/lcos/dataflow.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/lcos/local/futures_factory.hpp>
#include <hpx/runtime/threads/thread_executor.hpp>
Expand Down Expand Up @@ -192,22 +193,37 @@ namespace hpx { namespace threads
>::type func_result_type;

typedef std::vector<hpx::lcos::future<func_result_type> > result_type;
typedef hpx::lcos::future<result_type> result_future_type;

auto func =
parallel::execution::detail::make_fused_bulk_async_execute_helper<
result_type
>(exec, std::forward<F>(f), shape,
hpx::util::make_tuple(std::forward<Ts>(ts)...));

// void or std::vector<func_result_type>
typedef typename parallel::execution::detail::bulk_then_execute_result<
F, Shape, Future, Ts...
>::type vector_result_type;

typedef hpx::future<vector_result_type> result_future_type;

typedef typename hpx::traits::detail::shared_state_ptr<
result_type
result_future_type
>::type shared_state_type;

typedef typename std::decay<Future>::type future_type;

shared_state_type p =
lcos::detail::make_continuation_exec<result_type>(
lcos::detail::make_continuation_exec<result_future_type>(
std::forward<Future>(predecessor),
std::forward<Executor>(exec), std::move(func));
std::forward<Executor>(exec),
[HPX_CAPTURE_MOVE(func)](future_type&& predecessor) mutable
-> result_future_type
{
return hpx::dataflow(
hpx::util::functional::unwrap{},
func(std::move(predecessor)));
});

return hpx::traits::future_access<result_future_type>::create(
std::move(p));
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/executors/thread_pool_executors.hpp
Expand Up @@ -9,6 +9,7 @@
#define HPX_PARALLEL_EXECUTORS_THREAD_POOL_EXECUTORS_MAY_15_2015_0548PM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/parallel/executors/thread_execution_information.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/executors/thread_pool_os_executors.hpp
Expand Up @@ -9,6 +9,7 @@
#define HPX_PARALLEL_EXECUTORS_THREAD_POOL_OS_EXECUTORS_AUG_22_2015_0739PM

#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/parallel/executors/thread_execution_information.hpp>
Expand Down
2 changes: 1 addition & 1 deletion hpx/parallel/task_block.hpp
Expand Up @@ -10,8 +10,8 @@

#include <hpx/config.hpp>
#include <hpx/async.hpp>
#include <hpx/dataflow.hpp>
#include <hpx/exception.hpp>
#include <hpx/lcos/dataflow.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/lcos/local/spinlock.hpp>
#include <hpx/lcos/when_all.hpp>
Expand Down

0 comments on commit 7b7c183

Please sign in to comment.