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