1 # Copyright (c) 2006-2023. The SimGrid Team. All rights reserved.
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.
7 This example demonstrates how to create a variable load for operations.
8 We consider the following graph:
12 With a small load each comm operation is followed by an exec operation.
13 With a heavy load there is a burst of comm before the exec operation can even finish once.
16 from argparse import ArgumentParser
18 from simgrid import Engine, Operation, CommOp, ExecOp, Actor, this_actor
21 parser = ArgumentParser()
26 help='path to the platform description'
28 return parser.parse_args()
31 print(f'[{Engine.clock}] Operation {op} finished ({op.count})')
33 def variable_load(op):
34 print('--- Small load ---')
37 this_actor.sleep_for(100)
38 this_actor.sleep_for(1000)
39 print('--- Heavy load ---')
42 this_actor.sleep_for(1)
44 if __name__ == '__main__':
47 e.load_platform(args.platform)
51 tremblay = e.host_by_name('Tremblay')
52 jupiter = e.host_by_name('Jupiter')
55 comm = CommOp.init("comm", 1e7, tremblay, jupiter)
56 exec = ExecOp.init("exec", 1e9, jupiter)
58 # Create the graph by defining dependencies between operations
59 comm.add_successor(exec)
61 # Add a function to be called when operations end for log purpose
62 Operation.on_end_cb(callback)
64 # Create the actor that will inject load during the simulation
65 Actor.create("input", tremblay, variable_load, comm)