diff --git a/src/prefiltering/Prefiltering.cpp b/src/prefiltering/Prefiltering.cpp index 9efabdb30..14e8992ab 100644 --- a/src/prefiltering/Prefiltering.cpp +++ b/src/prefiltering/Prefiltering.cpp @@ -226,7 +226,7 @@ Prefiltering::Prefiltering(const std::string &queryDB, if (par.taxonList.length() > 0) { - taxonomyHook = new QueryMatcherTaxonomyHook(targetDB, tdbr, par.taxonList); + taxonomyHook = new QueryMatcherTaxonomyHook(targetDB, tdbr, par.taxonList, par.threads); } else { taxonomyHook = NULL; } diff --git a/src/prefiltering/QueryMatcherTaxonomyHook.h b/src/prefiltering/QueryMatcherTaxonomyHook.h index c8a86b00f..de32c332b 100644 --- a/src/prefiltering/QueryMatcherTaxonomyHook.h +++ b/src/prefiltering/QueryMatcherTaxonomyHook.h @@ -7,20 +7,30 @@ #include "DBReader.h" #include "TaxonomyExpression.h" +#ifdef OPENMP +#include +#endif + class QueryMatcherTaxonomyHook : public QueryMatcherHook { public: - QueryMatcherTaxonomyHook(std::string targetPath, DBReader* targetReader, const std::string& expressionString) - : targetReader(targetReader), dbFrom(0) { + QueryMatcherTaxonomyHook(std::string targetPath, DBReader* targetReader, const std::string& expressionString, unsigned int threads) + : targetReader(targetReader), dbFrom(0), threads(threads) { std::string targetName = dbPathWithoutIndex(targetPath); taxonomy = NcbiTaxonomy::openTaxonomy(targetName); taxonomyMapping = new MappingReader(targetName); - expression = new TaxonomyExpression(expressionString, *taxonomy); + expression = new TaxonomyExpression*[threads]; + for (unsigned int i = 0; i < threads; i++) { + expression[i] = new TaxonomyExpression(expressionString, *taxonomy); + } } ~QueryMatcherTaxonomyHook() { delete taxonomy; delete taxonomyMapping; - delete expression; + for (unsigned int i = 0; i < threads; i++) { + delete expression[i]; + } + delete[] expression; } void setDbFrom(unsigned int from) { @@ -28,12 +38,16 @@ class QueryMatcherTaxonomyHook : public QueryMatcherHook { } size_t afterDiagonalMatchingHook(QueryMatcher& matcher, size_t resultSize) { + unsigned int thread_idx = 0; +#ifdef OPENMP + thread_idx = (unsigned int) omp_get_thread_num(); +#endif size_t writePos = 0; for (size_t i = 0; i < resultSize; i++) { unsigned int currId = matcher.foundDiagonals[i].id; unsigned int key = targetReader->getDbKey(dbFrom + currId); TaxID currTax = taxonomyMapping->lookup(key); - if (expression->isAncestor(currTax)) { + if (expression[thread_idx]->isAncestor(currTax)) { if (i != writePos) { matcher.foundDiagonals[writePos] = matcher.foundDiagonals[i]; } @@ -63,9 +77,10 @@ class QueryMatcherTaxonomyHook : public QueryMatcherHook { NcbiTaxonomy* taxonomy; MappingReader* taxonomyMapping; DBReader* targetReader; - TaxonomyExpression* expression; + TaxonomyExpression** expression; unsigned int dbFrom; + unsigned int threads; }; #endif \ No newline at end of file diff --git a/src/prefiltering/ungappedprefilter.cpp b/src/prefiltering/ungappedprefilter.cpp index 09e2f516b..84bc0a96b 100644 --- a/src/prefiltering/ungappedprefilter.cpp +++ b/src/prefiltering/ungappedprefilter.cpp @@ -77,8 +77,8 @@ int prefilterInternal(int argc, const char **argv, const Command &command, int m QueryMatcherTaxonomyHook * taxonomyHook = NULL; - if(par.PARAM_TAXON_LIST.wasSet){ - taxonomyHook = new QueryMatcherTaxonomyHook(par.db2, tdbr, par.taxonList); + if (par.PARAM_TAXON_LIST.wasSet) { + taxonomyHook = new QueryMatcherTaxonomyHook(par.db2, tdbr, par.taxonList, par.threads); } Debug::Progress progress(qdbr->getSize()); @@ -121,7 +121,7 @@ int prefilterInternal(int argc, const char **argv, const Command &command, int m unsigned int targetKey = tdbr->getDbKey(tId); if(taxonomyHook != NULL){ TaxID currTax = taxonomyHook->taxonomyMapping->lookup(targetKey); - if (taxonomyHook->expression->isAncestor(currTax) == false) { + if (taxonomyHook->expression[thread_idx]->isAncestor(currTax) == false) { continue; } }