Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adapt to version 2 of platform files
[simgrid.git] / examples / gras / pmm / make_deployment.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 sub usage {
6     print STDERR <<EOH
7 Usage: make_deployment.pl platform_file.xml nb_host 
8   
9 This script generates a deployment file for the PMM program. It takes 
10 a SimGrid platform file as first argument and the number of wanted peers as 
11 second (optional) argument. If the amount of peers exceeds the amount of 
12 available hosts in the deployment file, several peers will be placed on the
13 same host.
14       
15 EOH
16       ;
17     die "\n";
18 }
19
20 my $input    = shift @ARGV || usage();
21 my $nb_slaves = shift @ARGV || "";
22 # my $source   = shift || "";
23
24 my @host;
25
26 open IN,$input || die "Cannot open $input: $!\n";
27
28 while (<IN>) {
29   next unless /<host id="([^"]*)"/; # "
30   
31   push @host, $1;
32 }
33
34 # map { print "$_\n" } @host;
35
36 die "No host found in $input. Is it really a SimGrid platform file?\nCheck that you didn't pass a deployment file, for example.\n"
37   unless (scalar @host);
38
39 if (! $nb_slaves) {
40     $nb_slaves = (scalar @host) - 1;
41 }
42
43 #
44 # generate the file. Master first (quite logical, indeed)
45
46 my $port_num = 4000;
47 my $master = $host[0];
48
49 print "<?xml version='1.0'?>\n";
50 print "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n";
51 print "<platform version=\"2\">\n\n";
52 print "  <!-- The master, argument :: port number -->\n";
53 print "  <process host=\"$master\" function=\"master\">\n";
54 print "    <argument value=\"$port_num\"/>\n";
55 print "  </process>\n";
56
57 # Start the slaves also
58 # reset iterators
59 my $it_host=1;
60
61 for (my $i=0; $i<$nb_slaves; $i++) {
62   print "  <process host=\"".$host[$it_host]."\" function=\"slave\"><argument value=\"$master:$port_num\"/></process>\n";
63     
64   $it_host ++;
65   if ($it_host == scalar @host) {
66     $it_host = 0;
67   }
68 }
69
70
71 print "</platform>\n";
72