9 #ifndef stk_algsup_AlgorithmRunner_hpp 10 #define stk_algsup_AlgorithmRunner_hpp 13 #include <stk_mesh/base/Types.hpp> 14 #include <stk_mesh/base/Bucket.hpp> 15 #include <stk_mesh/base/GetBuckets.hpp> 21 class AlgorithmInterface ;
22 class AlgorithmRunnerInterface ;
37 class AlgorithmRunnerInterface {
39 virtual ~AlgorithmRunnerInterface() {}
56 template<
class Algorithm >
57 void run_parts(
const mesh::Selector & selector ,
59 const std::vector< mesh::Bucket * > & buckets ,
60 const Algorithm & algorithm )
const ;
76 template<
class Algorithm >
77 void run(
const mesh::Selector & selector ,
79 const std::vector< mesh::Bucket * > & buckets ,
80 const Algorithm & algorithm )
const ;
112 template<
class Algorithm >
113 void run_parts(
const mesh::Selector & selector ,
115 const std::vector< mesh::Bucket * > & buckets ,
116 const Algorithm & algorithm ,
117 typename Algorithm::reduce_type * reduce_value )
const ;
137 template<
class Algorithm >
138 void run(
const mesh::Selector & selector ,
140 const std::vector< mesh::Bucket * > & buckets ,
141 const Algorithm & algorithm ,
142 typename Algorithm::reduce_type * reduce_value )
const ;
145 AlgorithmRunnerInterface (
const AlgorithmRunnerInterface & );
146 AlgorithmRunnerInterface & operator = (
const AlgorithmRunnerInterface & );
150 AlgorithmRunnerInterface() {}
153 virtual void run_alg(
const mesh::Selector & selector ,
155 const std::vector< mesh::Bucket * > & buckets ,
156 const AlgorithmInterface & algorithm ,
157 void * reduce )
const = 0 ;
166 const size_t m_maximum_entity_count ;
167 const size_t m_reduce_allocation_size ;
169 virtual void init(
void * out )
const = 0 ;
171 virtual void join(
void * inout ,
const void * in )
const = 0 ;
173 virtual void apply( mesh::Bucket::iterator i ,
174 mesh::Bucket::iterator j ,
176 void * reduce_inout )
const = 0 ;
187 void * reduce )
const ;
192 : m_maximum_entity_count( 0 ),
193 m_reduce_allocation_size( 0 ) {}
196 : m_maximum_entity_count( count ),
197 m_reduce_allocation_size( 0 ) {}
200 : m_maximum_entity_count( count ),
201 m_reduce_allocation_size( size ) {}
212 template<
class Algorithm >
215 void init(
void * )
const {}
216 void join(
void * ,
const void * )
const {}
218 const Algorithm & m_alg ;
220 void apply( mesh::Bucket::iterator i ,
221 mesh::Bucket::iterator j ,
223 { m_alg.apply( i , j ); }
225 explicit AlgorithmWrapper(
const Algorithm & alg )
226 : AlgorithmInterface( alg.maximum_entity_count ), m_alg( alg ) {}
229 template<
class Algorithm >
230 class AlgorithmWrapperParts :
public AlgorithmInterface {
232 void init(
void * )
const {}
233 void join(
void * ,
const void * )
const {}
235 const Algorithm & m_alg ;
237 void apply( mesh::Bucket::iterator i ,
238 mesh::Bucket::iterator j ,
240 { m_alg.apply( i , j , selected_parts ); }
242 explicit AlgorithmWrapperParts(
const Algorithm & alg )
243 : AlgorithmInterface( alg.maximum_entity_count ), m_alg( alg ) {}
246 template<
class Algorithm >
247 class AlgorithmWrapperReduce :
public AlgorithmInterface {
249 typedef typename Algorithm::reduce_type reduce_type ;
251 const Algorithm & m_alg ;
253 void init(
void * reduce_out )
const 254 { m_alg.init( (reduce_type *) reduce_out ); }
256 void join(
void * reduce_inout ,
const void * reduce_in )
const 258 m_alg.join( (reduce_type *) reduce_inout ,
259 (
const reduce_type *) reduce_in );
262 void apply( mesh::Bucket::iterator i ,
263 mesh::Bucket::iterator j ,
266 m_alg.apply( i , j , (reduce_type*) reduce_inout );
269 explicit AlgorithmWrapperReduce(
const Algorithm & alg )
270 : AlgorithmInterface( alg.maximum_entity_count ,
271 alg.reduce_count * sizeof( reduce_type ) ),
275 template<
class Algorithm >
276 class AlgorithmWrapperPartsReduce :
public AlgorithmInterface {
278 typedef typename Algorithm::reduce_type reduce_type ;
280 const Algorithm & m_alg ;
282 void init(
void * reduce_out )
const 284 m_alg.init( (reduce_type *) reduce_out );
287 void join(
void * reduce_inout ,
const void * reduce_in )
const 289 m_alg.join( (reduce_type *) reduce_inout ,
290 (
const reduce_type *) reduce_in );
293 void apply( mesh::Bucket::iterator i ,
294 mesh::Bucket::iterator j ,
296 void * reduce_inout )
const 298 m_alg.apply( i , j , selected_parts , (reduce_type*) reduce_inout );
301 explicit AlgorithmWrapperPartsReduce(
const Algorithm & alg )
302 : AlgorithmInterface( alg.maximum_entity_count ,
303 alg.reduce_count * sizeof(reduce_type) ),
309 template<
class Algorithm >
311 void AlgorithmRunnerInterface::run(
312 const mesh::Selector & selector ,
314 const std::vector< mesh::Bucket * > & buckets ,
315 const Algorithm & algorithm ,
316 typename Algorithm::reduce_type * reduce )
const 318 const AlgorithmWrapperReduce<Algorithm> wrap( algorithm );
320 run_alg( selector , union_parts, buckets , wrap , reduce );
323 template<
class Algorithm >
325 void AlgorithmRunnerInterface::run_parts(
326 const mesh::Selector & selector ,
328 const std::vector< mesh::Bucket * > & buckets ,
329 const Algorithm & algorithm ,
330 typename Algorithm::reduce_type * reduce )
const 332 const AlgorithmWrapperPartsReduce<Algorithm> wrap( algorithm );
334 run_alg( selector , union_parts, buckets , wrap , reduce );
337 template<
class Algorithm >
339 void AlgorithmRunnerInterface::run(
340 const mesh::Selector & selector ,
342 const std::vector< mesh::Bucket * > & buckets ,
343 const Algorithm & algorithm )
const 345 const AlgorithmWrapper<Algorithm> wrap( algorithm );
347 run_alg( selector , union_parts, buckets , wrap , NULL );
350 template<
class Algorithm >
352 void AlgorithmRunnerInterface::run_parts(
353 const mesh::Selector & selector ,
355 const std::vector< mesh::Bucket * > & buckets ,
356 const Algorithm & algorithm )
const 358 const AlgorithmWrapperParts<Algorithm> wrap( algorithm );
360 run_alg( selector , union_parts, buckets , wrap , NULL );
AlgorithmRunnerInterface * algorithm_runner_tbb(int nthreads)
AlgorithmRunnerInterface * algorithm_runner_tpi(int nthreads)
AlgorithmRunnerInterface * algorithm_runner_non_thread()
This is a class for selecting buckets based on a set of meshparts and set logic.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
A container for the field data of a homogeneous collection of entities.