From 350656206cc429faf9240f4ee13c43d389c6e268 Mon Sep 17 00:00:00 2001 From: smarco Date: Fri, 10 Jun 2022 15:30:03 +0200 Subject: [PATCH] Added debug info for biwfa --- tools/align_benchmark/align_benchmark.c | 2 +- wavefront/wavefront_align.c | 65 +++++++++++++---------- wavefront/wavefront_aligner.c | 50 +++++++++--------- wavefront/wavefront_bialign.c | 2 +- wavefront/wavefront_debug.c | 45 +++++++--------- wavefront/wavefront_debug.h | 10 +--- wavefront/wavefront_extend.c | 2 +- wavefront/wavefront_heuristic.c | 70 +++++++++++-------------- 8 files changed, 118 insertions(+), 128 deletions(-) diff --git a/tools/align_benchmark/align_benchmark.c b/tools/align_benchmark/align_benchmark.c index deafc19b..298b58c8 100644 --- a/tools/align_benchmark/align_benchmark.c +++ b/tools/align_benchmark/align_benchmark.c @@ -139,7 +139,7 @@ typedef struct { } benchmark_args; benchmark_args parameters = { // Algorithm - .algorithm = alignment_test, + .algorithm = alignment_edit_wavefront, // I/O .input_filename = NULL, .output_filename = NULL, diff --git a/wavefront/wavefront_align.c b/wavefront/wavefront_align.c index 2dd6fcfd..6f92299e 100644 --- a/wavefront/wavefront_align.c +++ b/wavefront/wavefront_align.c @@ -329,7 +329,7 @@ int wavefront_align_sequences( wf_aligner->align_status.status = WF_STATUS_SUCCESSFUL; return WF_STATUS_SUCCESSFUL; } -void wavefront_align_begin( +void wavefront_align_sequences_init( wavefront_aligner_t* const wf_aligner, const char* const pattern, const int pattern_length, @@ -337,8 +337,6 @@ void wavefront_align_begin( const int text_length) { // Parameters wavefront_align_status_t* const wf_align_status = &wf_aligner->align_status; - // DEBUG - wavefront_debug_prologue(wf_aligner,pattern,pattern_length,text,text_length); // Resize wavefront aligner wavefront_aligner_resize(wf_aligner,pattern,pattern_length,text,text_length,false); // Configure WF-compute function @@ -384,10 +382,8 @@ void wavefront_align_begin( wavefront_plot(wf_aligner,pattern,text,0); } } -void wavefront_align_end( +void wavefront_align_finish( wavefront_aligner_t* const wf_aligner) { - // Parameters - wavefront_align_status_t* const wf_align_status = &wf_aligner->align_status; // Reap memory (controlled reaping) uint64_t wf_memory_used = wavefront_aligner_get_size(wf_aligner); if (wf_memory_used > wf_aligner->system.max_memory_resident) { @@ -398,44 +394,37 @@ void wavefront_align_end( // Slab if (wf_memory_used > wf_aligner->system.max_memory_resident) { wavefront_slab_reap(wf_aligner->wavefront_slab); + if (wf_aligner->aligner_forward != NULL) { + wavefront_slab_reap(wf_aligner->aligner_forward->wavefront_slab); + } + if (wf_aligner->aligner_reverse != NULL) { + wavefront_slab_reap(wf_aligner->aligner_reverse->wavefront_slab); + } } } - // DEBUG - wavefront_debug_epilogue(wf_aligner, - wf_aligner->pattern,wf_aligner->pattern_length, - wf_aligner->text,wf_aligner->text_length, - wf_align_status->status,wf_memory_used); } /* * Wavefront Alignment */ -int wavefront_align_unidirectional( +void wavefront_align_unidirectional( wavefront_aligner_t* const wf_aligner, const char* const pattern, const int pattern_length, const char* const text, const int text_length) { - // Parameters - wavefront_align_status_t* const wf_align_status = &wf_aligner->align_status; // Prepare alignment - wavefront_align_begin(wf_aligner,pattern,pattern_length,text,text_length); + wavefront_align_sequences_init(wf_aligner,pattern,pattern_length,text,text_length); // Wavefront align sequences wavefront_align_sequences(wf_aligner); - // Check pause condition - if (wf_align_status->status == WF_STATUS_MAX_SCORE_REACHED) { - return WF_STATUS_MAX_SCORE_REACHED; // Alignment paused - } - // Finish alignment - wavefront_align_end(wf_aligner); - // Return - return wf_align_status->status; } -int wavefront_align_bidirectional( +void wavefront_align_bidirectional( wavefront_aligner_t* const wf_aligner, const char* const pattern, const int pattern_length, const char* const text, const int text_length) { + // Parameters + wavefront_align_status_t* const wf_align_status = &wf_aligner->align_status; // Allocate cigar cigar_t cigar; cigar_allocate(&cigar,2*(pattern_length+text_length),wf_aligner->mm_allocator); @@ -448,8 +437,8 @@ int wavefront_align_bidirectional( // Swap and free cigar SWAP(wf_aligner->cigar,cigar); cigar_free(&cigar); - // Return - return WF_STATUS_SUCCESSFUL; + // Finish + wf_align_status->status = WF_STATUS_SUCCESSFUL; // For the moment, all good } int wavefront_align( wavefront_aligner_t* const wf_aligner, @@ -457,12 +446,26 @@ int wavefront_align( const int pattern_length, const char* const text, const int text_length) { + // Parameters + wavefront_align_status_t* const wf_align_status = &wf_aligner->align_status; + // DEBUG + wavefront_debug_prologue(wf_aligner); // Dispatcher if (wf_aligner->bidirectional_alignment) { - return wavefront_align_bidirectional(wf_aligner,pattern,pattern_length,text,text_length); + wavefront_align_bidirectional(wf_aligner,pattern,pattern_length,text,text_length); } else { - return wavefront_align_unidirectional(wf_aligner,pattern,pattern_length,text,text_length); + wavefront_align_unidirectional(wf_aligner,pattern,pattern_length,text,text_length); + // Check pause condition + if (wf_align_status->status == WF_STATUS_MAX_SCORE_REACHED) { + return WF_STATUS_MAX_SCORE_REACHED; // Alignment paused + } } + // Finish alignment + wavefront_align_finish(wf_aligner); + // DEBUG + wavefront_debug_epilogue(wf_aligner,pattern,pattern_length,text,text_length); + // Return + return wf_align_status->status; } int wavefront_align_resume( wavefront_aligner_t* const wf_aligner) { @@ -480,7 +483,11 @@ int wavefront_align_resume( return WF_STATUS_MAX_SCORE_REACHED; // Alignment paused } // Finish alignment - wavefront_align_end(wf_aligner); + wavefront_align_finish(wf_aligner); + // DEBUG + wavefront_debug_epilogue(wf_aligner, + wf_aligner->pattern,wf_aligner->pattern_length, + wf_aligner->text,wf_aligner->text_length); // Return return wf_align_status->status; } diff --git a/wavefront/wavefront_aligner.c b/wavefront/wavefront_aligner.c index 72a9ebec..c75dc0ab 100644 --- a/wavefront/wavefront_aligner.c +++ b/wavefront/wavefront_aligner.c @@ -104,28 +104,22 @@ void wavefront_aligner_init_heuristic( // Select and configure heuristics if (wf_heuristic->strategy == wf_heuristic_none) { wavefront_heuristic_set_none(&wf_aligner->heuristic); - } else { - if ((wf_heuristic->strategy & wf_heuristic_banded_static) != 0) { - wavefront_heuristic_set_banded_static(&wf_aligner->heuristic, - wf_heuristic->min_k,wf_heuristic->max_k); - } - if ((wf_heuristic->strategy & wf_heuristic_banded_adaptive) != 0) { - wavefront_heuristic_set_banded_adaptive(&wf_aligner->heuristic, - wf_heuristic->min_k,wf_heuristic->max_k,wf_heuristic->steps_between_cutoffs); - } - if ((wf_heuristic->strategy & wf_heuristic_wfadaptive) != 0) { - wavefront_heuristic_set_wfadaptive( - &wf_aligner->heuristic,wf_heuristic->min_wavefront_length, - wf_heuristic->max_distance_threshold,wf_heuristic->steps_between_cutoffs); - } - if ((wf_heuristic->strategy & wf_heuristic_xdrop) != 0) { - wavefront_heuristic_set_xdrop(&wf_aligner->heuristic, - wf_heuristic->xdrop,wf_heuristic->steps_between_cutoffs); - } - if ((wf_heuristic->strategy & wf_heuristic_zdrop) != 0) { - wavefront_heuristic_set_zdrop(&wf_aligner->heuristic, - wf_heuristic->zdrop,wf_heuristic->steps_between_cutoffs); - } + } else if (wf_heuristic->strategy == wf_heuristic_banded_static) { + wavefront_heuristic_set_banded_static(&wf_aligner->heuristic, + wf_heuristic->min_k,wf_heuristic->max_k); + } else if (wf_heuristic->strategy == wf_heuristic_banded_adaptive) { + wavefront_heuristic_set_banded_adaptive(&wf_aligner->heuristic, + wf_heuristic->min_k,wf_heuristic->max_k,wf_heuristic->steps_between_cutoffs); + } else if (wf_heuristic->strategy == wf_heuristic_wfadaptive) { + wavefront_heuristic_set_wfadaptive( + &wf_aligner->heuristic,wf_heuristic->min_wavefront_length, + wf_heuristic->max_distance_threshold,wf_heuristic->steps_between_cutoffs); + } else if (wf_heuristic->strategy == wf_heuristic_xdrop) { + wavefront_heuristic_set_xdrop(&wf_aligner->heuristic, + wf_heuristic->xdrop,wf_heuristic->steps_between_cutoffs); + } else if (wf_heuristic->strategy == wf_heuristic_zdrop) { + wavefront_heuristic_set_zdrop(&wf_aligner->heuristic, + wf_heuristic->zdrop,wf_heuristic->steps_between_cutoffs); } } void wavefront_aligner_init_alignment( @@ -432,11 +426,19 @@ uint64_t wavefront_aligner_get_size( wavefront_aligner_t* const wf_aligner) { // Parameters wavefront_components_t* const wf_components = &wf_aligner->wf_components; - // Compute size + uint64_t sub_aligners = 0; + if (wf_aligner->aligner_forward != NULL) { + sub_aligners += wavefront_aligner_get_size(wf_aligner->aligner_forward); + } + if (wf_aligner->aligner_reverse != NULL) { + sub_aligners += wavefront_aligner_get_size(wf_aligner->aligner_reverse); + } + // Compute aligner size const uint64_t bt_buffer_size = (wf_components->bt_buffer) ? wf_backtrace_buffer_get_size_allocated(wf_components->bt_buffer) : 0; const uint64_t slab_size = wavefront_slab_get_size(wf_aligner->wavefront_slab); - return bt_buffer_size + slab_size; + // Return overall size + return sub_aligners + bt_buffer_size + slab_size; } /* * Display diff --git a/wavefront/wavefront_bialign.c b/wavefront/wavefront_bialign.c index 21ea319b..ddbcb616 100644 --- a/wavefront/wavefront_bialign.c +++ b/wavefront/wavefront_bialign.c @@ -501,7 +501,7 @@ void wavefront_bialign( const int breakpoint_h = WAVEFRONT_H(breakpoint.k_forward,breakpoint.offset_forward); const int breakpoint_v = WAVEFRONT_V(breakpoint.k_forward,breakpoint.offset_forward); // DEBUG - if (wf_aligner->system.verbose == 1) wavefront_bialign_debug(&breakpoint,rlevel); + if (wf_aligner->system.verbose >= 2) wavefront_bialign_debug(&breakpoint,rlevel); // Align half_0 alignment_form_t form_0; wavefront_bialign_init_half_0(form,&form_0); diff --git a/wavefront/wavefront_debug.c b/wavefront/wavefront_debug.c index 8cce88df..b1ec8ea6 100644 --- a/wavefront/wavefront_debug.c +++ b/wavefront/wavefront_debug.c @@ -142,15 +142,17 @@ void wavefront_report_lite( } fprintf(stream,"\n"); } -void wavefront_report_verbose_begin( +void wavefront_report_verbose( FILE* const stream, wavefront_aligner_t* const wf_aligner, const char* const pattern, const int pattern_length, const char* const text, - const int text_length) { + const int text_length, + const int wf_status, + const uint64_t wf_memory_used) { // Input sequences - fprintf(stream,"[WFA::Debug] WFA-Alignment\n"); + fprintf(stream,"[WFA::Debug] WFA-Alignment (obj=%p)\n",wf_aligner); if (wf_aligner->match_funct != NULL) { fprintf(stream,"[WFA::Debug]\tPattern\t%d\tcustom-funct()\n",pattern_length); fprintf(stream,"[WFA::Debug]\tText\t%d\tcustom-funct()\n",text_length); @@ -186,12 +188,7 @@ void wavefront_report_verbose_begin( CONVERT_B_TO_MB(wf_aligner->system.max_memory_compact), CONVERT_B_TO_MB(wf_aligner->system.max_memory_resident), CONVERT_B_TO_MB(wf_aligner->system.max_memory_abort)); -} -void wavefront_report_verbose_end( - FILE* const stream, - wavefront_aligner_t* const wf_aligner, - const int wf_status, - const uint64_t wf_memory_used) { + // Finish report fprintf(stream,"[WFA::Debug]\tFinish.status\t%d\n",wf_status); fprintf(stream,"[WFA::Debug]\tTime.taken\t"); timer_print_total(stream,&wf_aligner->system.timer); @@ -210,16 +207,9 @@ void wavefront_report_verbose_end( * Debug */ void wavefront_debug_prologue( - wavefront_aligner_t* const wf_aligner, - const char* const pattern, - const int pattern_length, - const char* const text, - const int text_length) { + wavefront_aligner_t* const wf_aligner) { if (wf_aligner->system.verbose >= 2) { timer_start(&wf_aligner->system.timer); - if (wf_aligner->system.verbose >= 3) { - wavefront_report_verbose_begin(stderr,wf_aligner,pattern,pattern_length,text,text_length); - } } } void wavefront_debug_epilogue( @@ -227,9 +217,11 @@ void wavefront_debug_epilogue( const char* const pattern, const int pattern_length, const char* const text, - const int text_length, - const int wf_align_status, - const uint64_t wf_memory_used) { + const int text_length) { + // Parameters + const int wf_align_status = wf_aligner->align_status.status; + const uint64_t wf_memory_used = wavefront_aligner_get_size(wf_aligner); + // Print Summary if (wf_aligner->system.verbose >= 2) { timer_stop(&wf_aligner->system.timer); if (wf_aligner->system.verbose == 2) { @@ -237,18 +229,19 @@ void wavefront_debug_epilogue( pattern,pattern_length,text,text_length, wf_align_status,wf_memory_used); } else { - wavefront_report_verbose_end(stderr, - wf_aligner,wf_align_status,wf_memory_used); + wavefront_report_verbose(stderr,wf_aligner, + pattern,pattern_length,text,text_length, + wf_align_status,wf_memory_used); } } + // Check correct if (wf_aligner->system.check_alignment_correct && wf_align_status == WF_STATUS_SUCCESSFUL && - wf_aligner->alignment_scope == compute_score) { + wf_aligner->alignment_scope == compute_alignment) { if (!wavefront_check_alignment(stderr,wf_aligner)) { fprintf(stderr,"[WFA::Check] Alignment incorrect\n"); - wavefront_report_verbose_begin(stderr,wf_aligner, - pattern,pattern_length,text,text_length); - wavefront_report_verbose_end(stderr,wf_aligner, + wavefront_report_verbose(stderr,wf_aligner, + pattern,pattern_length,text,text_length, wf_align_status,wf_memory_used); exit(1); } diff --git a/wavefront/wavefront_debug.h b/wavefront/wavefront_debug.h index 3ef033c9..3aba068d 100644 --- a/wavefront/wavefront_debug.h +++ b/wavefront/wavefront_debug.h @@ -38,18 +38,12 @@ * Debug */ void wavefront_debug_prologue( - wavefront_aligner_t* const wf_aligner, - const char* const pattern, - const int pattern_length, - const char* const text, - const int text_length); + wavefront_aligner_t* const wf_aligner); void wavefront_debug_epilogue( wavefront_aligner_t* const wf_aligner, const char* const pattern, const int pattern_length, const char* const text, - const int text_length, - const int wf_status, - const uint64_t wf_memory_used); + const int text_length); #endif /* WAVEFRONT_DEBUG_H_ */ diff --git a/wavefront/wavefront_extend.c b/wavefront/wavefront_extend.c index 12311dfa..95a7e6e5 100644 --- a/wavefront/wavefront_extend.c +++ b/wavefront/wavefront_extend.c @@ -441,7 +441,7 @@ int wavefront_extend_custom( const int max_score_scope = wf_aligner->wf_components.max_score_scope; const int score_mod = (memory_modular) ? score % max_score_scope : score; // Fetch m-wavefront - wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score]; + wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score_mod]; if (mwavefront==NULL) return 0; // Not done // Multithreading dispatcher const bool endsfree = (wf_aligner->alignment_form.span == alignment_endsfree); diff --git a/wavefront/wavefront_heuristic.c b/wavefront/wavefront_heuristic.c index 2e05da06..6e84927c 100644 --- a/wavefront/wavefront_heuristic.c +++ b/wavefront/wavefront_heuristic.c @@ -43,7 +43,7 @@ void wavefront_heuristic_set_banded_static( wavefront_heuristic_t* const wf_heuristic, const int band_min_k, const int band_max_k) { - wf_heuristic->strategy |= wf_heuristic_banded_static; + wf_heuristic->strategy = wf_heuristic_banded_static; wf_heuristic->min_k = band_min_k; wf_heuristic->max_k = band_max_k; } @@ -52,7 +52,7 @@ void wavefront_heuristic_set_banded_adaptive( const int band_min_k, const int band_max_k, const int steps_between_cutoffs) { - wf_heuristic->strategy |= wf_heuristic_banded_adaptive; + wf_heuristic->strategy = wf_heuristic_banded_adaptive; wf_heuristic->min_k = band_min_k; wf_heuristic->max_k = band_max_k; wf_heuristic->steps_between_cutoffs = steps_between_cutoffs; @@ -64,7 +64,7 @@ void wavefront_heuristic_set_wfadaptive( const int min_wavefront_length, const int max_distance_threshold, const int steps_between_cutoffs) { - wf_heuristic->strategy |= wf_heuristic_wfadaptive; + wf_heuristic->strategy = wf_heuristic_wfadaptive; wf_heuristic->min_wavefront_length = min_wavefront_length; wf_heuristic->max_distance_threshold = max_distance_threshold; wf_heuristic->steps_between_cutoffs = steps_between_cutoffs; @@ -75,7 +75,7 @@ void wavefront_heuristic_set_xdrop( wavefront_heuristic_t* const wf_heuristic, const int xdrop, const int steps_between_cutoffs) { - wf_heuristic->strategy |= wf_heuristic_xdrop; + wf_heuristic->strategy = wf_heuristic_xdrop; wf_heuristic->xdrop = xdrop; wf_heuristic->steps_between_cutoffs = steps_between_cutoffs; // Internals @@ -88,7 +88,7 @@ void wavefront_heuristic_set_zdrop( wavefront_heuristic_t* const wf_heuristic, const int zdrop, const int steps_between_cutoffs) { - wf_heuristic->strategy |= wf_heuristic_zdrop; + wf_heuristic->strategy = wf_heuristic_zdrop; wf_heuristic->zdrop = zdrop; wf_heuristic->steps_between_cutoffs = steps_between_cutoffs; // Internals @@ -480,19 +480,19 @@ bool wavefront_heuristic_cufoff( if (mwavefront==NULL || mwavefront->lo > mwavefront->hi) return false; // Not dropped // Cut-off m-wavefront --(wf_heuristic->steps_wait); - if ((wf_heuristic->strategy & wf_heuristic_banded_static) != 0) { + if (wf_heuristic->strategy == wf_heuristic_banded_static) { wavefront_cufoff_banded_static(wf_aligner,mwavefront); } - if ((wf_heuristic->strategy & wf_heuristic_banded_adaptive) != 0) { + if (wf_heuristic->strategy == wf_heuristic_banded_adaptive) { wavefront_cufoff_banded_adaptive(wf_aligner,mwavefront); } - if ((wf_heuristic->strategy & wf_heuristic_wfadaptive) != 0) { + if (wf_heuristic->strategy == wf_heuristic_wfadaptive) { wavefront_cufoff_wfadaptive(wf_aligner,mwavefront); } - if ((wf_heuristic->strategy & wf_heuristic_xdrop) != 0) { + if (wf_heuristic->strategy == wf_heuristic_xdrop) { wavefront_cufoff_xdrop(wf_aligner,mwavefront,score); } - if ((wf_heuristic->strategy & wf_heuristic_zdrop) != 0) { + if (wf_heuristic->strategy == wf_heuristic_zdrop) { wavefront_cufoff_zdrop(wf_aligner,mwavefront,score); } // Check wavefront length @@ -531,33 +531,27 @@ void wavefront_heuristic_print( // Select heuristic strategy if (wf_heuristic->strategy == wf_heuristic_none) { fprintf(stream,"(none)"); - } else { - if ((wf_heuristic->strategy & wf_heuristic_banded_static) != 0) { - fprintf(stream,"(banded-static,%d,%d)", - wf_heuristic->min_k, - wf_heuristic->max_k); - } - if ((wf_heuristic->strategy & wf_heuristic_banded_adaptive) != 0) { - fprintf(stream,"(banded-adapt,%d,%d,%d)", - wf_heuristic->min_k, - wf_heuristic->max_k, - wf_heuristic->steps_between_cutoffs); - } - if ((wf_heuristic->strategy & wf_heuristic_wfadaptive) != 0) { - fprintf(stream,"(wf-adapt,%d,%d,%d)", - wf_heuristic->min_wavefront_length, - wf_heuristic->max_distance_threshold, - wf_heuristic->steps_between_cutoffs); - } - if ((wf_heuristic->strategy & wf_heuristic_xdrop) != 0) { - fprintf(stream,"(xdrop,%d,%d)", - wf_heuristic->xdrop, - wf_heuristic->steps_between_cutoffs); - } - if ((wf_heuristic->strategy & wf_heuristic_zdrop) != 0) { - fprintf(stream,"(zdrop,%d,%d)", - wf_heuristic->zdrop, - wf_heuristic->steps_between_cutoffs); - } + } else if (wf_heuristic->strategy == wf_heuristic_banded_static) { + fprintf(stream,"(banded-static,%d,%d)", + wf_heuristic->min_k, + wf_heuristic->max_k); + } else if (wf_heuristic->strategy == wf_heuristic_banded_adaptive) { + fprintf(stream,"(banded-adapt,%d,%d,%d)", + wf_heuristic->min_k, + wf_heuristic->max_k, + wf_heuristic->steps_between_cutoffs); + } else if (wf_heuristic->strategy == wf_heuristic_wfadaptive) { + fprintf(stream,"(wf-adapt,%d,%d,%d)", + wf_heuristic->min_wavefront_length, + wf_heuristic->max_distance_threshold, + wf_heuristic->steps_between_cutoffs); + } else if (wf_heuristic->strategy == wf_heuristic_xdrop) { + fprintf(stream,"(xdrop,%d,%d)", + wf_heuristic->xdrop, + wf_heuristic->steps_between_cutoffs); + } else if (wf_heuristic->strategy == wf_heuristic_zdrop) { + fprintf(stream,"(zdrop,%d,%d)", + wf_heuristic->zdrop, + wf_heuristic->steps_between_cutoffs); } }