27 #ifndef OPM_TASKLETS_HPP 28 #define OPM_TASKLETS_HPP 31 #include <condition_variable> 48 : referenceCount_(refCount)
52 virtual void run() = 0;
53 virtual bool isEndMarker ()
const {
return false; }
56 { -- referenceCount_; }
58 int referenceCount()
const 59 {
return referenceCount_; }
98 explicit BarrierTasklet(
unsigned numWorkers);
105 unsigned numWorkers_;
106 unsigned numWaiting_;
108 std::condition_variable barrierCondition_;
109 std::mutex barrierMutex_;
120 bool isEndMarker()
const override 145 bool failure()
const;
158 {
return threads_.size(); }
165 void dispatch(std::shared_ptr<TaskletInterface> tasklet);
171 std::shared_ptr<FunctionRunnerTasklet<Fn> >
dispatchFunction(Fn &fn,
int numInvocations = 1)
174 auto tasklet = std::make_shared<Tasklet>(numInvocations, fn);
193 std::atomic<bool> failureFlag_ =
false;
202 std::vector<std::unique_ptr<std::thread> > threads_;
203 std::queue<std::shared_ptr<TaskletInterface> > taskletQueue_;
204 std::mutex taskletQueueMutex_;
205 std::condition_variable workAvailableCondition_;
208 static thread_local
int workerThreadIndex_;
213 #endif // OPM_TASKLETS_HPP int numWorkerThreads() const
Returns the number of worker threads for the tasklet runner.
Definition: tasklets.hpp:157
void barrier()
Make sure that all tasklets have been completed after this method has been called.
Definition: tasklets.cpp:135
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
std::shared_ptr< FunctionRunnerTasklet< Fn > > dispatchFunction(Fn &fn, int numInvocations=1)
Convenience method to construct a new function runner tasklet and dispatch it immediately.
Definition: tasklets.hpp:171
int workerThreadIndex() const
Returns the index of the current worker thread.
Definition: tasklets.cpp:94
~TaskletRunner()
Destructor.
Definition: tasklets.cpp:77
The base class for tasklets.
Definition: tasklets.hpp:44
Handles where a given tasklet is run.
Definition: tasklets.hpp:92
A simple tasklet that runs a function that returns void and does not take any arguments a given numbe...
Definition: tasklets.hpp:70
void dispatch(std::shared_ptr< TaskletInterface > tasklet)
Add a new tasklet.
Definition: tasklets.cpp:101
void run_()
do the work until the queue received an end tasklet
Definition: tasklets.cpp:157