perf(index): parallelize the SA-to-BWT pipeline with OpenMP - #8
Draft
nh13 wants to merge 2 commits into
Draft
Conversation
Parallelize the post-libsais index build: parallel seq fill, fused SSA
sampling + BWT inversion (reads bases via l2b so seq[] frees early),
byte-packed compaction of the wide suffix array, and a new
mb_bwt_init_from_inverted_sa that builds the rank dict via a 3-phase
parallel scan (per-thread local counts, serial prefix-sum, per-thread
offset fixup). OpenMP is gated on LIBSAIS_OPENMP, which the existing
Makefile probe already defines when the compiler supports -fopenmp, so
no build-system changes are needed.
Output is byte-identical to the serial mb_bwt_init_from_raw path for any
thread count; validated bit-identical against the pre-change index over
default/--meth/-u/-l variants and genbwt -t {1,2,4,8} on chrM and a
2 Mbp synthetic reference.
libminibwa.a now contains OpenMP code from the parallel SA-to-BWT pipeline, so the api-test example programs must link the OpenMP runtime. Without this, `make -C api-test` fails at link time wherever OpenMP is actually enabled -- Linux with gcc -- while passing on macOS, where the probe finds no libomp and the pragmas compile to nothing. Mirrors the parent Makefile's detection so the setting matches the library that was built.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the parallel SA→BWT index build from lh3#8, rebuilt on top of current
masterrather than recreated as-is. The original branch couldn't be cleanly re-applied (it conflicted withdc58b55, which had since landed the 32-bit suffix array, and it carried macOS/Homebrew build glue that is no longer needed).What changed vs. the original lh3#8
libompautodetection in the Makefile and thebuild-macosCI job. Currentmaster's existingompprobe already defines-DLIBSAIS_OPENMPand adds-fopenmpto every object (includingindex.o/bwt.o) when the compiler supports it, so no build-system changes are needed.dc58b55(already on master) instead of re-introducing the branch's own copy —mb_bwt_libsaisnow uses master'suse_int32logic.mb_bwt_libsais_serialfast-path; the single parallel-structured path handlesn_thread <= 1(and the no-OpenMP build) correctly, keeping the 32-bit SA in all cases.Pipeline
Parallel seq fill → libsais → free
seq[]→ fused SSA sampling + BWT inversion (reads bases vial2bsoseq[]is freed first) → byte-pack the wide SA to one byte per BWT char →mb_bwt_init_from_inverted_sa(new), which builds the rank dict via a 3-phase parallel scan: per-thread local counts → serial prefix-sum → per-thread offset fixup.Validation (bit-identical gate)
Output is byte-identical to the serial
mb_bwt_init_from_rawpath for every thread count. Verified against a golden index captured from pre-changemaster:indexoverdefault/--meth/-u 6/-lvariants —.l2band.mbwhashes match.genbwt -t {1,2,4,8}on chrM and a 2 Mbp synthetic reference (~15.6k 128-bp blocks, exercising the parallel prefix-sum) — every thread count byte-identical to-t1and to the golden.mbw.Does not touch the ksw2 SW kernels, so the differential kernel gate does not apply.