Skip to content

Commit

Permalink
(re-)added move()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Nov 20, 2022
1 parent ac53823 commit fdc096b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Build Status](https://github.com/mikekazakov/pstld/actions/workflows/build.yml/badge.svg)

# pstld
Experimental implementation of ParallelSTL on top of GCD aka libdispatch
Experimental implementation of ParallelSTL on top of Grand Central Dispatch aka libdispatch

The purpose of this library is to provide a drop-in implementation of C++ parallel algorithms for the Apple platforms.
Xcode comes with no parallel algorithms in libc++, so this library aims to fill the gap.
Expand Down Expand Up @@ -84,7 +84,7 @@ The library is not complete, this table shows which algorithms are currently ava
25.7.1 | std::copy | ✅ | ✅
| | std::copy_n | ✅ | ✅
| | std::copy_if | ✅ | ❌
25.7.2 | std::move | ✅ |
25.7.2 | std::move | ✅ |
25.7.3 | std::swap_ranges | ✅ | ✅
25.7.4 | std::transform | ✅ | ✅
25.7.5 | std::replace | ✅ | ✅
Expand Down Expand Up @@ -173,6 +173,7 @@ mismatch 0.30 0.67 0.68 1.10 1.10
equal 0.50 0.80 0.76 1.23 1.23 1.27
search 0.50 0.83 1.61 4.22 4.39 4.78
copy 0.29 0.74 0.37 0.73 0.96 1.87
move 0.18 1.09 2.22 1.15 1.11 1.76
swap_ranges 0.35 0.75 0.70 0.80 0.99 1.69
transform 0.14 0.84 0.44 0.76 0.84 2.30
replace 0.12 0.31 0.32 0.85 1.05 1.83
Expand Down
19 changes: 19 additions & 0 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ struct copy { // 25.7.1
}
};

template <class ExPo>
struct move { // 25.7.2
auto operator()(size_t size)
{
std::vector<std::string> v1;
std::vector<std::string> v2;
return measure(
[&] {
v1 = std::vector<std::string>(size, "Small string");
v2 = std::vector<std::string>(size);
},
[&] {
std::move(ExPo{}, v1.begin(), v1.end(), v2.begin());
noopt(v2);
});
}
};

template <class ExPo>
struct swap_ranges { // 25.7.3
auto operator()(size_t size)
Expand Down Expand Up @@ -691,6 +709,7 @@ int main()
results.emplace_back(record<benchmarks::equal>());
results.emplace_back(record<benchmarks::search>());
results.emplace_back(record<benchmarks::copy>());
results.emplace_back(record<benchmarks::move>());
results.emplace_back(record<benchmarks::swap_ranges>());
results.emplace_back(record<benchmarks::transform>());
results.emplace_back(record<benchmarks::replace>());
Expand Down
47 changes: 46 additions & 1 deletion pstld/pstld.h
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,48 @@ FwdIt destroy_n(FwdIt first, Size count) noexcept
return std::destroy_n(first, count);
}

//--------------------------------------------------------------------------------------------------
// move
//--------------------------------------------------------------------------------------------------

namespace internal {

template <class It1, class It2>
struct Move : Dispatchable<Move<It1, It2>> {
Partition<It1> m_partition1;
Partition<It2> m_partition2;

Move(size_t count, size_t chunks, It1 first1, It2 first2)
: m_partition1(first1, count, chunks), m_partition2(first2, count, chunks)
{
}

void run(size_t ind) noexcept
{
auto p1 = m_partition1.at(ind);
auto p2 = m_partition2.at(ind);
std::move(p1.first, p1.last, p2.first);
}
};

} // namespace internal

template <class FwdIt1, class FwdIt2>
FwdIt2 move(FwdIt1 first1, FwdIt1 last1, FwdIt2 first2) noexcept
{
const auto count = std::distance(first1, last1);
const auto chunks = internal::work_chunks_min_fraction_1(count);
if( chunks > 1 ) {
try {
internal::Move<FwdIt1, FwdIt2> op{static_cast<size_t>(count), chunks, first1, first2};
op.dispatch_apply(chunks);
return op.m_partition2.end();
} catch( const internal::parallelism_exception & ) {
}
}
return std::move(first1, last1, first2);
}

#if defined(PSTLD_INTERNAL_ARC)
} // inline namespace arc
#endif
Expand Down Expand Up @@ -3854,7 +3896,10 @@ template <class ExPo, class It1, class It2>
execution::__enable_if_execution_policy<ExPo, It2>
move(ExPo &&, It1 first, It1 last, It2 result) noexcept
{
return ::std::move(first, last, result); // stub only
if constexpr( execution::__pstld_enabled<ExPo> )
return ::pstld::move(first, last, result);
else
return ::std::move(first, last, result);
}

// 25.7.3 - swap_ranges ////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit fdc096b

Please sign in to comment.