OSDN Git Service

2007-09-17 Johannes Singler <singler@ira.uka.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / parallel / for_each.h
1 // -*- C++ -*-
2
3 // Copyright (C) 2007 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 2, 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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
20
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction.  Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License.  This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
30
31 /** @file parallel/for_each.h
32  *  @brief Main interface for embarrassingly parallel functions.
33  *
34  *  The explicit implementation are in other header files, like
35  *  workstealing.h, par_loop.h, omp_loop.h, and omp_loop_static.h.
36  *  This file is a GNU parallel extension to the Standard C++ Library.
37  */
38
39 // Written by Felix Putze.
40
41 #ifndef _GLIBCXX_PARALLEL_FOR_EACH_H
42 #define _GLIBCXX_PARALLEL_FOR_EACH_H 1
43
44 #include <parallel/settings.h>
45 #include <parallel/par_loop.h>
46 #include <parallel/omp_loop.h>
47 #include <parallel/workstealing.h>
48
49 namespace __gnu_parallel
50 {
51   /** @brief Chose the desired algorithm by evaluating @c parallelism_tag.
52    *  @param begin Begin iterator of input sequence.
53    *  @param end End iterator of input sequence.
54    *  @param user_op A user-specified functor (comparator, predicate,
55    *  associative operator,...)
56    *  @param functionality functor to "process" an element with
57    *  user_op (depends on desired functionality, e. g. accumulate,
58    *  for_each,...
59    *  @param reduction Reduction functor.
60    *  @param reduction_start Initial value for reduction.
61    *  @param output Output iterator.
62    *  @param bound Maximum number of elements processed.
63    *  @param parallelism_tag Parallelization method */
64   template<typename InputIterator, typename UserOp, typename Functionality, typename Red, typename Result>
65   UserOp
66   for_each_template_random_access(InputIterator begin, InputIterator end,
67                                   UserOp user_op, Functionality& functionality,
68                                   Red reduction, Result reduction_start,
69                                   Result& output,
70                                   typename std::iterator_traits<InputIterator>::difference_type bound, parallelism parallelism_tag)
71   {
72     if (parallelism_tag == parallel_unbalanced)
73       return for_each_template_random_access_ed(begin, end, user_op, functionality, reduction, reduction_start, output, bound);
74     else if (parallelism_tag == parallel_omp_loop)
75       return for_each_template_random_access_omp_loop(begin, end, user_op, functionality, reduction, reduction_start, output, bound);
76     else if (parallelism_tag == parallel_omp_loop_static)
77       return for_each_template_random_access_omp_loop(begin, end, user_op, functionality, reduction, reduction_start, output, bound);
78     else        //e. g. parallel_balanced
79       return for_each_template_random_access_workstealing(begin, end, user_op, functionality, reduction, reduction_start, output, bound);
80   }
81 }
82
83 #endif