From 2872871524e359c3f9932ac9aadaee197c5fb665 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 19 Apr 2024 23:49:51 -0500 Subject: [PATCH 1/6] Added time dependency for tests --- guix.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/guix.scm b/guix.scm index b356f5f..7dc12b8 100644 --- a/guix.scm +++ b/guix.scm @@ -1,6 +1,6 @@ ;; Set up build environment using GNU Guix packages ;; -;; CC0 license, Pjotr Prins (c) 2022-2023 +;; CC0 license, Pjotr Prins (c) 2022-2024 ;; ;; To use this file to build HEAD: ;; @@ -44,6 +44,7 @@ (gnu packages llvm) (gnu packages parallel) (gnu packages pkg-config) + (gnu packages time) (srfi srfi-1) (ice-9 popen) (ice-9 rdelim)) @@ -61,6 +62,7 @@ (build-system cmake-build-system) (inputs `(("bash" ,bash) + ("time" ,time) ("gdb" ,gdb))) (native-inputs `(("pkg-config" ,pkg-config))) From a9f49ca3d29eb1880a0924d96b279a726085c1e7 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 19 Apr 2024 23:50:28 -0500 Subject: [PATCH 2/6] Have git ignore test output --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6148fb8..4d9d332 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ lib/ bin/ build/ +Testing/ # Prerequisites *.d @@ -39,5 +40,5 @@ build/ tests/wfa.utest.log.correct tests/wfa.utest.log.mem tests/wfa.utest.log.time - +tests/*.alg From 8f6591b75cc1199b155ac31aa5cdd7eb03b4a953 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 19 Apr 2024 23:54:38 -0500 Subject: [PATCH 3/6] Minor fixes to test with vcflib: - Added -f switches to rm command so it does not fail on an empty list - One typo - Removed trailing spaces: to get a better view you may want to use --word-diff switch to git diff --- tests/wfa.utest.clean.sh | 2 +- tests/wfa.utest.cmp.sh | 7 +++-- tests/wfa.utest.performance.sh | 4 +-- tests/wfa.utest.sh | 53 +++++++++++++++++----------------- tests/wfa.utest.valgrind.sh | 2 +- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/wfa.utest.clean.sh b/tests/wfa.utest.clean.sh index 3a7a483..90ceaf3 100755 --- a/tests/wfa.utest.clean.sh +++ b/tests/wfa.utest.clean.sh @@ -9,5 +9,5 @@ OUTPUT="./tests" # Clear -rm $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null +rm -f $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null diff --git a/tests/wfa.utest.cmp.sh b/tests/wfa.utest.cmp.sh index e3efe49..200ef03 100755 --- a/tests/wfa.utest.cmp.sh +++ b/tests/wfa.utest.cmp.sh @@ -1,6 +1,6 @@ #!/bin/bash # PROJECT: Wavefront Alignments Algorithms (Unitary Tests) -# LICENCE: MIT License +# LICENCE: MIT License # AUTHOR(S): Santiago Marco-Sola # DESCRIPTION: Compares alignments (*.alg) from two folders # USAGE: ./wfa.utest.cmp.sh folder_1 folder_2 [--cmp-performance] @@ -20,6 +20,7 @@ STATUS=0 echo "> Comparing $FOLDER1 vs $FOLDER2" for FILE_ALG1 in $FOLDER1/*.alg do + echo $FILE_ALG1 FILENAME=$(basename -- "$FILE_ALG1") PREFIX=${FILENAME%.*} FILE_ALG2="$FOLDER2/$FILENAME" @@ -34,7 +35,7 @@ do continue fi # Check diff - if [[ $(diff $FILE_ALG1 $FILE_ALG2) ]] + if [[ $(diff $FILE_ALG1 $FILE_ALG2) ]] then if [[ $(diff <(awk '{if ($1<0) print -$1; else print $1}' $FILE_ALG1) <(awk '{if ($1<0) print -$1; else print $1}' $FILE_ALG2)) ]] then @@ -52,7 +53,7 @@ do if [[ $CMP_PERF == 1 ]] then T1=$(grep -m1 "Time.Alignment" $FOLDER1/$PREFIX.log | awk '{print $3" "$4}') - T2=$(grep -m1 "Time.Alignment" $FOLDER2/$PREFIX.log | awk '{print $3" "$4}') + T2=$(grep -m1 "Time.Alignment" $FOLDER2/$PREFIX.log | awk '{print $3" "$4}') M1=$(grep -m1 "Maximum resident set size" $FOLDER1/$PREFIX.log | tr -d "(:)" | awk '{print $6" "$5}') M2=$(grep -m1 "Maximum resident set size" $FOLDER2/$PREFIX.log | tr -d "(:)" | awk '{print $6" "$5}') echo -e "\tTIME($T1,$T2)\tMEM($M1,$M2)" diff --git a/tests/wfa.utest.performance.sh b/tests/wfa.utest.performance.sh index 78d4cdc..6476ef2 100755 --- a/tests/wfa.utest.performance.sh +++ b/tests/wfa.utest.performance.sh @@ -14,7 +14,7 @@ LOWMEMORY="--wfa-memory-mode=med" BIWFA="--wfa-memory-mode=ultralow" # Clear -rm $OUTPUT/*.log $OUTPUT/*.alg +rm -f $OUTPUT/*.log $OUTPUT/*.alg # Utest for length=100 \time -v ./bin/align_benchmark -a $ALGORITHM -i ../data/sim.l100.n100K.e2.seq -o $OUTPUT/sim.l100.e2.W.alg &> $OUTPUT/sim.l100.e2.W.log @@ -41,4 +41,4 @@ rm $OUTPUT/*.log $OUTPUT/*.alg echo ">>> " echo ">>> Performance [base vs new]: " echo ">>> " -./tests/wfa.utest.cmp.sh tests/wfa.utest.performance.check/ tests/ --cmp-performance \ No newline at end of file +./tests/wfa.utest.cmp.sh tests/wfa.utest.performance.check/ tests/ --cmp-performance diff --git a/tests/wfa.utest.sh b/tests/wfa.utest.sh index b4fb060..13e84e1 100755 --- a/tests/wfa.utest.sh +++ b/tests/wfa.utest.sh @@ -1,8 +1,8 @@ #!/bin/bash # PROJECT: Wavefront Alignments Algorithms (Unitary Tests) -# LICENCE: MIT License +# LICENCE: MIT License # AUTHOR(S): Santiago Marco-Sola -# DESCRIPTION: WFA unitary tests (correcness) +# DESCRIPTION: WFA unitary tests (correctness) # USAGE: ./wfa.utest.sh # Config @@ -13,49 +13,49 @@ LOG="$PREFIX/wfa.utest.log" CMP_SCORE=$(readlink -f "$PREFIX/../scripts/wfa.alg.cmp.score.sh") BIN=$(readlink -f "$PREFIX/../build/bin/align_benchmark") -if [ ! -f "$BIN" ] +if [ ! -f "$BIN" ] then BIN=$(readlink -f "$PREFIX/../bin/align_benchmark") if [ ! -f "$BIN" ] then - echo "[Error] Binaries not built. Please run cmake or make" + echo "[Error] Binaries not built. Please run cmake or make" exit -1 - fi + fi fi # Clear -rm $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null +rm -f $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null # Run tests for opt in "--check=correct","test" \ "--wfa-score-only","test.score" \ "--wfa-memory-mode=med --check=correct","test.pb" \ "--wfa-memory-mode=ultralow --check=correct","test.biwfa" \ - "--wfa-memory-mode=ultralow --wfa-score-only","test.biwfa.score" -do + "--wfa-memory-mode=ultralow --wfa-score-only","test.biwfa.score" +do # Config IFS=','; set -- $opt IFS=' '; MODE="$1"; NAME="$2" echo ">>> Testing '$NAME' ($MODE)" - + # Testing distance functions - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.indel.alg -a indel-wfa $MODE >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.edit.alg -a edit-wfa $MODE >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.alg -a gap-affine-wfa $MODE >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine2p.alg -a gap-affine2p-wfa $MODE >> $LOG 2>&1 - + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.indel.alg -a indel-wfa $MODE >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.edit.alg -a edit-wfa $MODE >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.alg -a gap-affine-wfa $MODE >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine2p.alg -a gap-affine2p-wfa $MODE >> $LOG 2>&1 + # Testing penalty-scores - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p0.alg -a gap-affine-wfa $MODE --affine-penalties="0,1,2,1" >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p1.alg -a gap-affine-wfa $MODE --affine-penalties="0,3,1,4" >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p2.alg -a gap-affine-wfa $MODE --affine-penalties="0,5,3,2" >> $LOG 2>&1 - - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p3.alg -a gap-affine-wfa $MODE --affine-penalties="-5,1,2,1" >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p4.alg -a gap-affine-wfa $MODE --affine-penalties="-2,3,1,4" >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p5.alg -a gap-affine-wfa $MODE --affine-penalties="-3,5,3,2" >> $LOG 2>&1 - + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p0.alg -a gap-affine-wfa $MODE --affine-penalties="0,1,2,1" >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p1.alg -a gap-affine-wfa $MODE --affine-penalties="0,3,1,4" >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p2.alg -a gap-affine-wfa $MODE --affine-penalties="0,5,3,2" >> $LOG 2>&1 + + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p3.alg -a gap-affine-wfa $MODE --affine-penalties="-5,1,2,1" >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p4.alg -a gap-affine-wfa $MODE --affine-penalties="-2,3,1,4" >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p5.alg -a gap-affine-wfa $MODE --affine-penalties="-3,5,3,2" >> $LOG 2>&1 + # Heuristics - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt0.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,1 >> $LOG 2>&1 - \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt1.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,10 >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt0.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,1 >> $LOG 2>&1 + \time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt1.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,10 >> $LOG 2>&1 done # Intra-tests @@ -91,9 +91,9 @@ grep "Maximum resident set size" $LOG | awk '{print $6}' | sort -n > $LOG.mem # Display performance echo ">>> Performance Time (s) [base vs new]: " -paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.time) <(tail -n 4 $OUTPUT/wfa.utest.log.time) +paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.time) <(tail -n 4 $OUTPUT/wfa.utest.log.time) echo ">>> Performance Mem (KB) [base vs new]: " -paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.mem) <(tail -n 4 $OUTPUT/wfa.utest.log.mem) +paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.mem) <(tail -n 4 $OUTPUT/wfa.utest.log.mem) # Display correct ./tests/wfa.utest.cmp.sh $OUTPUT $OUTPUT/wfa.utest.check @@ -110,4 +110,3 @@ else echo -e ">>>\n>>> ERROR\n>>>" exit -1 fi - diff --git a/tests/wfa.utest.valgrind.sh b/tests/wfa.utest.valgrind.sh index e902d39..23fc09b 100755 --- a/tests/wfa.utest.valgrind.sh +++ b/tests/wfa.utest.valgrind.sh @@ -12,7 +12,7 @@ OUTPUT="./tests" LOG="./tests/wfa.utest.log.valgrind" # Clear -rm $OUTPUT/*.alg $LOG +rm -f $OUTPUT/*.alg $LOG touch $LOG # Run tests From 86e9de925a3b6ba6a7f412835c9d2d5ca50426dd Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 20 Apr 2024 02:18:37 -0500 Subject: [PATCH 4/6] benchmark: disable test when OPENMP is not linked in --- tools/align_benchmark/align_benchmark.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/align_benchmark/align_benchmark.c b/tools/align_benchmark/align_benchmark.c index 5eae274..24a5a85 100644 --- a/tools/align_benchmark/align_benchmark.c +++ b/tools/align_benchmark/align_benchmark.c @@ -535,9 +535,11 @@ void align_benchmark_parallel() { if (seqs_batch == 0) break; // Parallel processing of the sequences batch timer_start(¶meters.timer_global); // PROFILE +#ifdef WFA_PARALLEL #pragma omp parallel num_threads(parameters.num_threads) { int tid = omp_get_thread_num(); + #pragma omp for for (int seq_idx=0;seq_idx Date: Sat, 20 Apr 2024 02:19:19 -0500 Subject: [PATCH 5/6] CMake can now build the benchmark and run the tests 'natively'. This is used by vcflib. --- CMakeLists.txt | 50 ++++++++++++++++++++++++++++++++++++++++++---- README.md | 10 ++-------- tests/wfa.utest.sh | 8 ++++++-- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acb3d90..dc7eb76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ # For Debian currently with # # cd build -# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo .. -# make -# make test +# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENMP=1 .. +# cmake --build . +# ctest . # make install # See below option statements and the README for build information @@ -192,12 +192,54 @@ set(wfa2lib_LIBS # add_dependencies(wfa2lib ${wfa2lib_DEPS}) # ---- Build all +# add_subdirectory(tools/align_benchmark) + + +add_executable(align_benchmark + tools/align_benchmark/align_benchmark_params.c + tools/align_benchmark/align_benchmark.c + tools/align_benchmark/benchmark/benchmark_check.c + tools/align_benchmark/benchmark/benchmark_edit.c + tools/align_benchmark/benchmark/benchmark_gap_affine2p.c + tools/align_benchmark/benchmark/benchmark_gap_affine.c + tools/align_benchmark/benchmark/benchmark_gap_linear.c + tools/align_benchmark/benchmark/benchmark_indel.c + tools/align_benchmark/benchmark/benchmark_utils.c + system/mm_allocator.c + system/mm_stack.c + system/profiler_counter.c + system/profiler_timer.c + utils/bitmap.c + utils/commons.c + utils/dna_text.c + utils/heatmap.c + utils/sequence_buffer.c + utils/vector.c + alignment/affine2p_penalties.c + alignment/affine_penalties.c + alignment/cigar.c + alignment/score_matrix.c + tools/align_benchmark/gap_affine/affine_matrix.c + tools/align_benchmark/gap_affine/swg.c + tools/align_benchmark/gap_linear/nw.c + tools/align_benchmark/gap_affine2p/affine2p_dp.c + tools/align_benchmark/gap_affine2p/affine2p_matrix.c + tools/align_benchmark/edit/edit_bpm.c + tools/align_benchmark/edit/edit_dp.c + tools/align_benchmark/indel/indel_dp.c +) +target_include_directories(align_benchmark PUBLIC . wavefront system utils tools/align_benchmark) +add_dependencies(align_benchmark wfa2) +target_link_libraries(align_benchmark m) +target_link_libraries(align_benchmark wfa2) +if(OPENMP) + target_link_libraries(align_benchmark OpenMP::OpenMP_C) +endif(OPENMP) # ---- Test enable_testing() - function(add_wfa_test) add_test( NAME wfa2lib diff --git a/README.md b/README.md index b3257fc..8a0e7a5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The WFA2 library implements the WFA algorithm for different distance metrics and ### 1.3 Getting started -Git clone and compile the library, tools, and examples (by default, use cmake). +Git clone and compile the library, tools, and examples (by default, use cmake for the library and benchmark build). ``` git clone https://github.com/smarco/WFA2-lib @@ -34,13 +34,7 @@ cmake .. -DOPENMP=TRUE cmake .. -DCMAKE_BUILD_TYPE=Release -DEXTRA_FLAGS="-ftree-vectorizer-verbose=5" ``` -To build a shared library (static is the default). - -``` -cmake -DBUILD_SHARED_LIBS=ON -``` - -Alternatively, the Makefile build system can be used. +Alternatively, the simple Makefile build system can be used. ``` $> git clone https://github.com/smarco/WFA2-lib diff --git a/tests/wfa.utest.sh b/tests/wfa.utest.sh index 13e84e1..bcb7d8a 100755 --- a/tests/wfa.utest.sh +++ b/tests/wfa.utest.sh @@ -18,8 +18,12 @@ then BIN=$(readlink -f "$PREFIX/../bin/align_benchmark") if [ ! -f "$BIN" ] then - echo "[Error] Binaries not built. Please run cmake or make" - exit -1 + BIN=$(readlink -f "$PREFIX/../build/align_benchmark") # cmake + if [ ! -f "$BIN" ] + then + echo "[Error] Binaries not built. Please run cmake or make" + exit -1 + fi fi fi From 151af8e02acb3924f991ef8796d87013b4936a13 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 20 Apr 2024 03:11:31 -0500 Subject: [PATCH 6/6] Pass path in of build dir so vcflib can find the benchmark binary --- CMakeLists.txt | 2 +- tests/wfa.utest.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc7eb76..6bcc597 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,7 +243,7 @@ enable_testing() function(add_wfa_test) add_test( NAME wfa2lib - COMMAND ./tests/wfa.utest.sh + COMMAND ./tests/wfa.utest.sh ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endfunction() diff --git a/tests/wfa.utest.sh b/tests/wfa.utest.sh index bcb7d8a..80c4b4d 100755 --- a/tests/wfa.utest.sh +++ b/tests/wfa.utest.sh @@ -12,7 +12,8 @@ OUTPUT="$PREFIX" LOG="$PREFIX/wfa.utest.log" CMP_SCORE=$(readlink -f "$PREFIX/../scripts/wfa.alg.cmp.score.sh") -BIN=$(readlink -f "$PREFIX/../build/bin/align_benchmark") + +BIN=$1/align_benchmark if [ ! -f "$BIN" ] then BIN=$(readlink -f "$PREFIX/../bin/align_benchmark")