From 788158f31984d2f52a65e53909c44fcaa0dc0916 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 8 Feb 2024 12:27:12 +0100 Subject: [PATCH 1/9] Fix script to run examples locally Ignore comment lines and empty lines in the example lists file. Signed-off-by: Christoph Niethammer --- examples/run-examples.sh | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index d9c4180632..fa1b2d50f9 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -1,21 +1,28 @@ #!/bin/bash # Testscript running all examples from example-list.txt # -# Copyright (c) 2017 Christoph Niethammer +# Copyright (c) 2017-2024 Christoph Niethammer # -MARDYN_EXE="mpirun -np 1 $PWD/../src/MarDyn" +MARDYN_EXE="mpirun -np 2 $PWD/../src/MarDyn" MARDYN_OPTIONS="--steps 10 -v" EXAMPLE_LIST_FILE=${EXAMPLE_LIST_FILE:=example-list.txt} LOGFILE=${LOGFILE:=$PWD/run-examples.log} -#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 - +all_examples=() failed_examples=() -# definitions for esear color output to display +while IFS= read -r line ; do + [[ "$line" =~ ^#.*$ ]] && continue + [[ "$line" =~ ^$ ]] && continue + + example="$line" + echo "Going to run example file $example" + all_examples+=("$example") +done < "$EXAMPLE_LIST_FILE" + + +# definitions for easy color output Color_Off='\e[0m' # Text Reset IGreen='\e[0;92m' # Intense Green IRed='\e[0;91m' # Intense Red @@ -23,11 +30,10 @@ IMagenta='\e[0;95m' # magenta 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" From ad059f492cf14720a9000df9400c6c8eea7b97fd Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Sun, 8 Dec 2024 19:31:33 +0100 Subject: [PATCH 2/9] Improve run script for local example execution - Added command line options - Add one second timeout at end of test to easy interruption - Updated default run parameters to match run-validation script Signed-off-by: Christoph Niethammer --- checks/run-validation.sh | 22 ++----- examples/run-examples.sh | 123 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 119 insertions(+), 26 deletions(-) diff --git a/checks/run-validation.sh b/checks/run-validation.sh index 02ec94be55..cb60abf56d 100755 --- a/checks/run-validation.sh +++ b/checks/run-validation.sh @@ -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 # 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}" - # 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 diff --git a/examples/run-examples.sh b/examples/run-examples.sh index fa1b2d50f9..c7867b2bc1 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -4,11 +4,108 @@ # Copyright (c) 2017-2024 Christoph Niethammer # -MARDYN_EXE="mpirun -np 2 $PWD/../src/MarDyn" -MARDYN_OPTIONS="--steps 10 -v" +# Some default values +MARDYN_EXE="$PWD/../src/MarDyn" +MARDYN_ARGS="--steps 20 -v" +MPIRUN_EXE="mpirun" +MPIRUN_ARGS="-n 4 --oversubscribe" EXAMPLE_LIST_FILE=${EXAMPLE_LIST_FILE:=example-list.txt} LOGFILE=${LOGFILE:=$PWD/run-examples.log} +TEMP=$(getopt -o vh --long "help,inputlist:,logfile:,mardyn_args:,mardyn_exe:,mpirun_args:,mpirun_exe:,verbose" -- $@) + +if [ $? -ne 0 ]; then + echo "Error parsing commandline" + exit 1 +fi + +eval set -- "$TEMP" +unset TEMP + +function print_help() { +cat < path to an inputfile list + --logfile path for the logfile + --mpirun_exe mpirun command or path to mpirun executable + --mpirun_args arguments to be passed to the mpirun command + --mardyn_exe path to a MarDyn executable + --mardyn_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_EXE="$2" + shift 2 + continue + ;; + '--mpirun_exe') + MARDYN_EXE="$2" + shift 2 + continue + ;; + '--mpirun_args') + MARDYN_EXE="$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=() @@ -17,16 +114,23 @@ while IFS= read -r line ; do [[ "$line" =~ ^$ ]] && continue example="$line" - echo "Going to run example file $example" + 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 -Color_Off='\e[0m' # Text Reset -IGreen='\e[0;92m' # Intense Green -IRed='\e[0;91m' # Intense Red -IMagenta='\e[0;95m' # magenta +# 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 @@ -36,7 +140,7 @@ for example in ${all_examples[@]} ; do 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=$? @@ -49,6 +153,7 @@ for example in ${all_examples[@]} ; 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 "----------------------------------------" From 55b3f3b987fae0d6d15ca4893f9621beea846499 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Mon, 9 Dec 2024 15:21:19 +0100 Subject: [PATCH 3/9] Update examples/run-examples.sh Co-authored-by: FG-TUM --- examples/run-examples.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index c7867b2bc1..42e68d7a5d 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -110,7 +110,9 @@ all_examples=() failed_examples=() while IFS= read -r line ; do + # Skip comment lines, starting with `#`. [[ "$line" =~ ^#.*$ ]] && continue + # Skip empty lines [[ "$line" =~ ^$ ]] && continue example="$line" From f43bf95c03970db5a680c24548485bca550b47b4 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Mon, 9 Dec 2024 15:22:08 +0100 Subject: [PATCH 4/9] Use basename to determine program name Co-authored-by: FG-TUM --- examples/run-examples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index 42e68d7a5d..87d1d91f2e 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -24,7 +24,7 @@ unset TEMP function print_help() { cat < Date: Fri, 13 Dec 2024 10:54:39 +0100 Subject: [PATCH 5/9] Fix incorrect variable assignments Co-authored-by: HomesGH <55833544+HomesGH@users.noreply.github.com> --- examples/run-examples.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index 87d1d91f2e..4232d16b74 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -60,17 +60,17 @@ while true; do continue ;; '--mardyn_args') - MARDYN_EXE="$2" + MARDYN_ARGS="$2" shift 2 continue ;; '--mpirun_exe') - MARDYN_EXE="$2" + MPIRUN_EXE="$2" shift 2 continue ;; '--mpirun_args') - MARDYN_EXE="$2" + MPIRUN_ARGS="$2" shift 2 continue ;; From 057f8e5a0a2ea84f31a03f18217ef8cc71dd77af Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Fri, 13 Dec 2024 10:56:53 +0100 Subject: [PATCH 6/9] Comment default arguments that are specific to Open MPI Co-authored-by: FG-TUM --- examples/run-examples.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index 4232d16b74..e9d7843216 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -8,6 +8,7 @@ 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" EXAMPLE_LIST_FILE=${EXAMPLE_LIST_FILE:=example-list.txt} LOGFILE=${LOGFILE:=$PWD/run-examples.log} From 276a07a802579af8eabf27563e611cef9fdf00ed Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 16 Jan 2025 02:30:55 +0100 Subject: [PATCH 7/9] Fix parsing option values in run-examples script Fix parameter expansion so option values are kept correctly. This fixes issues handling multi-value option arguments, e.g., allowing now > ./run-examples.sh --mpi_args "-n 2 --oversubscribe 2 ..." Signed-off-by: Christoph Niethammer --- examples/run-examples.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index e9d7843216..80eb821b13 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -1,7 +1,7 @@ #!/bin/bash # Testscript running all examples from example-list.txt # -# Copyright (c) 2017-2024 Christoph Niethammer +# Copyright (c) 2017-2025 Christoph Niethammer # # Some default values @@ -13,7 +13,7 @@ MPIRUN_ARGS="-n 4 --oversubscribe" EXAMPLE_LIST_FILE=${EXAMPLE_LIST_FILE:=example-list.txt} LOGFILE=${LOGFILE:=$PWD/run-examples.log} -TEMP=$(getopt -o vh --long "help,inputlist:,logfile:,mardyn_args:,mardyn_exe:,mpirun_args:,mpirun_exe:,verbose" -- $@) +TEMP=$(getopt -o vh --long "help,inputlist:,logfile:,mardyn_args:,mardyn_exe:,mpirun_args:,mpirun_exe:,verbose" -- "$@") if [ $? -ne 0 ]; then echo "Error parsing commandline" From b53855f6a412014ec667374c77410667d6610ebc Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 16 Jan 2025 02:34:25 +0100 Subject: [PATCH 8/9] Change command line argument names to use hyphens instead of underscores Signed-off-by: Christoph Niethammer --- examples/run-examples.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/run-examples.sh b/examples/run-examples.sh index 80eb821b13..a66715e7cb 100755 --- a/examples/run-examples.sh +++ b/examples/run-examples.sh @@ -13,7 +13,7 @@ MPIRUN_ARGS="-n 4 --oversubscribe" EXAMPLE_LIST_FILE=${EXAMPLE_LIST_FILE:=example-list.txt} LOGFILE=${LOGFILE:=$PWD/run-examples.log} -TEMP=$(getopt -o vh --long "help,inputlist:,logfile:,mardyn_args:,mardyn_exe:,mpirun_args:,mpirun_exe:,verbose" -- "$@") +TEMP=$(getopt -o vh --long "help,inputlist:,logfile:,mardyn-args:,mardyn-exe:,mpirun-args:,mpirun-exe:,verbose" -- "$@") if [ $? -ne 0 ]; then echo "Error parsing commandline" @@ -38,10 +38,10 @@ Usage: Options: -i,--inputlist path to an inputfile list --logfile path for the logfile - --mpirun_exe mpirun command or path to mpirun executable - --mpirun_args arguments to be passed to the mpirun command - --mardyn_exe path to a MarDyn executable - --mardyn_args arguments to be passed to MarDyn for each input file + --mpirun-exe mpirun command or path to mpirun executable + --mpirun-args arguments to be passed to the mpirun command + --mardyn-exe path to a MarDyn executable + --mardyn-args arguments to be passed to MarDyn for each input file -v,--verbose verbose output -h,--help show this help @@ -55,22 +55,22 @@ while true; do shift 2 continue ;; - '--mardyn_exe') + '--mardyn-exe') MARDYN_EXE="$2" shift 2 continue ;; - '--mardyn_args') + '--mardyn-args') MARDYN_ARGS="$2" shift 2 continue ;; - '--mpirun_exe') + '--mpirun-exe') MPIRUN_EXE="$2" shift 2 continue ;; - '--mpirun_args') + '--mpirun-args') MPIRUN_ARGS="$2" shift 2 continue From 23242b8667a28020c5dbcb73b1b2d4f851d8c6ee Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 16 Jan 2025 11:41:53 +0100 Subject: [PATCH 9/9] Remove unused run-validation.sh in favour of the run-examples.sh Signed-off-by: Christoph Niethammer --- checks/run-validation.sh | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100755 checks/run-validation.sh diff --git a/checks/run-validation.sh b/checks/run-validation.sh deleted file mode 100755 index cb60abf56d..0000000000 --- a/checks/run-validation.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# Testscript running validation tests according to GitHub Actions but without comparison to master -# -# Copyright (c) 2023 Simon Homes -# Copyright (c) 2024 Christoph Niethammer -# - -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} - -cd ${repoPath}/examples -./run-examples.sh -v --inputlist "${inputlist}" --logfile "${logfileName}" - -