Skip to content

Commit

Permalink
Merge pull request #2018 from STEllAR-GROUP/for_loop_algorithms
Browse files Browse the repository at this point in the history
For loop algorithms
  • Loading branch information
hkaiser committed Mar 16, 2016
2 parents 2c05ddf + bd1c01c commit fc3d1bf
Show file tree
Hide file tree
Showing 61 changed files with 3,289 additions and 423 deletions.
11 changes: 8 additions & 3 deletions docs/CMakeLists.txt
Expand Up @@ -68,6 +68,9 @@ set(doxygen_dependencies
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/fill.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/find.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/for_each.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/for_loop.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/for_loop_induction.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/for_loop_reduction.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/generate.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/includes.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/inclusive_scan.hpp"
Expand Down Expand Up @@ -182,10 +185,12 @@ set(doxygen_definition_list
"HPX_EXPORT="
"HPX_API_EXPORT="
"HPX_ALWAYS_EXPORT="
"HPX_STD_FUNCTION=std::function"
"extern="
"BOOST_NOEXCEPT="
"HPX_INLINE_NAMESPACE(x)=namespace x")
"HPX_NOEXCEPT="
"HPX_CONSTEXPR="
"HPX_FORCEINLINE="
"HPX_INLINE_NAMESPACE(x)=namespace x"
"HPX_CONCEPT_REQUIRES_(x)=")

#############################################################################
# Definitions for autodoc.doxy.in
Expand Down
21 changes: 19 additions & 2 deletions docs/hpx.idx
Expand Up @@ -176,11 +176,18 @@ parallel::find_end "find_end" "hpx\.parallel\.v1\.find_end.*"
parallel::find_first_of "find_first_of" "hpx\.parallel\.v1\.find_first_of.*"

# hpx/parallel/algorithms/for_each.hpp
parallel::for_each "for_each" "hpx\.parallel\.v1\.for_each$"
parallel::for_each "for_each" "hpx\.parallel\.v1\.for_each_id.*"
parallel::for_each_n "for_each_n" "hpx\.parallel\.v1\.for_each_n.*"

# hpx/parallel/algorithms/for_loop.hpp
parallel::for_loop "for_loop" "hpx\.parallel\.v2\.for_loop_id.*"
parallel::for_loop_strided "for_loop_strided" "hpx\.parallel\.v2\.for_loop_strided_id.*"

# hpx/parallel/algorithms/for_loop_induction.hpp
parallel::induction "induction" "hpx\.parallel\.v2\.induction"

# hpx/parallel/algorithms/generate.hpp
parallel::generate "generate" "hpx\.parallel\.v1\.generate$"
parallel::generate "generate" "hpx\.parallel\.v1\.generate_id.*"
parallel::generate_n "generate_n" "hpx\.parallel\.v1\.generate_n.*"

# hpx/parallel/algorithms/includes.hpp
Expand Down Expand Up @@ -216,6 +223,16 @@ parallel::move "move" "hpx\.parallel\.v1\.move$"
# hpx/parallel/algorithms/reduce.hpp
parallel::reduce "reduce" "hpx\.parallel\.v1\.reduce.*"

# hpx/parallel/algorithms/for_loop_reduction.hpp
parallel::reduction "reduction" "hpx\.parallel\.v2\.reduction"
parallel::reduction_plus "reduction_plus" "hpx\.parallel\.v2\.reduction_plus"
parallel::reduction_multiplies "reduction_multiplies" "hpx\.parallel\.v2\.reduction_multiplies"
parallel::reduction_bit_and "reduction_bit_and" "hpx\.parallel\.v2\.reduction_bit_and"
parallel::reduction_bit_or "reduction_bit_or" "hpx\.parallel\.v2\.reduction_bit_or"
parallel::reduction_bit_xor "reduction_bit_xor" "hpx\.parallel\.v2\.reduction_bit_xor"
parallel::reduction_min "reduction_min" "hpx\.parallel\.v2\.reduction_min"
parallel::reduction_max "reduction_max" "hpx\.parallel\.v2\.reduction_max"

# hpx/parallel/algorithms/remove_copy.hpp
parallel::remove_copy "remove_copy" "hpx\.parallel\.v1\.remove_copy$"
parallel::remove_copy_if "remove_copy_if" "hpx\.parallel\.v1\.remove_copy_if.*"
Expand Down
12 changes: 12 additions & 0 deletions hpx/include/parallel_for_loop.hpp
@@ -0,0 +1,12 @@
// Copyright (c) 2007-2016 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_PARALLEL_FOR_LOOP_MAR_04_2016_0654PM)
#define HPX_PARALLEL_FOR_LOOP_MAR_04_2016_0654PM

#include <hpx/parallel/algorithms/for_loop.hpp>

#endif

6 changes: 5 additions & 1 deletion hpx/parallel/algorithm.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2014 Grant Mercer
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -12,6 +12,7 @@
/// See N4310: 1.3/3
#include <algorithm>

// Parallelism TS V1
#include <hpx/parallel/algorithms/adjacent_find.hpp>
#include <hpx/parallel/algorithms/all_any_none.hpp>
#include <hpx/parallel/algorithms/copy.hpp>
Expand Down Expand Up @@ -40,4 +41,7 @@
#include <hpx/parallel/algorithms/sort.hpp>
#include <hpx/parallel/algorithms/swap_ranges.hpp>

// Parallelism TS V2
#include <hpx/parallel/algorithms/for_loop.hpp>

#endif
3 changes: 2 additions & 1 deletion hpx/parallel/algorithms/adjacent_find.hpp
Expand Up @@ -72,7 +72,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)

return util::partitioner<ExPolicy, FwdIter, void>::
call_with_index(
policy, hpx::util::make_zip_iterator(first, next), count-1,
policy, hpx::util::make_zip_iterator(first, next),
count-1, 1,
[op, tok](std::size_t base_idx, zip_iterator it,
std::size_t part_size) mutable
{
Expand Down
1 change: 0 additions & 1 deletion hpx/parallel/algorithms/all_any_none.hpp
Expand Up @@ -15,7 +15,6 @@
#include <hpx/parallel/config/inline_namespace.hpp>
#include <hpx/parallel/execution_policy.hpp>
#include <hpx/parallel/algorithms/detail/dispatch.hpp>
#include <hpx/parallel/algorithms/detail/is_negative.hpp>
#include <hpx/parallel/util/detail/algorithm_result.hpp>
#include <hpx/parallel/util/partitioner.hpp>
#include <hpx/parallel/util/loop.hpp>
Expand Down
16 changes: 9 additions & 7 deletions hpx/parallel/algorithms/copy.hpp
Expand Up @@ -11,11 +11,13 @@

#include <hpx/config.hpp>
#include <hpx/traits/concepts.hpp>
#include <hpx/traits/is_iterator.hpp>
#include <hpx/util/invoke.hpp>
#include <hpx/util/tagged_pair.hpp>

#include <hpx/parallel/execution_policy.hpp>
#include <hpx/parallel/tagspec.hpp>
#include <hpx/parallel/algorithms/detail/is_negative.hpp>
#include <hpx/parallel/algorithms/detail/predicates.hpp>
#include <hpx/parallel/algorithms/detail/dispatch.hpp>
#include <hpx/parallel/algorithms/for_each.hpp>
Expand Down Expand Up @@ -177,8 +179,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
template <typename ExPolicy, typename InIter, typename OutIter,
HPX_CONCEPT_REQUIRES_(
is_execution_policy<ExPolicy>::value &&
traits::is_iterator<InIter>::value &&
traits::is_iterator<OutIter>::value)>
hpx::traits::is_iterator<InIter>::value &&
hpx::traits::is_iterator<OutIter>::value)>
typename util::detail::algorithm_result<
ExPolicy, hpx::util::tagged_pair<tag::in(InIter), tag::out(OutIter)>
>::type
Expand Down Expand Up @@ -330,8 +332,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
typename OutIter,
HPX_CONCEPT_REQUIRES_(
is_execution_policy<ExPolicy>::value &&
traits::is_iterator<InIter>::value &&
traits::is_iterator<OutIter>::value)>
hpx::traits::is_iterator<InIter>::value &&
hpx::traits::is_iterator<OutIter>::value)>
typename util::detail::algorithm_result<
ExPolicy, hpx::util::tagged_pair<tag::in(InIter), tag::out(OutIter)>
>::type
Expand Down Expand Up @@ -360,7 +362,7 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
using hpx::util::make_tagged_pair;

// if count is representing a negative value, we do nothing
if (detail::is_negative<Size>::call(count))
if (detail::is_negative(count))
{
return util::detail::algorithm_result<
ExPolicy, tagged_pair<tag::in(InIter), tag::out(OutIter)>
Expand Down Expand Up @@ -577,8 +579,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
typename Proj = util::projection_identity,
HPX_CONCEPT_REQUIRES_(
is_execution_policy<ExPolicy>::value &&
traits::is_iterator<InIter>::value &&
traits::is_iterator<OutIter>::value &&
hpx::traits::is_iterator<InIter>::value &&
hpx::traits::is_iterator<OutIter>::value &&
traits::is_projected<Proj, InIter>::value &&
traits::is_indirect_callable<
F, traits::projected<Proj, InIter>
Expand Down
53 changes: 43 additions & 10 deletions hpx/parallel/algorithms/detail/is_negative.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2016 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)
Expand All @@ -14,23 +14,56 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1) { namespace detail
{
// main template represents non-integral types (raises error)
template <typename Size, typename Enable = void>
struct is_negative;
struct is_negative_helper;

// signed integral values may be negative
template <typename Size>
struct is_negative<Size,
typename boost::enable_if<boost::is_signed<Size> >::type>
template <typename T>
struct is_negative_helper<T,
typename boost::enable_if<boost::is_signed<T> >::type>
{
static bool call(Size const& size) { return size < 0; }
static bool call(T const& size) { return size < 0; }

static T abs(T const& val) { return val < 0 ? -val : val; }

static T negate(T const& val)
{
return -val;
}
};

// unsigned integral values are never negative
template <typename Size>
struct is_negative<Size,
typename boost::enable_if<boost::is_unsigned<Size> >::type>
template <typename T>
struct is_negative_helper<T,
typename boost::enable_if<boost::is_unsigned<T> >::type>
{
static bool call(Size const&) { return false; }
static bool call(T const&) { return false; }

static T abs(T const& val) { return val; }

static T negate(T const& val)
{
return val;
}
};

///////////////////////////////////////////////////////////////////////////
template <typename T>
bool is_negative(T const& val)
{
return is_negative_helper<T>::call(val);
}

template <typename T>
T abs(T const& val)
{
return is_negative_helper<T>::abs(val);
}

template <typename T>
T negate(T const& val)
{
return is_negative_helper<T>::negate(val);
}
}}}}

#endif
Expand Down

0 comments on commit fc3d1bf

Please sign in to comment.