Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
properly remove the old signals and prevent MC to fire Comm::on_this_completion
[simgrid.git] / examples / python / operation-io / operation-io.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 from argparse import ArgumentParser
7 import sys
8 from simgrid import Engine, Operation, ExecOp, IoOp, IoOpType
9
10 def parse():
11     parser = ArgumentParser()
12     parser.add_argument(
13         '--platform',
14         type=str,
15         required=True,
16         help='path to the platform description'
17     )
18     return parser.parse_args()
19
20 def callback(op):
21     print(f'[{Engine.clock}] Operation {op} finished ({op.count})')
22
23 if __name__ == '__main__':
24     args = parse()
25     e = Engine(sys.argv)
26     e.load_platform(args.platform)
27     Operation.init()
28
29     # Retrieve hosts
30     bob = e.host_by_name('bob')
31     carl = e.host_by_name('carl')
32
33     # Create operations
34     exec1 = ExecOp.init("exec1", 1e9, bob)
35     exec2 = ExecOp.init("exec2", 1e9, carl)
36     write = IoOp.init("write", 1e7, bob.disks[0], IoOpType.WRITE)
37     read = IoOp.init("read", 1e7, carl.disks[0], IoOpType.READ)
38
39    # Create the graph by defining dependencies between operations
40     exec1.add_successor(write)
41     write.add_successor(read)
42     read.add_successor(exec2)
43
44     # Add a function to be called when operations end for log purpose
45     Operation.on_end_cb(callback)
46
47     # Enqueue two executions for operation exec1
48     exec1.enqueue_execs(2)
49
50     # runs the simulation
51     e.run()