MADNESS  0.10.1
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
madness::TaskInterface Class Reference

All world tasks must be derived from this public interface. More...

#include <taskfn.h>

Inheritance diagram for madness::TaskInterface:
Inheritance graph
[legend]
Collaboration diagram for madness::TaskInterface:
Collaboration graph
[legend]

Classes

struct  Submit
 

Public Member Functions

 TaskInterface (const TaskAttributes &attr)
 Create a new task with zero dependencies and given attributes. More...
 
 TaskInterface (int ndepend, const char *caller, const TaskAttributes attr=TaskAttributes())
 
 TaskInterface (int ndepend=0, const TaskAttributes attr=TaskAttributes())
 Create a new task with ndepend dependencies (default 0) and given attributes. More...
 
virtual ~TaskInterface ()
 
Worldget_world () const
 
virtual void run (World &)
 Runs a single-threaded task ... derived classes must implement this. More...
 
virtual void run (World &world, const TaskThreadEnv &env)
 Runs a multi-threaded task. More...
 
- Public Member Functions inherited from madness::PoolTaskInterface
 PoolTaskInterface ()
 Default constructor. More...
 
 PoolTaskInterface (const TaskAttributes &attr)
 
virtual ~PoolTaskInterface ()=default
 Destructor. More...
 
void execute ()
 
void set_nthread (int nthread)
 Call this to reset the number of threads before the task is submitted. More...
 
- Public Member Functions inherited from madness::TaskAttributes
 TaskAttributes (const TaskAttributes &attr)
 Copy constructor. More...
 
 TaskAttributes (unsigned long flags=0)
 Sets the attributes to the desired values. More...
 
virtual ~TaskAttributes ()
 
int get_nthread () const
 Get the number of threads. More...
 
bool is_generator () const
 Test if the generator attribute is true. More...
 
bool is_high_priority () const
 Test if the high priority attribute is true. More...
 
bool is_stealable () const
 Test if the stealable attribute is true. More...
 
template<typename Archive >
void serialize (Archive &ar)
 Serializes the attributes for I/O. More...
 
TaskAttributesset_generator (bool generator_hint)
 Sets the generator attribute. More...
 
TaskAttributesset_highpriority (bool hipri)
 Sets the high priority attribute. More...
 
void set_nthread (int nthread)
 Set the number of threads. More...
 
TaskAttributesset_stealable (bool stealable)
 Sets the stealable attribute. More...
 
- Public Member Functions inherited from madness::DependencyInterface
 DependencyInterface (int ndep, const char *caller)
 
 DependencyInterface (int ndep=0)
 
virtual ~DependencyInterface ()
 Destructor. More...
 
void dec ()
 Decrement the number of dependencies and invoke the callback if ndepend==0. More...
 
void dec_debug (const char *caller)
 
void inc ()
 Increment the number of dependencies. More...
 
void inc_debug (const char *caller)
 Same as inc(), but keeps track of caller; calling dec_debug() will signal error if no matching inc_debug() had been invoked
More...
 
int ndep () const
 Returns the number of unsatisfied dependencies. More...
 
void notify ()
 Invoked by callbacks to notify of dependencies being satisfied. More...
 
void notify_debug (const char *caller)
 Overload of CallbackInterface::notify_debug(), updates dec() More...
 
bool probe () const
 Returns true if ndepend == 0 (no unsatisfied dependencies). More...
 
void register_callback (CallbackInterface *callback)
 Registers a callback that will be executed when ndepend==0; immediately invoked if ndepend==0. More...
 
void register_final_callback (CallbackInterface *callback)
 Registers the final callback to be executed when ndepend==0; immediately invoked if ndepend==0. More...
 
- Public Member Functions inherited from madness::CallbackInterface
virtual ~CallbackInterface ()
 

Static Public Attributes

static bool debug = false
 
- Static Public Attributes inherited from madness::TaskAttributes
static const unsigned long GENERATOR = 1ul<<8
 Mask for generator bit. More...
 
static const unsigned long HIGHPRIORITY = GENERATOR<<2
 Mask for priority bit. More...
 
static const unsigned long NTHREAD = 0xff
 Mask for nthread byte. More...
 
static const unsigned long STEALABLE = GENERATOR<<1
 Mask for stealable bit. More...
 

Protected Member Functions

virtual void run (const TaskThreadEnv &env)
 Override this method to implement a multi-threaded task. More...
 
- Protected Member Functions inherited from madness::CallbackInterface
virtual void notify_debug_impl (const char *caller)
 

Private Member Functions

void register_submit_callback ()
 Adds call back to schedule task when outstanding dependencies are satisfied. More...
 
void set_info (World *w, CallbackInterface *c)
 Set task info. More...
 

Private Attributes

CallbackInterfacecompletion
 
madness::TaskInterface::Submit submit
 
volatile Worldworld
 

Friends

class WorldTaskQueue
 

Additional Inherited Members

- Static Public Member Functions inherited from madness::TaskAttributes
static TaskAttributes generator ()
 
static TaskAttributes hipri ()
 
static TaskAttributes multi_threaded (int nthread)
 
- Static Protected Member Functions inherited from madness::PoolTaskInterface
template<typename fnobjT >
static std::enable_if<!(detail::function_traits< fnobjT >::value||detail::memfunc_traits< fnobjT >::value) >::type make_id (std::pair< void *, unsigned short > &id, const fnobjT &)
 
template<typename fnT >
static std::enable_if< detail::function_traits< fnT >::value||detail::memfunc_traits< fnT >::value >::type make_id (std::pair< void *, unsigned short > &id, fnT fn)
 

Detailed Description

All world tasks must be derived from this public interface.

Multiple worlds with independent queues feed tasks into shared task pool that is mapped to the H/W.

For simplicity and backward compatibility we maintain two run interfaces but new code should adopt the multithreaded interface

run(World&) - the user implements this for a single-threaded task

run(World&, const TaskThreadEnv&) - the user implements this for a multi-threaded task.

Constructor & Destructor Documentation

◆ TaskInterface() [1/3]

madness::TaskInterface::TaskInterface ( int  ndepend = 0,
const TaskAttributes  attr = TaskAttributes() 
)
inline

Create a new task with ndepend dependencies (default 0) and given attributes.

◆ TaskInterface() [2/3]

madness::TaskInterface::TaskInterface ( int  ndepend,
const char *  caller,
const TaskAttributes  attr = TaskAttributes() 
)
inline

Create a new task with ndepend dependencies (default 0) and given attributes, keep track of caller for debugging purposes.

◆ TaskInterface() [3/3]

madness::TaskInterface::TaskInterface ( const TaskAttributes attr)
inlineexplicit

Create a new task with zero dependencies and given attributes.

◆ ~TaskInterface()

virtual madness::TaskInterface::~TaskInterface ( )
inlinevirtual

Member Function Documentation

◆ get_world()

World* madness::TaskInterface::get_world ( ) const
inline

References world.

◆ register_submit_callback()

void madness::TaskInterface::register_submit_callback ( )
inlineprivate

Adds call back to schedule task when outstanding dependencies are satisfied.

References madness::DependencyInterface::register_final_callback(), and submit.

Referenced by madness::WorldTaskQueue::add().

◆ run() [1/3]

void madness::TaskInterface::run ( const TaskThreadEnv info)
protectedvirtual

Override this method to implement a multi-threaded task.

info.nthread() will be the number of threads collaborating on this task.

info.id() will be the index of the current thread id=0,...,nthread-1.

info.barrier() will be a barrier for all of the threads, and returns true for the last thread to enter the barrier (other threads get false).

Todo:
Description needed.
Parameters
[in]infoDescription needed.

Implements madness::PoolTaskInterface.

References completion, debug, MADNESS_ASSERT, w(), and world.

Referenced by run().

◆ run() [2/3]

virtual void madness::TaskInterface::run ( World )
inlinevirtual

Runs a single-threaded task ... derived classes must implement this.

This interface may disappear so new code should use the multi-threaded interface.

Reimplemented in TestTask, madness::MatrixInnerTask< T, R, NDIM >, and Task.

References MADNESS_EXCEPTION.

◆ run() [3/3]

virtual void madness::TaskInterface::run ( World world,
const TaskThreadEnv env 
)
inlinevirtual

◆ set_info()

void madness::TaskInterface::set_info ( World w,
CallbackInterface c 
)
inlineprivate

Set task info.

Parameters
wThe world object that contains the task
cCall this callback on completion

References c, completion, w(), and world.

Referenced by madness::WorldTaskQueue::add().

Friends And Related Function Documentation

◆ WorldTaskQueue

friend class WorldTaskQueue
friend

Member Data Documentation

◆ completion

CallbackInterface* madness::TaskInterface::completion
private

Referenced by ~TaskInterface(), run(), and set_info().

◆ debug

bool madness::TaskInterface::debug = false
static

Referenced by run().

◆ submit

madness::TaskInterface::Submit madness::TaskInterface::submit
private

◆ world

volatile World* madness::TaskInterface::world
private

The documentation for this class was generated from the following files: