From 7c8fa8de850f5d0e4916c288abd58a53fba8986d Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Fri, 20 Sep 2024 11:44:13 +0800 Subject: [PATCH] update --- .gitignore | 3 ++- src/main.cpp | 11 ++--------- src/tools/dna.hpp | 34 +++++++++++++++++++++++++++++----- xmake.lua | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3b76c95..c65c76f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build filteredReads.txt reversedSequence.txt -vsxmake* \ No newline at end of file +vsxmake* +*.txt \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e4c426c..beb5f44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,15 +10,8 @@ void reverseComplement(char *begin, char *end) {'G', 'C'}, {'g', 'C'} }; - // std::reverse(begin, end); //翻转DNA序列 - // 并行翻转序列 //似乎没用 - #pragma omp parallel for - for (ptrdiff_t i = 0; i < (end - begin) / 2; ++i) { - std::swap(begin[i], begin[(end - begin) - i - 1]); - } - - // 并行查表替换 - #pragma omp parallel for + std::reverse(begin, end); //翻转DNA序列 + for (ptrdiff_t i = 0; i < (end - begin); ++i) { static int _ = (zt::print(NAME_VALUE(omp_get_num_threads()),"\n"),0); // 打印线程数量 auto it = complement.find(begin[i]); diff --git a/src/tools/dna.hpp b/src/tools/dna.hpp index 7a4fd57..25cb1dc 100644 --- a/src/tools/dna.hpp +++ b/src/tools/dna.hpp @@ -117,13 +117,37 @@ namespace dna { { Spent calculate_spent(zt::fmt("calculate_chunk_id:[",chunk_id,"]")); - while((end_pos=buf_str_v.find('\n',start_pos)) != std::string_view::npos){ - if(get_lines_add()){ - reverseComplement(buf.data()+start_pos, buf.data()+end_pos); //我想要这个函数并行优化 + #pragma omp parallel + #pragma omp single + { + while ((end_pos = buf_str_v.find('\n', start_pos)) != std::string_view::npos) { + char *start = buf.data() + start_pos; + char *end = buf.data() + end_pos; + + // 确保每个任务只操作属于它的独立数据 + if (get_lines_add()) { + // 为每一块数据创建一个任务 + #pragma omp task firstprivate(start, end) + { + reverseComplement(start, end); // 任务内处理反转互补 + } + } + + start_pos = end_pos + 1; } - // lines=!lines; - start_pos=end_pos+1; + + // 等待所有任务完成 + #pragma omp taskwait } + + + // while((end_pos=buf_str_v.find('\n',start_pos)) != std::string_view::npos){ + // if(get_lines_add()){ + // reverseComplement(buf.data()+start_pos, buf.data()+end_pos); //我想要这个函数并行优化 + // } + // // lines=!lines; + // start_pos=end_pos+1; + // } } if(start_pos!=buf_len){ diff --git a/xmake.lua b/xmake.lua index 132ed5e..4bc8bf7 100644 --- a/xmake.lua +++ b/xmake.lua @@ -15,7 +15,7 @@ if is_mode("release")then end if is_plat("windows")then - add_cxxflags("/openmp") + add_cxxflags("/openmp:llvm") elseif is_plat("linux") or is_plat("mingw") or is_plat("clang")then add_cxxflags("-fopenmp") add_ldflags("-fopenmp")