Part one – Copy elements in parallel into the destination range

The first part copies the elements in chunks, resulting in the sparse destination illustrated in the following figure. Each chunk is conditionally copied in parallel, and the resulting range iterators are stored in the future for later retrieval:

Sparse destination range after first step of conditional copy
The following code implements the algorithm:
template <typename SrcIt, typename DstIt, typename Pred> 
auto par_copy_if_split(SrcIt first,SrcIt last,DstIt dst,Pred pred,size_t chunk_sz){ 
  // Part #1: Perform conditional copy in parallel auto n = static_cast<size_t>(std::distance(first, ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.