Skip to content

Commit ede2b78

Browse files
proberts-cinesitejohnhaddon
authored andcommitted
Primitive : Use tbb parallel_reduce to accelerate bounds compute
1 parent 97754ec commit ede2b78

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/IECoreScene/Primitive.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
#include "boost/algorithm/string.hpp"
4343

44+
#include <tbb/parallel_reduce.h>
45+
#include <tbb/blocked_range.h>
46+
4447
#include <cassert>
4548

4649
using namespace IECore;
@@ -78,10 +81,27 @@ Imath::Box3f Primitive::bound() const
7881
if( p )
7982
{
8083
const vector<V3f> &pp = p->readable();
81-
for( size_t i=0; i<pp.size(); i++ )
82-
{
83-
result.extendBy( pp[i] );
84-
}
84+
using RangeType = tbb::blocked_range< const V3f* >;
85+
tbb::this_task_arena::isolate( [ & result, & pp ]{
86+
tbb::task_group_context taskGroupContext( tbb::task_group_context::isolated );
87+
result = tbb::parallel_reduce( RangeType( pp.data(), pp.data() + pp.size(), 1000 ), Imath::Box3f(),
88+
[]( const RangeType& range, const Imath::Box3f& value ) -> Imath::Box3f
89+
{
90+
Imath::Box3f b( value );
91+
for( const V3f& pos : range )
92+
{
93+
b.extendBy( pos );
94+
}
95+
return b;
96+
},
97+
[]( const Imath::Box3f& lhs, const Imath::Box3f& rhs ) -> Imath::Box3f
98+
{
99+
Imath::Box3f b( lhs );
100+
b.extendBy( rhs );
101+
return b;
102+
},
103+
taskGroupContext );
104+
} );
85105
}
86106
}
87107
return result;

0 commit comments

Comments
 (0)