Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
we need the simgrid library too. True story.
[simgrid.git] / examples / msg / chord / generate.py
1 #!/usr/bin/python
2
3 # This script generates a specific deployment file for the Chord example.
4 # It assumes that the platform will be a cluster.
5 # Usage: python generate.py nb_nodes nb_bits end_date
6 # Example: python generate.py 100000 32 1000
7
8 import sys, random
9
10 if len(sys.argv) != 4:
11         print("Usage: python generate.py nb_nodes nb_bits end_date > deployment_file.xml")
12         sys.exit(1)
13
14 nb_nodes = int(sys.argv[1])
15 nb_bits = int(sys.argv[2])
16 end_date = int(sys.argv[3])
17
18 max_id = 2 ** nb_bits - 1
19 all_ids = [42]
20
21 sys.stdout.write("<?xml version='1.0'?>\n"
22 "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"
23 "<platform version=\"3\">\n"
24 "  <process host=\"c-0.me\" function=\"node\"><argument value=\"42\"/><argument value=\"%d\"/></process>\n" % end_date)
25
26 for i in range(1, nb_nodes):
27
28         ok = False
29         while not ok:
30                 my_id = random.randint(0, max_id)
31                 ok = not my_id in all_ids
32
33         known_id = all_ids[random.randint(0, len(all_ids) - 1)]
34         start_date = i * 10
35         line = "  <process host=\"c-%d.me\" function=\"node\"><argument value=\"%d\" /><argument value=\"%d\" /><argument value=\"%d\" /><argument value=\"%d\" /></process>\n" % (i, my_id, known_id, start_date, end_date)
36         sys.stdout.write(line)
37         all_ids.append(my_id)
38
39 sys.stdout.write("</platform>")
40