Skip to content

Commit

Permalink
phits-run runs both with and without GNU parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
kbat committed Nov 28, 2024
1 parent a4c9b61 commit 61c9c00
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions mctools/phits/phits-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ usage()
{
echo "Usage: $(basename $0) file.inp [prefix] [njobs]"
echo " file.inp: PHITS input file. Must contain the 'rseed = RSEED' string in the [Parameters] section"
echo " prefix: temporary folder prefix"
echo " njobs: number of jobs to run. Default=number of cores (output of nproc)"
echo " prefix: temporary folder prefix. Default: 'case'"
echo " njobs: number of jobs to run. Default: number of cores (output of nproc)"
exit 1
}

Expand All @@ -31,4 +31,35 @@ else
njobs=$(nproc)
fi

echo $inp $prefix $njobs
rseed=$(grep rseed $inp | xargs | tr -d '[:blank:]')

if echo $rseed | grep -qx "rseed=RSEED" 2>/dev/null; then
true
else
echo "ERROR: The 'rseed = RSEED' string not found in $inp"
usage
fi

for ((i=1; i<=$njobs; i++)); do
d=$prefix$i
if [ -d $d ]; then
echo "ERROR: $d folder already exists"
exit 2
else
mkdir -p $d
cat $inp | sed "s;RSEED;$i;" > $d/phits.inp
fi
done

if which parallel > /dev/null; then
parallel "cd {} && phits.sh phits.inp" ::: $prefix*
else
h=$(pwd)
for d in $prefix*; do
echo $d
cd $d
phits.sh phits.inp
cd $h
done
wait $(jobs -rp)
fi

0 comments on commit 61c9c00

Please sign in to comment.