3 require 'rexml/document'
10 @@doc = REXML::Document.new(xml)
11 @@doc.elements.each('platform') do |platform|
12 extract_hosts(platform)
16 def extract_hosts(doc)
17 doc.elements.each('AS') do |as|
18 extract_hosts_from_AS(as)
23 def extract_hosts_from_AS(doc)
24 doc.elements.each('host') do |h|
25 @@hosts << h.attributes['id']
26 puts "hosts %s" % h.attributes['id']
29 doc.elements.each('cluster') do |c|
30 prefix = c.attributes['prefix']
31 suffix = c.attributes['suffix']
32 puts "%s %s %s" % [prefix, c.attributes['radical'], suffix]
33 expand_radical(c.attributes['radical']).each do |num|
34 @@hosts << "%s%s%s" % [prefix, num, suffix]
43 def expand_radical(radical)
46 radical.split(',').each do |range|
47 range.scan(/^\d+$/) { |x| l << x }
48 range.scan(/^(\d+)-(\d+)$/) { |x, y| (x..y).each do |i| l << i end }
54 class DeploymentGenerator
58 @@outfile = File.new(fname, "w")
62 @@outfile.puts "<?xml version='1.0'?>"
63 @@outfile.puts "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">"
64 @@outfile.puts "<platform version=\"3\">"
67 def write_process(name, function, hosts, args)
68 @@outfile.puts " <!-- %s -->" % name
69 hosts.zip(args).each do |h, a|
70 @@outfile.puts " <process host=\"%s\" function=\"%s\">" % [h, function]
71 @@outfile.puts " <argument value=\"%s\"/>" % [a]
72 @@outfile.puts " </process>"
77 @@outfile.puts "</platform>"
81 xml = File.read(ARGV.shift)
82 he = HostsExtractor.new(xml)
84 raise "Cannot run with less than 2 hosts" unless he.hosts.size > 1
88 if n == nil or n.to_i < 2
95 dg = DeploymentGenerator.new(output)
99 broadcaster = he.hosts.shift
102 dg.write_process("Broadcaster", "broadcaster", [broadcaster], [n])
103 dg.write_process("Peers", "peer", peers[0..n-1], (1..n))