#! /bin/csh -x
#
# Rcsid[] = "$Id: run_fsim_part,v 6.1 1998/03/06 00:33:49 vivek Exp $";
#
#
# This is a script to partition a fault list into "n" parts,
# then run tdx_fsim on each part, and finally join the fault
# results together. This script makes the tdx_fsim runs in 
# serial fashion on a single host.
#
# Fault simulation performance can often be improved when
# one large run is partitioned into many smaller runs. The
# difference in performance is caused by the memory usage and
# "average fault list length" required for the different runs.
# One run with all the faults will use more memory which may
# result in disk paging and/or less efficient cache use on your
# host computer.
#
# This multi-pass script is also useful when the full fault run
# uses more virtual memory (swap space) than you have setup on
# your host computer.
#
# usage: run_fsim_part  model  #partitions
#
# To run "model" in 5 partitions use: run_fsim_part model 5
#
# 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.

if ($#argv != 2) then
    echo "usage: run_fsim_part  model  #partitions"
    exit 1
endif

set model=$argv[1]

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


# partition the master fault file
partflt -p $argv[2] 1700431 $model.flt $model

@ fn = 0

while ($fn < $argv[2])
    mkdir part_$fn
    tdx_fsim $model -spt null -vector_file $model.vec \
       -fault_file $model.$fn.flt -outmodel part_$fn/$model >& part_$fn/log
    @ fn++
end

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

reporter -f $model.out.flt $model
