Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
db190d090e2a6e4a7abb73118ad33896218a1362
[simgrid.git] / examples / python / actor-yield / actor-yield.py
1 # Copyright (c) 2017-2018. 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 import simgrid, sys
7
8 # This example does not much: It just spans over-polite actor that yield a large amount
9 # of time before ending.
10 #
11 # This serves as an example for the simgrid.yield() function, with which an actor can request
12 # to be rescheduled after the other actor that are ready at the current timestamp.
13 #
14 # It can also be used to benchmark our context-switching mechanism.
15
16 # Main function of the Yielder process 
17 class Yielder:
18     number_of_yields = 0
19     def __init__(self, *args):
20         self.number_of_yields = int(args[0])
21     def __call__(self):
22         for i in range(self.number_of_yields):
23             simgrid.yield_()
24         simgrid.info("I yielded {:d} times. Goodbye now!".format(self.number_of_yields))
25
26 if __name__ == '__main__':
27     e = simgrid.Engine(sys.argv)
28     
29     e.load_platform(sys.argv[1])             # Load the platform description 
30     e.register_actor("yielder", Yielder)  # Register the class representing the actors
31
32     e.load_deployment(sys.argv[2])
33
34     e.run() # - Run the simulation