Skip to content

Commit

Permalink
Added debug info for biwfa
Browse files Browse the repository at this point in the history
  • Loading branch information
smarco committed Jun 10, 2022
1 parent 6ff4fe9 commit 3506562
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 128 deletions.
2 changes: 1 addition & 1 deletion tools/align_benchmark/align_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
65 changes: 36 additions & 29 deletions wavefront/wavefront_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,14 @@ 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,
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,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
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -448,21 +437,35 @@ 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,
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;
// 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) {
Expand All @@ -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;
}
Expand Down
50 changes: 26 additions & 24 deletions wavefront/wavefront_aligner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wavefront/wavefront_bialign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 19 additions & 26 deletions wavefront/wavefront_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -210,45 +207,41 @@ 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(
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_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) {
wavefront_report_lite(stderr,wf_aligner,
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);
}
Expand Down
10 changes: 2 additions & 8 deletions wavefront/wavefront_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
2 changes: 1 addition & 1 deletion wavefront/wavefront_extend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 3506562

Please sign in to comment.