Peano
Loading...
Searching...
No Matches
ProcessReadyTask.cpp
Go to the documentation of this file.
1#include "ProcessReadyTask.h"
2
6
7
8const std::string tarch::multicore::taskfusion::ProcessReadyTask::ProcessFusedTasksStatisticsIdentifier = "tarch::multicore::taskfusion::process-fused-tasks";
9tarch::logging::Log tarch::multicore::taskfusion::ProcessReadyTask::_log( "tarch::multicore::taskfusion::ProcessReadyTask" );
10
11
13 Task(DontFuse,DefaultPriority),
14 _taskQueue(taskQueue) {
15}
16
17
19 tarch::multicore::Lock lock(_taskQueue->semaphore);
20 const int initialQueueSize = _taskQueue->tasks.size();
21 int processedTasks = 0;
22
23 logDebug( "run(...)", "process all tasks of type " << _taskQueue->type << " (initial queue size=" << initialQueueSize << ")" );
24
25 while (
26 not _taskQueue->tasks.empty()
27 and
28 // exploit LIFO
29 processedTasks < initialQueueSize
30 ) {
31 // can change from call to call
33
34 Task* firstTask = *_taskQueue->tasks.begin();
35 _taskQueue->tasks.pop_front();
36
37 int maxTasks = std::min(static_cast<int>(_taskQueue->tasks.size()), instruction.maxTasks-1);
38 ReadyFusableTasks::Tasks::iterator cutIterator = _taskQueue->tasks.begin();
39 std::advance(cutIterator, maxTasks);
40 ReadyFusableTasks::Tasks extractedTasks;
41 extractedTasks.splice(extractedTasks.end(), _taskQueue->tasks, _taskQueue->tasks.begin(), cutIterator);
42
43 logDebug( "run(...)", "max tasks on top of first task=" << maxTasks );
44
45 lock.free();
46
47 tarch::logging::Statistics::getInstance().log(ProcessFusedTasksStatisticsIdentifier, extractedTasks.size());
48 processedTasks += extractedTasks.size() + 1;
49
50 if (instruction.minTasks > static_cast<int>(_taskQueue->tasks.size()) + 1) {
51 logDebug( "run(...)", "here we go with " << extractedTasks.size() << " task(s) as we have to fuse at least " << instruction.minTasks << " task(s)" );
52 for (auto& task: extractedTasks) {
53 while (task->run()) {
55 }
56 delete task;
57 }
58 logDebug( "run(...)", "now run first task manually" );
59 while (firstTask->run()) {
61 }
62 delete firstTask;
63 }
64 else {
65 logDebug( "run(...)", "fuse them" );
66 native::processFusedTask(firstTask, extractedTasks, instruction.device);
67 }
68
69 lock.lock();
70 }
71
72 return false;
73}
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
Log Device.
Definition Log.h:516
void log(const std::string &identifier, double value, bool disableSampling=false)
Definition Statistics.h:105
static Statistics & getInstance()
This is not the canonical realisation of singletons as I use it usually for stats in Peano.
static Core & getInstance()
Definition Core.cpp:56
void yield()
Wrapper around backend-specific yield.
Definition Core.cpp:80
Create a lock around a boolean semaphore region.
Definition Lock.h:19
void free()
Free the lock.
Definition Lock.cpp:37
Abstract super class for a job.
Definition Task.h:21
virtual bool run()=0
virtual FuseInstruction fuse(int taskType)=0
How many tasks shall system hold back from tasking runtime in user-defined queues.
static const std::string ProcessFusedTasksStatisticsIdentifier
virtual bool run() override
Run the task.
void processFusedTask(Task *myTask, const std::list< tarch::multicore::Task * > &tasksOfSameType, int device)
Process a fused task.
Definition Tasks.cpp:141
tarch::multicore::orchestration::Strategy & getOrchestration()
Definition multicore.cpp:75
Task queue of tasks which we hold back.
Definition taskfusion.h:48
std::list< tarch::multicore::Task * > Tasks
Definition taskfusion.h:52