@@ -30,67 +30,48 @@ fmc::BiFMIndex<5> load_index(config const & config, size_t const id)
3030 return index;
3131}
3232
33- std::vector<wip_alignment> fmindex (config const & config, meta & meta, std::vector<hit> hits)
33+ void fmindex (config const & config,
34+ meta & meta,
35+ scq::slotted_cart_queue<size_t > & filter_queue,
36+ scq::slotted_cart_queue<alignment_info> & alignment_queue)
3437{
35- // todo capacity
36- // each slot = 1 bin
37- // a cart is full if it has 5 elements (hits)
38- alignment_vector res;
38+ #pragma omp parallel num_threads(config.threads)
3939 {
40- scq::slotted_cart_queue<size_t > queue{
41- {.slots = meta.number_of_bins , .carts = meta.number_of_bins , .capacity = 5 }};
42- size_t thread_id{};
43-
44- auto get_thread = [&]()
40+ while (true )
4541 {
46- return std::jthread (
47- [&, thread_id = thread_id++]()
42+ scq::cart_future<size_t > cart = filter_queue.dequeue ();
43+ if (!cart.valid ())
44+ break ;
45+ auto [slot, span] = cart.get ();
46+ auto index = load_index (config, slot.value );
47+ for (auto idx : span)
48+ {
49+ auto callback = [&](auto cursor, size_t )
4850 {
49- while ( true )
51+ for ( auto j : cursor )
5052 {
51- scq::cart_future<size_t > cart = queue.dequeue ();
52- if (!cart.valid ())
53- return ;
54- auto [slot, span] = cart.get ();
55- auto index = load_index (config, slot.value );
56- for (auto idx : span)
57- {
58- auto callback = [&](auto cursor, size_t )
59- {
60- for (auto j : cursor)
61- {
62- auto [entry, offset] = index.locate (j);
63- auto [seqId, pos] = entry;
64- res.emplace_back (wip_alignment{.bin = slot.value ,
65- .sequence_number = seqId,
66- .position = pos + offset,
67- .idx = idx});
68- }
69- };
70-
71- auto seq_view = std::views::transform (meta.queries [idx].sequence (),
72- [](seqan3::dna4 const in) -> uint8_t
73- {
74- return in.to_rank () + 1u ;
75- });
76-
77- fmc::search<true >(index, seq_view, config.errors , callback);
78- }
53+ auto [entry, offset] = index.locate (j);
54+ auto [seqId, pos] = entry;
55+ alignment_queue.enqueue (scq::slot_id{0u },
56+ alignment_info{.bin = slot.value ,
57+ .sequence_number = seqId,
58+ .position = pos + offset,
59+ .idx = idx});
7960 }
80- });
81- };
61+ };
8262
83- std::vector<std::jthread> worker (config.threads );
84- std::ranges::generate (worker, get_thread);
63+ auto seq_view = std::views::transform (meta.queries [idx].sequence (),
64+ [](seqan3::dna4 const in) -> uint8_t
65+ {
66+ return in.to_rank () + 1u ;
67+ });
8568
86- for (auto && [idx, hit] : seqan::stl::views::enumerate (hits))
87- for (auto bin : hit.bins )
88- queue.enqueue (scq::slot_id{bin}, idx);
89-
90- queue.close ();
91- } // Wait for threads to finish
69+ fmc::search<true >(index, seq_view, config.errors , callback);
70+ }
71+ }
72+ }
9273
93- return res. get ();
74+ alignment_queue. close ();
9475}
9576
9677} // namespace search
0 commit comments