[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] running scripts
On Wednesday 01 August 2001 07:59, Michele C. Weigle wrote:
> I use a perl script (run.pl) to drive the simulation, a Tcl
> script (sim-template.tcl) as a template for each simulation, and a
> shell script (changeword) to convert the template to a suitable NS
> Tcl script. Then, I just have a shell script that runs run.pl with
> the suitable parameters. They're all short, so I've just appended
> them below my signature. If someone else has an easier suggestion,
> I'd love to hear it, too.
Use command line arguments to the same script.
> sim.tcl:
# sim.tcl
# expecting 2 command line arguments
if { $argc != 2 } {
exit 1
}
# get the command line args into variables
set exp [lindex $argv 0]
set length [lindex $argv 1]
# instantiate the Simulator
set ns [new Simulator]
# setup the variables
set warmup $length; # warmup interval (s)
set duration [expr $warmup + $length]; # total simulation time (s)
# Rest snipped for brevity
>
> run.pl:
#!/usr/local/bin/perl
# run.pl Michele Weigle March 19, 2001
# modified by Brian Lee Bowers 1 August 2001
#
# Usage: run.pl EXP
# EXP must be a positive integer (preferably fairly small)
# Run a sequence of experiments - EXP total
# Duration of each experiment is a 2 ** EXP seconds
# 1 -- 2 seconds
# 2 -- 4 seconds
# 3 -- 8 seconds (etc)
#
# Example: run.pl 8
# runs 8 experiments, the last having a duration of 256 seconds
#
use strict;
sub pow2 {
my ($val) = @_;
my $tot;
$tot = 1;
my $c;
$c = 0;
while ($c < $val) {
$tot *= 2;
$c++;
}
return $tot;
}
my $EXPDIR;
$EXPDIR = "/playpen1/clark/nsexps/";
my $argc;
$argc = $#ARGV + 1;
if ($argc != 1) {
die "Need 1 argument but got $argc arguments.\n";
}
my $exp;
$exp = @ARGV[0];
# run sim.tcl using command line arguments
my $c;
$c = 1;
while ($c <= $exp) {
my $length;
$length = pow2($c);
printf ("Starting run %d for %d seconds (%d s)...\n",
$exp, $length);
`ns $EXPDIR/sim.tcl $length >$exp-${length}s.out`;
$c++;
}
print "DONE\n";