21 #ifndef __TBB_SERIAL_parallel_for_H 22 #define __TBB_SERIAL_parallel_for_H 24 #if !TBB_USE_EXCEPTIONS && _MSC_VER 26 #pragma warning (push) 27 #pragma warning (disable: 4530) 33 #if !TBB_USE_EXCEPTIONS && _MSC_VER 37 #include "tbb_annotate.h" 39 #ifndef __TBB_NORMAL_EXECUTION 40 #include "tbb/blocked_range.h" 41 #include "tbb/partitioner.h" 46 namespace interface9 {
50 template<
typename Range,
typename Body,
typename Partitioner >
54 typename Partitioner::task_partition_type my_partition;
58 start_for(
const Range& range,
const Body& body, Partitioner& partitioner ) :
61 my_partition( partitioner )
68 my_range( parent_.my_range, split_obj ),
69 my_body( parent_.my_body ),
70 my_partition( parent_.my_partition, split_obj )
75 static void run(
const Range& range,
const Body& body, Partitioner& partitioner ) {
76 if( !range.empty() ) {
77 ANNOTATE_SITE_BEGIN( tbb_parallel_for );
82 ANNOTATE_SITE_END( tbb_parallel_for );
87 template<
typename Range,
typename Body,
typename Partitioner >
89 if( !my_range.is_divisible() || !my_partition.is_divisible() ) {
90 ANNOTATE_TASK_BEGIN( tbb_parallel_for_range );
94 ANNOTATE_TASK_END( tbb_parallel_for_range );
96 typename Partitioner::split_type split_obj;
105 template<
typename Range,
typename Body>
112 template<
typename Range,
typename Body>
113 void parallel_for(
const Range& range,
const Body& body,
const simple_partitioner& partitioner ) {
119 template<
typename Range,
typename Body>
120 void parallel_for(
const Range& range,
const Body& body,
const auto_partitioner& partitioner ) {
124 #if TBB_PREVIEW_STATIC_PARTITIONER 127 template<
typename Range,
typename Body>
128 void parallel_for(
const Range& range,
const Body& body,
const static_partitioner& partitioner ) {
135 template<
typename Range,
typename Body>
136 void parallel_for(
const Range& range,
const Body& body, affinity_partitioner& partitioner ) {
141 template <
typename Index,
typename Function,
typename Partitioner>
142 void parallel_for_impl(Index first, Index last, Index step,
const Function& f, Partitioner& ) {
144 throw std::invalid_argument(
"nonpositive_step" );
145 else if (last > first) {
147 ANNOTATE_SITE_BEGIN( tbb_parallel_for );
148 for( Index i = first; i < last; i = i + step ) {
149 ANNOTATE_TASK_BEGIN( tbb_parallel_for_iteration );
151 ANNOTATE_TASK_END( tbb_parallel_for_iteration );
153 ANNOTATE_SITE_END( tbb_parallel_for );
158 template <
typename Index,
typename Function>
159 void parallel_for(Index first, Index last, Index step,
const Function& f) {
160 parallel_for_impl<Index,Function,const auto_partitioner>(first, last, step, f, auto_partitioner());
163 template <
typename Index,
typename Function>
164 void parallel_for(Index first, Index last, Index step,
const Function& f,
const simple_partitioner& p) {
165 parallel_for_impl<Index,Function,const simple_partitioner>(first, last, step, f, p);
168 template <
typename Index,
typename Function>
169 void parallel_for(Index first, Index last, Index step,
const Function& f,
const auto_partitioner& p) {
170 parallel_for_impl<Index,Function,const auto_partitioner>(first, last, step, f, p);
172 #if TBB_PREVIEW_STATIC_PARTITIONER 173 template <
typename Index,
typename Function>
175 void parallel_for(Index first, Index last, Index step,
const Function& f,
const static_partitioner& p) {
176 parallel_for_impl<Index,Function,const static_partitioner>(first, last, step, f, p);
179 template <
typename Index,
typename Function>
181 void parallel_for(Index first, Index last, Index step,
const Function& f, affinity_partitioner& p) {
182 parallel_for_impl(first, last, step, f, p);
186 template <
typename Index,
typename Function>
187 void parallel_for(Index first, Index last,
const Function& f) {
188 parallel_for_impl<Index,Function,const auto_partitioner>(first, last,
static_cast<Index
>(1), f, auto_partitioner());
191 template <
typename Index,
typename Function>
192 void parallel_for(Index first, Index last,
const Function& f,
const simple_partitioner& p) {
193 parallel_for_impl<Index,Function,const simple_partitioner>(first, last,
static_cast<Index
>(1), f, p);
196 template <
typename Index,
typename Function>
197 void parallel_for(Index first, Index last,
const Function& f,
const auto_partitioner& p) {
198 parallel_for_impl<Index,Function,const auto_partitioner>(first, last,
static_cast<Index
>(1), f, p);
200 #if TBB_PREVIEW_STATIC_PARTITIONER 201 template <
typename Index,
typename Function>
203 void parallel_for(Index first, Index last,
const Function& f,
const static_partitioner& p) {
204 parallel_for_impl<Index,Function,const static_partitioner>(first, last,
static_cast<Index
>(1), f, p);
207 template <
typename Index,
typename Function>
209 void parallel_for(Index first, Index last,
const Function& f, affinity_partitioner& p) {
210 parallel_for_impl(first, last, static_cast<Index>(1), f, p);
219 #ifndef __TBB_NORMAL_EXECUTION Definition: parallel_for.h:51
void parallel_for(const Range &range, const Body &body)
Parallel iteration over range with default partitioner.
Definition: parallel_for.h:185
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
void parallel_for(const Range &range, const Body &body, affinity_partitioner &partitioner, task_group_context &context)
Parallel iteration over range with affinity_partitioner and user-supplied context.
Definition: parallel_for.h:253