libstdc++
for_each.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10 
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file parallel/for_each.h
26  * @brief Main interface for embarrassingly parallel functions.
27  *
28  * The explicit implementation are in other header files, like
29  * workstealing.h, par_loop.h, omp_loop.h, and omp_loop_static.h.
30  * This file is a GNU parallel extension to the Standard C++ Library.
31  */
32 
33 // Written by Felix Putze.
34 
35 #ifndef _GLIBCXX_PARALLEL_FOR_EACH_H
36 #define _GLIBCXX_PARALLEL_FOR_EACH_H 1
37 
38 #include <parallel/settings.h>
39 #include <parallel/par_loop.h>
40 #include <parallel/omp_loop.h>
41 #include <parallel/workstealing.h>
42 
43 namespace __gnu_parallel
44 {
45  /** @brief Chose the desired algorithm by evaluating @c parallelism_tag.
46  * @param begin Begin iterator of input sequence.
47  * @param end End iterator of input sequence.
48  * @param user_op A user-specified functor (comparator, predicate,
49  * associative operator,...)
50  * @param functionality functor to "process" an element with
51  * user_op (depends on desired functionality, e. g. accumulate,
52  * for_each,...
53  * @param reduction Reduction functor.
54  * @param reduction_start Initial value for reduction.
55  * @param output Output iterator.
56  * @param bound Maximum number of elements processed.
57  * @param parallelism_tag Parallelization method */
58  template<typename InputIterator, typename UserOp,
59  typename Functionality, typename Red, typename Result>
60  UserOp
61  for_each_template_random_access(InputIterator begin, InputIterator end,
62  UserOp user_op,
63  Functionality& functionality,
64  Red reduction, Result reduction_start,
65  Result& output, typename
67  difference_type bound,
68  _Parallelism parallelism_tag)
69  {
70  if (parallelism_tag == parallel_unbalanced)
71  return for_each_template_random_access_ed(begin, end, user_op,
72  functionality, reduction,
73  reduction_start,
74  output, bound);
75  else if (parallelism_tag == parallel_omp_loop)
76  return for_each_template_random_access_omp_loop(begin, end, user_op,
77  functionality,
78  reduction,
79  reduction_start,
80  output, bound);
81  else if (parallelism_tag == parallel_omp_loop_static)
82  return for_each_template_random_access_omp_loop(begin, end, user_op,
83  functionality,
84  reduction,
85  reduction_start,
86  output, bound);
87  else //e. g. parallel_balanced
89  user_op,
90  functionality,
91  reduction,
92  reduction_start,
93  output, bound);
94  }
95 }
96 
97 #endif /* _GLIBCXX_PARALLEL_FOR_EACH_H */
Parallelization of embarrassingly parallel execution by means of an OpenMP for loop. This file is a GNU parallel extension to the Standard C++ Library.
Parallel unbalanced (equal-sized chunks).
Definition: types.h:48
Parallel with OpenMP static load-balancing.
Definition: types.h:57
_Parallelism
Run-time equivalents for the compile-time tags.
Definition: types.h:42
Runtime settings and tuning parameters, heuristics to decide whether to use parallelized algorithms...
Op for_each_template_random_access_workstealing(RandomAccessIterator begin, RandomAccessIterator end, Op op, Fu &f, Red r, Result base, Result &output, typename std::iterator_traits< RandomAccessIterator >::difference_type bound)
Work stealing algorithm for random access iterators.
Definition: workstealing.h:99
UserOp for_each_template_random_access(InputIterator begin, InputIterator end, UserOp user_op, Functionality &functionality, Red reduction, Result reduction_start, Result &output, typename std::iterator_traits< InputIterator >::difference_type bound, _Parallelism parallelism_tag)
Chose the desired algorithm by evaluating parallelism_tag.
Definition: for_each.h:61
Op for_each_template_random_access_ed(RandomAccessIterator begin, RandomAccessIterator end, Op o, Fu &f, Red r, Result base, Result &output, typename std::iterator_traits< RandomAccessIterator >::difference_type bound)
Embarrassingly parallel algorithm for random access iterators, using hand-crafted parallelization by ...
Definition: par_loop.h:68
Op for_each_template_random_access_omp_loop(RandomAccessIterator begin, RandomAccessIterator end, Op o, Fu &f, Red r, Result base, Result &output, typename std::iterator_traits< RandomAccessIterator >::difference_type bound)
Embarrassingly parallel algorithm for random access iterators, using an OpenMP for loop...
Definition: omp_loop.h:67
Parallelization of embarrassingly parallel execution by means of work-stealing.
Parallel with OpenMP dynamic load-balancing.
Definition: types.h:54
Parallelization of embarrassingly parallel execution by means of equal splitting. This file is a GNU ...