#! /bin/csh -x
#
# Rcsid[] = "$Id: run_fsim_dist,v 6.1 1998/03/06 00:33:40 vivek Exp $";
#
# This is a script to run a tdx_fsim on multiple hosts
# concurrently. Each host will fault simulate part of the
# master fault list. At the end of all the runs, the fault
# results are joined together.
#
# usage: run_fsim_dist  model  host1 host2 ... hostn
#
# To run "model" on three hosts use:
#
#       run_fsim_dist model hosta hostb hostc
#
# The input fault file should be named <model>.flt
# and the vector file should be named <model>.vec.
# If you wish to use different file names, or additional tdx_fsim
# command-line options, you will have to make a custom version
# of the script.
#
# This script requires that the rsh unix command be installed
# on each host, and that your login shell on each host is csh.
# Some systems may have problems with unix NFS and the "$cwd"
# use below. You may have to hard-code the actual path name
# to the working directory for the "rsh" command to work on
# all of the hosts. Some systems are setup to insert and/or
# require "export", "tmp_mnt", etc. in path names.

if ($#argv < 2) then
    echo "usage: run_fsim_dist  model  host1 host2 ... hostn"
    exit 1
endif
 
set model=$argv[1]

# You may have to hard-code the path name
#set base_dir=$HOME/bench/model
set base_dir=$cwd

#remove previous partflt file and run directories
rm -rf $model.[0-9]*.flt  part_*  $model.out.flt

@ num_parts = $#argv - 1

# partition the master fault file
partflt -p $num_parts 1700431 $model.flt $model

@ fn = 0
@ hn = 2

while ($fn < $num_parts)
    mkdir part_$fn
    rsh -n $argv[$hn] "cd $base_dir; tdx_fsim $model -spt null -vector_file $model.vec \\
           -fault_file $model.$fn.flt -outmodel part_$fn/$model >& part_$fn/log" &
    @ fn++
    @ hn++
end

wait

mergeflt $model -o $model.out.flt $model.flt part_*/$model.out.flt

reporter -f $model.out.flt $model
