23#include <QtConcurrent/QtConcurrent>
32 void setup(
const QList<ResourceUnit*> &resourceUnitList);
33 void setup(
const QList<Species*> &speciesList) { mSpeciesMap = speciesList; }
36 void setMultithreading(
const bool do_multithreading) { mMultithreaded = do_multithreading; }
39 void run(
void (*funcptr)(
ResourceUnit*),
const bool forceSingleThreaded=
false )
const;
40 void run(
void (*funcptr)(
Species*),
const bool forceSingleThreaded=
false )
const;
42 template<
class T>
void run(T* (*funcptr)(T*),
const QVector<T*> &container,
const bool forceSingleThreaded=
false)
const;
43 template<
class T>
void run(
void (*funcptr)(T&), QVector<T> &container,
const bool forceSingleThreaded=
false)
const;
45 template<
class T>
void runGrid(
void (*funcptr)(T*, T*), T* begin, T* end,
const bool forceSingleThreaded=
false,
int minsize=10000,
int maxchunks=10000)
const;
47 QList<ResourceUnit*> mMap1, mMap2;
48 QList<Species*> mSpeciesMap;
49 static bool mMultithreaded;
53void ThreadRunner::runGrid(
void (*funcptr)(T *, T*), T *begin, T *end,
const bool forceSingleThreaded,
int minsize,
int maxchunks)
const
55 int length = end - begin;
56 if (mMultithreaded && length>minsize*3 && forceSingleThreaded==
false) {
58 int chunksize = minsize;
59 if (length > chunksize*maxchunks) {
60 chunksize = length / maxchunks;
65 T* pend = std::min(p+chunksize, end);
66 QtConcurrent::run(funcptr, p, pend);
71 (*funcptr)(begin, end);
77void ThreadRunner::run(T *(*funcptr)(T *),
const QVector<T *> &container,
const bool forceSingleThreaded)
const
79 if (mMultithreaded && container.count() > 3 && forceSingleThreaded==
false) {
81 QtConcurrent::blockingMap(container,funcptr);
85 foreach(element, container)
93void ThreadRunner::run(
void (*funcptr)(T &), QVector<T> &container,
const bool forceSingleThreaded)
const
95 if (mMultithreaded && container.count() > 3 && forceSingleThreaded==
false) {
97 QtConcurrent::blockingMap(container,funcptr);
100 for (
int i=0;i<container.size();++i)
101 (*funcptr)(container[i]);
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
The behavior and general properties of tree species.
Definition: species.h:75
Encapsulates the invokation of multiple threads for paralellized tasks.
Definition: threadrunner.h:27
void setMultithreading(const bool do_multithreading)
Definition: threadrunner.h:36
ThreadRunner(const QList< Species * > &speciesList)
Definition: threadrunner.h:30
void runGrid(void(*funcptr)(T *, T *), T *begin, T *end, const bool forceSingleThreaded=false, int minsize=10000, int maxchunks=10000) const
Definition: threadrunner.h:53
void setup(const QList< Species * > &speciesList)
Definition: threadrunner.h:33
void setup(const QList< ResourceUnit * > &resourceUnitList)
Definition: threadrunner.cpp:44
ThreadRunner()
Definition: threadrunner.cpp:33
bool multithreading() const
Definition: threadrunner.h:35
void run(void(*funcptr)(ResourceUnit *), const bool forceSingleThreaded=false) const
execute 'funcptr' for all resource units in parallel
Definition: threadrunner.cpp:60
void print()
print useful debug messages
Definition: threadrunner.cpp:38