diff --git a/Makefile b/Makefile index 8341ffdb..b5b40a8f 100644 --- a/Makefile +++ b/Makefile @@ -86,11 +86,14 @@ else ifneq (,$(findstring $(ARCH), aarch64 arm64 s390x powerpc64 powerpc64le ppc POPCNT_CAPABILITY ?= 0 endif -ifdef USE_SAIS +ifeq (1, $(if $(or $(USE_SAIS),$(USE_SAIS_OPENMP)),1)) CPPFLAGS += -Ithird_party/libsais/include - CXXFLAGS += -fopenmp -DUSE_SAIS - LDFLAGS += -Lthird_party/libsais/lib - LDLIBS += -lsais +ifdef USE_SAIS_OPENMP + BUILD_CXXFLAGS += -fopenmp +endif + BUILD_CXXFLAGS += -DUSE_SAIS + BUILD_LDFLAGS += -Lthird_party/libsais/lib + BUILD_LDLIBS += -lsais endif # msys will always be 32 bit so look at the cpu arch instead. @@ -322,6 +325,9 @@ else $(BOWTIE2_BIN_LIST_SAN): $(error "Compiler does not support...") endif +bowtie2-build-%: CXXFLAGS += $(BUILD_CXXFLAGS) +bowtie2-build-%: LDFLAGS += $(BUILD_LDFLAGS) +bowtie2-build-%: LDLIBS += $(BUILD_LDLIBS) # # bowtie2-build targets # @@ -576,6 +582,16 @@ static-libs: rm -rf zstd-1.5.5* ; \ fi +.PHONY: libsais +libsais: + if [ ! -d $(CURDIR)/third_party/libsais ]; then \ + git submodule init && git submodule update --recursive ; \ + fi ; \ + if [ -n "$(USE_SAIS_OPENMP)" ]; then \ + export CFLAGS="$(CFLAGS) -fopenmp -O2" ; \ + fi ; \ + cd $(CURDIR)/third_party/libsais && $(MAKE) -B CC=$(CC) && $(MAKE) install PREFIX=$$PWD ; + .PHONY: sra-deps sra-deps: DL=$$( ( which wget >/dev/null 2>&1 && echo "wget --no-check-certificate" ) || echo "curl -LOk") ; \ diff --git a/blockwise_sa.h b/blockwise_sa.h index 90be5245..1e7574f1 100644 --- a/blockwise_sa.h +++ b/blockwise_sa.h @@ -204,11 +204,18 @@ class SAISBlockwiseSA : public InorderBlockwiseSA { __text.wbuf()[__text.length()] = (char)127; // $ is larger than any character in the suffix array _suffixes.resize(__text.length() + 1); #ifdef BOWTIE_64BIT_INDEX +#ifdef _OPENMP libsais64_omp((const uint8_t *)__text.buf(), (int64_t *)(_suffixes.ptr()), (int64_t)_suffixes.size(), 0, NULL, _nthreads); +#else + libsais64((const uint8_t *)__text.buf(), (int64_t *)(_suffixes.ptr()), (int64_t)_suffixes.size(), 0, NULL); +#endif #else +#ifdef _OPENMP libsais_omp((const uint8_t *)__text.buf(), (int32_t *)(_suffixes.ptr()), (int32_t)_suffixes.size(), 0, NULL, _nthreads); - +#else + libsais((const uint8_t *)__text.buf(), (int32_t *)(_suffixes.ptr()), (int32_t)_suffixes.size(), 0, NULL); +#endif #endif _suffixes[__text.length()] = __text.length(); } @@ -231,7 +238,7 @@ class SAISBlockwiseSA : public InorderBlockwiseSA { } bool hasMoreBlocks() const { - return _i == _suffixes.size(); + return _i < _suffixes.size(); } private: diff --git a/bt2_idx.h b/bt2_idx.h index d34439f5..e35dc298 100644 --- a/bt2_idx.h +++ b/bt2_idx.h @@ -1067,13 +1067,17 @@ class Ebwt { bmax = (TIndexOffU)sqrt(s.length()); VMSG_NL("bmax defaulted to: " << bmax); } +#ifndef USE_SAIS int iter = 0; bool first = true; streampos out1pos = out1.tellp(); streampos out2pos = out2.tellp(); +#endif + // Look for bmax/dcv parameters that work. thread_pool pool(nthreads - 1); while(true) { +#ifndef USE_SAIS if(!first && bmax < 40 && _passMemExc) { cerr << "Could not find approrpiate bmax/dcv settings for building this index." << endl; if(!isPacked()) { @@ -1107,7 +1111,9 @@ class Ebwt { VMSG_NL(" --dcv " << dcv); } iter++; +#endif try { +#ifndef USE_SAIS { VMSG_NL(" Doing ahead-of-time memory usage test"); // Make a quick-and-dirty attempt to force a bad_alloc iff @@ -1135,10 +1141,12 @@ class Ebwt { } VMSG_NL(""); } - VMSG_NL("Constructing suffix-array element generator"); +#endif #ifdef USE_SAIS + VMSG_NL("Using SAIS algorithm for constructing suffix array"); SAISBlockwiseSA bsa(s, bmax, nthreads); #else + VMSG_NL("Constructing suffix-array element generator"); KarkkainenBlockwiseSA bsa(s, bmax, nthreads, pool, dcv, seed, _sanity, _passMemExc, _verbose, outfile); #endif assert(bsa.suffixItrIsReset()); @@ -1161,6 +1169,10 @@ class Ebwt { } break; } catch(bad_alloc& e) { +#ifdef USE_SAIS + cerr << "Out of memory while constructing suffix array. Please try using a smaller" << endl; + throw 1; +#else if(_passMemExc) { VMSG_NL(" Ran out of memory; automatically trying more memory-economical parameters."); } else { @@ -1168,8 +1180,12 @@ class Ebwt { << "number of blocks by specifying a smaller --bmax or a larger --bmaxdivn" << endl; throw 1; } +#endif } +#ifndef USE_SAIS first = false; +#endif + } assert(repOk()); // Now write reference sequence names on the end