-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabcTasks.py
More file actions
53 lines (39 loc) · 1.7 KB
/
abcTasks.py
File metadata and controls
53 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import taskr
REPETITIONS = 5
ITERATIONS = 100
def abcTasks(runtime):
# TODO: Setting onTaskFinish callback to free up task memory when it finishes (not sure if we will have this)
# runtime.setTaskCallbackHandler(HiCR::tasking::Task::callback_t::onTaskFinish, [&taskr](taskr::Task *task) { delete task; })
# runtime.setTaskCallbackHandler(taskr.onTaskFinish, lambda task : del task)
# Create the taskr Tasks
taskAfc = taskr.Function(lambda task : print(f"Task A {task.getLabel()}"))
taskBfc = taskr.Function(lambda task : print(f"Task B {task.getLabel()}"))
taskCfc = taskr.Function(lambda task : print(f"Task C {task.getLabel()}"))
# Initializing taskr
runtime.initialize()
# Our connection with the previous iteration is the last task C, null in the first iteration
prevTaskC = taskr.Task(0, taskCfc)
# Creating the execution units (functions that the tasks will run)
for r in range(REPETITIONS):
# Calculating the base task id for this repetition
repetitionLabel = r * ITERATIONS * 3
for i in range(ITERATIONS):
taskA = taskr.Task(repetitionLabel + i * 3 + 0, taskAfc)
taskB = taskr.Task(repetitionLabel + i * 3 + 1, taskBfc)
taskC = taskr.Task(repetitionLabel + i * 3 + 2, taskCfc)
# Creating dependencies
if i > 0: taskA.addDependency(prevTaskC)
taskB.addDependency(taskA)
taskC.addDependency(taskB)
# Adding to taskr runtime
runtime.addTask(taskA)
runtime.addTask(taskB)
runtime.addTask(taskC)
# Refreshing previous task C
prevTaskC = taskC
# Running taskr for the current repetition
runtime.run()
# Waiting current repetition to end
runtime.await_()
# Finalizing taskr
runtime.finalize()