LAMA
|
Class for asynchronous tasks. More...
#include <Task.hpp>
Public Types | |
typedef unsigned int | Id |
Public Member Functions | |
Task (boost::function< void()> function, int numOmpThreads=0) | |
Construct a new task that will execute a void function, no arguments. | |
~Task () | |
Destructor. | |
void | synchronize () |
Method synchronize waits for finalization of the task. | |
bool | probe () const |
Method test if this Task is already finished. | |
Id | getId () const |
Query a task for its id. | |
virtual void | writeAt (std::ostream &stream) const |
Override method of Printable. | |
Private Member Functions | |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
Static Private Member Functions | |
static LAMAThreadPool & | getThreadPool () |
Private Attributes | |
boost::shared_ptr< LAMAThreadTask > | mTask |
Static Private Attributes | |
static boost::shared_ptr < LAMAThreadPool > | theThreadPool |
Thread pool will be allocated on need, shared pointer guarantees deallocation. |
Class for asynchronous tasks.
Task represents a asynchronous task, which allows synchronization. To start an asynchronous task one simply have to construct a Task object and pass a pointer to the function to execute to its constructor. If the signature of the function does not fit boost::bind can be used to build an appropriate function pointer. Be careful with reference because they need special wrapper objects. E.g.
void foo( Vector& y, const Matrix& A, Scalar alpha, const Vector& x); ... void bar( Vector& y, const Matrix& A, const Scalar alpha, const Vector& x) { //construct function pointer boost::function<void()> function = boost::bind( foo, boost::ref(y), alpha ,boost::cref(A), boost::cref(x) ); //start asynchronous tasks Task task( function ); //do other work //wait for asynchronous task to finish task.synchronize(); }
typedef unsigned int lama::Task::Id |
lama::Task::Task | ( | boost::function< void()> | function, |
int | numOmpThreads = 0 |
||
) |
Construct a new task that will execute a void function, no arguments.
Its safe to start a recursive Task, e.g. to start a Task from a Task. The recursive Task might execute synchronously to avoid deadlock situations.
[in] | function | is void() function executed by the new created task. |
[in] | numOmpThreads | number of openmp threads the task should use (if numOmpThreads == 0 omp_get_max_threads() is used) |
By using boost::function, it is possible to bind arguments via boost::bind.
References getThreadPool(), mTask, and lama::LAMAThreadPool::schedule().
Destructor.
Implicitly synchronizes the Task.
Task::Id lama::Task::getId | ( | ) | const |
LAMAThreadPool & lama::Task::getThreadPool | ( | ) | [static, private] |
References theThreadPool.
Referenced by synchronize(), and Task().
lama::Task::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [private] |
bool lama::Task::probe | ( | ) | const |
Method test if this Task is already finished.
References lama::LAMAThreadTask::FINISHED, and mTask.
void lama::Task::synchronize | ( | ) |
Method synchronize waits for finalization of the task.
References getThreadPool(), LAMA_THROWEXCEPTION, mTask, and lama::LAMAThreadPool::wait().
void lama::Task::writeAt | ( | std::ostream & | stream | ) | const [virtual] |
boost::shared_ptr<LAMAThreadTask> lama::Task::mTask [private] |
Referenced by getId(), probe(), synchronize(), and Task().
boost::shared_ptr< LAMAThreadPool > lama::Task::theThreadPool [static, private] |
Thread pool will be allocated on need, shared pointer guarantees deallocation.
Referenced by getThreadPool().