Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __MRPT_PARALLELIZATION_H
00029 #define __MRPT_PARALLELIZATION_H
00030
00031 #include <mrpt/config.h>
00032
00033
00034
00035
00036
00037 #if MRPT_HAS_TBB
00038 #include <tbb/tbb_stddef.h>
00039 #if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
00040 #include <tbb/tbb.h>
00041 #include <tbb/task.h>
00042 #undef min
00043 #undef max
00044 #else
00045 #undef MRPT_HAS_TBB
00046 #define MRPT_HAS_TBB 0
00047 #endif
00048 #endif
00049
00050
00051
00052 namespace mrpt
00053 {
00054 namespace system
00055 {
00056 #if MRPT_HAS_TBB
00057 typedef tbb::blocked_range<int> BlockedRange;
00058
00059 template<typename Body> static inline
00060 void parallel_for( const BlockedRange& range, const Body& body )
00061 {
00062 tbb::parallel_for(range, body);
00063 }
00064
00065 template<typename Iterator, typename Body> static inline
00066 void parallel_do( Iterator first, Iterator last, const Body& body )
00067 {
00068 tbb::parallel_do(first, last, body);
00069 }
00070
00071 typedef tbb::split Split;
00072
00073 template<typename Body> static inline
00074 void parallel_reduce( const BlockedRange& range, Body& body )
00075 {
00076 tbb::parallel_reduce(range, body);
00077 }
00078
00079
00080 #else
00081
00082 class BlockedRange
00083 {
00084 public:
00085 BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
00086 BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
00087 int begin() const { return _begin; }
00088 int end() const { return _end; }
00089 int grainsize() const { return _grainsize; }
00090 protected:
00091 int _begin, _end, _grainsize;
00092 };
00093
00094 template<typename Body> static inline
00095 void parallel_for( const BlockedRange& range, const Body& body )
00096 {
00097 body(range);
00098 }
00099 typedef std::vector<Rect> ConcurrentRectVector;
00100
00101 template<typename Iterator, typename Body> static inline
00102 void parallel_do( Iterator first, Iterator last, const Body& body )
00103 {
00104 for( ; first != last; ++first )
00105 body(*first);
00106 }
00107
00108 class Split {};
00109
00110 template<typename Body> static inline
00111 void parallel_reduce( const BlockedRange& range, Body& body )
00112 {
00113 body(range);
00114 }
00115
00116 #endif // MRPT_HAS_TBB
00117
00118 }
00119 }
00120
00121 #endif