Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mitsuba::Scheduler Class Reference

Centralized task scheduler implementation. More...

#include <mitsuba/core/sched.h>

+ Inheritance diagram for mitsuba::Scheduler:

Public Member Functions

bool schedule (ParallelProcess *process)
 Schedule a parallelizable process for execution. More...
 
bool wait (const ParallelProcess *process)
 Block until the process has successfully been completed or canceled prematurely. More...
 
bool cancel (ParallelProcess *proc)
 Cancel the execution of a parallelizable process. More...
 
int registerResource (SerializableObject *resource)
 Register a serializable resource with the scheduler. More...
 
int registerMultiResource (std::vector< SerializableObject * > &resources)
 Register a multiple resource with the scheduler. More...
 
void retainResource (int resourceID)
 Increase the reference count of a previously registered resource. More...
 
bool unregisterResource (int id)
 Unregister a resource from the scheduler. More...
 
int getResourceID (const SerializableObject *resource) const
 Return the ID of a registered resource. More...
 
void registerWorker (Worker *processor)
 Register a worker with the scheduler. More...
 
void unregisterWorker (Worker *processor)
 Unregister a worker from the scheduler. More...
 
size_t getWorkerCount () const
 Get the number of workers. More...
 
size_t getLocalWorkerCount () const
 Get the number of local workers. More...
 
WorkergetWorker (int index)
 Retrieve one of the workers by index. More...
 
void start ()
 Start all workers and begin execution of any scheduled processes. More...
 
void pause ()
 Pause the distribution of work units and shut down all running workers. More...
 
void stop ()
 Cancel all running processes and free memory used by resources. More...
 
size_t getCoreCount () const
 Return the total number of cores exposed through this scheduler. More...
 
bool hasLocalWorkers () const
 Does the scheduler have one or more local workers? More...
 
bool hasRemoteWorkers () const
 Does the scheduler have one or more remote workers? More...
 
bool isRunning () const
 Has the scheduler been started? More...
 
bool isBusy () const
 Is the scheduler currently executing work? More...
 
virtual const ClassgetClass () const
 Retrieve this object's class. More...
 
SerializableObjectgetResource (int id, int coreIndex=-1)
 Look up a resource by ID & core index. More...
 
const MemoryStreamgetResourceStream (int id)
 Return a resource in the form of a binary data stream. More...
 
bool isMultiResource (int id) const
 Test whether this is a multi-resource, i.e. different for every core. More...
 
- Public Member Functions inherited from Object
 Object ()
 Construct a new object. More...
 
int getRefCount () const
 Return the current reference count. More...
 
void incRef () const
 Increase the reference count of the object by one. More...
 
void decRef (bool autoDeallocate=true) const
 Decrease the reference count of the object and possibly deallocate it. More...
 
virtual std::string toString () const
 Return a human-readable string representation of the object's contents. More...
 

Static Public Member Functions

static SchedulergetInstance ()
 Return a pointer to the scheduler of this process. More...
 
static void staticInitialization ()
 Initialize the scheduler of this process – called once in main() More...
 
static void staticShutdown ()
 Free the memory taken by staticInitialization() More...
 
- Static Public Member Functions inherited from Object
static void staticInitialization ()
 Initializes the built-in reference count debugger (if enabled) More...
 
static void staticShutdown ()
 Free the memory taken by staticInitialization() More...
 

Static Public Attributes

static Classm_theClass
 
- Static Public Attributes inherited from Object
static Classm_theClass
 Pointer to the object's class descriptor. More...
 

Protected Member Functions

 Scheduler ()
 Protected constructor. More...
 
virtual ~Scheduler ()
 Virtual destructor. More...
 
EStatus acquireWork (Item &item, bool local, bool onlyTry, bool keepLock)
 
void releaseLock ()
 Release the main scheduler lock – internally used by the remote worker. More...
 
void releaseWork (Item &item)
 
bool cancel (ParallelProcess *proc, bool reduceInflight)
 
void setProcessByID (Item &item, int id)
 
void signalProcessTermination (ParallelProcess *proc, ProcessRecord *rec)
 Announces the termination of a process. More...
 
- Protected Member Functions inherited from Object
virtual ~Object ()
 Virtual private deconstructor. (Will only be called by ref) More...
 

Friends

class Worker
 

Detailed Description

Centralized task scheduler implementation.

Accepts parallelizable jobs and distributes their computational load both locally and remotely. This is done by associating different types of Worker instances with the scheduler. These try to acquire work units from the scheduler, which are then executed on the current machine or sent to remote nodes over a network connection.

Constructor & Destructor Documentation

mitsuba::Scheduler::Scheduler ( )
protected

Protected constructor.

virtual mitsuba::Scheduler::~Scheduler ( )
protectedvirtual

Virtual destructor.

Member Function Documentation

EStatus mitsuba::Scheduler::acquireWork ( Item &  item,
bool  local,
bool  onlyTry,
bool  keepLock 
)
protected

Acquire a piece of work from the scheduler – internally used by the different worker implementations.

bool mitsuba::Scheduler::cancel ( ParallelProcess proc)
inline

Cancel the execution of a parallelizable process.

Upon return, no more work from this process is running. Returns false if the process does not exist (anymore).

bool mitsuba::Scheduler::cancel ( ParallelProcess proc,
bool  reduceInflight 
)
protected

Cancel the execution of a parallelizable process. Upon return, no more work from this process is running. When the second parameter is set to true, the number of in-flight work units for this process is reduced by one.

virtual const Class* mitsuba::Scheduler::getClass ( ) const
virtual

Retrieve this object's class.

Reimplemented from Object.

size_t mitsuba::Scheduler::getCoreCount ( ) const

Return the total number of cores exposed through this scheduler.

static Scheduler* mitsuba::Scheduler::getInstance ( )
inlinestatic

Return a pointer to the scheduler of this process.

size_t mitsuba::Scheduler::getLocalWorkerCount ( ) const

Get the number of local workers.

SerializableObject* mitsuba::Scheduler::getResource ( int  id,
int  coreIndex = -1 
)

Look up a resource by ID & core index.

int mitsuba::Scheduler::getResourceID ( const SerializableObject resource) const

Return the ID of a registered resource.

Throws an exception if the resource cannot be found.

const MemoryStream* mitsuba::Scheduler::getResourceStream ( int  id)

Return a resource in the form of a binary data stream.

Worker* mitsuba::Scheduler::getWorker ( int  index)

Retrieve one of the workers by index.

size_t mitsuba::Scheduler::getWorkerCount ( ) const

Get the number of workers.

bool mitsuba::Scheduler::hasLocalWorkers ( ) const

Does the scheduler have one or more local workers?

bool mitsuba::Scheduler::hasRemoteWorkers ( ) const

Does the scheduler have one or more remote workers?

bool mitsuba::Scheduler::isBusy ( ) const

Is the scheduler currently executing work?

bool mitsuba::Scheduler::isMultiResource ( int  id) const

Test whether this is a multi-resource, i.e. different for every core.

bool mitsuba::Scheduler::isRunning ( ) const
inline

Has the scheduler been started?

void mitsuba::Scheduler::pause ( )

Pause the distribution of work units and shut down all running workers.

Any currently scheduled work units are still completed. Processing can be resumed via start().

int mitsuba::Scheduler::registerMultiResource ( std::vector< SerializableObject * > &  resources)

Register a multiple resource with the scheduler.

Multi means that in comparison to the previous method, a separate instance is provided for every core. An example where this is useful is to distribute random generator state when performing parallel Monte Carlo simulations. resources must be a vector whose length is equal to getCoreCount().

int mitsuba::Scheduler::registerResource ( SerializableObject resource)

Register a serializable resource with the scheduler.

A resource should be thought of as a constant state that is shared amongst all processing nodes. Resources can be reused by subsequent parallel processes, and consequently do not have to be re-transmitted over the network. Returns a resource ID, which can be used to reference the associated data.

void mitsuba::Scheduler::registerWorker ( Worker processor)

Register a worker with the scheduler.

void mitsuba::Scheduler::releaseLock ( )
inlineprotected

Release the main scheduler lock – internally used by the remote worker.

void mitsuba::Scheduler::releaseWork ( Item &  item)
inlineprotected
void mitsuba::Scheduler::retainResource ( int  resourceID)

Increase the reference count of a previously registered resource.

The resource must be unregistered an additional time after calling this function.

See Also
unregisterResource
bool mitsuba::Scheduler::schedule ( ParallelProcess process)

Schedule a parallelizable process for execution.

If the scheduler is currently running and idle, its execution will begin immediately. Returns false if the process is already scheduled and has not yet terminated and true in any other case.

void mitsuba::Scheduler::setProcessByID ( Item &  item,
int  id 
)
inlineprotected

Internally used to prepare a Scheduler::Item structure when only the process ID is known.

void mitsuba::Scheduler::signalProcessTermination ( ParallelProcess proc,
ProcessRecord *  rec 
)
protected

Announces the termination of a process.

void mitsuba::Scheduler::start ( )

Start all workers and begin execution of any scheduled processes.

static void mitsuba::Scheduler::staticInitialization ( )
static

Initialize the scheduler of this process – called once in main()

static void mitsuba::Scheduler::staticShutdown ( )
static

Free the memory taken by staticInitialization()

void mitsuba::Scheduler::stop ( )

Cancel all running processes and free memory used by resources.

bool mitsuba::Scheduler::unregisterResource ( int  id)

Unregister a resource from the scheduler.

Note that the resource's won't be removed until all processes using it have terminated)

Returns
false if the resource could not be found
void mitsuba::Scheduler::unregisterWorker ( Worker processor)

Unregister a worker from the scheduler.

bool mitsuba::Scheduler::wait ( const ParallelProcess process)

Block until the process has successfully been completed or canceled prematurely.

Returns false if the process does not exist or has already finished by the time wait() is invoked.

Friends And Related Function Documentation

friend class Worker
friend

Member Data Documentation

Class* mitsuba::Scheduler::m_theClass
static

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