32 #ifndef CNC_DEFAULT_TUNER_H_ALREADY_INCLUDED 33 #define CNC_DEFAULT_TUNER_H_ALREADY_INCLUDED 35 #include <cnc/internal/cnc_api.h> 36 #include <cnc/default_partitioner.h> 37 #include <cnc/internal/step_delayer.h> 38 #include <cnc/internal/cnc_tag_hash_compare.h> 39 #include <cnc/internal/no_range.h> 40 #include <cnc/internal/no_tag_table.h> 41 #include <cnc/internal/hash_tag_table.h> 42 #include <cnc/internal/item_properties.h> 43 #include <cnc/internal/item_properties.h> 44 #include <cnc/internal/dist/distributor.h> 45 #include <cnc/internal/tbbcompat.h> 46 #include <tbb/atomic.h> 47 #include <tbb/concurrent_unordered_set.h> 52 template<
class T >
class context;
54 template<
class Tag,
class Range,
class StepColl,
class RangeStepI,
class TIR,
bool deps >
struct range_step;
89 return Internal::distributor::myPid();
95 return Internal::distributor::numProcs();
98 template<
typename Ctxt >
101 return ctxt.numThreads();
118 template<
bool check_deps = true >
126 template<
typename Tag,
typename Arg >
149 template<
typename Tag,
typename Arg,
typename T >
150 void depends(
const Tag & tag, Arg & arg, T & dC )
const 189 template<
typename Tag,
typename Arg >
201 template<
typename Tag,
typename Arg >
214 static const bool check_deps_in_ranges = check_deps;
229 template<
typename Tag,
typename Arg >
238 template<
typename Tag,
typename Arg >
256 template<
bool check_deps = true,
typename Partitioner = default_partitioner<> >
259 template<
typename Tag,
typename Arg >
260 int priority(
const Tag & tag, Arg & arg )
const 265 template<
typename Tag,
typename Arg,
typename T >
266 void depends(
const Tag & tag, Arg & arg, T & dC )
const 270 bool preschedule()
const 275 template<
typename Tag,
typename Arg >
276 int affinity(
const Tag & , Arg & )
const 281 static const bool check_deps_in_ranges = check_deps;
283 typedef Partitioner partitioner_type;
285 partitioner_type partitioner()
const 287 return typename pfor_tuner< check_deps, Partitioner >::partitioner_type();
296 static const char SINGLE = 0;
297 static const char ALL = 1;
298 static const char RESET = 2;
322 template<
typename Tag,
bool check_deps =
true,
327 template<
typename C >
329 : Internal::distributable(
"cancel_tuner" ), m_context( ctxt ), m_canceledTags(), m_cancelAll()
331 m_context.subscribe(
this );
337 m_context.unsubscribe(
this );
341 void cancel(
const Tag & t,
bool from_msg =
false )
343 if( ! m_cancelAll ) {
345 if( !from_msg && Internal::distributor::numProcs() > 1 ) {
346 serializer * _ser = m_context.new_serializer(
this );
347 (*_ser) & CT::SINGLE & t;
348 m_context.bcast_msg( _ser );
351 m_canceledTags.insert( t );
359 if( !from_msg && Internal::distributor::numProcs() > 1 ) {
360 serializer * _ser = m_context.new_serializer(
this );
362 m_context.bcast_msg( _ser );
370 unsafe_reset(
true );
374 template<
typename Arg >
377 return m_cancelAll ==
true || m_canceledTags.count( tag ) > 0;
384 CNC_ASSERT( Internal::distributor::active() );
391 this->cancel( _tag,
true );
394 this->cancel_all(
true );
397 this->unsafe_reset(
false );
400 CNC_ABORT(
"Unexpected message received (cancel_tuner)." );
409 virtual void unsafe_reset(
bool dist )
412 if( dist && Internal::distributor::numProcs() > 1 ) {
413 serializer * _ser = m_context.new_serializer(
this );
415 m_context.bcast_msg( _ser );
418 m_canceledTags.clear();
422 Internal::distributable_context & m_context;
423 tbb::concurrent_unordered_set< Tag, Hasher, Equality > m_canceledTags;
424 tbb::atomic< bool > m_cancelAll;
434 template<
template<
typename T,
typename I,
typename A >
class TT >
444 template<
typename Item >
448 typedef tbb::scalable_allocator< Item > type;
456 template<
typename Tag,
typename Item,
typename Coll >
459 table_type(
const Coll * c,
size_t sz = 0 ) : TT< Tag, Item, Coll >( c, sz ) {}
466 template<
typename Tag,
typename Item,
typename Coll >
478 template<
typename Tag >
495 template<
typename Tag >
509 template<
typename Tag >
519 template<
typename Tag,
typename ItemT,
typename Coll >
class hash_item_table;
520 template<
typename Tag,
typename ItemT,
typename Coll >
class vec_item_table;
552 template<
typename Range = Internal::no_range,
typename Partitioner = default_partitioner<> >
582 template<
typename Tag,
typename H = cnc_hash< Tag >,
typename E = cnc_equal< Tag > >
588 bool preserve_tags()
const 598 template<
typename Tuner >
599 const Tuner & get_default_tuner()
601 static tbb::atomic< Tuner * > s_tuner;
602 if( s_tuner == NULL ) {
603 Tuner * _tmp =
new Tuner;
604 if( s_tuner.compare_and_swap( _tmp, NULL ) != NULL )
delete _tmp;
612 #endif //CNC_DEFAULT_TUNER_H_ALREADY_INCLUDED int priority(const Tag &tag, Arg &arg) const
Allows definition of priorities to individual steps (which are identified by the tag).
The tuner base for vector-based item-tuners.
int was_canceled(const Tag &tag, Arg &) const
implements/overwrites step_tuner::was_canceled(...)
Provides hash operators for hashing.
default affinity to current thread
Partitioner partitioner_type
The type of the partitioner.
let tuner::compute_on return COMPUTE_ON_ALL_OTHERS if the step should be executed on all processes...
Default (NOP) implementations of the pfor_tuner interface.
void cancel(const Tag &t, bool from_msg=false)
cancel given step (identified by tag)
all processes consume given item
consumer process of given item is unkown
int compute_on(const Tag &, Arg &) const
tell the scheduler on which process to run the step (or range of steps) (distCnC) ...
static int numThreads(const Ctxt &ctxt)
returns number of threads used by scheduler in given context
int consumed_on(const Tag &tag) const
Tells the scheduler on which process(es) this item is going to be consumed.
Default implementations of the item-tuner interface for item-collections.
void init_table(TT< Tag, Item, Coll > &stbl) const
Initialize the internal storage.
partitioner_type partitioner() const
return a partitioner for range-based features, such as parallel_for
Default (NOP) implementations of the step_tuner interface.
Range range_type
A tag tuner must provide the type of the range, default is no range.
Internal::no_tag_table tag_table_type
A tag tuner must provide a tag-table type; default is no tag-table.
consumer process of given item is the local process
Default implementations of the tag-tuner interface for tag-collections.
int get_count(const Tag &tag) const
Allows specifying the number of gets to the given item.
The tuner base for hashmap-based item-tuners.
producer process of dependent item is unknown
Defines the type of the internal data store.
producer process of dependent item is local process
Step tuner with convenient cancelation capabilities.
void depends(const Tag &tag, Arg &arg, T &dC) const
Allows declaration of data dependencies (to items) of given step (identified by the tag)...
int was_canceled(const Tag &, Arg &) const
check for cancelation of given step
Handles serilialization of data-objects.
Provides equality operators for hashing.
let tuner::compute_on return COMPUTE_ON_LOCAL if the step should be executed locally ...
Internal::hash_tag_table< Tag, H, E > tag_table_type
A tag tuner must provide a tag-table type; default is no tag-table.
Class which manages item creation/uncreation..
void cancel_all(bool from_msg=false)
cancel all steps
bool sequentialize(const Tag &, Arg &) const
check if given step-instance needs to be executed sequentially
int produced_on(const Tag &tag) const
Tells the scheduler on which process(es) this item is going to be produced.
all processes but this consume given item
bool preserve_tags() const
return true if tag memoization is wanted; returns false by default (with no_tag_table) ...
let tuner::compute_on return COMPUTE_ON_ROUND_ROBIN to let the scheduler distribute it in a round-rob...
let tuner::compute_on return COMPUTE_ON_ALL if the step should be executed on all processes...
bool preschedule() const
Returns whether the step should be pre-scheduled.
int affinity(const Tag &, Arg &) const
Tell the scheduler the preferred thread for executing given step.