diff --git a/src/cell.h b/src/cell.h index bbc731b33e0e66a07a8343ec15c4fcd6ae90b26a..59d26413c6c333a32874f45aaf9288a6f254b725 100644 --- a/src/cell.h +++ b/src/cell.h @@ -55,7 +55,7 @@ struct cell { float dx_max; /* The depth of this cell in the tree. */ - int depth, split; + int depth, split, maxdepth; /* Nr of parts. */ int count; diff --git a/src/space.c b/src/space.c index 71bcded65211d43db49fe9f7ccdc2fd8df184007..97fad5127eb5f72a13bb6e29ba5eab0098876912 100644 --- a/src/space.c +++ b/src/space.c @@ -922,7 +922,7 @@ void space_splittasks ( struct space *s ) { if ( ci->split ) { /* Make a sub? */ - if ( space_dosub && ci->count < space_subsize ) { + if ( space_dosub && ci->count < space_subsize && ci->maxdepth - ci->depth < space_maxsubdepth ) { /* convert to a self-subtask. */ t->type = task_type_sub; @@ -981,6 +981,7 @@ void space_splittasks ( struct space *s ) { /* Replace by a single sub-task? */ if ( space_dosub && ci->count < space_subsize && cj->count < space_subsize && + ci->maxdepth - ci->depth < space_maxsubdepth && cj->maxdepth - cj->depth < space_maxsubdepth && sid != 0 && sid != 2 && sid != 6 && sid != 8 ) { /* Make this task a sub task. */ @@ -1344,7 +1345,7 @@ void space_maketasks ( struct space *s , int do_sort ) { void space_split ( struct space *s , struct cell *c ) { - int k, count = c->count; + int k, count = c->count, maxdepth = 0; float h, h_max = 0.0f, dt, dt_min = c->parts[0].dt, dt_max = dt_min; double x[3]; struct cell *temp; @@ -1397,16 +1398,16 @@ void space_split ( struct space *s , struct cell *c ) { } else { space_split( s , c->progeny[k] ); - if ( c->progeny[k]->h_max > h_max ) - h_max = c->progeny[k]->h_max; - if ( c->progeny[k]->dt_min < dt_min ) - dt_min = c->progeny[k]->dt_min; - if ( c->progeny[k]->dt_max > dt_max ) - dt_max = c->progeny[k]->dt_max; + h_max = fmaxf( h_max , c->progeny[k]->h_max ); + dt_min = fminf( dt_min , c->progeny[k]->dt_min ); + dt_max = fmaxf( dt_max , c->progeny[k]->dt_max ); + if ( c->progeny[k]->maxdepth > maxdepth ) + maxdepth = c->progeny[k]->maxdepth; } c->h_max = h_max; c->dt_min = dt_min; c->dt_max = dt_max; + c->maxdepth = maxdepth; } @@ -1416,6 +1417,7 @@ void space_split ( struct space *s , struct cell *c ) { /* Clear the progeny. */ bzero( c->progeny , sizeof(struct cell *) * 8 ); c->split = 0; + c->maxdepth = c->depth; /* Get dt_min/dt_max. */ diff --git a/src/space.h b/src/space.h index 43c9837751e029ea47b8549f354becd30a326145..0e1b504710c70a0e4796880ba89582991582ba17 100644 --- a/src/space.h +++ b/src/space.h @@ -26,6 +26,7 @@ #define space_splitratio 0.875f #define space_splitsize_default 400 #define space_subsize_default 5000 +#define space_maxsubdepth 3 #define space_dosub 1 #define space_stretch 1.05f #define space_maxtaskspercell 31