Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Complete the other activityset examples in python
[simgrid.git] / examples / python / activityset-waitall / activityset-waitall.py
1 # Copyright (c) 2017-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 Usage: activityset-waitall.py platform_file [other parameters]
8 """
9
10 import sys
11 from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor
12
13 def bob():
14   mbox = Mailbox.by_name("mbox")
15   disk = Host.current().get_disks()[0]
16
17   this_actor.info("Create my asynchronous activities")
18   exec = this_actor.exec_async(5e9)
19   comm, payload = mbox.get_async()
20   io   = disk.read_async(300000000)
21
22   pending_activities = ActivitySet([exec, comm])
23   pending_activities.push(io) # Activities can be pushed after creation, too
24  
25   this_actor.info("Wait for asynchronous activities to complete, all in one shot.")
26   pending_activities.wait_all()
27
28   this_actor.info("All activities are completed.")
29
30 def alice():
31   this_actor.info("Send 'Message'")
32   Mailbox.by_name("mbox").put("Message", 600000000)
33
34 if __name__ == '__main__':
35   e = Engine(sys.argv)
36   e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n")
37
38   # Load the platform description
39   e.load_platform(sys.argv[1])
40
41   Actor.create("bob",   Host.by_name("bob"), bob)
42   Actor.create("alice", Host.by_name("alice"), alice)
43
44   e.run()