Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6b4e2e31545fd20d507474f375615a25e3f116e8
[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 (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 If a third argument is passed, this is the source of the broadcast
15 (given as a number between 0 and nb_host-1).
16 EOH
17       ;
18     die "\n";
19 }
20
21 my $input    = shift @ARGV || usage();
22 my $nb_hosts = shift @ARGV || usage();
23 my $source   = shift;
24
25 my @host;
26
27 open IN,$input || die "Cannot open $input: $!\n";
28
29 while (<IN>) {
30   next unless /<cpu name="([^"]*)"/; # "
31   
32   push @host, $1;
33 }
34
35 # map { print "$_\n" } @host;
36
37 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"
38   unless (scalar @host);
39
40
41 # Build the receiver string
42
43 my $receivers;    # strings containing sender argument describing all receivers.
44
45 my $it_host=0;    # iterator
46 my $it_port=4000; # iterator, in case we have so much processes to add that we must change it
47
48 for (my $i=0; $i<$nb_hosts; $i++) {
49   $receivers .= "    <argument value=\"$host[$it_host]:$it_port\"/>\n";
50   $it_host ++;
51   if ($it_host == scalar @host) {
52     $it_host=0;
53     $it_port++;
54   }
55 }
56
57 #
58 # and now, really generate the file. Receiver first.
59
60 print "<?xml version='1.0'?>\n";
61 print "<!DOCTYPE platform_description SYSTEM \"surfxml.dtd\">\n";
62 print "<platform_description>\n\n";
63
64 # reset iterators
65 $it_port=4000;
66 $it_host=0;
67
68 for (my $i=0; $i<$nb_hosts; $i++) {
69   print "  <process host=\"".$host[$it_host]."\" function=\"receiver\">\n";
70   print "    <argument value=\"$it_port\"/><argument value=\"".(undef($source)?$nb_hosts:1)."\"/>\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 #
81 # Here come the sender(s)
82
83 # reset iterators
84 $it_port=4000;
85 $it_host=0;
86
87 for (my $i=0; $i<$nb_hosts; $i++) {
88   if (undef($source) || $source == $i) {
89       print "  <process host=\"".$host[$it_host]."\" function=\"sender\">\n";
90       print $receivers;
91       print "  </process>\n";
92   }
93     
94   $it_host ++;
95   if ($it_host == scalar @host) {
96     $it_host=0;
97     $it_port++;
98   }
99 }
100
101 print "</platform_description>\n";