From 8935e919b6f2f42e45733cfcbbea2034e1b8adb4 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <pedro.gonnet@durham.ac.uk> Date: Sat, 6 Apr 2013 20:32:43 +0000 Subject: [PATCH] only re-build queues if needed. Former-commit-id: 609b7ad602364c31eefc085a208db6f1552409c4 --- src/engine.c | 52 ++++++++++++++++++++++++++++++++-------------------- src/space.c | 5 ++++- src/space.h | 2 +- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/engine.c b/src/engine.c index c75ca2e5dd..b9ae4506ed 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 b2b139b9f3..1810713d8b 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 9e2f8ae24a..d5cb42f14d 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 ); -- GitLab