Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid
[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 size_msg (bcast source?)
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
14 The third argument is a size of the message to send ( octets )  
15
16 If a fourth argument is passed, this is the source of the broadcast
17 (given as a number between 0 and nb_host-1).
18 EOH
19       ;
20     die "\n";
21 }
22
23 my $input    = shift @ARGV || usage();
24 my $size_msg = shift @ARGV || usage();
25 my $source   = shift @ARGV || "";
26 my $nb_hosts = shift @ARGV || 0;
27
28 my @host;
29
30 open IN,$input || die "Cannot open $input: $!\n";
31
32 while (<IN>) {
33   next unless /<host id="([^"]*)"/; # "
34   
35   push @host, $1;
36 }
37
38 # map { print "$_\n" } @host;
39
40 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"
41   unless (scalar @host);
42
43 if (! $nb_hosts) {
44     $nb_hosts = scalar @host;
45 }
46
47
48
49 # Build the receiver string
50
51 my @receivers;    # strings containing sender argument describing all receivers.
52
53 my $it_host=0;    # iterator
54 my $it_port=4000; # iterator, in case we have so much processes to add that we must change it
55
56 for (my $i=0; $i<$nb_hosts; $i++) {
57   push (@receivers, "$host[$it_host]:$it_port");
58   $it_host ++;
59   if ($it_host == scalar @host) {
60     $it_host=0;
61     $it_port++;
62   }
63 }
64
65 #
66 # and now, really generate the file. Receiver first.
67
68 print "<?xml version='1.0'?>\n";
69 print "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n";
70 print "<platform version=\"2\">\n\n";
71
72 for my $r (@receivers) {
73     my ($h, $p) = split(':', $r);
74     print "  <process host=\"".$h."\" function=\"receiver\">\n";
75     print "    <argument value=\"$p\"/><argument value=\"".(length($source)?1:$nb_hosts)."\"/>\n";
76     print "  </process>\n\n";
77 }
78
79 #
80 # Here come the sender(s)
81
82 if(length($source)) {
83     print "  <process host=\"".$host[$source % (scalar @host)].
84         "\" function=\"sender\">\n";
85     for my $r (@receivers) {
86         print "    <argument value=\"$r\"/>\n"; 
87     }
88     print "    <argument value=\"$size_msg\"/>\n"; 
89     print "  </process>\n";
90 } else {
91     my $i = 0; 
92     for my $r (@receivers) {
93         my ($h, $p) = split(":", $r); 
94         print "  <process host=\"".$h."\" function=\"sender\">\n";
95         for (my $j = 0; $j < $nb_hosts; $j++) {
96            my $r2 = $receivers[($i + $j) % ($nb_hosts)]; 
97            print "    <argument value=\"$r2\"/>\n"; 
98         }
99         print "    <argument value=\"$size_msg\"/>\n"; 
100         print "  </process>\n";
101         $i++;
102     }
103 }
104
105 print "</platform>\n";
106
107 # print "source='$source' nb_hosts=$nb_hosts\n";