Commit 8935e919 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

only re-build queues if needed.


Former-commit-id: 609b7ad602364c31eefc085a208db6f1552409c4
parent e83aa571
......@@ -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;
}
}
......
......@@ -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;
}
......
......@@ -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 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment