update
This commit is contained in:
parent
39e7c8320f
commit
1be6d9d2b9
@ -27,9 +27,12 @@ foreach(SRC_CPP IN LISTS SRC_CPPS)
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# add_executable(${PROJECT_NAME}_bin ${SRC_HPPS} ${SRC_CPPS})
|
# add_executable(${PROJECT_NAME}_bin ${SRC_HPPS} ${SRC_CPPS})
|
||||||
|
set(TBB_TEST OFF)
|
||||||
add_subdirectory(pybind11)
|
add_subdirectory(pybind11)
|
||||||
|
# add_subdirectory(oneTBB)
|
||||||
|
|
||||||
pybind11_add_module(${PROJECT_NAME} ${SRC_HPPS} ${SRC_CPPS})
|
pybind11_add_module(${PROJECT_NAME} ${SRC_HPPS} ${SRC_CPPS})
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE DNA_IS_PYBIND)
|
target_compile_definitions(${PROJECT_NAME} PRIVATE DNA_IS_PYBIND)
|
||||||
|
|
||||||
|
# target_link_libraries(${PROJECT_NAME} PRIVATE TBB::tbb)
|
34
src/main.cpp
34
src/main.cpp
@ -10,10 +10,17 @@
|
|||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
// #define DNA_USE_TBB
|
||||||
|
#ifdef DNA_USE_TBB
|
||||||
|
#include <tbb/parallel_for_each.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
static constexpr size_t default_buffer_size{512*1024*1024};
|
static constexpr size_t default_buffer_size{512*1024*1024};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define DNA_USE_BUFFER
|
||||||
static const std::unordered_map<char, char> complement = { //这里使用查表的方式大大提高CPU速度,因为if分支CPU不容易命中缓存,需要使用查表加速
|
static const std::unordered_map<char, char> complement = { //这里使用查表的方式大大提高CPU速度,因为if分支CPU不容易命中缓存,需要使用查表加速
|
||||||
{'A', 'T'}, {'a', 'T'},
|
{'A', 'T'}, {'a', 'T'},
|
||||||
{'T', 'A'}, {'t', 'A'},
|
{'T', 'A'}, {'t', 'A'},
|
||||||
@ -25,14 +32,22 @@ void reverseComplement(char *begin, char *end)
|
|||||||
{
|
{
|
||||||
//注意end是开区间,不能访问end
|
//注意end是开区间,不能访问end
|
||||||
std::reverse(begin, end); //翻转DNA序列
|
std::reverse(begin, end); //翻转DNA序列
|
||||||
|
#ifndef DNA_USE_TBB
|
||||||
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]);
|
||||||
if (it != complement.end()) {
|
if (it != complement.end()) {
|
||||||
begin[i] = it->second;
|
begin[i] = it->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
#else
|
||||||
|
tbb::parallel_for_each(begin,end,[](char &c){
|
||||||
|
const auto it = complement.find(c);
|
||||||
|
if (it != complement.end()) {
|
||||||
|
c = it->second;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert_from_file(
|
void convert_from_file(
|
||||||
@ -42,7 +57,7 @@ void convert_from_file(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// std::iostream::sync_with_stdio(false);
|
// std::iostream::sync_with_stdio(false);
|
||||||
|
|
||||||
const size_t max_size_pre_dna{(size_t)5e4+5};
|
const size_t max_size_pre_dna{(size_t)5e4+5};
|
||||||
const size_t all_buf_size = {buffer_size};
|
const size_t all_buf_size = {buffer_size};
|
||||||
const size_t read_bufsize{all_buf_size/2},write_bufsize{all_buf_size/2};
|
const size_t read_bufsize{all_buf_size/2},write_bufsize{all_buf_size/2};
|
||||||
@ -57,9 +72,12 @@ void convert_from_file(
|
|||||||
std::ofstream ofs(destination_file);
|
std::ofstream ofs(destination_file);
|
||||||
if(ofs.is_open()==false)throw std::runtime_error(fmt("Cannot open output file stream\nfilename: ",destination_file,'\n'));
|
if(ofs.is_open()==false)throw std::runtime_error(fmt("Cannot open output file stream\nfilename: ",destination_file,'\n'));
|
||||||
std::cout<<"Open file ok ,getting memory\n";
|
std::cout<<"Open file ok ,getting memory\n";
|
||||||
|
|
||||||
|
#ifdef DNA_USE_BUFFER
|
||||||
std::vector<char> read_buf(read_bufsize), write_buf(write_bufsize);
|
std::vector<char> read_buf(read_bufsize), write_buf(write_bufsize);
|
||||||
ifs.rdbuf()->pubsetbuf(read_buf.data(), read_buf.size());
|
ifs.rdbuf()->pubsetbuf(read_buf.data(), read_buf.size());
|
||||||
ofs.rdbuf()->pubsetbuf(write_buf.data(), write_buf.size());
|
ofs.rdbuf()->pubsetbuf(write_buf.data(), write_buf.size());
|
||||||
|
#endif
|
||||||
|
|
||||||
std::array<char, max_size_pre_dna> dna_buf;
|
std::array<char, max_size_pre_dna> dna_buf;
|
||||||
bool is_dna_line{false};
|
bool is_dna_line{false};
|
||||||
|
Loading…
Reference in New Issue
Block a user