Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename enqueue_execs into enqueue_firings
[simgrid.git] / examples / python / task-simple / task-simple.py
1 # Copyright (c) 2006-2023. The SimGrid Team. All rights reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
5
6 """
7 This example demonstrates basic use of the task plugin.
8 We model the following graph:
9
10 exec1 -> comm -> exec2
11
12 exec1 and exec2 are execution tasks.
13 comm is a communication task.
14 """
15
16 from argparse import ArgumentParser
17 import sys
18 from simgrid import Engine, Task, CommTask, ExecTask
19
20 def parse():
21     parser = ArgumentParser()
22     parser.add_argument(
23         '--platform',
24         type=str,
25         required=True,
26         help='path to the platform description'
27     )
28     return parser.parse_args()
29
30 def callback(t):
31     print(f'[{Engine.clock}] {t} finished ({t.count})')
32
33 if __name__ == '__main__':
34     args = parse()
35     e = Engine(sys.argv)
36     e.load_platform(args.platform)
37
38     # Retrieve hosts
39     tremblay = e.host_by_name('Tremblay')
40     jupiter = e.host_by_name('Jupiter')
41
42     # Create tasks
43     exec1 = ExecTask.init("exec1", 1e9, tremblay)
44     exec2 = ExecTask.init("exec2", 1e9, jupiter)
45     comm = CommTask.init("comm", 1e7, tremblay, jupiter)
46
47     # Create the graph by defining dependencies between tasks
48     exec1.add_successor(comm)
49     comm.add_successor(exec2)
50
51     # Add a function to be called when tasks end for log purpose
52     Task.on_completion_cb(callback)
53
54     # Enqueue two firings for task exec1
55     exec1.enqueue_firings(2)
56
57     # runs the simulation
58     e.run()