From 0cb58f5161233b54daf4ec85b66967051c6313fc Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Fri, 24 Feb 2017 01:34:30 +0100 Subject: [PATCH] Introducing execution- and launch policies --- .../ex.06.pattern-visualizer/main.cpp | 3 + dash/include/dash/Execution.h | 69 +++++++++++++++++++ dash/include/dash/Future.h | 8 ++- dash/include/dash/LaunchPolicy.h | 18 +++-- dash/include/dash/algorithm/Copy.h | 40 ++++++----- dash/include/libdash.h | 17 +++-- 6 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 dash/include/dash/Execution.h diff --git a/dash/examples/ex.06.pattern-visualizer/main.cpp b/dash/examples/ex.06.pattern-visualizer/main.cpp index db5c46e35..f4a7e424e 100644 --- a/dash/examples/ex.06.pattern-visualizer/main.cpp +++ b/dash/examples/ex.06.pattern-visualizer/main.cpp @@ -5,6 +5,9 @@ #include +#include + + using std::cout; using std::cerr; using std::endl; diff --git a/dash/include/dash/Execution.h b/dash/include/dash/Execution.h new file mode 100644 index 000000000..32b4625ed --- /dev/null +++ b/dash/include/dash/Execution.h @@ -0,0 +1,69 @@ +#ifndef DASH__EXECUTION_H__INCLUDED +#define DASH__EXECUTION_H__INCLUDED + +#include + + +namespace dash { + +/** + * Execution policy type trait. + */ +template +struct is_execution_policy +: public std::integral_constant +{ }; + +namespace execution { + + /** + * Sequential execution policy. + */ + class sequenced_policy { }; + + /** + * Parallel execution policy. + */ + class parallel_policy { }; + + /** + * Parallel non-sequential execution policy. + */ + class parallel_unsequenced_policy { }; + + constexpr sequenced_policy seq; + constexpr parallel_policy par; + constexpr parallel_unsequenced_policy par_unseq; + +} // namespace execution + +/** + * Specialization of execution policy type trait for sequential execution + * policy. + */ +template<> +struct is_execution_policy +: public std::integral_constant +{ }; + +/** + * Specialization of execution policy type trait for parallel execution + * policy. + */ +template<> +struct is_execution_policy +: public std::integral_constant +{ }; + +/** + * Specialization of execution policy type trait for parallel non-sequential + * execution policy. + */ +template<> +struct is_execution_policy +: public std::integral_constant +{ }; + +} // namespace dash + +#endif // DASH__EXECUTION_H__INCLUDED diff --git a/dash/include/dash/Future.h b/dash/include/dash/Future.h index ab796ba25..b8cc3b58e 100644 --- a/dash/include/dash/Future.h +++ b/dash/include/dash/Future.h @@ -1,14 +1,16 @@ #ifndef DASH__FUTURE_H__INCLUDED #define DASH__FUTURE_H__INCLUDED +#include +#include + +#include + #include #include #include #include -#include -#include - namespace dash { diff --git a/dash/include/dash/LaunchPolicy.h b/dash/include/dash/LaunchPolicy.h index 6e7e11c43..9cf9f2954 100644 --- a/dash/include/dash/LaunchPolicy.h +++ b/dash/include/dash/LaunchPolicy.h @@ -1,18 +1,22 @@ -#ifndef DASH__LAUNCH__H__INCLUDED -#define DASH__LAUNCH__H__INCLUDED +#ifndef DASH__LAUNCH_POLICY_H__INCLUDED +#define DASH__LAUNCH_POLICY_H__INCLUDED #include namespace dash { enum class launch : uint16_t { -/// synchronous launch policy -sync = 0x1, -/// async launch policy -async = 0x2 + /// synchronous launch policy + sync = 0x1, + /// async launch policy + async = 0x2, + /// deferred launch policy + deferred = 0x4, + /// unspecified launch policy + any = sync | async | deferred }; } -#endif // DASH__LAUNCH__H__INCLUDED +#endif // DASH__LAUNCH_POLICY_H__INCLUDED diff --git a/dash/include/dash/algorithm/Copy.h b/dash/include/dash/algorithm/Copy.h index 77e85ae9d..cfed4646d 100644 --- a/dash/include/dash/algorithm/Copy.h +++ b/dash/include/dash/algorithm/Copy.h @@ -49,7 +49,7 @@ namespace dash { * \ingroup DashAlgorithms */ template < - typename ValueType, + class ValueType, class InputIt, class OutputIt > OutputIt copy( @@ -58,23 +58,28 @@ OutputIt copy( OutputIt out_first); /** - * Asynchronous variant of \c dash::copy. + * Asynchronous or deferred execution of \c dash::copy. * Copies the elements in the range, defined by \c [in_first, in_last), to * another range beginning at \c out_first. * * In terms of data distribution, source and destination ranges passed to - * \c dash::copy can be local (\c *ValueType) or global (\c GlobIter). + * \c dash::copy can be + * + * - local (\c *ValueType) + * - or global (\c GlobIter) * - * For a blocking variant of \c dash::copy_async, see \c dash::copy. + * For a blocking variant, see \c dash::copy without launch policy parameter. * * Example: * * \code * // Start asynchronous copying * dash::Future fut_dest_end = - * dash::copy_async(array_a.block(0).begin(), - * array_a.block(0).end(), - * local_array); + * dash::copy( + * dash::launch::async, + * array_a.block(0).begin(), + * array_a.block(0).end(), + * local_array); * // Overlapping computation here * // ... * // Wait for completion of asynchronous copying: @@ -88,12 +93,14 @@ OutputIt copy( * \ingroup DashAlgorithms */ template < - typename ValueType, + class ExecutionPolicy, + class ValueType, class GlobInputIt > -dash::Future copy_async( - InputIt in_first, - InputIt in_last, - OutputIt out_first); +dash::Future copy( + ExecutionPolicy && policy, + InputIt in_first, + InputIt in_last, + OutputIt out_first); #else // DOXYGEN @@ -1028,15 +1035,14 @@ ValueType * copy( template < typename ValueType, class GlobOutputIt > -dash::Future copy_async( +constexpr dash::Future copy_async( ValueType * in_first, ValueType * in_last, GlobOutputIt out_first) { - auto fut = dash::internal::copy_async_impl(in_first, - in_last, - out_first); - return fut; + return dash::internal::copy_async_impl(in_first, + in_last, + out_first); } /** diff --git a/dash/include/libdash.h b/dash/include/libdash.h index a8af19ddf..9ad6d0f8d 100644 --- a/dash/include/libdash.h +++ b/dash/include/libdash.h @@ -33,17 +33,26 @@ namespace dash { #include +#include +#include #include +#include + #include +#include +#include +#include +#include + +#include + #include #include + #include #include #include -#include - -#include #include #include @@ -63,6 +72,4 @@ namespace dash { #include #include -#include - #endif // DASH__LIBDASH_H_