xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/parallel/for_each.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // -*- C++ -*-
2*e4b17023SJohn Marino 
3*e4b17023SJohn Marino // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4*e4b17023SJohn Marino //
5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the terms
7*e4b17023SJohn Marino // of the GNU General Public License as published by the Free Software
8*e4b17023SJohn Marino // Foundation; either version 3, or (at your option) any later
9*e4b17023SJohn Marino // version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, but
12*e4b17023SJohn Marino // WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*e4b17023SJohn Marino // General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino /** @file parallel/for_each.h
26*e4b17023SJohn Marino  *  @brief Main interface for embarrassingly parallel functions.
27*e4b17023SJohn Marino  *
28*e4b17023SJohn Marino  *  The explicit implementation are in other header files, like
29*e4b17023SJohn Marino  *  workstealing.h, par_loop.h, omp_loop.h, and omp_loop_static.h.
30*e4b17023SJohn Marino  *  This file is a GNU parallel extension to the Standard C++ Library.
31*e4b17023SJohn Marino  */
32*e4b17023SJohn Marino 
33*e4b17023SJohn Marino // Written by Felix Putze.
34*e4b17023SJohn Marino 
35*e4b17023SJohn Marino #ifndef _GLIBCXX_PARALLEL_FOR_EACH_H
36*e4b17023SJohn Marino #define _GLIBCXX_PARALLEL_FOR_EACH_H 1
37*e4b17023SJohn Marino 
38*e4b17023SJohn Marino #include <parallel/settings.h>
39*e4b17023SJohn Marino #include <parallel/par_loop.h>
40*e4b17023SJohn Marino #include <parallel/omp_loop.h>
41*e4b17023SJohn Marino #include <parallel/workstealing.h>
42*e4b17023SJohn Marino 
43*e4b17023SJohn Marino namespace __gnu_parallel
44*e4b17023SJohn Marino {
45*e4b17023SJohn Marino   /** @brief Chose the desired algorithm by evaluating @c __parallelism_tag.
46*e4b17023SJohn Marino    *  @param __begin Begin iterator of input sequence.
47*e4b17023SJohn Marino    *  @param __end End iterator of input sequence.
48*e4b17023SJohn Marino    *  @param __user_op A user-specified functor (comparator, predicate,
49*e4b17023SJohn Marino    *  associative operator,...)
50*e4b17023SJohn Marino    *  @param __functionality functor to @a process an element with
51*e4b17023SJohn Marino    *  __user_op (depends on desired functionality, e. g. accumulate,
52*e4b17023SJohn Marino    *  for_each,...
53*e4b17023SJohn Marino    *  @param __reduction Reduction functor.
54*e4b17023SJohn Marino    *  @param __reduction_start Initial value for reduction.
55*e4b17023SJohn Marino    *  @param __output Output iterator.
56*e4b17023SJohn Marino    *  @param __bound Maximum number of elements processed.
57*e4b17023SJohn Marino    *  @param __parallelism_tag Parallelization method */
58*e4b17023SJohn Marino   template<typename _IIter, typename _UserOp,
59*e4b17023SJohn Marino            typename _Functionality, typename _Red, typename _Result>
60*e4b17023SJohn Marino     _UserOp
__for_each_template_random_access(_IIter __begin,_IIter __end,_UserOp __user_op,_Functionality & __functionality,_Red __reduction,_Result __reduction_start,_Result & __output,typename std::iterator_traits<_IIter>::difference_type __bound,_Parallelism __parallelism_tag)61*e4b17023SJohn Marino     __for_each_template_random_access(_IIter __begin, _IIter __end,
62*e4b17023SJohn Marino                                       _UserOp __user_op,
63*e4b17023SJohn Marino                                       _Functionality& __functionality,
64*e4b17023SJohn Marino                                       _Red __reduction,
65*e4b17023SJohn Marino                                       _Result __reduction_start,
66*e4b17023SJohn Marino                                       _Result& __output, typename
67*e4b17023SJohn Marino                                       std::iterator_traits<_IIter>::
68*e4b17023SJohn Marino                                       difference_type __bound,
69*e4b17023SJohn Marino                                       _Parallelism __parallelism_tag)
70*e4b17023SJohn Marino     {
71*e4b17023SJohn Marino       if (__parallelism_tag == parallel_unbalanced)
72*e4b17023SJohn Marino         return __for_each_template_random_access_ed
73*e4b17023SJohn Marino 	  (__begin, __end, __user_op, __functionality, __reduction,
74*e4b17023SJohn Marino 	   __reduction_start, __output, __bound);
75*e4b17023SJohn Marino       else if (__parallelism_tag == parallel_omp_loop)
76*e4b17023SJohn Marino         return __for_each_template_random_access_omp_loop
77*e4b17023SJohn Marino 	  (__begin, __end, __user_op, __functionality, __reduction,
78*e4b17023SJohn Marino 	   __reduction_start, __output, __bound);
79*e4b17023SJohn Marino       else if (__parallelism_tag == parallel_omp_loop_static)
80*e4b17023SJohn Marino         return __for_each_template_random_access_omp_loop
81*e4b17023SJohn Marino 	  (__begin, __end, __user_op, __functionality, __reduction,
82*e4b17023SJohn Marino 	   __reduction_start, __output, __bound);
83*e4b17023SJohn Marino       else      //e. g. parallel_balanced
84*e4b17023SJohn Marino         return __for_each_template_random_access_workstealing
85*e4b17023SJohn Marino 	  (__begin, __end, __user_op, __functionality, __reduction,
86*e4b17023SJohn Marino 	   __reduction_start, __output, __bound);
87*e4b17023SJohn Marino   }
88*e4b17023SJohn Marino }
89*e4b17023SJohn Marino 
90*e4b17023SJohn Marino #endif /* _GLIBCXX_PARALLEL_FOR_EACH_H */
91