[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
Parallel Processing |
Classes | |
class | ParallelOptions |
Option base class for parallel algorithms. More... | |
class | ThreadPool |
Thread pool class to manage a set of parallel workers. More... | |
Functions | |
template<class F > | |
threading::future< void > | enqueue (F &&f) |
template<class F > | |
auto | enqueueReturning (F &&f) -> threading::future< decltype(f(0))> |
template<... > | |
void | parallel_foreach (...) |
Apply a functor to all items in a range in parallel. More... | |
~ThreadPool () | |
void vigra::parallel_foreach | ( | ... | ) |
Apply a functor to all items in a range in parallel.
Declarations:
Create a thread pool (or use an existing one) to apply the functor
[begin, end)
in parallel. size_t
and T
, where the first argument is the thread index (starting at 0) and T is convertible from the iterator's reference_type
(i.e. the result of *begin
).If the iterators are forward iterators (std::forward_iterator_tag
), you can provide the optional argument nItems
to avoid the a std::distance(begin, end)
call to compute the range's length.
Parameter nThreads
controls the number of threads. parallel_foreach
will split the work into about three times as many parallel tasks. If nThreads = ParallelOptions::Auto
, the number of threads is set to the machine default (std::thread::hardware_concurrency()
).
If nThreads = 0
, the function will not use threads, but will call the functor sequentially. This can also be enforced by setting the preprocessor flag VIGRA_SINGLE_THREADED
, ignoring the value of nThreads
(useful for debugging).
Usage:
~ThreadPool | ( | ) |
The destructor joins all threads.
auto enqueueReturning | ( | F && | f | ) | -> threading::future<decltype(f(0))> |
threading::future< void > enqueue | ( | F && | f | ) |
Enqueue function for tasks without return value. This is a special case of the enqueueReturning template function, but some compilers fail on std::result_of<F(int)>::type
for void(int) functions.
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|