Skip to content

Commit

Permalink
Merge pull request #2734 from STEllAR-GROUP/range
Browse files Browse the repository at this point in the history
Add C++11 range utilities
  • Loading branch information
hkaiser committed Jul 6, 2017
2 parents cdaac22 + 9a45b37 commit f819772
Show file tree
Hide file tree
Showing 242 changed files with 4,171 additions and 4,069 deletions.
7 changes: 7 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -439,6 +439,13 @@ macro(hpx_check_for_cxx11_std_lock_guard)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_range_access)
add_hpx_config_test(HPX_WITH_CXX11_RANGE_ACCESS
SOURCE cmake/tests/cxx11_std_range_access.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_reference_wrapper)
add_hpx_config_test(HPX_WITH_CXX11_REFERENCE_WRAPPER
Expand Down
3 changes: 3 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Expand Up @@ -106,6 +106,9 @@ macro(hpx_perform_cxx_feature_tests)
hpx_check_for_cxx11_std_lock_guard(
REQUIRED "HPX needs support for C++11 std::lock_guard")

hpx_check_for_cxx11_std_range_access(
REQUIRED "HPX needs support for C++11 std::begin/end")

hpx_check_for_cxx11_std_reference_wrapper(
REQUIRED "HPX needs support for C++11 std::ref and std::reference_wrapper")

Expand Down
20 changes: 20 additions & 0 deletions cmake/tests/cxx11_std_range_access.cpp
@@ -0,0 +1,20 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016 Agustin Berge
//
// 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)
////////////////////////////////////////////////////////////////////////////////

#include <iterator>
#include <vector>

int main()
{
int array[3] = { 0, 1, 2 };
int* array_begin = std::begin(array);
int* array_end = std::begin(array);

std::vector<int> vector(3);
std::vector<int>::iterator vector_begin = std::begin(vector);
std::vector<int>::iterator vector_end = std::begin(vector);
};
2 changes: 1 addition & 1 deletion examples/1d_stencil/1d_stencil_4.cpp
Expand Up @@ -144,7 +144,7 @@ struct stepper
std::size_t b = 0;
auto range = boost::irange(b, np);
using hpx::parallel::execution::par;
hpx::parallel::for_each(par, boost::begin(range), boost::end(range),
hpx::parallel::for_each(par, std::begin(range), std::end(range),
[&U, nx](std::size_t i)
{
U[0][i] = hpx::make_ready_future(partition_data(nx, double(i)));
Expand Down
4 changes: 2 additions & 2 deletions examples/1d_stencil/1d_stencil_4_repart.cpp
Expand Up @@ -232,7 +232,7 @@ struct stepper
auto range = boost::irange(b, np);
using hpx::parallel::execution::par;
hpx::parallel::for_each(
par, boost::begin(range), boost::end(range),
par, std::begin(range), std::end(range),
[&U, nx](std::size_t i)
{
U[0][i] = hpx::make_ready_future(
Expand All @@ -246,7 +246,7 @@ struct stepper
auto range = boost::irange(b, np);
using hpx::parallel::execution::par;
hpx::parallel::for_each(
par, boost::begin(range), boost::end(range),
par, std::begin(range), std::end(range),
[&U, nx, data](std::size_t i)
{
U[0][i] = hpx::make_ready_future(
Expand Down
3 changes: 1 addition & 2 deletions examples/1d_stencil/1d_stencil_4_throttle.cpp
Expand Up @@ -213,8 +213,7 @@ struct stepper
std::size_t b = 0;
auto range = boost::irange(b, np);
using hpx::parallel::execution::par;
hpx::parallel::for_each(par,
boost::begin(range), boost::end(range),
hpx::parallel::for_each(par, std::begin(range), std::end(range),
[&U, nx](std::size_t i)
{
U[0][i] = hpx::make_ready_future(partition_data(nx, double(i)));
Expand Down
4 changes: 2 additions & 2 deletions examples/quickstart/pipeline1.cpp
Expand Up @@ -7,12 +7,12 @@
#include <hpx/hpx_main.hpp>

#include <iostream>
#include <iterator>
#include <string>
#include <utility>
#include <vector>

#include <boost/algorithm/string/trim.hpp>
#include <boost/range/functions.hpp>
#include <boost/regex.hpp>

struct pipeline
Expand Down Expand Up @@ -58,7 +58,7 @@ int main()
"Notice: qux",
"\tError: abc"
};
std::vector<std::string> input(boost::begin(inputs), boost::end(inputs));
std::vector<std::string> input(std::begin(inputs), std::end(inputs));

pipeline::process(input);

Expand Down
7 changes: 3 additions & 4 deletions examples/quickstart/safe_object.cpp
Expand Up @@ -7,11 +7,10 @@
#include <hpx/hpx_init.hpp>
#include <hpx/include/parallel_algorithm.hpp>

#include <boost/range/functions.hpp>

#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -67,7 +66,7 @@ struct safe_object
std::vector<int> random_fill(std::size_t size)
{
std::vector<int> c(size);
std::generate(boost::begin(c), boost::end(c), std::rand);
std::generate(std::begin(c), std::end(c), std::rand);
return c;
}

Expand All @@ -86,7 +85,7 @@ int hpx_main(int argc, char* argv[])

// run a parallel loop to demonstrate thread safety of safe-object
safe_object<std::vector<int> > ho;
for_each(par, boost::begin(data), boost::end(data),
for_each(par, std::begin(data), std::end(data),
[&ho](int d)
{
if (satisfies_criteria(d))
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart/vector_counting_dotproduct.cpp
Expand Up @@ -10,9 +10,9 @@
#include <hpx/include/iostreams.hpp>

#include <boost/iterator/counting_iterator.hpp>
#include <boost/range/functions.hpp>

#include <algorithm>
#include <iterator>
#include <string>
#include <vector>

Expand All @@ -22,8 +22,8 @@ int hpx_main()
// lets say we have two vectors that simulate.. 10007D
std::vector<double> xvalues(10007);
std::vector<double> yvalues(10007);
std::fill(boost::begin(xvalues), boost::end(xvalues), 1.0);
std::fill(boost::begin(yvalues), boost::end(yvalues), 1.0);
std::fill(std::begin(xvalues), std::end(xvalues), 1.0);
std::fill(std::begin(yvalues), std::end(yvalues), 1.0);

double result =
hpx::parallel::transform_reduce(
Expand Down
11 changes: 5 additions & 6 deletions examples/quickstart/vector_zip_dotproduct.cpp
Expand Up @@ -9,8 +9,7 @@
#include <hpx/include/parallel_algorithm.hpp>
#include <hpx/include/iostreams.hpp>

#include <boost/range/functions.hpp>

#include <iterator>
#include <string>
#include <vector>

Expand All @@ -20,8 +19,8 @@ int hpx_main()
// lets say we have two vectors that simulate.. 10007D
std::vector<double> xvalues(10007);
std::vector<double> yvalues(10007);
std::fill(boost::begin(xvalues), boost::end(xvalues), 1.0);
std::fill(boost::begin(yvalues), boost::end(yvalues), 1.0);
std::fill(std::begin(xvalues), std::end(xvalues), 1.0);
std::fill(std::begin(yvalues), std::end(yvalues), 1.0);

using hpx::util::make_zip_iterator;
using hpx::util::tuple;
Expand All @@ -30,8 +29,8 @@ int hpx_main()
double result =
hpx::parallel::transform_reduce(
hpx::parallel::execution::par,
make_zip_iterator(boost::begin(xvalues), boost::begin(yvalues)),
make_zip_iterator(boost::end(xvalues), boost::end(yvalues)),
make_zip_iterator(std::begin(xvalues), std::begin(yvalues)),
make_zip_iterator(std::end(xvalues), std::end(yvalues)),
0.0,
std::plus<double>(),
[](tuple<double, double> r)
Expand Down
6 changes: 3 additions & 3 deletions examples/transpose/transpose_await.cpp
Expand Up @@ -282,7 +282,7 @@ int hpx_main(boost::program_options::variables_map& vm)

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
std::shared_ptr<block_component> A_ptr =
Expand Down Expand Up @@ -314,7 +314,7 @@ int hpx_main(boost::program_options::variables_map& vm)
auto range = boost::irange(blocks_start, blocks_end);

const std::uint64_t block_size = block_order * block_order;
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
transpose_phase(A, B, block_order, b,
Expand Down Expand Up @@ -439,7 +439,7 @@ double test_results(std::uint64_t order, std::uint64_t block_order,
// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
double errsq =
transform_reduce(par, boost::begin(range), boost::end(range), 0.0,
transform_reduce(par, std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
[&](std::uint64_t b) -> double
{
Expand Down
6 changes: 3 additions & 3 deletions examples/transpose/transpose_block.cpp
Expand Up @@ -247,7 +247,7 @@ int hpx_main(boost::program_options::variables_map& vm)

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
std::shared_ptr<block_component> A_ptr =
Expand Down Expand Up @@ -297,7 +297,7 @@ int hpx_main(boost::program_options::variables_map& vm)
std::vector<hpx::future<void> > block_futures;
block_futures.resize(num_local_blocks);

for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
std::vector<hpx::future<void> > phase_futures;
Expand Down Expand Up @@ -451,7 +451,7 @@ double test_results(std::uint64_t order, std::uint64_t block_order,
// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
double errsq =
transform_reduce(par, boost::begin(range), boost::end(range), 0.0,
transform_reduce(par, std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
[&](std::uint64_t b) -> double
{
Expand Down
10 changes: 5 additions & 5 deletions examples/transpose/transpose_block_numa.cpp
Expand Up @@ -356,7 +356,7 @@ int hpx_main(boost::program_options::variables_map& vm)

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
std::shared_ptr<block_component> A_ptr =
Expand Down Expand Up @@ -418,15 +418,15 @@ int hpx_main(boost::program_options::variables_map& vm)

auto range = numa_ranges[domain];

std::uint64_t block_start = *boost::begin(range);
std::uint64_t block_end = *boost::end(range);
std::uint64_t block_start = *std::begin(range);
std::uint64_t block_end = *std::end(range);
std::uint64_t blocks_size = block_end - block_start;

std::vector<hpx::future<void> > block_futures;
block_futures.resize(blocks_size);

for_each(par.on(execs[domain]),
boost::begin(range), boost::end(range),
std::begin(range), std::end(range),
[
domain, &block_futures, num_blocks,
block_start, block_order, tile_size, &A, &B
Expand Down Expand Up @@ -649,7 +649,7 @@ double test_results(std::uint64_t order, std::uint64_t block_order,
double errsq =
transform_reduce(
par.on(execs[domain]),
boost::begin(range), boost::end(range), 0.0,
std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
[&](std::uint64_t b) -> double
{
Expand Down
8 changes: 4 additions & 4 deletions examples/transpose/transpose_smp.cpp
Expand Up @@ -59,7 +59,7 @@ int hpx_main(boost::program_options::variables_map& vm)
// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(start, order);
// parallel for
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t i)
{
for(std::uint64_t j = 0; j < order; ++j)
Expand All @@ -82,7 +82,7 @@ int hpx_main(boost::program_options::variables_map& vm)
{
auto range = boost::irange(start, order+tile_size, tile_size);
// parallel for
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t i)
{
for(std::uint64_t j = 0; j < order; j += tile_size)
Expand All @@ -105,7 +105,7 @@ int hpx_main(boost::program_options::variables_map& vm)
{
auto range = boost::irange(start, order);
// parallel for
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t i)
{
for(std::uint64_t j = 0; j < order; ++j)
Expand Down Expand Up @@ -186,7 +186,7 @@ double test_results(std::uint64_t order, std::vector<double> const & trans)
auto range = boost::irange(start, order);
// parallel reduce
double errsq =
transform_reduce(par, boost::begin(range), boost::end(range), 0.0,
transform_reduce(par, std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
[&](std::uint64_t i) -> double
{
Expand Down
8 changes: 4 additions & 4 deletions examples/transpose/transpose_smp_block.cpp
Expand Up @@ -69,7 +69,7 @@ int hpx_main(boost::program_options::variables_map& vm)

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(start, num_blocks);
for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
for(std::uint64_t i = 0; i < order; ++i)
Expand Down Expand Up @@ -99,12 +99,12 @@ int hpx_main(boost::program_options::variables_map& vm)
std::vector<hpx::shared_future<void> > transpose_futures;
transpose_futures.resize(num_blocks);

for_each(par, boost::begin(range), boost::end(range),
for_each(par, std::begin(range), std::end(range),
[&](std::uint64_t b)
{
transpose_futures[b] =
for_each(par(task),
boost::begin(range), boost::end(range),
std::begin(range), std::end(range),
[&, b](std::uint64_t phase)
{
const std::uint64_t block_size = block_order * block_order;
Expand Down Expand Up @@ -230,7 +230,7 @@ double test_results(std::uint64_t order, std::uint64_t block_order,
// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(start, end);
double errsq =
transform_reduce(par, boost::begin(range), boost::end(range), 0.0,
transform_reduce(par, std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
[&](std::uint64_t b) -> double
{
Expand Down
8 changes: 1 addition & 7 deletions hpx/compute/cuda/concurrent_executor.hpp
Expand Up @@ -169,13 +169,7 @@ namespace hpx { namespace compute { namespace cuda
std::vector<hpx::future<void> >
bulk_async_execute(F && f, Shape const& shape, Ts &&... ts)
{
// Before Boost V1.56 boost::size() does not respect the iterator category of
// its argument.
#if BOOST_VERSION < 105600
std::size_t cnt = std::distance(boost::begin(shape), boost::end(shape));
#else
std::size_t cnt = boost::size(shape);
#endif
std::size_t cnt = util::size(shape);
std::vector<hpx::future<void> > result;
result.reserve(cnt);

Expand Down

0 comments on commit f819772

Please sign in to comment.