GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
tbb/map.h
Go to the documentation of this file.
1 /*
2 * @version GrPPI v0.2
3 * @copyright Copyright (C) 2017 Universidad Carlos III de Madrid. All rights reserved.
4 * @license GNU/GPL, see LICENSE.txt
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You have received a copy of the GNU General Public License in LICENSE.txt
16 * also available in <http://www.gnu.org/licenses/gpl.html>.
17 *
18 * See COPYRIGHT.txt for copyright notices and details.
19 */
20 
21 #ifndef GRPPI_TBB_MAP_H
22 #define GRPPI_TBB_MAP_H
23 
24 #ifdef GRPPI_TBB
25 
26 #include "parallel_execution_tbb.h"
27 
28 #include <tbb/tbb.h>
29 
30 namespace grppi {
31 
52 template <typename InputIt, typename OutputIt, typename Transformer>
54  InputIt first, InputIt last,
55  OutputIt first_out,
56  Transformer && transf_op)
57 {
58  tbb::parallel_for(
59  static_cast<std::size_t>(0),
60  static_cast<std::size_t>((last-first)),
61  [&] (std::size_t index){
62  auto current = (first_out+index);
63  *current = transf_op(*(first+index));
64  }
65  );
66 }
67 
82 template <typename InputIt, typename OutputIt,
83  typename Transformer,
84  typename ... OtherInputIts>
86  InputIt first, InputIt last, OutputIt first_out,
87  Transformer && transf_op,
88  OtherInputIts ... more_firsts)
89 {
90  tbb::parallel_for(
91  static_cast<std::size_t>(0),
92  static_cast<std::size_t>((last-first)),
93  [&] (std::size_t index){
94  auto current = (first_out+index);
95  *current = transf_op(*(first+index), *(more_firsts+index)...);
96  }
97  );
98 
99 }
100 
101 }
102 
103 #endif
104 
105 #endif
Definition: callable_traits.h:24
TBB parallel execution policy.
Definition: parallel_execution_tbb.h:37
void map(parallel_execution_native &ex, InputIt first, InputIt last, OutputIt first_out, Transformer &&transf_op)
Invoke Map pattern on a data sequence with native paralell execution.
Definition: native/map.h:50