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 tasks.
8 We consider the following graph:
12 With a small load each comm task is followed by an exec task.
13 With a heavy load there is a burst of comm before the exec task can even finish once.
16 from argparse import ArgumentParser
18 from simgrid import Engine, Task, CommTask, ExecTask, Actor, this_actor
21 parser = ArgumentParser()
26 help='path to the platform description'
28 return parser.parse_args()
31 print(f'[{Engine.clock}] {t} finished ({t.count})')
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)
50 tremblay = e.host_by_name('Tremblay')
51 jupiter = e.host_by_name('Jupiter')
54 comm = CommTask.init("comm", 1e7, tremblay, jupiter)
55 exec = ExecTask.init("exec", 1e9, jupiter)
57 # Create the graph by defining dependencies between tasks
58 comm.add_successor(exec)
60 # Add a function to be called when tasks end for log purpose
61 Task.on_completion_cb(callback)
63 # Create the actor that will inject load during the simulation
64 Actor.create("input", tremblay, variable_load, comm)