diff --git a/src/engine.c b/src/engine.c index c75ca2e5dd0f7e1c8cb5f82e0ba8e4addf83dccc..b9ae4506ed9a6b5634808f11cd579967e67ed32f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -61,7 +61,7 @@ void engine_prepare ( struct engine *e ) { - int j, k, qid; + int j, k, qid, rebuild; struct space *s = e->s; struct queue *q; @@ -69,24 +69,36 @@ void engine_prepare ( struct engine *e ) { /* Rebuild the space. */ // tic = getticks(); - space_prepare( e->s ); + rebuild = ( space_prepare( e->s ) || e->step == 0 ); // printf( "engine_prepare: space_prepare took %.3f ms.\n" , (double)(getticks() - tic) / CPU_TPS * 1000 ); - // tic = getticks(); - /* Init the queues (round-robin). */ - for ( qid = 0 ; qid < e->nr_queues ; qid++ ) - queue_init( &e->queues[qid] , s->nr_tasks , s->tasks ); - - /* Fill the queues (round-robin). */ - for ( qid = 0 , k = 0 ; k < s->nr_tasks ; k++ ) { - if ( s->tasks[ s->tasks_ind[k] ].skip ) - continue; - q = &e->queues[qid]; - qid = ( qid + 1 ) % e->nr_queues; - q->tid[ q->count ] = s->tasks_ind[k]; - q->count += 1; + /* The queues only need to be re-built if we have variable time-steps + or the space was rebuilt. */ + if ( !(e->policy & engine_policy_fixdt) || rebuild ) { + + // tic = getticks(); + /* Init the queues (round-robin). */ + for ( qid = 0 ; qid < e->nr_queues ; qid++ ) + queue_init( &e->queues[qid] , s->nr_tasks , s->tasks ); + + /* Fill the queues (round-robin). */ + for ( qid = 0 , k = 0 ; k < s->nr_tasks ; k++ ) { + if ( s->tasks[ s->tasks_ind[k] ].skip ) + continue; + q = &e->queues[qid]; + qid = ( qid + 1 ) % e->nr_queues; + q->tid[ q->count ] = s->tasks_ind[k]; + q->count += 1; + } + // printf( "engine_prepare: re-filling queues took %.3f ms.\n" , (double)(getticks() - tic) / CPU_TPS * 1000 ); + + } + + /* Otherwise, just re-set them. */ + else { + for ( qid = 0 ; qid < e->nr_queues ; qid++ ) + e->queues[qid].next = 0; } - // printf( "engine_prepare: re-filling queues took %.3f ms.\n" , (double)(getticks() - tic) / CPU_TPS * 1000 ); /* Run throught the tasks and get all the waits right. */ // tic = getticks(); @@ -492,12 +504,11 @@ void engine_step ( struct engine *e , int sort_queues ) { // printf( "engine_step: total entropic function is %e .\n", ent ); fflush(stdout); printf( "engine_step: updated %i parts (dt_step=%.3e).\n" , count , dt_step ); fflush(stdout); - /* Increase the step counter. */ - e->step += 1; - /* Does the time step need adjusting? */ - if ( e->policy & engine_policy_fixdt ) + if ( e->policy & engine_policy_fixdt ) { e->dt = e->dt_orig; + e->step += 1; + } else { if ( e->dt == 0 ) { e->dt = e->dt_orig; @@ -518,6 +529,7 @@ void engine_step ( struct engine *e , int sort_queues ) { e->step /= 2; printf( "engine_step: dt_min is larger than twice the time step, adjusting to dt=%e.\n" , e->dt ); } + e->step += 1; } } diff --git a/src/space.c b/src/space.c index b2b139b9f3e9a4e72c1a4c0041e1cddf08271166..1810713d8bee7de035da633e5ea0703cd27fb6d8 100644 --- a/src/space.c +++ b/src/space.c @@ -161,7 +161,7 @@ int space_marktasks ( struct space *s ) { * cell tree for those tasks and triggers a rebuild if necessary. */ -void space_prepare ( struct space *s ) { +int space_prepare ( struct space *s ) { int k, rebuild; // struct task *t; @@ -216,6 +216,9 @@ void space_prepare ( struct space *s ) { printf( " skipped=%i ]\n" , counts[ task_type_count ] ); fflush(stdout); printf( "space_prepare: task counting took %.3f ms.\n" , (double)(getticks() - tic) / CPU_TPS * 1000 ); */ + /* Let whoever cares know if we rebuilt. */ + return rebuild; + } diff --git a/src/space.h b/src/space.h index 9e2f8ae24a1889b65e5e08fcf67fc7296e5184c1..d5cb42f14dff889d9c3f885461099bb6014f4ff8 100644 --- a/src/space.h +++ b/src/space.h @@ -114,7 +114,7 @@ void space_maketasks ( struct space *s , int do_sort ); void space_map_cells_pre ( struct space *s , int full , void (*fun)( struct cell *c , void *data ) , void *data ); void space_map_parts ( struct space *s , void (*fun)( struct part *p , struct cell *c , void *data ) , void *data ); void space_map_cells_post ( struct space *s , int full , void (*fun)( struct cell *c , void *data ) , void *data ); -void space_prepare ( struct space *s ); +int space_prepare ( struct space *s ); void space_ranktasks ( struct space *s ); void space_rebuild ( struct space *s , double h_max ); void space_recycle ( struct space *s , struct cell *c );