AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
agx::Job Class Reference

An abstract job/workblock representation, which allows work threads to execute arbitrary tasks. More...

#include <Job.h>

+ Inheritance diagram for agx::Job:

Public Member Functions

 Job ()
 
 Job (const Callback &callback, agx::UInt32 costEstimate=100)
 
 Job (const Job &other)
 
virtual ~Job ()
 
void addDependency (Job *parent)
 Add a dependency to a job.
 
void clearChildDependencies ()
 Remove all child dependencies.
 
void decrementNumDependencies (agx::UInt32 size=1)
 Explicitly decrement the number of parent dependencies.
 
Thread * getAssignedThread ()
 
const Callback & getCallback () const
 Return the current callback.
 
const JobPtrVector & getChildDependencies () const
 
agx::UInt32 getCostEstimate () const
 
Real getExecutionTime () const
 
const char * getName () const
 
agx::UInt32 getNumDependencies () const
 
const JobPtrVector & getParentDependencies () const
 
SyncTag * getSyncTag ()
 
agx::UInt32 getTag () const
 
Thread * getTargetThread ()
 
Task * getTask ()
 
const Timer & getTimer () const
 
bool hasDependency (Job *parent)
 
virtual void implementation ()
 Job implementation, override in subclass.
 
void incrementNumDependencies (agx::UInt32 size=1)
 Explicitly increment the number of parent dependencies.
 
agx::Index & index ()
 
const agx::Index & index () const
 
void init (const Callback &callback=Callback(), agx::UInt32 costEstimate=100)
 Initialize the job.
 
Job & operator= (const Job &other)
 
void removeAllDependencies ()
 Remove all parent dependencies.
 
void removeDependency (Job *parent)
 Remove a dependency from a job.
 
bool resolve ()
 Increase the dependency counter for the job, and queue job for execution if all dependencies are resolved.
 
void setCallback (const Callback &callback)
 Set the callback which is called when execute() runs.
 
void setCostEstimate (agx::UInt32 cost)
 Specify the cost estimate for this job.
 
void setName (const char *name)
 Set the name of the job, for debugging.
 
void setNumDependencies (agx::UInt32 numDependencies)
 Explicitly set the number of parent dependencies.
 
void setSyncTag (SyncTag *tag)
 Set the synchronization tag which must enter completion status before the job is executed.
 
void setTag (agx::UInt32 tag)
 Set the job tag, can be used to keep track of different job classes etc.
 
void setTargetThread (Thread *thread)
 Set the target thread which the job will be executed on.
 
void setTask (Task *task)
 Set the task which the job belongs to.
 
void spawn ()
 Schedule job for execution in thread pool.
 
- Public Member Functions inherited from agx::Callback
 Callback ()
 
 Callback (const CallbackFunction &func, bool repeatEnable=true)
 
template<class ClassT >
 Callback (void(ClassT::*fun)(), ClassT *obj, bool repeatEnable=true)
 
const CallbackFunction & implementation () const
 Return the std representation.
 
bool isRepeating () const
 
bool isValid () const
 
 operator bool () const
 
 operator const CallbackFunction & () const
 
void operator() () const
 Execute the callback.
 
void run () const
 

Protected Attributes

Thread * m_assignedThread
 
Callback m_callback
 
JobPtrVector m_children
 
agx::UInt32 m_cost
 
std::atomic< Int32 > m_dependencyCounter
 
agx::Index m_index
 
const char * m_name
 
agx::UInt32 m_numDependencies
 
JobPtrVector m_parents
 
SyncTagRef m_syncTag
 
agx::UInt32 m_tag
 
Thread * m_targetThread
 
Task * m_task
 
Timer m_timer
 

Additional Inherited Members

- Public Types inherited from agx::Callback
typedef std::function< void()> CallbackFunction
 

Detailed Description

An abstract job/workblock representation, which allows work threads to execute arbitrary tasks.

The jobs have specified dependecies which enables them to be organized in an execution graph.

Definition at line 60 of file Job.h.

Constructor & Destructor Documentation

◆ Job() [1/3]

agx::Job::Job ( )

Definition at line 418 of file Job.h.

◆ Job() [2/3]

agx::Job::Job ( const Job &  other)

Definition at line 432 of file Job.h.

◆ Job() [3/3]

agx::Job::Job ( const Callback &  callback,
agx::UInt32  costEstimate = 100 
)

Definition at line 453 of file Job.h.

◆ ~Job()

virtual agx::Job::~Job ( )
virtual

References agx::init().

Member Function Documentation

◆ addDependency()

void agx::Job::addDependency ( Job *  parent)

Add a dependency to a job.

Parameters
parentThe parent dependency

Definition at line 503 of file Job.h.

References agxAssert, m_children, m_numDependencies, m_parents, and agx::VectorPOD< T, Allocator >::push_back().

◆ clearChildDependencies()

void agx::Job::clearChildDependencies ( )

Remove all child dependencies.

NOTE: Parent dependencies in children are not updated

Definition at line 536 of file Job.h.

References agx::VectorPOD< T, Allocator >::clear(), and m_children.

◆ decrementNumDependencies()

void agx::Job::decrementNumDependencies ( agx::UInt32  size = 1)

Explicitly decrement the number of parent dependencies.

Definition at line 548 of file Job.h.

References m_numDependencies.

◆ getAssignedThread()

Thread * agx::Job::getAssignedThread ( )
Returns
The thread which executed the job.

Definition at line 497 of file Job.h.

References m_assignedThread.

◆ getCallback()

const Job::Callback & agx::Job::getCallback ( ) const

Return the current callback.

Definition at line 553 of file Job.h.

References m_callback.

◆ getChildDependencies()

const JobPtrVector & agx::Job::getChildDependencies ( ) const
Returns
The list of child dependencies.

Definition at line 550 of file Job.h.

References m_children.

◆ getCostEstimate()

agx::UInt32 agx::Job::getCostEstimate ( ) const
Returns
The estimated job size.

Definition at line 575 of file Job.h.

References m_cost.

Referenced by agx::JobGroup::addJob().

◆ getExecutionTime()

Real agx::Job::getExecutionTime ( ) const
Returns
The execution time, in ms.

Definition at line 573 of file Job.h.

References agx::Timer::getTime(), and m_timer.

◆ getName()

const char * agx::Job::getName ( ) const
Returns
The name of the job.

Definition at line 488 of file Job.h.

References m_name.

◆ getNumDependencies()

agx::UInt32 agx::Job::getNumDependencies ( ) const
Returns
The number of parent dependencies.

Definition at line 546 of file Job.h.

References m_numDependencies.

◆ getParentDependencies()

const JobPtrVector & agx::Job::getParentDependencies ( ) const
Returns
The parent jobs. NOTE Only available in debug build, in release the vector is always empty.

Definition at line 534 of file Job.h.

References m_parents.

◆ getSyncTag()

SyncTag * agx::Job::getSyncTag ( )
Returns
The synchronization tag for this job.

Definition at line 495 of file Job.h.

References m_syncTag.

◆ getTag()

agx::UInt32 agx::Job::getTag ( ) const
Returns
The job tag.

Definition at line 499 of file Job.h.

References m_tag.

◆ getTargetThread()

Thread * agx::Job::getTargetThread ( )
Returns
The thread this job is bound to. nullptr if no explicit thread binding.

Definition at line 491 of file Job.h.

References m_targetThread.

◆ getTask()

Task * agx::Job::getTask ( )
Returns
The task which this job is part of.

Definition at line 493 of file Job.h.

References m_task.

◆ getTimer()

const Timer & agx::Job::getTimer ( ) const
Returns
The execution timer.

Definition at line 574 of file Job.h.

References m_timer.

◆ hasDependency()

bool agx::Job::hasDependency ( Job *  parent)
Parameters
parent- The parent job to check
Returns
True if the specified job is a direct parent dependency, not recursive.

Definition at line 528 of file Job.h.

References agxAssert, agx::VectorPOD< T, Allocator >::contains(), and m_children.

◆ implementation()

virtual void agx::Job::implementation ( )
virtual

Job implementation, override in subclass.

Default implementation use a generic callback.

Reimplemented in agx::RangeJob, agx::RangeJobT< T >, and agx::JobGroup.

◆ incrementNumDependencies()

void agx::Job::incrementNumDependencies ( agx::UInt32  size = 1)

Explicitly increment the number of parent dependencies.

Definition at line 547 of file Job.h.

References m_numDependencies.

◆ index() [1/2]

agx::Index & agx::Job::index ( )
Returns
The index of the job (for parallel kernels)

Definition at line 578 of file Job.h.

References m_index.

◆ index() [2/2]

const agx::Index & agx::Job::index ( ) const

Definition at line 579 of file Job.h.

References m_index.

◆ init()

void agx::Job::init ( const Callback &  callback = Callback(),
agx::UInt32  costEstimate = 100 
)

◆ operator=()

Job & agx::Job::operator= ( const Job &  other)

◆ removeAllDependencies()

void agx::Job::removeAllDependencies ( )

Remove all parent dependencies.

NOTE: Child dependencies in parents are not updated

Definition at line 538 of file Job.h.

References agx::VectorPOD< T, Allocator >::clear(), m_numDependencies, and m_parents.

◆ removeDependency()

void agx::Job::removeDependency ( Job *  parent)

Remove a dependency from a job.

Parameters
parentThe parent dependency

Definition at line 515 of file Job.h.

References agxAssert, agxVerify, agx::VectorPOD< T, Allocator >::findAndErase(), m_children, m_numDependencies, and m_parents.

◆ resolve()

bool agx::Job::resolve ( )

Increase the dependency counter for the job, and queue job for execution if all dependencies are resolved.

Automatically called as parent dependencies are completed.

Returns
true if all dependencies are resolved

◆ setCallback()

void agx::Job::setCallback ( const Callback &  callback)

Set the callback which is called when execute() runs.

Definition at line 552 of file Job.h.

References m_callback.

◆ setCostEstimate()

void agx::Job::setCostEstimate ( agx::UInt32  cost)

Specify the cost estimate for this job.

Definition at line 576 of file Job.h.

References m_cost.

◆ setName()

void agx::Job::setName ( const char *  name)

Set the name of the job, for debugging.

Definition at line 489 of file Job.h.

References m_name.

◆ setNumDependencies()

void agx::Job::setNumDependencies ( agx::UInt32  numDependencies)

Explicitly set the number of parent dependencies.

NOTE: Only use if you know what you are doing....

Definition at line 537 of file Job.h.

References m_numDependencies.

Referenced by init().

◆ setSyncTag()

void agx::Job::setSyncTag ( SyncTag *  tag)

Set the synchronization tag which must enter completion status before the job is executed.

Definition at line 496 of file Job.h.

References m_syncTag.

◆ setTag()

void agx::Job::setTag ( agx::UInt32  tag)

Set the job tag, can be used to keep track of different job classes etc.

Definition at line 500 of file Job.h.

References m_tag.

◆ setTargetThread()

void agx::Job::setTargetThread ( Thread *  thread)

Set the target thread which the job will be executed on.

Definition at line 492 of file Job.h.

References m_targetThread.

◆ setTask()

void agx::Job::setTask ( Task *  task)

Set the task which the job belongs to.

Normally handled automatically.

Definition at line 494 of file Job.h.

References m_task.

◆ spawn()

void agx::Job::spawn ( )

Schedule job for execution in thread pool.

Member Data Documentation

◆ m_assignedThread

Thread* agx::Job::m_assignedThread
protected

Definition at line 266 of file Job.h.

Referenced by getAssignedThread(), init(), and operator=().

◆ m_callback

Callback agx::Job::m_callback
protected

Definition at line 260 of file Job.h.

Referenced by getCallback(), init(), operator=(), and setCallback().

◆ m_children

JobPtrVector agx::Job::m_children
protected

◆ m_cost

agx::UInt32 agx::Job::m_cost
protected

◆ m_dependencyCounter

std::atomic<Int32> agx::Job::m_dependencyCounter
protected

Definition at line 263 of file Job.h.

Referenced by operator=().

◆ m_index

agx::Index agx::Job::m_index
protected

Definition at line 270 of file Job.h.

Referenced by index(), init(), and operator=().

◆ m_name

const char* agx::Job::m_name
protected

Definition at line 257 of file Job.h.

Referenced by getName(), operator=(), and setName().

◆ m_numDependencies

◆ m_parents

JobPtrVector agx::Job::m_parents
protected

◆ m_syncTag

SyncTagRef agx::Job::m_syncTag
protected

Definition at line 267 of file Job.h.

Referenced by getSyncTag(), operator=(), and setSyncTag().

◆ m_tag

agx::UInt32 agx::Job::m_tag
protected

Definition at line 269 of file Job.h.

Referenced by getTag(), init(), operator=(), and setTag().

◆ m_targetThread

Thread* agx::Job::m_targetThread
protected

Definition at line 265 of file Job.h.

Referenced by getTargetThread(), init(), operator=(), and setTargetThread().

◆ m_task

Task* agx::Job::m_task
protected

Definition at line 264 of file Job.h.

Referenced by getTask(), operator=(), and setTask().

◆ m_timer

Timer agx::Job::m_timer
protected

Definition at line 261 of file Job.h.

Referenced by getExecutionTime(), getTimer(), and operator=().


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