Skip to content

Commit af94ccf

Browse files
committed
[FEATURE] import modified inplaceradixsort bei @meiers
1 parent f79d577 commit af94ccf

5 files changed

Lines changed: 116 additions & 31 deletions

File tree

src/index_sa_sort.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <parallel/algorithm>
4242
#endif
4343

44+
#include "radix_inplace.h"
45+
4446
namespace seqan
4547
{
4648

@@ -57,6 +59,8 @@ struct MergeSortTag {};
5759

5860
struct QuickSortBucketTag {};
5961

62+
struct InPlaceRadixTag {};
63+
6064
template <typename TIndex>
6165
struct SaAdvancedSortAlgoTag
6266
{
@@ -553,6 +557,45 @@ createSuffixArray(TSA & sa,
553557
// std::cout << suffix(text[sa[dir[i]].i1], sa[dir[i]].i2) << "\n";
554558
}
555559

560+
inline std::function<void(unsigned)>
561+
progressWrapper2(std::function<void(void)> const &)
562+
{
563+
return [] (unsigned) {};
564+
}
565+
566+
inline std::function<void(unsigned)>
567+
progressWrapper2(std::function<void(unsigned)> const & l)
568+
{
569+
return l;
570+
}
571+
572+
template <typename TSA,
573+
typename TString,
574+
typename TSSetSpec,
575+
typename TLambda>
576+
inline void
577+
createSuffixArray(TSA & SA,
578+
StringSet<TString, TSSetSpec> const & s,
579+
SaAdvancedSort<InPlaceRadixTag> const &,
580+
TLambda const & progressCallback = [] (unsigned) {})
581+
{
582+
typedef typename Size<TSA>::Type TSize;
583+
typedef typename Iterator<TSA, Standard>::Type TIter;
584+
585+
// 1. Fill suffix array with a permutation (the identity)
586+
TIter it = begin(SA, Standard());
587+
for(unsigned j = 0; j < length(s); ++j)
588+
{
589+
TSize len = length(s[j]);
590+
for(TSize i = 0; i < len; ++i, ++it)
591+
*it = Pair<unsigned, TSize>(j, i);
592+
}
593+
594+
// 2. Sort suffix array with inplace radix Sort
595+
// std::cerr << "I am really in radix sort" << std::endl;
596+
inPlaceRadixSort(SA, s, progressWrapper2(progressCallback));
597+
}
598+
556599
// general case discards the callback
557600
template <typename TSA,
558601
typename TString,

src/lambda_indexer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ argConv2(LambdaIndexerOptions const & options,
180180
return realMain(options, BlastProgramSelector<p>(), TRedAlph(), SaAdvancedSort<QuickSortTag>());
181181
else if (options.algo == "quicksortbuckets")
182182
return realMain(options, BlastProgramSelector<p>(), TRedAlph(), SaAdvancedSort<QuickSortBucketTag>());
183+
else if (options.algo == "radixsort")
184+
return realMain(options, BlastProgramSelector<p>(), TRedAlph(), SaAdvancedSort<InPlaceRadixTag>());
183185
else
184186
return realMain(options, BlastProgramSelector<p>(), TRedAlph(), Nothing());
185187
}

src/lambda_indexer.hpp

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -343,38 +343,84 @@ convertMaskingFile(uint64_t numberOfSeqs,
343343
template <typename TIndex, typename TText, typename TFibre>
344344
inline void
345345
createIndexActual(TIndex & index,
346-
TText const & text,
347-
TFibre const &,
348-
SaAdvancedSort<MergeSortTag> const &)
346+
TText const & text,
347+
TFibre const &,
348+
SaAdvancedSort<MergeSortTag> const &,
349+
bool print)
349350
{
350351
ComparisonCounter<TText, std::true_type> counter(text);
351-
indexCreate(index, text, TFibre(), [&counter] () { counter.inc(); });
352-
printProgressBar(counter._lastPercent, 100);
352+
353+
if (print)
354+
{
355+
indexCreate(index, text, TFibre(), [&counter] () { counter.inc(); });
356+
printProgressBar(counter._lastPercent, 100);
357+
}
358+
else
359+
{
360+
indexCreate(index, text, TFibre(), [] () {});
361+
}
353362
}
354363

355364
template <typename TIndex, typename TText, typename TFibre>
356365
inline void
357366
createIndexActual(TIndex & index,
358-
TText const & text,
359-
TFibre const &,
360-
SaAdvancedSort<QuickSortBucketTag> const &)
367+
TText const & text,
368+
TFibre const &,
369+
SaAdvancedSort<QuickSortBucketTag> const &,
370+
bool print)
361371
{
362-
uint64_t _lastPercent = 0;
363-
indexCreate(index, text, TFibre(),
364-
[&_lastPercent] (uint64_t curPerc)
365-
{
366-
if (TID == 0)
367-
printProgressBar(_lastPercent, curPerc);
368-
});
369-
printProgressBar(_lastPercent, 100);
372+
if (print)
373+
{
374+
uint64_t _lastPercent = 0;
375+
376+
indexCreate(index, text, TFibre(),
377+
[&_lastPercent] (uint64_t curPerc)
378+
{
379+
SEQAN_OMP_PRAGMA(critical(progressBar))
380+
printProgressBar(_lastPercent, curPerc);
381+
});
382+
printProgressBar(_lastPercent, 100);
383+
}
384+
else
385+
{
386+
indexCreate(index, text, TFibre(), [] (uint64_t) {});
387+
}
388+
}
389+
390+
// same as above, TODO templatize more intelligently
391+
template <typename TIndex, typename TText, typename TFibre>
392+
inline void
393+
createIndexActual(TIndex & index,
394+
TText const & text,
395+
TFibre const &,
396+
SaAdvancedSort<InPlaceRadixTag> const &,
397+
bool print)
398+
{
399+
if (print)
400+
{
401+
uint64_t _lastPercent = 0;
402+
indexCreate(index, text, TFibre(),
403+
[&_lastPercent] (uint64_t curPerc)
404+
{
405+
// SEQAN_OMP_PRAGMA(critical(progressBar))
406+
if (TID == 0)
407+
printProgressBar(_lastPercent, curPerc);
408+
});
409+
printProgressBar(_lastPercent, 100);
410+
}
411+
else
412+
{
413+
indexCreate(index, text, TFibre(), [] (uint64_t) {});
414+
}
370415
}
371416

372417
template <typename TIndex, typename TText, typename TFibre, typename TAlgo>
373418
inline void
374419
createIndexActual(TIndex & index,
375-
TText const & text,
376-
TFibre const &,
377-
TAlgo const &)
420+
TText const & text,
421+
TFibre const &,
422+
TAlgo const &,
423+
bool) // default can't print progress anyway
378424
{
379425
indexCreate(index, text, TFibre(), [] () {});
380426
}
@@ -419,10 +465,9 @@ generateIndexAndDump(StringSet<TString, TSpec> & seqs,
419465
FibreSALF,
420466
FibreSA>::type;
421467
static bool constexpr
422-
hasProgress = std::is_same<TIndexSpecSpec,
423-
SaAdvancedSort<QuickSortBucketTag>>::value
424-
|| std::is_same<TIndexSpecSpec,
425-
SaAdvancedSort<MergeSortTag>>::value;
468+
hasProgress = std::is_same<TIndexSpecSpec, SaAdvancedSort<QuickSortBucketTag>>::value ||
469+
std::is_same<TIndexSpecSpec, SaAdvancedSort<MergeSortTag>>::value ||
470+
std::is_same<TIndexSpecSpec, SaAdvancedSort<InPlaceRadixTag>>::value;
426471

427472
// using TCountPartial = std::is_same<TIndexSpecSpec,
428473
// SaAdvancedSort<MergeSortTag>>;
@@ -455,12 +500,7 @@ generateIndexAndDump(StringSet<TString, TSpec> & seqs,
455500
// instantiate SA
456501

457502
// create SA with progressCallback function
458-
if (options.verbosity >= 1)
459-
createIndexActual(dbIndex, redSubjSeqs, TFullFibre(),
460-
TIndexSpecSpec());
461-
else // don't print progress (independent of algo)
462-
createIndexActual(dbIndex, redSubjSeqs, TFullFibre(),
463-
Nothing());
503+
createIndexActual(dbIndex, redSubjSeqs, TFullFibre(), TIndexSpecSpec(), (options.verbosity >= 1));
464504

465505
// instantiate potential rest
466506
// std::cout << "\nActualNumComparisons: " << counter._comparisons

src/misc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ printProgressBar(uint64_t & lastPercent, uint64_t curPerc)
129129
//round down to even
130130
curPerc = curPerc & ~1;
131131
// #pragma omp critical(stdout)
132-
if ((lastPercent != curPerc) && (curPerc <= 100))
132+
if ((curPerc > lastPercent) && (curPerc <= 100))
133133
{
134134
for (uint64_t i = lastPercent + 2; i <= curPerc; i+=2)
135135
{

src/options.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ parseCommandLine(LambdaIndexerOptions & options, int argc, char const ** argv)
893893
" Requirements below!).",
894894
ArgParseArgument::STRING,
895895
"STR"));
896-
setValidValues(parser, "algorithm", "mergesort quicksortbuckets quicksort skew7ext");
896+
setValidValues(parser, "algorithm", "mergesort quicksortbuckets quicksort radixsort skew7ext");
897897
setDefaultValue(parser, "algorithm", "mergesort");
898898
setAdvanced(parser, "algorithm");
899899

0 commit comments

Comments
 (0)