ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches

The executor [see Executor.h] on the parallel algorithms of the standard library, beyond the book: StdParExecutor< Policy > runs bulk( n , f ) as std::for_each( Policy() , first , last , g ) on the indices \( 0 , \ldots , n - 1 \), so that the threads are those of the backend of the vendor (oneTBB under libstdc++, the pool of MSVC, the backends of libc++, the threads of nvc++ -stdpar=multicore), and a program that runs only on the standard library does not start the pool of ADS beside them. More...

#include <version>
#include "ADS/Contract.h"
#include "ADS/parallel/Executor.h"
#include <algorithm>
#include <compare>
#include <cstddef>
#include <execution>
#include <iterator>
#include <thread>
#include <type_traits>

Go to the source code of this file.

Classes

class  ADS::StdParExecutor< Policy >
 the executor on a policy of the parallel algorithms of the standard library More...

Namespaces

namespace  ADS

Detailed description

The executor [see Executor.h] on the parallel algorithms of the standard library, beyond the book: StdParExecutor< Policy > runs bulk( n , f ) as std::for_each( Policy() , first , last , g ) on the indices \( 0 , \ldots , n - 1 \), so that the threads are those of the backend of the vendor (oneTBB under libstdc++, the pool of MSVC, the backends of libc++, the threads of nvc++ -stdpar=multicore), and a program that runs only on the standard library does not start the pool of ADS beside them.

The policy is std::execution::par by default; par_unseq is not allowed, since the calls of ADS take locks and wait for each other, which a vectorized policy forbids. The indices come from an iterator of ADS, detail::IndexIterator, since those of std::views::iota are random-access iterators of C++20 but only input iterators of C++17, and the parallel algorithms ask for forward ones. The standard has no query of the threads of a policy, so that concurrency() is the number given to the constructor, the hardware threads by default. The header is compiled where the standard library has the parallel algorithms (__cpp_lib_parallel_algorithm); with libstdc++ and oneTBB on the path the program links oneTBB (-ltbb), which the CMake target ADS::StdPar does.

Nothing is added to the call of the standard library: the calls of bulk() are tasks of the backend, and a call nested in another is a nested for_each, which the backends run as they run their own (oneTBB as its tasks, the others possibly in order on the calling thread). There is no run(), since the standard does not promise that the calls of a parallel algorithm run at the same time.

The contracts [see Contract.h]: \( p \ge 1 \); an exception thrown by \( f \) stops the claims and is thrown again by bulk(), since the standard library calls std::terminate() on an exception that leaves the function of a parallel algorithm.

See also
ISO/IEC 14882:2020, Programming languages, C++, section 25.3 [algorithms.parallel]
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa