From c9e4d9645c5dc08f69b1e8088b5b931dac1f129f Mon Sep 17 00:00:00 2001 From: zzh Date: Fri, 18 Aug 2023 20:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E5=B9=B6=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=BC=80=E8=BE=9F=E5=86=85=E5=AD=98=E7=9A=84bug=EF=BC=88?= =?UTF-8?q?=E5=BC=80=E8=BE=9F=E6=8C=87=E9=92=88=E6=97=B6=E5=80=99=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=80=83=E8=99=91=E6=AF=8F=E4=B8=AA=E6=8C=87=E9=92=88?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=E7=9A=84=E5=AD=97=E8=8A=82=E6=95=B0=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E7=94=A8clock=E8=AF=95=E8=AF=95=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ksw_normal.c | 12 +++++----- main.c | 68 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/ksw_normal.c b/ksw_normal.c index d90b755..282a977 100644 --- a/ksw_normal.c +++ b/ksw_normal.c @@ -127,12 +127,12 @@ int ksw_normal(int qlen, const uint8_t *query, int tlen, const uint8_t *target, } } // update beg and end for the next round - for (j = beg; LIKELY(j < end) && eh[j].h == 0 && eh[j].e == 0; ++j) - ; - beg = j; - for (j = end; LIKELY(j >= beg) && eh[j].h == 0 && eh[j].e == 0; --j) - ; - end = j + 2 < qlen ? j + 2 : qlen; // 剪枝没考虑f,即insert + // for (j = beg; LIKELY(j < end) && eh[j].h == 0 && eh[j].e == 0; ++j) + // ; + // beg = j; + // for (j = end; LIKELY(j >= beg) && eh[j].h == 0 && eh[j].e == 0; --j) + // ; + // end = j + 2 < qlen ? j + 2 : qlen; // 剪枝没考虑f,即insert beg = 0, end = qlen; // uncomment this line for debugging // fprintf(stderr, "\n"); // fprintf(stderr, "%d\n", end); diff --git a/main.c b/main.c index d6d6ac5..db9e44c 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "sys/time.h" #define SW_NORMAL 0 @@ -14,14 +15,17 @@ #define READ_BUF_SIZE 2048 #define SEQ_BUF_SIZE (BLOCK_BUF_SIZE + READ_BUF_SIZE) +#define DIVIDE_BY (CLOCKS_PER_SEC * 1.0) + #ifdef SHOW_PERF // 用来调试,计算感兴趣部分的运行时间 // 获取当前毫秒数 int64_t get_mseconds() { - struct timeval tv; - gettimeofday(&tv, NULL); - return (int64_t)1000 * (tv.tv_sec + ((1e-6) * tv.tv_usec)); + // struct timeval tv; + // gettimeofday(&tv, NULL); + // return (int64_t)1000 * (tv.tv_sec + ((1e-6) * tv.tv_usec)); + return clock(); } int64_t time_sw_normal = 0, @@ -111,8 +115,8 @@ int main(int argc, char *argv[]) // 读取测试数据 char *query_arr = (char *)malloc(SEQ_BUF_SIZE); char *target_arr = (char *)malloc(SEQ_BUF_SIZE); - int *info_buf = (int *)malloc(SEQ_BUF_SIZE); - int **info_arr = (int **)malloc(SEQ_BUF_SIZE); + int *info_buf = (int *)malloc(SEQ_BUF_SIZE * sizeof(int)); + int **info_arr = (int **)malloc(SEQ_BUF_SIZE * sizeof(int *)); FILE *query_f = 0, *target_f = 0, *info_f = 0; // const char *qf_path = "q.fa"; // const char *tf_path = "t.fa"; @@ -120,18 +124,18 @@ int main(int argc, char *argv[]) // const char *qf_path = "bug_q.fa"; // const char *tf_path = "bug_t.fa"; // const char *if_path = "bug_i.txt"; - // const char *qf_path = "/public/home/zzh/data/sw/q_s.fa"; - // const char *tf_path = "/public/home/zzh/data/sw/t_s.fa"; - // const char *if_path = "/public/home/zzh/data/sw/i_s.txt"; - // const char *qf_path = "/public/home/zzh/data/sw/q_m.fa"; - // const char *tf_path = "/public/home/zzh/data/sw/t_m.fa"; - // const char *if_path = "/public/home/zzh/data/sw/i_m.txt"; - const char *qf_path = "/public/home/zzh/data/sw/q_l.fa"; - const char *tf_path = "/public/home/zzh/data/sw/t_l.fa"; - const char *if_path = "/public/home/zzh/data/sw/i_l.txt"; - // const char *qf_path = "/public/home/zzh/data/sw/query.fa"; - // const char *tf_path = "/public/home/zzh/data/sw/target.fa"; - // const char *if_path = "/public/home/zzh/data/sw/info.txt"; + // const char *qf_path = "/home/zzh/data/sw/q_s.fa"; + // const char *tf_path = "/home/zzh/data/sw/t_s.fa"; + // const char *if_path = "/home/zzh/data/sw/i_s.txt"; + const char *qf_path = "/home/zzh/data/sw/q_m.fa"; + const char *tf_path = "/home/zzh/data/sw/t_m.fa"; + const char *if_path = "/home/zzh/data/sw/i_m.txt"; + // const char *qf_path = "/home/zzh/data/sw/q_l.fa"; + // const char *tf_path = "/home/zzh/data/sw/t_l.fa"; + // const char *if_path = "/home/zzh/data/sw/i_l.txt"; + // const char *qf_path = "/public/home/zzh/data/sw/query.fa"; + // const char *tf_path = "/public/home/zzh/data/sw/target.fa"; + // const char *if_path = "/public/home/zzh/data/sw/info.txt"; query_f = fopen(qf_path, "r"); target_f = fopen(tf_path, "r"); info_f = fopen(if_path, "r"); @@ -149,7 +153,6 @@ int main(int argc, char *argv[]) // const int max_read = READ_BUF_SIZE; // 每次最多读取的字符 char read_buf[READ_BUF_SIZE]; // 读文件缓存 // int ret_code = 0; - // 初始化info_arr数组 i = 0; j = 0; @@ -160,6 +163,7 @@ int main(int argc, char *argv[]) info_arr[i] = &info_buf[j]; i += 1; j += 3; + // fprintf(stderr, "%d\t%d\n", i, j); } int score_normal = 0, score_avx2 = 0, score_avx2_u8 = 0, score_bsw_avx2 = 0; @@ -167,6 +171,7 @@ int main(int argc, char *argv[]) while (!feof(target_f)) { + // fprintf(stderr, "debug\n"); block_line_num = 0; // target序列一般占用存储最多,先读取target,看一个buf能读多少行,query和info就按照这个行数来读 int cur_read_size = 0; @@ -187,8 +192,10 @@ int main(int argc, char *argv[]) strncpy(target_arr + cur_read_size, read_buf, line_size); cur_read_size += line_size; // fprintf(stderr, "%d %d \n", line_size, cur_read_size); + // fprintf(stderr, "%d %d \n", block_line_num, total_line_num); } + // fprintf(stderr, "here\n"); // 读query cur_read_size = 0; for (i = 0; i < block_line_num; ++i) @@ -223,7 +230,6 @@ int main(int argc, char *argv[]) // 性能测试 - // 普通 sw int cur_query_pos = 0; int cur_target_pos = 0; for (i = 0; i < block_line_num; ++i) @@ -231,6 +237,7 @@ int main(int argc, char *argv[]) #ifdef SHOW_PERF int64_t start_time = get_mseconds(); #endif + // 普通 sw score_normal = ksw_normal( info_arr[i][0], (uint8_t *)query_arr + cur_query_pos, @@ -370,16 +377,19 @@ int main(int argc, char *argv[]) // fprintf(stderr, "%d \n", score_normal); #ifdef SHOW_PERF - fprintf(stderr, "time_sw_normal: %f s; score: %d\n", time_sw_normal / 1000.0, score_normal_total); - fprintf(stderr, "time_bsw_avx2: %f s; score: %d\n", time_bsw_avx2 / 1000.0, score_bsw_avx2_total); - // fprintf(stderr, "time_sw_avx2: %f s; score: %d\n", time_sw_avx2 / 1000.0, score_avx2_total); - fprintf(stderr, "time_sw_avx2_u8: %f s; score: %d\n", time_sw_avx2_u8 / 1000.0, score_avx2_u8_total); + fprintf(stderr, "time_sw_normal: %f s; score: %d\n", time_sw_normal / DIVIDE_BY, score_normal_total); + fprintf(stderr, "time_bsw_avx2: %f s; score: %d\n", time_bsw_avx2 / DIVIDE_BY, score_bsw_avx2_total); + // fprintf(stderr, "time_sw_avx2: %f s; score: %d\n", time_sw_avx2 / DIVIDE_BY, score_avx2_total); + fprintf(stderr, "time_sw_avx2_u8: %f s; score: %d\n", time_sw_avx2_u8 / DIVIDE_BY, score_avx2_u8_total); - fprintf(stderr, "time_bsw_init: %f s\n", time_bsw_init / 1000.0); - fprintf(stderr, "time_bsw_main_loop: %f s\n", (time_bsw_main_loop - time_compare) / 1000.0); - fprintf(stderr, "time_bsw_find_max: %f s\n", (time_bsw_find_max - time_compare) / 1000.0); - fprintf(stderr, "time_bsw_adjust_bound: %f s\n", (time_bsw_adjust_bound - time_compare) / 1000.0); - fprintf(stderr, "time_compare: %f s\n", time_compare / 1000.0); + fprintf(stderr, "time_bsw_init: %f s\n", time_bsw_init / DIVIDE_BY); + // fprintf(stderr, "time_bsw_main_loop: %f s\n", (time_bsw_main_loop) / DIVIDE_BY); + // fprintf(stderr, "time_bsw_find_max: %f s\n", (time_bsw_find_max) / DIVIDE_BY); + // fprintf(stderr, "time_bsw_adjust_bound: %f s\n", (time_bsw_adjust_bound) / DIVIDE_BY); + fprintf(stderr, "time_bsw_main_loop: %f s\n", (time_bsw_main_loop - time_compare) / DIVIDE_BY); + fprintf(stderr, "time_bsw_find_max: %f s\n", (time_bsw_find_max - time_compare) / DIVIDE_BY); + fprintf(stderr, "time_bsw_adjust_bound: %f s\n", (time_bsw_adjust_bound - time_compare) / DIVIDE_BY); + fprintf(stderr, "time_compare: %f s\n", time_compare / DIVIDE_BY); #endif if (query_f != 0) @@ -396,4 +406,4 @@ int main(int argc, char *argv[]) fclose(normal_out_f); if (bsw_avx2_out_f != 0) fclose(bsw_avx2_out_f); -} \ No newline at end of file +}