Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Generate a deployment where each host is used at most once.
authorvelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 25 Nov 2008 16:18:18 +0000 (16:18 +0000)
committervelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 25 Nov 2008 16:18:18 +0000 (16:18 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6097 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/msg/gtnets/generate_random_deployment.pl

index ceb98aa..32476b0 100755 (executable)
@@ -1,6 +1,17 @@
 #!/usr/bin/perl -w
 use strict;
 
+sub melange {
+    my $tableau=shift;
+    my($i,$j);
+    
+    for($i = @$tableau ; --$i; ) {
+       $j = int rand ($i+1);
+       next if $i==$j;
+       @$tableau[$i,$j] = @$tableau[$j,$i];
+    }
+}
+
 sub read_file {
     my($filename)=shift;
     my($line);
@@ -22,6 +33,7 @@ sub generate_random_deployment{
     my($host_list,$nflows,$filename)=@_;
     my(%pairs);
     my($nhost) = scalar(@$host_list);
+    my(%taken);
 
     $nflows< $nhost*$nhost-$nhost or die "Too much flows! I can't do it\n";
     
@@ -32,9 +44,61 @@ sub generate_random_deployment{
 
        if($src!=$dst && !defined($pairs{"$$host_list[$src] $$host_list[$dst]"})) {
            $pairs{"$$host_list[$src] $$host_list[$dst]"}=1;
+           $taken{"$$host_list[$src]"}=1;
+           $taken{"$$host_list[$dst]"}=1;
+#         && !$taken{$$host_list[$src]} && !$taken{$$host_list[$dst]}
        }
     }
     my($p);
+
+    my($count)=0;
+
+    print OUTPUT <<EOF;
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+EOF
+
+    foreach $p (keys %pairs) {
+       my($src,$dst)=split(/ /,$p);
+       print OUTPUT "  <process host='$src' function='master'>\n";
+       print OUTPUT "    <argument value='10000000'/>\n";
+       print OUTPUT "    <argument value='$dst'/>\n";
+       print OUTPUT "    <argument value='$count'/>\n";
+       print OUTPUT "  </process>\n";
+       print OUTPUT "  <process host='$dst' function='slave'>\n";
+       print OUTPUT "    <argument value='$count'/>\n";
+       print OUTPUT "  </process>\n";
+       $count++;
+    }
+
+    print OUTPUT <<EOF;
+</platform>
+EOF
+    close(OUTPUT);
+}
+
+
+sub generate_random_deployment2{
+    my($host_list,$nflows,$filename)=@_;
+    my(%pairs);
+    my($nhost) = scalar(@$host_list);
+    my(%taken);
+
+    melange($host_list);
+    $nflows< $nhost/2 or die "Too much flows! I can't do it\n";
+    
+    open(OUTPUT,"> $filename");
+    foreach (0..$nflows-1) {
+       my($src)=shift(@$host_list);
+       my($dst)=shift(@$host_list);
+
+       $pairs{"$src $dst"}=1;
+    }
+    my($p);
+
+    my($count)=0;
+
     print OUTPUT <<EOF;
 <?xml version='1.0'?>
 <!DOCTYPE platform SYSTEM "simgrid.dtd">
@@ -44,11 +108,16 @@ EOF
     foreach $p (keys %pairs) {
        my($src,$dst)=split(/ /,$p);
        print OUTPUT "  <process host='$src' function='master'>\n";
-       print OUTPUT "    <argument value='1000000'/>\n";
+       print OUTPUT "    <argument value='10000000'/>\n";
        print OUTPUT "    <argument value='$dst'/>\n";
+       print OUTPUT "    <argument value='$count'/>\n";
        print OUTPUT "  </process>\n";
-       print OUTPUT "  <process host='$dst' function='slave'/>\n";
+       print OUTPUT "  <process host='$dst' function='slave'>\n";
+       print OUTPUT "    <argument value='$count'/>\n";
+       print OUTPUT "  </process>\n";
+       $count++;
     }
+
     print OUTPUT <<EOF;
 </platform>
 EOF
@@ -65,7 +134,7 @@ sub main {
     $filename =~ s/-p$//g;
     
     $host_list = read_file $ARGV[0];
-    generate_random_deployment($host_list,$nflows,"$filename-d.xml");
+    generate_random_deployment2($host_list,$nflows,"$filename-d.xml");
 }
 
 main;