From f1142746dbf58e434fc0c27c77bd2ed7bd6c355b Mon Sep 17 00:00:00 2001 From: alegrand Date: Thu, 16 Oct 2008 14:41:04 +0000 Subject: [PATCH] Add a convenient script to create a random deployment file. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5999 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- .../msg/gtnets/generate_random_deployment.pl | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 examples/msg/gtnets/generate_random_deployment.pl diff --git a/examples/msg/gtnets/generate_random_deployment.pl b/examples/msg/gtnets/generate_random_deployment.pl new file mode 100755 index 0000000000..ceb98aa3c3 --- /dev/null +++ b/examples/msg/gtnets/generate_random_deployment.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl -w +use strict; + +sub read_file { + my($filename)=shift; + my($line); + my(@host_list); + open(INPUT,"$filename"); + while(defined($line=)) { + chomp $line; + if($line=~/host id/) { + $line=~ s/.*host id="//; + $line=~ s/\".*$//; + push @host_list,$line; + } + } + close(INPUT); + return \@host_list; +} + +sub generate_random_deployment{ + my($host_list,$nflows,$filename)=@_; + my(%pairs); + my($nhost) = scalar(@$host_list); + + $nflows< $nhost*$nhost-$nhost or die "Too much flows! I can't do it\n"; + + open(OUTPUT,"> $filename"); + while(scalar(keys(%pairs))<$nflows) { + my($src)=int(rand(scalar(@$host_list))); + my($dst)=int(rand(scalar(@$host_list))); + + if($src!=$dst && !defined($pairs{"$$host_list[$src] $$host_list[$dst]"})) { + $pairs{"$$host_list[$src] $$host_list[$dst]"}=1; + } + } + my($p); + print OUTPUT < + + +EOF + + foreach $p (keys %pairs) { + my($src,$dst)=split(/ /,$p); + print OUTPUT " \n"; + print OUTPUT " \n"; + print OUTPUT " \n"; + print OUTPUT " \n"; + print OUTPUT " \n"; + } + print OUTPUT < +EOF + close(OUTPUT); +} + +sub main { + my($nodes,$edges,$interferences,$host_list,$count_interferences); + + $#ARGV>=1 or die "Need a xml platform file and a number of flows!"; + my($filename)=$ARGV[0]; + my($nflows)=$ARGV[1]; + $filename =~ s/\.xml$//g; + $filename =~ s/-p$//g; + + $host_list = read_file $ARGV[0]; + generate_random_deployment($host_list,$nflows,"$filename-d.xml"); +} + +main; -- 2.20.1