opm-simulators
Loading...
Searching...
No Matches
Opm::TaskletRunner Class Reference

Handles where a given tasklet is run. More...

#include <tasklets.hpp>

Public Member Functions

 TaskletRunner (const TaskletRunner &)=delete
 TaskletRunner (unsigned numWorkers)
 Creates a tasklet runner with numWorkers underling threads for doing work.
 ~TaskletRunner ()
 Destructor.
bool failure () const
int workerThreadIndex () const
 Returns the index of the current worker thread.
int numWorkerThreads () const
 Returns the number of worker threads for the tasklet runner.
void dispatch (std::shared_ptr< TaskletInterface > tasklet)
 Add a new tasklet.
template<class Fn>
std::shared_ptr< FunctionRunnerTasklet< Fn > > dispatchFunction (Fn &fn, int numInvocations=1)
 Convenience method to construct a new function runner tasklet and dispatch it immediately.
void barrier ()
 Make sure that all tasklets have been completed after this method has been called.

Protected Member Functions

void run_ ()
 do the work until the queue received an end tasklet

Static Protected Member Functions

static void startWorkerThread_ (TaskletRunner *taskletRunner, int workerThreadIndex)

Protected Attributes

std::vector< std::unique_ptr< std::thread > > threads_
std::queue< std::shared_ptr< TaskletInterface > > taskletQueue_
std::mutex taskletQueueMutex_
std::condition_variable workAvailableCondition_

Static Protected Attributes

static TaskletRunner * taskletRunner_ = nullptr
static int workerThreadIndex_ = -1

Detailed Description

Handles where a given tasklet is run.

Depending on the number of worker threads, a tasklet can either be run in a separate worker thread or by the main thread.

Constructor & Destructor Documentation

◆ TaskletRunner()

Opm::TaskletRunner::TaskletRunner ( unsigned numWorkers)
explicit

Creates a tasklet runner with numWorkers underling threads for doing work.

The number of worker threads may be 0. In this case, all work is done by the main thread (synchronous mode).

◆ ~TaskletRunner()

Opm::TaskletRunner::~TaskletRunner ( )

Destructor.

If worker threads were created to run the tasklets, this method waits until all worker threads have been terminated, i.e. all scheduled tasklets are guaranteed to be completed.

Member Function Documentation

◆ dispatch()

void Opm::TaskletRunner::dispatch ( std::shared_ptr< TaskletInterface > tasklet)

Add a new tasklet.

The tasklet is either run immediately or deferred to a separate thread.

◆ workerThreadIndex()

int Opm::TaskletRunner::workerThreadIndex ( ) const

Returns the index of the current worker thread.

If the current thread is not a worker thread, -1 is returned.


The documentation for this class was generated from the following files:
  • opm/models/parallel/tasklets.hpp
  • opm/models/parallel/tasklets.cpp