3 # Copyright (c) 2012-2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
9 require 'rexml/document'
16 @@doc = REXML::Document.new(xml)
17 @@doc.elements.each('platform') do |platform|
18 extract_hosts(platform)
22 def extract_hosts(doc)
23 doc.elements.each('AS') do |as|
24 extract_hosts_from_AS(as)
29 def extract_hosts_from_AS(doc)
30 doc.elements.each('host') do |h|
31 @@hosts << h.attributes['id']
32 puts "hosts %s" % h.attributes['id']
35 doc.elements.each('cluster') do |c|
36 prefix = c.attributes['prefix']
37 suffix = c.attributes['suffix']
38 puts "%s %s %s" % [prefix, c.attributes['radical'], suffix]
39 expand_radical(c.attributes['radical']).each do |num|
40 @@hosts << "%s%s%s" % [prefix, num, suffix]
49 def expand_radical(radical)
52 radical.split(',').each do |range|
53 range.scan(/^\d+$/) { |x| l << x }
54 range.scan(/^(\d+)-(\d+)$/) { |x, y| (x..y).each do |i| l << i end }
60 class DeploymentGenerator
64 @@outfile = File.new(fname, "w")
68 @@outfile.puts "<?xml version='1.0'?>"
69 @@outfile.puts "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">"
70 @@outfile.puts "<platform version=\"3\">"
73 def write_process(name, function, hosts, args)
74 @@outfile.puts " <!-- %s -->" % name
75 hosts.zip(args).each do |h, a|
76 @@outfile.puts " <process host=\"%s\" function=\"%s\">" % [h, function]
77 @@outfile.puts " <argument value=\"%s\"/>" % [a]
78 @@outfile.puts " </process>"
83 @@outfile.puts "</platform>"
87 xml = File.read(ARGV.shift)
88 he = HostsExtractor.new(xml)
90 raise "Cannot run with less than 2 hosts" unless he.hosts.size > 1
94 if n == nil or n.to_i < 2
101 dg = DeploymentGenerator.new(output)
105 broadcaster = he.hosts.shift
108 dg.write_process("Broadcaster", "broadcaster", [broadcaster], [n])
109 dg.write_process("Peers", "peer", peers[0..n-1], (1..n))