This commit is contained in:
Zengtudor 2024-09-20 11:44:13 +08:00
parent 29d63c2424
commit 7c8fa8de85
4 changed files with 34 additions and 16 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ build
filteredReads.txt filteredReads.txt
reversedSequence.txt reversedSequence.txt
vsxmake* vsxmake*
*.txt

View File

@ -10,15 +10,8 @@ void reverseComplement(char *begin, char *end)
{'G', 'C'}, {'g', 'C'} {'G', 'C'}, {'g', 'C'}
}; };
// std::reverse(begin, end); //翻转DNA序列 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
for (ptrdiff_t i = 0; i < (end - begin); ++i) { for (ptrdiff_t i = 0; i < (end - begin); ++i) {
static int _ = (zt::print(NAME_VALUE(omp_get_num_threads()),"\n"),0); // 打印线程数量 static int _ = (zt::print(NAME_VALUE(omp_get_num_threads()),"\n"),0); // 打印线程数量
auto it = complement.find(begin[i]); auto it = complement.find(begin[i]);

View File

@ -117,13 +117,37 @@ namespace dna {
{ {
Spent calculate_spent(zt::fmt("calculate_chunk_id:[",chunk_id,"]")); Spent calculate_spent(zt::fmt("calculate_chunk_id:[",chunk_id,"]"));
while((end_pos=buf_str_v.find('\n',start_pos)) != std::string_view::npos){ #pragma omp parallel
if(get_lines_add()){ #pragma omp single
reverseComplement(buf.data()+start_pos, buf.data()+end_pos); //我想要这个函数并行优化 {
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){ if(start_pos!=buf_len){

View File

@ -15,7 +15,7 @@ if is_mode("release")then
end end
if is_plat("windows")then 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 elseif is_plat("linux") or is_plat("mingw") or is_plat("clang")then
add_cxxflags("-fopenmp") add_cxxflags("-fopenmp")
add_ldflags("-fopenmp") add_ldflags("-fopenmp")