Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Modify the all2all to support all data Message Size
[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 $nb_hosts = shift @ARGV || usage();
25 my $size_msg = shift @ARGV || usage();
26 my $source   = shift || "";
27
28 my @host;
29
30 open IN,$input || die "Cannot open $input: $!\n";
31
32 while (<IN>) {
33   next unless /<cpu name="([^"]*)"/; # "
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
44 # Build the receiver string
45
46 my $receivers;    # strings containing sender argument describing all receivers.
47
48 my $it_host=0;    # iterator
49 my $it_port=4000; # iterator, in case we have so much processes to add that we must change it
50
51 for (my $i=0; $i<$nb_hosts; $i++) {
52   $receivers .= "    <argument value=\"$host[$it_host]:$it_port\"/>\n";
53   $it_host ++;
54   if ($it_host == scalar @host) {
55     $it_host=0;
56     $it_port++;
57   }
58 }
59 $receivers .= "    <argument value=\"$size_msg\"/>\n";
60
61 #
62 # and now, really generate the file. Receiver first.
63
64 print "<?xml version='1.0'?>\n";
65 print "<!DOCTYPE platform_description SYSTEM \"surfxml.dtd\">\n";
66 print "<platform_description version=\"1\">\n\n";
67
68 # reset iterators
69 $it_port=4000;
70 $it_host=0;
71
72 for (my $i=0; $i<$nb_hosts; $i++) {
73   print "  <process host=\"".$host[$it_host]."\" function=\"receiver\">\n";
74   print "    <argument value=\"$it_port\"/><argument value=\"".(length($source)?1:$nb_hosts)."\"/>\n";
75   print "  </process>\n\n";
76     
77   $it_host ++;
78   if ($it_host == scalar @host) {
79     $it_host=0;
80     $it_port++;
81   }
82 }
83
84 #
85 # Here come the sender(s)
86
87 # reset iterators
88 $it_port=4000;
89 $it_host=0;
90
91 for (my $i=0; $i<$nb_hosts; $i++) {
92   if (!length($source) || $source == $i) {
93       print "  <process host=\"".$host[$it_host]."\" function=\"sender\">\n";
94       print $receivers;
95       print "  </process>\n";
96   }
97     
98   $it_host ++;
99   if ($it_host == scalar @host) {
100     $it_host=0;
101     $it_port++;
102   }
103 }
104
105 print "</platform_description>\n";
106
107 # print "source='$source' nb_hosts=$nb_hosts\n";