Centralized task scheduler implementation. More...
#include <mitsuba/core/sched.h>
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... | |
Worker * | getWorker (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 Class * | getClass () const |
Retrieve this object's class. More... | |
SerializableObject * | getResource (int id, int coreIndex=-1) |
Look up a resource by ID & core index. More... | |
const MemoryStream * | getResourceStream (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 Scheduler * | getInstance () |
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 Class * | m_theClass |
Static Public Attributes inherited from Object | |
static Class * | m_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 |
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.
|
protected |
Protected constructor.
|
protectedvirtual |
Virtual destructor.
|
protected |
Acquire a piece of work from the scheduler – internally used by the different worker implementations.
|
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).
|
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 |
Retrieve this object's class.
Reimplemented from Object.
size_t mitsuba::Scheduler::getCoreCount | ( | ) | const |
Return the total number of cores exposed through this scheduler.
|
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.
|
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.
|
inlineprotected |
Release the main scheduler lock – internally used by the remote worker.
|
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.
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.
|
inlineprotected |
Internally used to prepare a Scheduler::Item structure when only the process ID is known.
|
protected |
Announces the termination of a process.
void mitsuba::Scheduler::start | ( | ) |
Start all workers and begin execution of any scheduled processes.
|
static |
Initialize the scheduler of this process – called once in main()
|
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)
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.
|
friend |
|
static |