# for_each.h

Go to the documentation of this file.

    00001 // -*- C++ -*-
    00002
    00003 // Copyright (C) 2007, 2008 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 2, 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 // You should have received a copy of the GNU General Public License
    00017 // along with this library; see the file COPYING.  If not, write to
    00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
    00019 // MA 02111-1307, USA.
    00020
    00021 // As a special exception, you may use this file as part of a free
    00022 // software library without restriction.  Specifically, if other files
    00023 // instantiate templates or use macros or inline functions from this
    00024 // file, or you compile this file and link it with other files to
    00025 // produce an executable, this file does not by itself cause the
    00026 // resulting executable to be covered by the GNU General Public
    00027 // License.  This exception does not however invalidate any other
    00028 // reasons why the executable file might be covered by the GNU General
    00029 // Public License.
    00030
    00031 /** @file parallel/for_each.h
    00032  *  @brief Main interface for embarrassingly parallel functions.
    00033  *
    00034  *  The explicit implementation are in other header files, like
    00035  *  workstealing.h, par_loop.h, omp_loop.h, and omp_loop_static.h.
    00036  *  This file is a GNU parallel extension to the Standard C++ Library.
    00037  */
    00038
    00039 // Written by Felix Putze.
    00040
    00041 #ifndef _GLIBCXX_PARALLEL_FOR_EACH_H
    00042 #define _GLIBCXX_PARALLEL_FOR_EACH_H 1
    00043
    00044 #include <parallel/settings.h>
    00045 #include <parallel/par_loop.h>
    00046 #include <parallel/omp_loop.h>
    00047 #include <parallel/workstealing.h>
    00048
    00049 namespace __gnu_parallel
    00050 {
    00051   /** @brief Chose the desired algorithm by evaluating @c parallelism_tag.
    00052    *  @param begin Begin iterator of input sequence.
    00053    *  @param end End iterator of input sequence.
    00054    *  @param user_op A user-specified functor (comparator, predicate,
    00055    *  associative operator,...)
    00056    *  @param functionality functor to "process" an element with
    00057    *  user_op (depends on desired functionality, e. g. accumulate,
    00058    *  for_each,...
    00059    *  @param reduction Reduction functor.
    00060    *  @param reduction_start Initial value for reduction.
    00061    *  @param output Output iterator.
    00062    *  @param bound Maximum number of elements processed.
    00063    *  @param parallelism_tag Parallelization method */
    00064   template<typename InputIterator, typename UserOp,
    00065        typename Functionality, typename Red, typename Result>
    00066     UserOp
    00067     for_each_template_random_access(InputIterator begin, InputIterator end,
    00068                     UserOp user_op,
    00069                     Functionality& functionality,
    00070                     Red reduction, Result reduction_start,
    00071                     Result& output, typename
    00072                     std::iterator_traits<InputIterator>::
    00073                     difference_type bound,
    00074                     _Parallelism parallelism_tag)
    00075     {
    00076       if (parallelism_tag == parallel_unbalanced)
    00077     return for_each_template_random_access_ed(begin, end, user_op,
    00078                           functionality, reduction,
    00079                           reduction_start,
    00080                           output, bound);
    00081       else if (parallelism_tag == parallel_omp_loop)
    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 if (parallelism_tag == parallel_omp_loop_static)
    00088     return for_each_template_random_access_omp_loop(begin, end, user_op,
    00089                             functionality,
    00090                             reduction,
    00091                             reduction_start,
    00092                             output, bound);
    00093       else  //e. g. parallel_balanced
    00094     return for_each_template_random_access_workstealing(begin, end,
    00095                                 user_op,
    00096                                 functionality,
    00097                                 reduction,
    00098                                 reduction_start,
    00099                                 output, bound);
    00100   }
    00101 }
    00102
    00103 #endif