|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Parallel functional programming utilities (ah-parallel.H): map/filter/fold/predicates/zip/sort. More...
#include <ah-parallel.H>#include <iostream>#include <iomanip>#include <vector>#include <cmath>#include <chrono>#include <numeric>#include <random>#include <string>Go to the source code of this file.
Functions | |
| void | print_header (const std::string &title) |
| void | example_parallel_map () |
| void | example_parallel_filter () |
| void | example_parallel_fold () |
| void | example_parallel_predicates () |
| void | example_parallel_find () |
| void | example_parallel_aggregations () |
| void | example_parallel_sort () |
| void | example_parallel_zip () |
| void | example_variadic_zip () |
| void | example_parallel_enumerate () |
| void | example_performance_comparison () |
| int | main () |
Parallel functional programming utilities (ah-parallel.H): map/filter/fold/predicates/zip/sort.
This example demonstrates Aleph-w's parallel functional programming helpers from ah-parallel.H. The API provides ML-style operations (map, filter, fold, predicates, etc.) that execute in parallel using an Aleph::ThreadPool.
The file is structured as a series of demos covering:
std::vector<int>, std::vector<double>, std::vector<std::string>ThreadPool pool(std::thread::hardware_concurrency())This example has no command-line options; it runs all demos.
Common signature pattern:
ThreadPool&Core operations demonstrated:
pmaps(pool, container, f)pfilter(pool, container, pred)pfoldl(pool, container, init, op)pall / pexists / pnone / pcount_ifpfind / pfind_valuepsum / pproduct / pmin / pmaxpsortpzip_*, penumerate_*Asymptotically, most operations have the same work complexity as the sequential version (e.g. O(n) for map/filter), but with wall-clock time reduced by parallelization.
Actual speedups depend on:
pfoldl, the binary operator should be associative to ensure that parallel reduction is well-defined.pall, pexists, pfind) may stop early.ah-parallel.Hthread_pool_example.cc (ThreadPool usage) Definition in file ah_parallel_example.cc.
| void example_parallel_aggregations | ( | ) |
Definition at line 358 of file ah_parallel_example.cc.
References Aleph::maps(), Aleph::mean(), Aleph::pmax(), Aleph::pmin(), Aleph::pminmax(), print_header(), Aleph::psum(), rng, and Aleph::sum().
Referenced by main().
| void example_parallel_enumerate | ( | ) |
Definition at line 584 of file ah_parallel_example.cc.
References Aleph::maps(), Aleph::penumerate_for_each(), Aleph::penumerate_maps(), and print_header().
Referenced by main().
| void example_parallel_filter | ( | ) |
Definition at line 163 of file ah_parallel_example.cc.
References StlAlephIterator< SetName >::begin(), StlAlephIterator< SetName >::end(), is_prime(), Aleph::maps(), Aleph::pfilter(), primes, print_header(), and Aleph::HTList::size().
Referenced by main().
| void example_parallel_find | ( | ) |
Definition at line 314 of file ah_parallel_example.cc.
References Aleph::maps(), Aleph::pfind(), Aleph::pfind_value(), print_header(), and rng.
Referenced by main().
| void example_parallel_fold | ( | ) |
Definition at line 222 of file ah_parallel_example.cc.
References Aleph::maps(), Aleph::pfoldl(), print_header(), Aleph::psum(), and Aleph::sum().
Referenced by main().
| void example_parallel_map | ( | ) |
Definition at line 113 of file ah_parallel_example.cc.
References StlAlephIterator< SetName >::begin(), StlAlephIterator< SetName >::end(), Aleph::maps(), Aleph::ThreadPool::num_threads(), Aleph::pmaps(), print_header(), and Aleph::HTList::size().
Referenced by main().
| void example_parallel_predicates | ( | ) |
Definition at line 268 of file ah_parallel_example.cc.
References Aleph::maps(), Aleph::pall(), Aleph::pcount_if(), Aleph::pexists(), Aleph::pnone(), and print_header().
Referenced by main().
| void example_parallel_sort | ( | ) |
Definition at line 404 of file ah_parallel_example.cc.
References Aleph::is_sorted(), Aleph::maps(), print_header(), Aleph::psort(), and rng.
Referenced by main().
| void example_parallel_zip | ( | ) |
Definition at line 458 of file ah_parallel_example.cc.
References Aleph::maps(), print_header(), Aleph::pzip_foldl(), Aleph::pzip_for_each(), Aleph::pzip_maps(), Aleph::sum(), and y.
Referenced by main().
| void example_performance_comparison | ( | ) |
Definition at line 625 of file ah_parallel_example.cc.
References StlAlephIterator< SetName >::begin(), StlAlephIterator< SetName >::end(), Aleph::maps(), Aleph::ThreadPool::num_threads(), Aleph::pmaps(), and print_header().
Referenced by main().
| void example_variadic_zip | ( | ) |
Definition at line 516 of file ah_parallel_example.cc.
References Aleph::count(), Aleph::maps(), print_header(), Aleph::pzip_all_n(), Aleph::pzip_count_if_n(), Aleph::pzip_maps_n(), and y.
Referenced by main().
| int main | ( | ) |
Definition at line 690 of file ah_parallel_example.cc.
References example_parallel_aggregations(), example_parallel_enumerate(), example_parallel_filter(), example_parallel_find(), example_parallel_fold(), example_parallel_map(), example_parallel_predicates(), example_parallel_sort(), example_parallel_zip(), example_performance_comparison(), and example_variadic_zip().
| void print_header | ( | const std::string & | title | ) |
Definition at line 93 of file ah_parallel_example.cc.
References Aleph::maps().