Skip to content

Commit

Permalink
Replacing facilities from Boost.Range
Browse files Browse the repository at this point in the history
- flyby: fixing MacOS compilation issue
  • Loading branch information
hkaiser committed Dec 6, 2022
1 parent 5212508 commit 2b478f4
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 170 deletions.
Expand Up @@ -14,37 +14,41 @@

#if !defined(HPX_WINDOWS)
#include <hpx/components/process/util/posix/initializers/initializer_base.hpp>
#include <boost/range/algorithm/for_each.hpp>

#include <unistd.h>

namespace hpx { namespace components { namespace process { namespace posix {

namespace initializers {

template <class Range>
class close_fds_ : public initializer_base
{
public:
explicit close_fds_(const Range &fds) : fds_(fds) {}

template <class PosixExecutor>
void on_exec_setup(PosixExecutor&) const
{
boost::for_each(fds_, ::close);
}

private:
Range fds_;
};

template <class Range>
close_fds_<Range> close_fds(const Range &fds)
{
return close_fds_<Range>(fds);
}

}

}}}}
namespace initializers {

template <class Range>
class close_fds_ : public initializer_base
{
public:
explicit close_fds_(const Range& fds)
: fds_(fds)
{
}

template <class PosixExecutor>
void on_exec_setup(PosixExecutor&) const
{
for (auto& fd : fds_)
{
::close(fd);
}
}

private:
Range fds_;
};

template <class Range>
close_fds_<Range> close_fds(const Range& fds)
{
return close_fds_<Range>(fds);
}

}}}}} // namespace hpx::components::process::posix::initializers

#endif
Expand Up @@ -15,10 +15,6 @@
#if !defined(HPX_WINDOWS)
#include <hpx/components/process/util/posix/initializers/initializer_base.hpp>

#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/counting_range.hpp>

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
Expand Down Expand Up @@ -46,13 +42,13 @@ class close_fds_if_ : public initializer_base
template <class PosixExecutor>
void on_exec_setup(PosixExecutor&) const
{
boost::for_each(
boost::adaptors::filter(
boost::counting_range(0, upper_bound()),
pred_
),
close
);
for (int fd = 0; fd != upper_bound(); ++fd)
{
if (pred_(fd))
{
close(fd);
}
}
}

private:
Expand Down
6 changes: 2 additions & 4 deletions examples/1d_stencil/1d_stencil_4.cpp
Expand Up @@ -20,10 +20,9 @@
#include <hpx/local/chrono.hpp>
#include <hpx/local/future.hpp>
#include <hpx/local/init.hpp>
#include <hpx/modules/iterator_support.hpp>
#include <hpx/modules/synchronization.hpp>

#include <boost/range/irange.hpp>

#include <cstddef>
#include <cstdint>
#include <iostream>
Expand Down Expand Up @@ -157,8 +156,7 @@ struct stepper
s.resize(np);

// Initial conditions: f(0, i) = i
std::size_t b = 0;
auto range = boost::irange(b, np);
auto range = hpx::util::counting_shape(np);
using hpx::execution::par;
hpx::ranges::for_each(par, range, [&U, nx](std::size_t i) {
U[0][i] = hpx::make_ready_future(partition_data(nx, double(i)));
Expand Down
9 changes: 3 additions & 6 deletions examples/1d_stencil/1d_stencil_4_repart.cpp
Expand Up @@ -21,15 +21,14 @@

#include <hpx/algorithm.hpp>
#include <hpx/include/performance_counters.hpp>
#include <hpx/modules/iterator_support.hpp>

#if !defined(HPX_HAVE_CXX17_SHARED_PTR_ARRAY)
#include <boost/shared_array.hpp>
#else
#include <memory>
#endif

#include <boost/range/irange.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -264,8 +263,7 @@ struct stepper
if (!data)
{
// Initial conditions: f(0, i) = i
std::size_t b = 0;
auto range = boost::irange(b, np);
auto range = hpx::util::counting_shape(np);
using hpx::execution::par;
hpx::ranges::for_each(par, range, [&U, nx](std::size_t i) {
U[0][i] = hpx::make_ready_future(partition_data(nx, double(i)));
Expand All @@ -274,8 +272,7 @@ struct stepper
else
{
// Initialize from existing data
std::size_t b = 0;
auto range = boost::irange(b, np);
auto range = hpx::util::counting_shape(np);
using hpx::execution::par;
hpx::ranges::for_each(par, range, [&U, nx, data](std::size_t i) {
U[0][i] = hpx::make_ready_future(
Expand Down
7 changes: 3 additions & 4 deletions examples/1d_stencil/1d_stencil_4_throttle.cpp
Expand Up @@ -21,11 +21,11 @@
#include <hpx/hpx_init.hpp>

#include <hpx/algorithm.hpp>
#include <boost/range/irange.hpp>

#include <hpx/include/actions.hpp>
#include <hpx/include/performance_counters.hpp>
#include <hpx/include/util.hpp>
#include <hpx/modules/iterator_support.hpp>

#include "print_time_results.hpp"

#include <cstddef>
Expand Down Expand Up @@ -233,8 +233,7 @@ struct stepper
s.resize(np);

// Initial conditions: f(0, i) = i
std::size_t b = 0;
auto range = boost::irange(b, np);
auto range = hpx::util::counting_shape(np);
using hpx::execution::par;
hpx::ranges::for_each(par, range, [&U, nx](std::size_t i) {
U[0][i] = hpx::make_ready_future(partition_data(nx, double(i)));
Expand Down
17 changes: 0 additions & 17 deletions examples/jacobi/jacobi_component/row_range.hpp
Expand Up @@ -12,9 +12,6 @@
#include <hpx/include/util.hpp>
#include <hpx/modules/memory.hpp>

#include <boost/range/iterator.hpp>
#include <boost/range/mutable_iterator.hpp>

#include <cstddef>
#include <vector>

Expand Down Expand Up @@ -149,18 +146,4 @@ namespace jacobi {
}
} // namespace jacobi

namespace boost {
template <>
struct range_mutable_iterator<jacobi::row_range>
{
typedef std::vector<double>::iterator type;
};

template <>
struct range_const_iterator<jacobi::row_range>
{
typedef std::vector<double>::const_iterator type;
};
} // namespace boost

#endif
24 changes: 16 additions & 8 deletions examples/transpose/transpose_await.cpp
Expand Up @@ -4,15 +4,17 @@
// 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 <hpx/algorithm.hpp>
#include <hpx/assert.hpp>
#if defined(HPX_HAVE_CXX20_COROUTINES)

#include <hpx/hpx.hpp>
#include <hpx/init.hpp>

#include <hpx/algorithm.hpp>
#include <hpx/assert.hpp>
#include <hpx/modules/iterator_support.hpp>
#include <hpx/modules/serialization.hpp>
#include <hpx/numeric.hpp>

#include <boost/range/irange.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -203,7 +205,7 @@ hpx::future<sub_block> transpose_phase(std::vector<block> const& A,
const std::uint64_t from_phase = b;
const std::uint64_t A_offset = from_phase * block_size;

auto phase_range = boost::irange(static_cast<std::uint64_t>(0), num_blocks);
auto phase_range = hpx::util::counting_shape(num_blocks);
for (std::uint64_t phase : phase_range)
{
const std::uint64_t from_block = phase;
Expand Down Expand Up @@ -288,7 +290,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
using hpx::ranges::for_each;

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);
for_each(par, range, [&](std::uint64_t b) {
std::shared_ptr<block_component> A_ptr =
hpx::get_ptr<block_component>(A[b].get_id()).get();
Expand Down Expand Up @@ -317,7 +319,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
{
hpx::chrono::high_resolution_timer t;

auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);

const std::uint64_t block_size = block_order * block_order;
for_each(par, range, [&](std::uint64_t b) {
Expand Down Expand Up @@ -445,7 +447,7 @@ double test_results(std::uint64_t order, std::uint64_t block_order,
using hpx::execution::par;

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);
double errsq = transform_reduce(
par, std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
Expand Down Expand Up @@ -473,3 +475,9 @@ double test_results(std::uint64_t order, std::uint64_t block_order,

return errsq;
}
#else
int main(int, char*[])
{
return 0;
}
#endif
15 changes: 7 additions & 8 deletions examples/transpose/transpose_block.cpp
Expand Up @@ -10,10 +10,9 @@
#include <hpx/hpx_init.hpp>

#include <hpx/algorithm.hpp>
#include <hpx/modules/iterator_support.hpp>
#include <hpx/numeric.hpp>

#include <boost/range/irange.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -263,7 +262,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
using hpx::ranges::for_each;

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);
for_each(par, range, [&](std::uint64_t b) {
std::shared_ptr<block_component> A_ptr =
hpx::get_ptr<block_component>(A[b].get_id()).get();
Expand Down Expand Up @@ -308,7 +307,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
{
hpx::chrono::high_resolution_timer t;

auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);

std::vector<hpx::future<void>> block_futures;
block_futures.resize(num_local_blocks);
Expand All @@ -317,8 +316,8 @@ int hpx_main(hpx::program_options::variables_map& vm)
std::vector<hpx::future<void>> phase_futures;
phase_futures.reserve(num_blocks);

auto phase_range =
boost::irange(static_cast<std::uint64_t>(0), num_blocks);
auto phase_range = hpx::util::counting_shape(
static_cast<std::uint64_t>(0), num_blocks);
for (std::uint64_t phase : phase_range)
{
const std::uint64_t block_size = block_order * block_order;
Expand Down Expand Up @@ -380,7 +379,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
}
{
// unregister names...
auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);
for (auto b : range)
{
hpx::unregister_with_basename(A_block_basename, b);
Expand Down Expand Up @@ -469,7 +468,7 @@ double test_results(std::uint64_t order, std::uint64_t block_order,
using hpx::execution::par;

// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(blocks_start, blocks_end);
auto range = hpx::util::counting_shape(blocks_start, blocks_end);
double errsq = transform_reduce(
par, std::begin(range), std::end(range), 0.0,
[](double lhs, double rhs) { return lhs + rhs; },
Expand Down

0 comments on commit 2b478f4

Please sign in to comment.