-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabcTasks.py
More file actions
50 lines (36 loc) · 1.4 KB
/
abcTasks.py
File metadata and controls
50 lines (36 loc) · 1.4 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
import taskr
REPETITIONS = 5
ITERATIONS = 100
def abcTasks(runtime):
# Create the taskr Tasks
taskAfc = taskr.Function(lambda task : print(f"Task A {task.getTaskId()}"))
taskBfc = taskr.Function(lambda task : print(f"Task B {task.getTaskId()}"))
taskCfc = taskr.Function(lambda task : print(f"Task C {task.getTaskId()}"))
# 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
repetitionTaskId = r * ITERATIONS * 3
for i in range(ITERATIONS):
taskA = taskr.Task(repetitionTaskId + i * 3 + 0, taskAfc)
taskB = taskr.Task(repetitionTaskId + i * 3 + 1, taskBfc)
taskC = taskr.Task(repetitionTaskId + 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.wait()
# Finalizing taskr
runtime.finalize()