for_each.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009 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 "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 InputIterator, typename UserOp,
00059        typename Functionality, typename Red, typename Result>
00060     UserOp
00061     for_each_template_random_access(InputIterator begin, InputIterator end,
00062                     UserOp user_op,
00063                     Functionality& functionality,
00064                     Red reduction, Result reduction_start,
00065                     Result& output, typename
00066                     std::iterator_traits<InputIterator>::
00067                     difference_type bound,
00068                     _Parallelism parallelism_tag)
00069     {
00070       if (parallelism_tag == parallel_unbalanced)
00071     return for_each_template_random_access_ed(begin, end, user_op,
00072                           functionality, reduction,
00073                           reduction_start,
00074                           output, bound);
00075       else if (parallelism_tag == parallel_omp_loop)
00076     return for_each_template_random_access_omp_loop(begin, end, user_op,
00077                             functionality,
00078                             reduction,
00079                             reduction_start,
00080                             output, bound);
00081       else if (parallelism_tag == parallel_omp_loop_static)
00082     return for_each_template_random_access_omp_loop(begin, end, user_op,
00083                             functionality,
00084                             reduction,
00085                             reduction_start,
00086                             output, bound);
00087       else  //e. g. parallel_balanced
00088     return for_each_template_random_access_workstealing(begin, end,
00089                                 user_op,
00090                                 functionality,
00091                                 reduction,
00092                                 reduction_start,
00093                                 output, bound);
00094   }
00095 }
00096 
00097 #endif /* _GLIBCXX_PARALLEL_FOR_EACH_H */

Generated on Tue Apr 21 13:13:26 2009 for libstdc++ by  doxygen 1.5.8