Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cf0e4c063f5b0870f7e6ad0bd6a1cd8e0301e9e1
[simgrid.git] / examples / gras / all2all / make_deployment.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 sub usage {
6     print STDERR <<EOH
7 Usage: all2all_make_deployment.pl platform_file.xml nb_host
8   
9 This script generates a deployment file for the all2all 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 EOH
14       ;
15     die "\n";
16 }
17
18 my $input    = shift @ARGV || usage();
19 my $nb_hosts = shift @ARGV || usage();
20
21 my @host;
22
23 open IN,$input || die "Cannot open $input: $!\n";
24
25 while (<IN>) {
26   next unless /<cpu name="([^"]*)"/; # "
27   
28   push @host, $1;
29 }
30
31 # map { print "$_\n" } @host;
32
33 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"
34   unless (scalar @host);
35
36
37 # Build the receiver string
38
39 my $receivers;    # strings containing sender argument describing all receivers.
40
41 my $it_host=0;    # iterator
42 my $it_port=4000; # iterator, in case we have so much processes to add that we must change it
43
44 for (my $i=0; $i<$nb_hosts; $i++) {
45   $receivers .= "    <argument value=\"$host[$it_host]:$it_port\"/>\n";
46   $it_host ++;
47   if ($it_host == scalar @host) {
48     $it_host=0;
49     $it_port++;
50   }
51 }
52
53 #
54 # and now, really generate the file
55
56 print "<?xml version='1.0'?>\n";
57 print "<!DOCTYPE platform_description SYSTEM \"surfxml.dtd\">\n";
58 print "<platform_description>\n\n";
59
60 # reset iterators
61 $it_port=4000;
62 $it_host=0;
63
64 for (my $i=0; $i<$nb_hosts; $i++) {
65   print "  <process host=\"".$host[$it_host]."\" function=\"sender\">\n";
66   print $receivers;
67   print "  </process>\n";
68     
69   print "  <process host=\"".$host[$it_host]."\" function=\"receiver\">\n";
70   print "    <argument value=\"$it_port\"/><argument value=\"$nb_hosts\"/>\n";
71   print "  </process>\n\n";
72     
73   $it_host ++;
74   if ($it_host == scalar @host) {
75     $it_host=0;
76     $it_port++;
77   }
78 }
79
80 print "</platform_description>\n";