Commit 4fe80ee1 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

more civilized way of dealing with fixed time-steps.


Former-commit-id: 3102b06a40327392ec4313bba788536ce71697ec
parent fe1984a1
......@@ -411,10 +411,13 @@ void engine_step ( struct engine *e , int sort_queues ) {
TIMER_TIC2
/* Get the maximum dt. */
dt_step = 2.0f*dt;
for ( k = 0 ; k < 32 && (e->step & (1 << k)) == 0 ; k++ )
dt_step *= 2;
// dt_step = FLT_MAX;
if ( e->policy & engine_policy_fixdt )
dt_step = FLT_MAX;
else {
dt_step = 2.0f*dt;
for ( k = 0 ; k < 32 && (e->step & (1 << k)) == 0 ; k++ )
dt_step *= 2;
}
/* Set the maximum dt. */
e->dt_step = dt_step;
......@@ -493,24 +496,28 @@ void engine_step ( struct engine *e , int sort_queues ) {
e->step += 1;
/* Does the time step need adjusting? */
if ( e->dt == 0 ) {
if ( e->policy & engine_policy_fixdt )
e->dt = e->dt_orig;
while ( dt_min < e->dt )
e->dt *= 0.5;
while ( dt_min > 2*e->dt )
e->dt *= 2.0;
printf( "engine_step: dt_min=%.3e, adjusting time step to dt=%e.\n" , dt_min , e->dt );
}
else {
while ( dt_min < e->dt ) {
e->dt *= 0.5;
e->step *= 2;
printf( "engine_step: dt_min dropped below time step, adjusting to dt=%e.\n" , e->dt );
if ( e->dt == 0 ) {
e->dt = e->dt_orig;
while ( dt_min < e->dt )
e->dt *= 0.5;
while ( dt_min > 2*e->dt )
e->dt *= 2.0;
printf( "engine_step: dt_min=%.3e, adjusting time step to dt=%e.\n" , dt_min , e->dt );
}
while ( dt_min > 2*e->dt && (e->step & 1) == 0 ) {
e->dt *= 2.0;
e->step /= 2;
printf( "engine_step: dt_min is larger than twice the time step, adjusting to dt=%e.\n" , e->dt );
else {
while ( dt_min < e->dt ) {
e->dt *= 0.5;
e->step *= 2;
printf( "engine_step: dt_min dropped below time step, adjusting to dt=%e.\n" , e->dt );
}
while ( dt_min > 2*e->dt && (e->step & 1) == 0 ) {
e->dt *= 2.0;
e->step /= 2;
printf( "engine_step: dt_min is larger than twice the time step, adjusting to dt=%e.\n" , e->dt );
}
}
}
......
......@@ -25,6 +25,7 @@
#define engine_policy_steal 2
#define engine_policy_keep 4
#define engine_policy_block 8
#define engine_policy_fixdt 16
#define engine_queue_scale 1.2
......
......@@ -89,17 +89,14 @@ int queue_counter[ queue_counter_count ];
void queue_insert ( struct queue *q , struct task *t ) {
int k;
/* Lock the queue. */
if ( lock_lock( &q->lock ) != 0 )
error( "Failed to get queue lock." );
/* Bubble-up the tasks. */
for ( k = q->count ; k > q->next ; k-- )
q->tid[k] = q->tid[k-1];
q->tid[ q->next ] = t - q->tasks;
/* Swap next task to end. */
q->tid[ q->count ] = q->tid[ q->next ];
q->count += 1;
q->tid[ q->next ] = t - q->tasks;
q->next += 1;
/* Unlock the queue. */
......
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