From 0914dbe422bf46449a6ec4efb0b59461aafec9cd Mon Sep 17 00:00:00 2001 From: Venelin Mitov Date: Thu, 7 Nov 2019 10:50:02 +0100 Subject: [PATCH] Update to new SPLITT.h version --- src/SPLITT.h | 75 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/src/SPLITT.h b/src/SPLITT.h index 0f4b8ad..2e79459 100644 --- a/src/SPLITT.h +++ b/src/SPLITT.h @@ -110,6 +110,8 @@ //' \item{\link[=SPLITT::ThreadExceptionHandler]{ThreadExceptionHandler}}{} //' } //' +//' // to enable generation of man-pages use Rcpp::export below (no spaces between :'s). +//' [[Rcpp : : export]] namespace SPLITT{ @@ -584,6 +586,10 @@ class TraversalTask { return spec_.StateAtRoot(); } + StateType StateAtNode(uint i) { + return spec_.StateAtNode(i); + } + TreeType & tree() { return tree_; } @@ -2007,20 +2013,29 @@ class PostOrderTraversal: public TraversalAlgorithm { void TraverseTreeSingleThreadLoopPostorder() { _PRAGMA_OMP_SIMD for(uint i = 0; i < ParentType::ref_tree_.num_nodes(); i++) { - ParentType::ref_spec_.InitNode(i); + exception_handler_.Run([=]{ + ParentType::ref_spec_.InitNode(i); + }); } + exception_handler_.Rethrow(); for(uint i = 0; i < ParentType::ref_tree_.num_nodes() - 1; i++) { - ParentType::ref_spec_.VisitNode(i); - ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); + exception_handler_.Run([=]{ + ParentType::ref_spec_.VisitNode(i); + ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); + }); } + exception_handler_.Rethrow(); } void TraverseTreeSingleThreadLoopPrunes() { _PRAGMA_OMP_SIMD for(uint i = 0; i < ParentType::ref_tree_.num_nodes(); i++) { - ParentType::ref_spec_.InitNode(i); + exception_handler_.Run([=]{ + ParentType::ref_spec_.InitNode(i); + }); } + exception_handler_.Rethrow(); for(uint i_prune = 0; i_prune < ParentType::ref_tree_.num_parallel_ranges_prune(); @@ -2029,33 +2044,42 @@ class PostOrderTraversal: public TraversalAlgorithm { _PRAGMA_OMP_SIMD for(uint i = range_prune[0]; i <= range_prune[1]; i++) { - ParentType::ref_spec_.VisitNode(i); - ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); + exception_handler_.Run([=]{ + ParentType::ref_spec_.VisitNode(i); + ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); + }); } + exception_handler_.Rethrow(); } } void TraverseTreeSingleThreadLoopVisits() { _PRAGMA_OMP_SIMD for(uint i = 0; i < ParentType::ref_tree_.num_nodes(); i++) { - ParentType::ref_spec_.InitNode(i); + exception_handler_.Run([=]{ + ParentType::ref_spec_.InitNode(i); + }); } + exception_handler_.Rethrow(); for(uint i_level = 0; i_level < ParentType::ref_tree_.num_levels(); i_level++) { auto range_visit = ParentType::ref_tree_.RangeIdVisitNode(i_level); _PRAGMA_OMP_SIMD for(uint i = range_visit[0]; i <= range_visit[1]; i++) { - if(i < ParentType::ref_tree_.num_tips()) { - // i is a tip (only Visit) - ParentType::ref_spec_.VisitNode(i); - } else { - // i is internal - for(uint j: ParentType::ref_tree_.FindChildren(i)) { - ParentType::ref_spec_.PruneNode(j, i); + exception_handler_.Run([=]{ + if(i < ParentType::ref_tree_.num_tips()) { + // i is a tip (only Visit) + ParentType::ref_spec_.VisitNode(i); + } else { + // i is internal + for(uint j: ParentType::ref_tree_.FindChildren(i)) { + ParentType::ref_spec_.PruneNode(j, i); + } + ParentType::ref_spec_.VisitNode(i); } - ParentType::ref_spec_.VisitNode(i); - } + }); } + exception_handler_.Rethrow(); } // VisitNode not called on the root node @@ -2074,6 +2098,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.InitNode(i); }); } + exception_handler_.Rethrow(); uint i_prune = 0; for(uint i_level = 0; i_level < ParentType::ref_tree_.num_levels(); i_level++) { @@ -2087,6 +2112,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.VisitNode(i); }); } + exception_handler_.Rethrow(); uint num_branches_done = 0; @@ -2100,6 +2126,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); }); } + exception_handler_.Rethrow(); num_branches_done += range_prune[1] - range_prune[0] + 1; ++i_prune; @@ -2124,6 +2151,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.InitNode(i); }); } + exception_handler_.Rethrow(); for(uint i_level = 0; i_level < ParentType::ref_tree_.num_levels(); i_level++) { auto range_visit = ParentType::ref_tree_.RangeIdVisitNode(i_level); @@ -2142,6 +2170,7 @@ class PostOrderTraversal: public TraversalAlgorithm { } }); } + exception_handler_.Rethrow(); } } // VisitNode not called on the root node @@ -2187,6 +2216,7 @@ class PostOrderTraversal: public TraversalAlgorithm { } }); } +exception_handler_.Rethrow(); } void TraverseTreeMultiThreadLoopPrunes() { @@ -2199,6 +2229,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.InitNode(i); }); } + exception_handler_.Rethrow(); for(uint i_prune = 0; i_prune < ParentType::ref_tree_.num_parallel_ranges_prune(); i_prune++) { auto range_prune = ParentType::ref_tree_.RangeIdPruneNode(i_prune); @@ -2210,6 +2241,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); }); } + exception_handler_.Rethrow(); } } } @@ -2252,6 +2284,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.InitNode(i); }); } + exception_handler_.Rethrow(); uint i_prune = 0; for(uint i_level = 0; i_level < ParentType::ref_tree_.num_levels(); i_level++) { @@ -2265,6 +2298,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.VisitNode(i); }); } + exception_handler_.Rethrow(); } else if(tid == 0) { // only the master thread executes this _PRAGMA_OMP_SIMD @@ -2273,6 +2307,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.VisitNode(i); }); } + exception_handler_.Rethrow(); } if (tid == 0) { @@ -2286,6 +2321,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); }); } + exception_handler_.Rethrow(); num_branches_done += range_prune[1] - range_prune[0] + 1; ++i_prune; @@ -2312,6 +2348,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.InitNode(i); }); } + exception_handler_.Rethrow(); for(uint i_prune = 0; i_prune < ParentType::ref_tree_.num_parallel_ranges_prune(); i_prune++) { @@ -2326,6 +2363,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); }); } + exception_handler_.Rethrow(); } else if (tid == 0) { // only one (master) thread executes this _PRAGMA_OMP_SIMD @@ -2335,6 +2373,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.PruneNode(i, ParentType::ref_tree_.FindIdOfParent(i)); }); } + exception_handler_.Rethrow(); } } } @@ -2357,6 +2396,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.InitNode(i); }); } + exception_handler_.Rethrow(); for(uint i_level = 0; i_level < ParentType::ref_tree_.num_levels(); i_level++) { auto range_visit = ParentType::ref_tree_.RangeIdVisitNode(i_level); @@ -2378,6 +2418,7 @@ class PostOrderTraversal: public TraversalAlgorithm { } }); } + exception_handler_.Rethrow(); } else if(tid == 0) { // only the master thread executes this _PRAGMA_OMP_SIMD @@ -2395,6 +2436,7 @@ class PostOrderTraversal: public TraversalAlgorithm { } }); } + exception_handler_.Rethrow(); } } } @@ -2404,6 +2446,7 @@ class PostOrderTraversal: public TraversalAlgorithm { ParentType::ref_spec_.PruneNode(j, ParentType::ref_tree_.num_nodes() - 1); }); } + exception_handler_.Rethrow(); } };