Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix script to run examples locally #285

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions checks/run-validation.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
#!/bin/bash
# Testscript running validation tests according to GitHub Actions but without comparison to master
#
# Copyright (c) 2023 Simon Homes
# Copyright (c) 2023 Simon Homes
# Copyright (c) 2024 Christoph Niethammer <[email protected]>
#

repoPath="$PWD/.." # Path to root directory

export OMP_NUM_THREADS=2

inputlist="${repoPath}/examples/example-list.txt"
logfileName="${repoPath}/examples/run-validation.log"
rm -f ${logfileName}

IFS=$'\n'
for i in $(cat "${repoPath}/examples/example-list.txt" )
do
# skip if comment or empty line
if [[ $i == \#* || -z "$i" ]]
then
continue
fi
cd ${repoPath}/examples/$(dirname $i)
cd ${repoPath}/examples
./run-examples.sh -v --inputlist "${inputlist}" --logfile "${logfileName}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use the options --{mardyn,mpirun}_{exe,args} here. Or we could just get rid of the entire file since its use case is already covered by the default settings of run-examples.sh, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I could not find any use case inside the codebase/workflows so I would get rid of the validation.sh script then.


# run the examples
printf "Running example: ${i} ... " | tee -a ${logfileName}
EXE=${repoPath}/build/src/MarDyn

mpirun --oversubscribe -np 4 ${EXE} $(basename $i) --steps=20 | tee -a ${logfileName}
printf "done\n"
done

144 changes: 129 additions & 15 deletions examples/run-examples.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,149 @@
#!/bin/bash
# Testscript running all examples from example-list.txt
#
# Copyright (c) 2017 Christoph Niethammer <[email protected]>
# Copyright (c) 2017-2024 Christoph Niethammer <[email protected]>
#

MARDYN_EXE="mpirun -np 1 $PWD/../src/MarDyn"
MARDYN_OPTIONS="--steps 10 -v"
# Some default values
MARDYN_EXE="$PWD/../src/MarDyn"
MARDYN_ARGS="--steps 20 -v"
MPIRUN_EXE="mpirun"
# Oversubscribe is specific to OpenMPI. If you use something different this flag needs to be removed / replaced.
MPIRUN_ARGS="-n 4 --oversubscribe"
cniethammer marked this conversation as resolved.
Show resolved Hide resolved
EXAMPLE_LIST_FILE=${EXAMPLE_LIST_FILE:=example-list.txt}
LOGFILE=${LOGFILE:=$PWD/run-examples.log}
cniethammer marked this conversation as resolved.
Show resolved Hide resolved

#mapfile -t all_examples < $EXAMPLE_LIST_FILE # requires bash4 ...
declare -a all_examples
while IFS= read -r; do all_examples+=("$REPLY"); done < $EXAMPLE_LIST_FILE
TEMP=$(getopt -o vh --long "help,inputlist:,logfile:,mardyn_args:,mardyn_exe:,mpirun_args:,mpirun_exe:,verbose" -- $@)
cniethammer marked this conversation as resolved.
Show resolved Hide resolved

if [ $? -ne 0 ]; then
echo "Error parsing commandline"
exit 1
fi

eval set -- "$TEMP"
unset TEMP

function print_help() {
cat <<EOF
$(basename $0) is a script to execute MarDyn examples from a inputfile list file

A inputlist file contains one path per line to a configuration file to be passed to MarDyn.
MarDyn is executed with one configuration file at a time.
In the inputlist file empty lines and lines starting with '#' are ignored.

Usage:
$0 [OPTIONS ...]
$0 [-h|--help]

Options:
-i,--inputlist <FILE> path to an inputfile list
--logfile <FILE> path for the logfile
--mpirun_exe <mpirun> mpirun command or path to mpirun executable
--mpirun_args <ARGS> arguments to be passed to the mpirun command
--mardyn_exe <MarDyn> path to a MarDyn executable
--mardyn_args <ARGS> arguments to be passed to MarDyn for each input file
-v,--verbose verbose output
-h,--help show this help

EOF
}

while true; do
case "$1" in
'--logfile')
LOGFILE="$2"
shift 2
continue
;;
'--mardyn_exe')
MARDYN_EXE="$2"
shift 2
continue
;;
'--mardyn_args')
MARDYN_ARGS="$2"
shift 2
continue
;;
'--mpirun_exe')
MPIRUN_EXE="$2"
shift 2
continue
;;
'--mpirun_args')
MPIRUN_ARGS="$2"
shift 2
continue
;;
'--inputlist')
EXAMPLE_LIST_FILE="$2"
shift 2
continue
;;
'-v'|'--verbose')
VERBOSE=true
shift
continue
;;
'-h'|'--help')
PRINT_HELP_AND_EXIT=true
shift
break
;;
'--')
shift
break
;;
* )
echo "ERROR Unknown Option $1"
exit 1
;;
esac
done

if [ $PRINT_HELP_AND_EXIT ]; then
print_help
exit 0
fi


all_examples=()
failed_examples=()

# definitions for esear color output to display
Color_Off='\e[0m' # Text Reset
IGreen='\e[0;92m' # Intense Green
IRed='\e[0;91m' # Intense Red
IMagenta='\e[0;95m' # magenta
while IFS= read -r line ; do
# Skip comment lines, starting with `#`.
[[ "$line" =~ ^#.*$ ]] && continue
# Skip empty lines
[[ "$line" =~ ^$ ]] && continue

example="$line"
if [ $VERBOSE ]; then
echo "Going to run example file $example"
fi
all_examples+=("$example")
done < "$EXAMPLE_LIST_FILE"

if [ $VERBOSE ]; then
echo "Writing test outputs to $LOGFILE"
fi

# definitions for easy color output if we are running in a terminal
if [ -t 0 -a -t 1 -a -t 2 ]; then
Color_Off='\e[0m' # Text Reset
IGreen='\e[0;92m' # Intense Green
IRed='\e[0;91m' # Intense Red
IMagenta='\e[0;95m' # magenta
fi

logfile=$LOGFILE
date > $logfile
for example in ${all_examples[@]}
do
for example in ${all_examples[@]} ; do
example_dir=$(dirname $example)
example_inp_file=$(basename $example)
echo -e -n "Running example ${IMagenta}$example_inp_file${Color_Off} in $example_dir ... "
echo -e -n "Running example ${IMagenta}$example_inp_file${Color_Off} in ${IMagenta}$example_dir${Color_Off} ... "
echo "Running example $example_inp_file in $example_dir" >> $logfile
pushd "$example_dir" >/dev/null
cmd="$MARDYN_EXE $MARDYN_OPTIONS $example_inp_file"
cmd="$MPIRUN_EXE $MPIRUN_ARGS $MARDYN_EXE $MARDYN_ARGS $example_inp_file"
echo $cmd >>$logfile
{ $cmd ; } >>$logfile 2>&1
ret=$?
Expand All @@ -43,6 +156,7 @@ do
echo "Running example $example_inp_file in $example_dir ... Result: failed" >> $logfile
fi
popd >/dev/null
sleep 1 # sleep for 1 second to make cancelation with CTR-C easier
done

echo "----------------------------------------"
Expand Down
Loading