3030#pragma once
3131
3232#include < cmath>
33- #include < mutex>
34-
35- #include < async++.h>
3633
3734#include < geode/basic/pimpl_impl.hpp>
3835
@@ -81,52 +78,25 @@ namespace geode
8178 return morton_mapping< dimension >( points );
8279 }() )
8380 {
84- index_t depth = 1 ;
8581 if ( bboxes.empty () )
8682 {
8783 tree_.resize ( ROOT_INDEX );
8884 }
8985 else
9086 {
91- const auto [ max_node_index, max_depth] =
92- max_node_index_recursive ( ROOT_INDEX, 0 , bboxes.size (), 0 );
87+ const auto max_node_index =
88+ max_node_index_recursive ( ROOT_INDEX, 0 , bboxes.size () );
9389 tree_.resize ( ROOT_INDEX + max_node_index );
94- depth = max_depth;
9590 initialize_tree_recursive (
9691 bboxes, ROOT_INDEX, 0 , bboxes.size () );
9792 }
98- const auto grain = async::detail::auto_grain_size ( bboxes.size () );
99- if ( grain < 8 )
100- {
101- async_depth_ = 0 ;
102- }
103- else
104- {
105- const auto nb_async_depth = std::log2 ( grain );
106- async_depth_ = depth - nb_async_depth;
107- }
10893 }
10994
11095 [[nodiscard]] index_t nb_bboxes () const
11196 {
11297 return mapping_morton_.size ();
11398 }
11499
115- [[nodiscard]] bool parallel () const
116- {
117- return parallel_;
118- }
119-
120- void set_parallel ( bool parallel )
121- {
122- parallel_ = parallel;
123- }
124-
125- [[nodiscard]] index_t initial_depth () const
126- {
127- return parallel_ ? 0 : async_depth_ + 1 ;
128- }
129-
130100 [[nodiscard]] static bool is_leaf (
131101 index_t element_begin, index_t element_end )
132102 {
@@ -156,26 +126,22 @@ namespace geode
156126 return mapping_morton_[index];
157127 }
158128
159- [[nodiscard]] static std::tuple< index_t , index_t >
160- max_node_index_recursive ( index_t node_index,
161- index_t element_begin,
162- index_t element_end,
163- index_t depth )
129+ [[nodiscard]] static index_t max_node_index_recursive (
130+ index_t node_index, index_t element_begin, index_t element_end )
164131 {
165132 OPENGEODE_ASSERT ( element_end > element_begin,
166133 " End box index should be after Begin box index" );
167134 if ( is_leaf ( element_begin, element_end ) )
168135 {
169- return std::make_tuple ( node_index, depth ) ;
136+ return node_index;
170137 }
171138 const auto it = get_recursive_iterators (
172139 node_index, element_begin, element_end );
173- const auto [node_left, depth_left] = max_node_index_recursive (
174- it.child_left , element_begin, it.element_middle , depth + 1 );
175- const auto [node_right, depth_right] = max_node_index_recursive (
176- it.child_right , it.element_middle , element_end, depth + 1 );
177- return std::make_tuple ( std::max ( node_left, node_right ),
178- std::max ( depth_left, depth_right ) );
140+ const auto node_left = max_node_index_recursive (
141+ it.child_left , element_begin, it.element_middle );
142+ const auto node_right = max_node_index_recursive (
143+ it.child_right , it.element_middle , element_end );
144+ return std::max ( node_left, node_right );
179145 }
180146
181147 void initialize_tree_recursive (
@@ -280,7 +246,6 @@ namespace geode
280246 bool self_intersect_recursive ( index_t node_index1,
281247 index_t element_begin1,
282248 index_t element_end1,
283- index_t depth,
284249 index_t node_index2,
285250 index_t element_begin2,
286251 index_t element_end2,
@@ -327,48 +292,32 @@ namespace geode
327292 const auto it = get_recursive_iterators (
328293 node_index2, element_begin2, element_end2 );
329294 if ( self_intersect_recursive ( node_index1, element_begin1,
330- element_end1, depth, it.child_left , element_begin2,
295+ element_end1, it.child_left , element_begin2,
331296 it.element_middle , action ) )
332297 {
333298 return true ;
334299 }
335300 return self_intersect_recursive ( node_index1, element_begin1,
336- element_end1, depth, it.child_right , it.element_middle ,
301+ element_end1, it.child_right , it.element_middle ,
337302 element_end2, action );
338303 }
339304 const auto it = get_recursive_iterators (
340305 node_index1, element_begin1, element_end1 );
341- if ( depth > async_depth_ )
342- {
343- if ( self_intersect_recursive ( it.child_left , element_begin1,
344- it.element_middle , depth + 1 , node_index2,
345- element_begin2, element_end2, action ) )
346- {
347- return true ;
348- }
349- return self_intersect_recursive ( it.child_right ,
350- it.element_middle , element_end1, depth + 1 , node_index2,
351- element_begin2, element_end2, action );
352- }
353- auto task = async::local_spawn ( [&] {
354- return self_intersect_recursive ( it.child_left , element_begin1,
355- it.element_middle , depth + 1 , node_index2, element_begin2,
356- element_end2, action );
357- } );
358- if ( self_intersect_recursive ( it.child_right , it.element_middle ,
359- element_end1, depth + 1 , node_index2, element_begin2,
306+ if ( self_intersect_recursive ( it.child_left , element_begin1,
307+ it.element_middle , node_index2, element_begin2,
360308 element_end2, action ) )
361309 {
362310 return true ;
363311 }
364- return task.get ();
312+ return self_intersect_recursive ( it.child_right , it.element_middle ,
313+ element_end1, node_index2, element_begin2, element_end2,
314+ action );
365315 }
366316
367317 template < typename ACTION >
368318 bool other_intersect_recursive ( index_t node_index1,
369319 index_t element_begin1,
370320 index_t element_end1,
371- index_t depth,
372321 const AABBTree< dimension >& other_tree,
373322 index_t node_index2,
374323 index_t element_begin2,
@@ -405,49 +354,33 @@ namespace geode
405354 const auto it = get_recursive_iterators (
406355 node_index2, element_begin2, element_end2 );
407356 if ( other_intersect_recursive ( node_index1, element_begin1,
408- element_end1, depth, other_tree, it.child_left ,
409- element_begin2, it.element_middle , action ) )
357+ element_end1, other_tree, it.child_left , element_begin2 ,
358+ it.element_middle , action ) )
410359 {
411360 return true ;
412361 }
413362 return other_intersect_recursive ( node_index1, element_begin1,
414- element_end1, depth, other_tree, it.child_right ,
415- it. element_middle , element_end2, action );
363+ element_end1, other_tree, it.child_right , it. element_middle ,
364+ element_end2, action );
416365 }
417366 const auto it = get_recursive_iterators (
418367 node_index1, element_begin1, element_end1 );
419- if ( depth > async_depth_ )
420- {
421- if ( other_intersect_recursive ( it.child_left , element_begin1,
422- it.element_middle , depth + 1 , other_tree, node_index2,
423- element_begin2, element_end2, action ) )
424- {
425- return true ;
426- }
427- return other_intersect_recursive ( it.child_right ,
428- it.element_middle , element_end1, depth + 1 , other_tree,
429- node_index2, element_begin2, element_end2, action );
430- }
431- auto task = async::local_spawn ( [&] {
432- return other_intersect_recursive ( it.child_left , element_begin1,
433- it.element_middle , depth + 1 , other_tree, node_index2,
434- element_begin2, element_end2, action );
435- } );
436- if ( other_intersect_recursive ( it.child_right , it.element_middle ,
437- element_end1, depth + 1 , other_tree, node_index2,
438- element_begin2, element_end2, action ) )
368+ if ( other_intersect_recursive ( it.child_left , element_begin1,
369+ it.element_middle , other_tree, node_index2, element_begin2,
370+ element_end2, action ) )
439371 {
440372 return true ;
441373 }
442- return task.get ();
374+ return other_intersect_recursive ( it.child_right , it.element_middle ,
375+ element_end1, other_tree, node_index2, element_begin2,
376+ element_end2, action );
443377 }
444378
445379 template < typename BOX_FILTER, typename ACTION >
446380 bool generic_intersect_recursive ( const BOX_FILTER& box_filter,
447381 index_t node_index,
448382 index_t element_begin,
449383 index_t element_end,
450- index_t depth,
451384 ACTION& action ) const
452385 {
453386 OPENGEODE_ASSERT (
@@ -468,26 +401,13 @@ namespace geode
468401
469402 const auto it = get_recursive_iterators (
470403 node_index, element_begin, element_end );
471- if ( depth > async_depth_ )
472- {
473- if ( generic_intersect_recursive ( box_filter, it.child_left ,
474- element_begin, it.element_middle , depth + 1 , action ) )
475- {
476- return true ;
477- }
478- return generic_intersect_recursive ( box_filter, it.child_right ,
479- it.element_middle , element_end, depth + 1 , action );
480- }
481- auto task = async::local_spawn ( [&] {
482- return generic_intersect_recursive ( box_filter, it.child_left ,
483- element_begin, it.element_middle , depth + 1 , action );
484- } );
485- if ( generic_intersect_recursive ( box_filter, it.child_right ,
486- it.element_middle , element_end, depth + 1 , action ) )
404+ if ( generic_intersect_recursive ( box_filter, it.child_left ,
405+ element_begin, it.element_middle , action ) )
487406 {
488407 return true ;
489408 }
490- return task.get ();
409+ return generic_intersect_recursive ( box_filter, it.child_right ,
410+ it.element_middle , element_end, action );
491411 }
492412
493413 [[nodiscard]] index_t closest_element_box_hint (
@@ -519,10 +439,8 @@ namespace geode
519439 void containing_boxes_recursive ( index_t node_index,
520440 index_t element_begin,
521441 index_t element_end,
522- index_t depth,
523442 const Point< dimension >& query,
524- std::vector< index_t >& result,
525- std::mutex& mutex ) const
443+ std::vector< index_t >& result ) const
526444 {
527445 OPENGEODE_ASSERT (
528446 node_index < tree_.size (), " Node index out of tree" );
@@ -534,36 +452,20 @@ namespace geode
534452 }
535453 if ( is_leaf ( element_begin, element_end ) )
536454 {
537- std::lock_guard< std::mutex > lock ( mutex );
538455 result.push_back ( mapping_morton ( element_begin ) );
539456 return ;
540457 }
541458 const auto it = get_recursive_iterators (
542459 node_index, element_begin, element_end );
543- if ( depth > async_depth_ )
544- {
545- containing_boxes_recursive ( it.child_left , element_begin,
546- it.element_middle , depth + 1 , query, result, mutex );
547- containing_boxes_recursive ( it.child_right , it.element_middle ,
548- element_end, depth + 1 , query, result, mutex );
549- }
550- else
551- {
552- auto task = async::local_spawn ( [&] {
553- containing_boxes_recursive ( it.child_left , element_begin,
554- it.element_middle , depth + 1 , query, result, mutex );
555- } );
556- containing_boxes_recursive ( it.child_right , it.element_middle ,
557- element_end, depth + 1 , query, result, mutex );
558- task.get ();
559- }
460+ containing_boxes_recursive ( it.child_left , element_begin,
461+ it.element_middle , query, result );
462+ containing_boxes_recursive (
463+ it.child_right , it.element_middle , element_end, query, result );
560464 }
561465
562466 private:
563467 std::vector< BoundingBox< dimension > > tree_;
564468 std::vector< index_t > mapping_morton_;
565- index_t async_depth_{ 0 };
566- bool parallel_{ true };
567469 };
568470
569471 template < index_t dimension >
@@ -604,7 +506,7 @@ namespace geode
604506 return ;
605507 }
606508 impl_->self_intersect_recursive ( Impl::ROOT_INDEX, 0 , nb_bboxes (),
607- impl_-> initial_depth (), Impl::ROOT_INDEX, 0 , nb_bboxes (), action );
509+ Impl::ROOT_INDEX, 0 , nb_bboxes (), action );
608510 }
609511
610512 template < index_t dimension >
@@ -618,8 +520,7 @@ namespace geode
618520 return ;
619521 }
620522 impl_->other_intersect_recursive ( Impl::ROOT_INDEX, 0 , nb_bboxes (),
621- impl_->initial_depth (), other_tree, Impl::ROOT_INDEX, 0 ,
622- other_tree.nb_bboxes (), action );
523+ other_tree, Impl::ROOT_INDEX, 0 , other_tree.nb_bboxes (), action );
623524 }
624525
625526 template < index_t dimension >
@@ -653,8 +554,8 @@ namespace geode
653554 {
654555 return ;
655556 }
656- impl_->generic_intersect_recursive ( box_filter, Impl::ROOT_INDEX, 0 ,
657- nb_bboxes (), impl_-> initial_depth (), action );
557+ impl_->generic_intersect_recursive (
558+ box_filter, Impl::ROOT_INDEX, 0 , nb_bboxes (), action );
658559 }
659560
660561 template < index_t dimension >
0 commit comments