77#include < cstdio>
88#include < signal.h>
99#include < tbb/parallel_for.h>
10- #include < tbb/task_group.h >
10+ #include < taskflow/taskflow.hpp >
1111#include < unordered_map>
1212#include < utility>
1313#include < vector>
@@ -378,7 +378,7 @@ struct Main_Tree_Searcher {
378378#ifdef DETAILED_MERGER_CHECK
379379 Mutation_Set &sample_mutations;
380380#endif
381- Main_Tree_Searcher (int curr_lower_bound,MAT ::Node *node,
381+ Main_Tree_Searcher (int curr_lower_bound, const MAT ::Node *node,
382382 Output<Main_Tree_Target> &output
383383#ifdef DETAILED_MERGER_CHECK
384384 ,
@@ -393,8 +393,7 @@ struct Main_Tree_Searcher {
393393#endif
394394 {
395395 }
396- void execute () {
397- tbb::task_group tg;
396+ void operator ()(tf::Subflow& sf) {
398397#ifndef BOUND_CHECK
399398 if (curr_lower_bound>output.best_par_score ) {
400399 return ;
@@ -404,8 +403,10 @@ struct Main_Tree_Searcher {
404403 search_serial (node, this_muts, output);
405404 return ;
406405 }
407- std::vector<Main_Tree_Searcher> children_tasks;
408- children_tasks.reserve (node->children .size () + 1 );
406+ auto * output_ptr = &output;
407+ #ifdef DETAILED_MERGER_CHECK
408+ auto * samples_ptr = &sample_mutations;
409+ #endif
409410 Main_Tree_Target target;
410411 for (const auto child : node->children ) {
411412 target.target_node = child;
@@ -434,14 +435,20 @@ struct Main_Tree_Searcher {
434435#ifndef BOUND_CHECK
435436 if (lower_bound <= output.best_par_score ) {
436437#endif
437- children_tasks. emplace_back (lower_bound, child, output
438+ sf. emplace ([=, muts = std::move (descendant_mutations)
438439#ifdef DETAILED_MERGER_CHECK
439440 ,
440441 sample_mutations
441442#endif
442- );
443- children_tasks.back ().this_muts =
444- std::move (descendant_mutations);
443+ ](tf::Subflow& child_sf) mutable {
444+ Main_Tree_Searcher child_searcher (lower_bound, child, *output_ptr
445+ #ifdef DETAILED_MERGER_CHECK
446+ , *samples_ptr
447+ #endif
448+ );
449+ child_searcher.this_muts = std::move (muts);
450+ child_searcher (child_sf);
451+ });
445452#ifndef BOUND_CHECK
446453 }
447454#endif
@@ -452,12 +459,6 @@ struct Main_Tree_Searcher {
452459 assert (parsimony_score>=curr_lower_bound);
453460 register_target (target, parsimony_score,output);
454461 }
455- for (auto & child : children_tasks) {
456- tg.run ([&child]{
457- child.execute ();
458- });
459- }
460- tg.wait ();
461462 }
462463};
463464
@@ -487,21 +488,25 @@ place_main_tree(const std::vector<To_Place_Sample_Mutation> &mutations,
487488 }
488489 }
489490 output.targets .push_back (target);
490- std::vector<To_Place_Sample_Mutation> initial_muts = mutations;
491- initial_muts.push_back (temp);
492491
493- Main_Tree_Searcher main_tree_task_root{0 ,main_tree.root ,
492+ tf::Executor executor;
493+ tf::Taskflow taskflow;
494+
495+ taskflow.emplace ([&](tf::Subflow& sf) {
496+ Main_Tree_Searcher root_searcher (0 ,main_tree.root ,
494497 output
495498#ifdef DETAILED_MERGER_CHECK
496499 ,
497500 sample_mutations
498501#endif
499- };
500- main_tree_task_root.this_muts = mutations;
501- main_tree_task_root.this_muts .push_back (temp);
502- main_tree_task_root.execute ();
502+ );
503+ root_searcher.this_muts = mutations;
504+ root_searcher.this_muts .push_back (temp);
505+ root_searcher (sf);
506+ });
507+
508+ executor.run (taskflow).wait ();
503509
504510 assert (!output.targets .empty ());
505-
506511 return std::make_tuple (std::move (output.targets ), output.best_par_score );
507512}
0 commit comments