24 #ifndef _GEMA_TASK_MANAGER_H_ 25 #define _GEMA_TASK_MANAGER_H_ 55 virtual int nextNode() = 0;
58 virtual void reset() = 0;
69 virtual GmCell* nextCell() = 0;
72 virtual void reset() = 0;
84 NPS_SEQUENTIAL_BLOCK = 0,
99 CPS_SEQUENTIAL_BLOCK = 0,
112 static NodePartitionStrategy str2NodePartitionStrategy(
QString str);
113 static CellPartitionStrategy str2CellPartitionStrategy(
QString str);
119 int numTasks()
const {
return _threadManager->numTasks(); }
123 int ntasks = 0, NodePartitionStrategy strategy = NPS_DEFAULT,
127 int ntasks = 0, NodePartitionStrategy strategy = NPS_DEFAULT,
132 int ntasks = 0, CellPartitionStrategy strategy = CPS_DEFAULT,
137 int ntasks = 0, CellPartitionStrategy strategy = CPS_DEFAULT,
141 void execParallelCellLoop(
GmCellMesh* m,
bool activeOnly, T& taskObj,
142 int ntasks = 0, CellPartitionStrategy strategy = CPS_DEFAULT,
146 int ntasks, NodePartitionStrategy strategy,
int nworkers,
149 template <
class M,
class T>
bool addCellTasks(M* m,
bool activeOnly, T& taskObj,
150 int ntasks, CellPartitionStrategy strategy,
int nworkers,
154 void adjustExecParameters(
int* ntasks,
int* nworkers);
157 NodePartitionStrategy strategy)
const;
161 CellPartitionStrategy strategy)
const;
213 if(!addNodeTasks<T>(m, affNodes, taskObj, ntasks, strategy, nworkers, taskAffinity, &ok))
230 if(!addNodeTasks<T>(m, affNodes, taskObj, ntasks, strategy, nworkers, taskAffinity, &ok))
261 assert(ntasks > 0 && nworkers >= 0 && strategy >= 0 && strategy <
NPS_NUM_STRATEGIES);
269 bool useAffinity = !taskAffinity.
isEmpty();
270 if(useAffinity && taskData.
size() != taskAffinity.
size())
272 qDeleteAll(taskData);
283 NodeTask(T& task,
GmNodeTaskDataSet* dataSet) : _task(task), _dataSet(dataSet) {}
284 virtual ~NodeTask() {
delete _dataSet; }
343 if(!addCellTasks<GmCellMesh, T>(m, activeOnly, taskObj, ntasks, strategy, nworkers, taskAffinity, &ok))
360 if(!addCellTasks<GmCellGroupSet, T>(gs, activeOnly, taskObj, ntasks, strategy, nworkers, taskAffinity, &ok))
377 if(!addCellTasks<GmCellMesh, T>(m, activeOnly, taskObj, ntasks, strategy, nworkers, taskAffinity, &ok))
394 template <
class M,
class T>
407 assert(ntasks > 0 && nworkers >= 0 && strategy >= 0 && strategy <
CPS_NUM_STRATEGIES);
415 bool useAffinity = !taskAffinity.
isEmpty();
416 if(useAffinity && taskData.
size() != taskAffinity.
size())
418 qDeleteAll(taskData);
429 CellTask(T& task,
GmCellTaskDataSet* dataSet) : _task(task), _dataSet(dataSet) {}
430 virtual ~CellTask() {
delete _dataSet; }
void addTask(GmThreadTask *task, int tid=0)
Adds a task to the manager. The manager gets the task ownership and will delete it after execution....
Definition: gmThreadManager.cpp:400
The number of partition strategies.
Definition: gmTaskManager.h:107
bool addCellTasks(M *m, bool activeOnly, T &taskObj, int ntasks, CellPartitionStrategy strategy, int nworkers, const QVector< int > &taskAffinity, bool *ok)
Worker function for adding cell tasks to the thread manager. See runParallelCellLoop() for parameter ...
Definition: gmTaskManager.h:395
GmThreadManager * _threadManager
The thread manager used to run tasks in multiple threads.
Definition: gmTaskManager.h:163
Our thread wrapper, specialized for running tasks from the thread manager queue.
Definition: gmThreadManager.h:217
Base class for accessing the set of cells belonging to a mesh partition.
Definition: gmTaskManager.h:62
void execTasks(int nthreads)
Similar to runTasks() but raising a lua error if the execution was either canceled or aborted.
Definition: gmThreadManager.cpp:575
Interface for helping managing mesh cell groups and returning the elements in their union.
Definition: gmCellGroupSet.h:34
const GmLogCategory & logger()
Returns the thread manager logger.
Definition: gmThreadManager.h:147
GmAffectedNodes
Affected node types for node based values (GM_NODE_COORDINATES, GM_NODE_ATTRIBUTE or GM_NODE_STATEVAR...
Definition: gmValueInfo.h:91
Declaration of usefull configuration definitions for the Core library.
Declaration of the GmValueInfo class.
#define S_TRACE()
Macro for run time stack tracking at release build.
Definition: gmTrace.h:44
Base interface for mesh cells.
Definition: gmCell.h:81
GmThreadTaskResult
Possible results for running a task.
Definition: gmThreadManager.h:60
The thread finished its execution without errors.
Definition: gmThreadManager.h:62
void execParallelNodeLoop(const GmMesh *m, GmAffectedNodes affNodes, T &taskObj, int ntasks=0, NodePartitionStrategy strategy=NPS_DEFAULT, int nworkers=-1, const QVector< int > &taskAffinity=QVector< int >())
Similar to runParallelNodeLoop() but raising a lua error if the execution was either canceled or abor...
Definition: gmTaskManager.h:222
QVector< GmCellTaskDataSet * > buildCellPartition(M *m, int n, bool activeOnly, CellPartitionStrategy strategy) const
Creates a list with the 'n' parallel cell tasks to be executed, given the destination mesh,...
Definition: gmTaskManager.cpp:205
QString tr(const char *sourceText, const char *disambiguation, int n)
The number of partition strategies.
Definition: gmTaskManager.h:92
NodePartitionStrategy
Partition strategies for a parallel node loop.
Definition: gmTaskManager.h:81
bool addNodeTasks(const GmMesh *m, GmAffectedNodes affNodes, T &taskObj, int ntasks, NodePartitionStrategy strategy, int nworkers, const QVector< int > &taskAffinity, bool *ok)
Worker function for adding node tasks to the thread manager. See runParallelNodeLoop() for parameter ...
Definition: gmTaskManager.h:249
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
Declaration of the GmThreadManager class.
int _defNumTasks
The default number of tasks for a parallel loop. Negative numbers are multiples of the number of work...
Definition: gmTaskManager.h:165
The thread aborted.
Definition: gmThreadManager.h:64
Base interface class for CellMesh type plugins.
Definition: gmCellMesh.h:39
Interface for a task executed by a thread manager thread.
Definition: gmThreadManager.h:68
GmThreadTaskResult runTasks(int nthreads)
Executes the set of tasks in the queue using at most 'nthreads'. Waits for the threads to finish befo...
Definition: gmThreadManager.cpp:444
LuaEnv * threadLuaEnv(int tid) const
Returns the Lua environment associated with the given thread id.
Definition: gmThreadManager.cpp:350
Uses the default strategy given by simulation options or CPS_SEQUENTIAL_BLOCK if missing.
Definition: gmTaskManager.h:98
Base class for accessing the set of nodes belonging to a mesh partition.
Definition: gmTaskManager.h:43
Uses the default strategy given by simulation options or NPS_SEQUENTIAL_BLOCK if missing.
Definition: gmTaskManager.h:83
virtual ~GmCellTaskDataSet()
Virtual destructor.
Definition: gmTaskManager.h:66
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
GmThreadTaskResult runParallelNodeLoop(const GmMesh *m, GmAffectedNodes affNodes, T &taskObj, int ntasks=0, NodePartitionStrategy strategy=NPS_DEFAULT, int nworkers=-1, const QVector< int > &taskAffinity=QVector< int >())
Parallel executes the given task over mesh nodes.
Definition: gmTaskManager.h:205
bool isEmpty() const const
QVector< GmNodeTaskDataSet * > buildNodePartition(const GmMesh *m, int n, GmAffectedNodes affNodes, NodePartitionStrategy strategy) const
Creates a list with the 'n' parallel node tasks to be executed, given the destination mesh,...
Definition: gmTaskManager.cpp:159
int numTasks() const
Returns the number of tasks added to the queue by addNodetasks or addCellTasks.
Definition: gmTaskManager.h:119
virtual ~GmNodeTaskDataSet()
Virtual destructor.
Definition: gmTaskManager.h:47
CellPartitionStrategy _defCellStrategy
The default strategy for cell partitioning.
Definition: gmTaskManager.h:167
Thread manager used for handling parallel executions.
Definition: gmThreadManager.h:94
GmThreadManager * threadManager() const
Returns the associated thread manager.
Definition: gmTaskManager.h:116
NodePartitionStrategy _defNodeStrategy
The default strategy for node partitioning.
Definition: gmTaskManager.h:166
void adjustExecParameters(int *ntasks, int *nworkers)
Adjusts task execution parameters, converting possible default options to real values.
Definition: gmTaskManager.cpp:142
CellPartitionStrategy
Partition strategies for a parallel cell loop.
Definition: gmTaskManager.h:96
Base interface class for Mesh type plugins.
Definition: gmMesh.h:44
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Auxiliary configuration file used to enable or disable compiling the GeMA tools with support for usin...
Task manager used for handling parallel executions.
Definition: gmTaskManager.h:76
void execParallelCellLoop(GmCellMesh *m, bool activeOnly, T &taskObj, int ntasks=0, CellPartitionStrategy strategy=CPS_DEFAULT, int nworkers=-1, const QVector< int > &taskAffinity=QVector< int >())
Similar to runParallelCellLoop() but raising a lua error if the execution was either canceled or abor...
Definition: gmTaskManager.h:369
GmThreadTaskResult runParallelCellLoop(GmCellMesh *m, bool activeOnly, T &taskObj, int ntasks=0, CellPartitionStrategy strategy=CPS_DEFAULT, int nworkers=-1, const QVector< int > &taskAffinity=QVector< int >())
Parallel executes the given task over mesh cells.
Definition: gmTaskManager.h:335