Main MRPT website > C++ reference for MRPT 1.5.7
parallelization.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef __MRPT_PARALLELIZATION_H
10 #define __MRPT_PARALLELIZATION_H
11 
12 #include <mrpt/config.h>
13 
14 // This file declares helper structs for usage with TBB
15 // Refer to http://threadingbuildingblocks.org/
16 // (The following code blocks are based on OpenCV code - BSD license)
17 
18 #if MRPT_HAS_TBB
19  #include <tbb/tbb_stddef.h>
20  #if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
21  #include <tbb/tbb.h>
22  #include <tbb/task.h>
23  #undef min
24  #undef max
25  #else
26  #undef MRPT_HAS_TBB
27  #define MRPT_HAS_TBB 0
28  #endif
29 #endif
30 
31 
32 // Define a common interface so if we don't have TBB it falls back to a good-old for loop:
33 namespace mrpt
34 {
35  namespace system
36  {
37 #if MRPT_HAS_TBB
38  typedef tbb::blocked_range<int> BlockedRange;
39 
40  template<typename Body> static inline
41  void parallel_for( const BlockedRange& range, const Body& body )
42  {
43  tbb::parallel_for(range, body);
44  }
45 
46  template<typename Iterator, typename Body> static inline
47  void parallel_do( Iterator first, Iterator last, const Body& body )
48  {
49  tbb::parallel_do(first, last, body);
50  }
51 
52  typedef tbb::split Split;
53 
54  template<typename Body> static inline
55  void parallel_reduce( const BlockedRange& range, Body& body )
56  {
58  }
59 
60  //typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
61 #else
62  // Emulate TBB-like classes which fall back to an old "for"
64  {
65  public:
66  BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
67  BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
68  int begin() const { return _begin; }
69  int end() const { return _end; }
70  int grainsize() const { return _grainsize; }
71  protected:
73  };
74 
75  template<typename Body> static inline
76  void parallel_for( const BlockedRange& range, const Body& body )
77  {
78  body(range);
79  }
80  typedef std::vector<Rect> ConcurrentRectVector;
81 
82  template<typename Iterator, typename Body> static inline
83  void parallel_do( Iterator first, Iterator last, const Body& body )
84  {
85  for( ; first != last; ++first )
86  body(*first);
87  }
88 
89  class Split {};
90 
91  template<typename Body> static inline
92  void parallel_reduce( const BlockedRange& range, Body& body )
93  {
94  body(range);
95  }
96 
97 #endif // MRPT_HAS_TBB
98 
99  } // end NS
100 } // end NS
101 
102 #endif
GLsizei range
Definition: glext.h:5281
GLint * first
Definition: glext.h:3703
static void parallel_do(Iterator first, Iterator last, const Body &body)
BlockedRange(int b, int e, int g=1)
std::vector< Rect > ConcurrentRectVector
static void parallel_reduce(const BlockedRange &range, Body &body)
GLubyte g
Definition: glext.h:5575
GLubyte GLubyte b
Definition: glext.h:5575
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static void parallel_for(const BlockedRange &range, const Body &body)



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019