CnC
Public Member Functions | Static Public Attributes | List of all members
step_tuner< check_deps > Struct Template Reference

Default (NOP) implementations of the step_tuner interface. More...

Inherits tuner_base.

Inherited by cancel_tuner< Tag, check_deps, Hasher, Equality >.

Public Member Functions

template<typename Tag , typename Arg >
int priority (const Tag &tag, Arg &arg) const
 Allows definition of priorities to individual steps (which are identified by the tag). More...
 
template<typename Tag , typename Arg , typename T >
void depends (const Tag &tag, Arg &arg, T &dC) const
 Allows declaration of data dependencies (to items) of given step (identified by the tag). More...
 
bool preschedule () const
 Returns whether the step should be pre-scheduled. More...
 
template<typename Tag , typename Arg >
int affinity (const Tag &, Arg &) const
 Tell the scheduler the preferred thread for executing given step. More...
 
template<typename Tag , typename Arg >
int compute_on (const Tag &, Arg &) const
 tell the scheduler on which process to run the step (or range of steps) (distCnC) More...
 
template<typename Tag , typename Arg >
int was_canceled (const Tag &, Arg &) const
 check for cancelation of given step More...
 
template<typename Tag , typename Arg >
bool sequentialize (const Tag &, Arg &) const
 check if given step-instance needs to be executed sequentially More...
 

Static Public Attributes

static const bool check_deps_in_ranges = check_deps
 true if steps launched through ranges consume items or need global locking, false otherwise. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from tuner_base
static int myPid ()
 
static int numProcs ()
 
template<typename Ctxt >
static int numThreads (const Ctxt &ctxt)
 returns number of threads used by scheduler in given context
 

Detailed Description

template<bool check_deps = true>
struct CnC::step_tuner< check_deps >

Default (NOP) implementations of the step_tuner interface.

Also defines the interface a user-provided tuner must satisfy. Derive your tuner from this (to avoid implementing the entire interface).

It is recommended that your tuner does not implement the methods as templates. Instead, you should use the actual types that it expects.

#include <cnc/default_tuner.h>

Definition at line 119 of file default_tuner.h.

Member Function Documentation

◆ affinity()

int affinity ( const Tag &  ,
Arg &   
) const
inline

Tell the scheduler the preferred thread for executing given step.

Not all schedulers might actually evaluate this call (see Scheduler); it involves a virtual function call whenever a step is (re-)scheduled. This feature is most useful in combination with the CNC_PIN_THREADS environment variable (Scheduler Control).

Returns
thread id or AFFINITY_HERE (default)

Definition at line 190 of file default_tuner.h.

191  {
192  return AFFINITY_HERE;
193  }
default affinity to current thread
Definition: default_tuner.h:73

◆ compute_on()

int compute_on ( const Tag &  ,
Arg &   
) const
inline

tell the scheduler on which process to run the step (or range of steps) (distCnC)

return process id where the step will be executed, or COMPUTE_ON_ROUND_ROBIN, or COMPUTE_ON_LOCAL, or COMPUTE_ON_ALL, or COMPUTE_ON_ALL_OTHERS

Definition at line 202 of file default_tuner.h.

203  {
204  return COMPUTE_ON_ROUND_ROBIN;
205  }
let tuner::compute_on return COMPUTE_ON_ROUND_ROBIN to let the scheduler distribute it in a round-rob...
Definition: default_tuner.h:63

◆ depends()

void depends ( const Tag &  tag,
Arg &  arg,
T &  dC 
) const
inline

Allows declaration of data dependencies (to items) of given step (identified by the tag).

When a step-instance is prescribed through a corresponding tag_collection::put, this method will be called. You can declare dependencies to items by calling dC.depends( item_collection, dependent_item_tag ) for every item the step is going to 'get' in its execute method. The actual step execution will be delayed until all dependencies can be satisfied. The default implementation does nothing (NOP). Your implementation must accept dC by reference (T&).

Parameters
tagthe tag which identifies the step to be executed.
argthe argument as passed to context< Derived >::prescribed (usually the context)
dCopaque object (must be by reference!) providing method depends to declare item dependencies

Definition at line 150 of file default_tuner.h.

151  {
152  }

◆ preschedule()

bool preschedule ( ) const
inline

Returns whether the step should be pre-scheduled.

Pre-scheduling provides an alternative method for detecting data dependencies, in particular if it is combined with item_collection::unsafe_get and context::flush_gets() in the step-code.

The step instance will be run immediately when prescribed by a tag_collection::put. All items that are not yet available when accessed by the blocking item_collection::get() and/or non-blocking item_collection::unsafe_get() methods will automatically be treated as dependent items. The pre-run will end at the first unsuccessful blocking get or at context::flush_gets() (if any items got through item_collection::unsafe_get() were unavailable). Execution stops by throwing an exception, similar to un unsuccessful item_collection::get(). The step execution will be delayed until all detected dependencies can be satisfied.

Note
If all dependent items are available in the pre-scheduling execution the step gets fully executed. This can lead to very deep call-stacks if items are always available and new control is produced in steps.

Definition at line 177 of file default_tuner.h.

178  {
179  return false;
180  }

◆ priority()

int priority ( const Tag &  tag,
Arg &  arg 
) const
inline

Allows definition of priorities to individual steps (which are identified by the tag).

Returns
the default implementation always return 1.
Parameters
tagthe tag which identifies the step to be executed
argthe argument as passed to context< Derived >::prescribed (usually the context)
See also
also CNCROOT/samples/floyd_warshall

Definition at line 127 of file default_tuner.h.

128  {
129  return 1;
130  }

◆ sequentialize()

bool sequentialize ( const Tag &  ,
Arg &   
) const
inline

check if given step-instance needs to be executed sequentially

Returns
false by default, if true, step-instance gets queued for execution in a sequential phase (after all workers are quienscent)

Definition at line 239 of file default_tuner.h.

240  {
241  return false;
242  }

◆ was_canceled()

int was_canceled ( const Tag &  ,
Arg &   
) const
inline

check for cancelation of given step

Returns
true if step was canceled, false otherwise (default)
Note
Must be thread-safe. Runtime will try to not execute the step, but it might still get executed. Best effort - but no guarantees. Canceling steps makes all determinism guarantees void.

For distributed memory your implementation might require to sync its state across processes. Currently there is no API exposed to do that conveniently. However, an example implementatino CnC::cancel_tuner is provided which works on distributed memory.

See also
also CNCROOT/samples/floyd_warshall

Definition at line 230 of file default_tuner.h.

231  {
232  return false;
233  }

Member Data Documentation

◆ check_deps_in_ranges

const bool check_deps_in_ranges = check_deps
static

true if steps launched through ranges consume items or need global locking, false otherwise.

Avoiding checks for dependencies and global locks saves overhead and will perform better (e.g. for parallel_for). Safe execution (with checks) is the default (check_deps template argument).

Definition at line 214 of file default_tuner.h.


The documentation for this struct was generated from the following file: