libstdc++
for_each.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the terms
00007 // of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 3, or (at your option) any later
00009 // version.
00010 
00011 // This library is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file parallel/for_each.h
00026  *  @brief Main interface for embarrassingly parallel functions.
00027  *
00028  *  The explicit implementation are in other header files, like
00029  *  workstealing.h, par_loop.h, omp_loop.h, and omp_loop_static.h.
00030  *  This file is a GNU parallel extension to the Standard C++ Library.
00031  */
00032 
00033 // Written by Felix Putze.
00034 
00035 #ifndef _GLIBCXX_PARALLEL_FOR_EACH_H
00036 #define _GLIBCXX_PARALLEL_FOR_EACH_H 1
00037 
00038 #include <parallel/settings.h>
00039 #include <parallel/par_loop.h>
00040 #include <parallel/omp_loop.h>
00041 #include <parallel/workstealing.h>
00042 
00043 namespace __gnu_parallel
00044 {
00045   /** @brief Chose the desired algorithm by evaluating @c __parallelism_tag.
00046    *  @param __begin Begin iterator of input sequence.
00047    *  @param __end End iterator of input sequence.
00048    *  @param __user_op A user-specified functor (comparator, predicate,
00049    *  associative operator,...)
00050    *  @param __functionality functor to @a process an element with
00051    *  __user_op (depends on desired functionality, e. g. accumulate,
00052    *  for_each,...
00053    *  @param __reduction Reduction functor.
00054    *  @param __reduction_start Initial value for reduction.
00055    *  @param __output Output iterator.
00056    *  @param __bound Maximum number of elements processed.
00057    *  @param __parallelism_tag Parallelization method */
00058   template<typename _IIter, typename _UserOp,
00059            typename _Functionality, typename _Red, typename _Result>
00060     _UserOp
00061     __for_each_template_random_access(_IIter __begin, _IIter __end,
00062                                       _UserOp __user_op,
00063                                       _Functionality& __functionality,
00064                                       _Red __reduction,
00065                                       _Result __reduction_start,
00066                                       _Result& __output, typename
00067                                       std::iterator_traits<_IIter>::
00068                                       difference_type __bound,
00069                                       _Parallelism __parallelism_tag)
00070     {
00071       if (__parallelism_tag == parallel_unbalanced)
00072         return __for_each_template_random_access_ed
00073       (__begin, __end, __user_op, __functionality, __reduction,
00074        __reduction_start, __output, __bound);
00075       else if (__parallelism_tag == parallel_omp_loop)
00076         return __for_each_template_random_access_omp_loop
00077       (__begin, __end, __user_op, __functionality, __reduction,
00078        __reduction_start, __output, __bound);
00079       else if (__parallelism_tag == parallel_omp_loop_static)
00080         return __for_each_template_random_access_omp_loop
00081       (__begin, __end, __user_op, __functionality, __reduction,
00082        __reduction_start, __output, __bound);
00083       else      //e. g. parallel_balanced
00084         return __for_each_template_random_access_workstealing
00085       (__begin, __end, __user_op, __functionality, __reduction,
00086        __reduction_start, __output, __bound);
00087   }
00088 }
00089 
00090 #endif /* _GLIBCXX_PARALLEL_FOR_EACH_H */