Skip to content
Snippets Groups Projects
Commit e2afccea authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

guess initial time step if dt_min is zero.

Former-commit-id: 67c1f9a70e35d07310a59e4c00b2ae08eef12952
parent b551eafe
No related branches found
No related tags found
No related merge requests found
...@@ -519,6 +519,8 @@ void engine_step ( struct engine *e , int sort_queues ) { ...@@ -519,6 +519,8 @@ void engine_step ( struct engine *e , int sort_queues ) {
e->step += 1; e->step += 1;
/* Does the time step need adjusting? */ /* Does the time step need adjusting? */
if ( e->dt == 0 )
e->dt = e->dt_orig;
while ( dt_min < e->dt ) { while ( dt_min < e->dt ) {
e->dt *= 0.5; e->dt *= 0.5;
e->step *= 2; e->step *= 2;
...@@ -529,6 +531,9 @@ void engine_step ( struct engine *e , int sort_queues ) { ...@@ -529,6 +531,9 @@ void engine_step ( struct engine *e , int sort_queues ) {
e->step /= 2; e->step /= 2;
printf( "engine_step: dt_min is larger than twice the time step, adjusting to dt=%e.\n" , e->dt ); printf( "engine_step: dt_min is larger than twice the time step, adjusting to dt=%e.\n" , e->dt );
} }
/* Set the system time. */
e->time = e->dt * e->step;
TIMER_TOC2(timer_step); TIMER_TOC2(timer_step);
...@@ -553,6 +558,7 @@ void engine_init ( struct engine *e , struct space *s , float dt , int nr_thread ...@@ -553,6 +558,7 @@ void engine_init ( struct engine *e , struct space *s , float dt , int nr_thread
cpu_set_t cpuset; cpu_set_t cpuset;
#endif #endif
int k; int k;
float dt_min = dt;
/* Store the values. */ /* Store the values. */
e->s = s; e->s = s;
...@@ -571,11 +577,16 @@ void engine_init ( struct engine *e , struct space *s , float dt , int nr_thread ...@@ -571,11 +577,16 @@ void engine_init ( struct engine *e , struct space *s , float dt , int nr_thread
e->barrier_count = 0; e->barrier_count = 0;
/* Run through the parts and get the minimum time step. */ /* Run through the parts and get the minimum time step. */
e->dt_orig = dt;
for ( k = 0 ; k < s->nr_parts ; k++ ) for ( k = 0 ; k < s->nr_parts ; k++ )
if ( s->parts[k].dt > 0.0f ) if ( s->parts[k].dt < dt_min )
while ( s->parts[k].dt < dt ) dt_min = s->parts[k].dt;
dt *= 0.5; if ( dt_min == 0.0f )
e->dt_min = dt; dt = 0.0f;
else
while ( dt > dt_min )
dt *= 0.5f;
e->dt = dt;
/* Allocate the queues. */ /* Allocate the queues. */
if ( posix_memalign( (void *)(&e->queues) , 64 , nr_queues * sizeof(struct queue) ) != 0 ) if ( posix_memalign( (void *)(&e->queues) , 64 , nr_queues * sizeof(struct queue) ) != 0 )
......
...@@ -57,11 +57,14 @@ struct engine { ...@@ -57,11 +57,14 @@ struct engine {
float dt_min; float dt_min;
/* The system time step. */ /* The system time step. */
float dt; float dt, dt_orig;
/* The current step number. */ /* The current step number. */
int step; int step;
/* The current system time. */
float time;
/* Data for the threads' barrier. */ /* Data for the threads' barrier. */
pthread_mutex_t barrier_mutex; pthread_mutex_t barrier_mutex;
pthread_cond_t barrier_cond; pthread_cond_t barrier_cond;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment