Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Gras_stub_generator does not produce the same files as it used to
[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 argument. If the amount of peers exceeds the amount of available 
12 hosts in the deployment file, several peers will be placed on the same host.
13       
14 EOH
15       ;
16     die "\n";
17 }
18
19 my $input    = shift @ARGV || usage();
20 my $nb_hosts = shift @ARGV || usage();
21 my $source   = shift || "";
22
23 my @host;
24
25 open IN,$input || die "Cannot open $input: $!\n";
26
27 while (<IN>) {
28   next unless /<cpu name="([^"]*)"/; # "
29   
30   push @host, $1;
31 }
32
33 # map { print "$_\n" } @host;
34
35 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"
36   unless (scalar @host);
37
38
39 #
40 # generate the file. Master first (quite logical, indeed)
41
42 print "<?xml version='1.0'?>\n";
43 print "<!DOCTYPE platform_description SYSTEM \"surfxml.dtd\">\n";
44 print "<platform_description version=\"1\">\n\n";
45 print "  <!-- The master, arguments :: all others nodes -->\n";
46 print "  <process host=\"$host[0]\" function=\"master\">\n";
47
48 # put the slaves as argument of the master
49
50 my $it_host=0;    # iterator
51 my $it_port=4000; # iterator, in case we have so much processes to add that we must change it
52 for (my $i=0; $i<$nb_hosts; $i++) {
53   print "    <argument value=\"$host[$it_host]:$it_port\"/>\n";
54   $it_host ++;
55   if ($it_host == scalar @host) {
56     $it_host=0;
57     $it_port++;
58   }
59 }
60 print "  </process>\n";
61
62 # Start the slaves also
63 # reset iterators
64 $it_port=4000;
65 $it_host=0;
66
67 for (my $i=0; $i<$nb_hosts; $i++) {
68   print "  <process host=\"".$host[$it_host]."\" function=\"slave\"><argument value=\"$it_port\"/></process>\n";
69     
70   $it_host ++;
71   if ($it_host == scalar @host) {
72     $it_host=0;
73     $it_port++;
74   }
75 }
76
77
78 print "</platform_description>\n";
79