Commit 8f95784d authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'timebin_optimization' into gravity_multi_dt

parents 2a597d23 965b89f7
......@@ -602,7 +602,7 @@ int main(int argc, char *argv[]) {
clocks_getunit());
/* Main simulation loop */
for (int j = 0; !engine_is_done(&e) && e.step != nsteps; j++) {
for (int j = 0; !engine_is_done(&e) && e.step - 1 != nsteps; j++) {
/* Reset timers */
timers_reset(timers_mask_all);
......
......@@ -105,10 +105,12 @@ __attribute__((always_inline)) INLINE static int cell_is_all_active(
__attribute__((always_inline)) INLINE static int part_is_active(
const struct part *p, const struct engine *e) {
const integertime_t ti_current = e->ti_current;
const integertime_t ti_end = get_integer_time_end(ti_current, p->time_bin);
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t part_bin = p->time_bin;
#ifdef SWIFT_DEBUG_CHECKS
const integertime_t ti_current = e->ti_current;
const integertime_t ti_end = get_integer_time_end(ti_current, p->time_bin);
if (ti_end < ti_current)
error(
"particle in an impossible time-zone! p->ti_end=%lld "
......@@ -116,7 +118,7 @@ __attribute__((always_inline)) INLINE static int part_is_active(
ti_end, ti_current);
#endif
return (ti_end == ti_current);
return (part_bin <= max_active_bin);
}
/**
......@@ -129,10 +131,13 @@ __attribute__((always_inline)) INLINE static int part_is_active(
__attribute__((always_inline)) INLINE static int gpart_is_active(
const struct gpart *gp, const struct engine *e) {
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t gpart_bin = gp->time_bin;
#ifdef SWIFT_DEBUG_CHECKS
const integertime_t ti_current = e->ti_current;
const integertime_t ti_end = get_integer_time_end(ti_current, gp->time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (ti_end < ti_current)
error(
"g-particle in an impossible time-zone! gp->ti_end=%lld "
......@@ -140,7 +145,7 @@ __attribute__((always_inline)) INLINE static int gpart_is_active(
ti_end, ti_current);
#endif
return (ti_end == ti_current);
return (gpart_bin <= max_active_bin);
}
/**
......@@ -153,10 +158,13 @@ __attribute__((always_inline)) INLINE static int gpart_is_active(
__attribute__((always_inline)) INLINE static int spart_is_active(
const struct spart *sp, const struct engine *e) {
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t spart_bin = sp->time_bin;
#ifdef SWIFT_DEBUG_CHECKS
const integertime_t ti_current = e->ti_current;
const integertime_t ti_end = get_integer_time_end(ti_current, sp->time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (ti_end < ti_current)
error(
"s-particle in an impossible time-zone! sp->ti_end=%lld "
......@@ -164,7 +172,7 @@ __attribute__((always_inline)) INLINE static int spart_is_active(
ti_end, ti_current);
#endif
return (ti_end == ti_current);
return (spart_bin <= max_active_bin);
}
/* Are cells / particles active for kick1 tasks ? */
......@@ -201,11 +209,14 @@ __attribute__((always_inline)) INLINE static int cell_is_starting(
__attribute__((always_inline)) INLINE static int part_is_starting(
const struct part *p, const struct engine *e) {
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t part_bin = p->time_bin;
#ifdef SWIFT_DEBUG_CHECKS
const integertime_t ti_current = e->ti_current;
const integertime_t ti_beg =
get_integer_time_begin(ti_current + 1, p->time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (ti_beg > ti_current)
error(
"particle in an impossible time-zone! p->ti_beg=%lld "
......@@ -213,7 +224,7 @@ __attribute__((always_inline)) INLINE static int part_is_starting(
ti_beg, ti_current);
#endif
return (ti_beg == ti_current);
return (part_bin <= max_active_bin);
}
/**
......@@ -226,11 +237,14 @@ __attribute__((always_inline)) INLINE static int part_is_starting(
__attribute__((always_inline)) INLINE static int gpart_is_starting(
const struct gpart *gp, const struct engine *e) {
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t gpart_bin = gp->time_bin;
#ifdef SWIFT_DEBUG_CHECKS
const integertime_t ti_current = e->ti_current;
const integertime_t ti_beg =
get_integer_time_begin(ti_current + 1, gp->time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (ti_beg > ti_current)
error(
"g-particle in an impossible time-zone! gp->ti_beg=%lld "
......@@ -238,7 +252,7 @@ __attribute__((always_inline)) INLINE static int gpart_is_starting(
ti_beg, ti_current);
#endif
return (ti_beg == ti_current);
return (gpart_bin <= max_active_bin);
}
/**
......@@ -251,11 +265,14 @@ __attribute__((always_inline)) INLINE static int gpart_is_starting(
__attribute__((always_inline)) INLINE static int spart_is_starting(
const struct spart *sp, const struct engine *e) {
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t spart_bin = sp->time_bin;
#ifdef SWIFT_DEBUG_CHECKS
const integertime_t ti_current = e->ti_current;
const integertime_t ti_beg =
get_integer_time_begin(ti_current + 1, sp->time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (ti_beg > ti_current)
error(
"s-particle in an impossible time-zone! sp->ti_beg=%lld "
......@@ -263,6 +280,6 @@ __attribute__((always_inline)) INLINE static int spart_is_starting(
ti_beg, ti_current);
#endif
return (ti_beg == ti_current);
return (spart_bin <= max_active_bin);
}
#endif /* SWIFT_ACTIVE_H */
......@@ -2804,6 +2804,18 @@ void engine_print_stats(struct engine *e) {
const ticks tic = getticks();
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all cells have been drifted to the current time.
* That can include cells that have not
* previously been active on this rank. */
space_check_drift_point(e->s, e->ti_current);
/* Be verbose about this */
message("Saving statistics at t=%e.", e->time);
#else
if (e->verbose) message("Saving statistics at t=%e.", e->time);
#endif
e->save_stats = 0;
struct statistics stats;
......@@ -3010,7 +3022,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) {
#endif
/* Ready to go */
e->step = -1;
e->step = 0;
e->forcerebuild = 1;
e->wallclock_time = (float)clocks_diff(&time1, &time2);
......@@ -3031,14 +3043,6 @@ void engine_step(struct engine *e) {
e->tic_step = getticks();
/* Move forward in time */
e->ti_old = e->ti_current;
e->ti_current = e->ti_end_min;
e->step += 1;
e->time = e->ti_current * e->timeBase + e->timeBegin;
e->timeOld = e->ti_old * e->timeBase + e->timeBegin;
e->timeStep = (e->ti_current - e->ti_old) * e->timeBase;
if (e->nodeID == 0) {
/* Print some information to the screen */
......@@ -3053,6 +3057,15 @@ void engine_step(struct engine *e) {
fflush(e->file_timesteps);
}
/* Move forward in time */
e->ti_old = e->ti_current;
e->ti_current = e->ti_end_min;
e->max_active_bin = get_max_active_bin(e->ti_end_min);
e->step += 1;
e->time = e->ti_current * e->timeBase + e->timeBegin;
e->timeOld = e->ti_old * e->timeBase + e->timeBegin;
e->timeStep = (e->ti_current - e->ti_old) * e->timeBase;
/* Prepare the tasks to be launched, rebuild or repartition if needed. */
engine_prepare(e);
......@@ -3566,6 +3579,7 @@ void engine_init(struct engine *e, struct space *s,
e->time = e->timeBegin;
e->ti_old = 0;
e->ti_current = 0;
e->max_active_bin = num_time_bins;
e->timeStep = 0.;
e->timeBase = 0.;
e->timeBase_inv = 0.;
......
......@@ -122,6 +122,9 @@ struct engine {
double time;
integertime_t ti_current;
/* The highest active bin at this time */
timebin_t max_active_bin;
/* Time step */
double timeStep;
......
......@@ -1403,6 +1403,8 @@ void runner_do_recv_part(struct runner *r, struct cell *c, int timer) {
integertime_t ti_end_min = max_nr_timesteps;
integertime_t ti_end_max = 0;
timebin_t time_bin_min = num_time_bins;
timebin_t time_bin_max = 0;
float h_max = 0.f;
/* If this cell is a leaf, collect the particle data. */
......@@ -1410,10 +1412,9 @@ void runner_do_recv_part(struct runner *r, struct cell *c, int timer) {
/* Collect everything... */
for (size_t k = 0; k < nr_parts; k++) {
const integertime_t ti_end =
get_integer_time_end(ti_current, parts[k].time_bin);
ti_end_min = min(ti_end_min, ti_end);
ti_end_max = max(ti_end_max, ti_end);
if(parts[k].time_bin == time_bin_inhibited) continue;
time_bin_min = min(time_bin_min, parts[k].time_bin);
time_bin_max = max(time_bin_max, parts[k].time_bin);
h_max = max(h_max, parts[k].h);
#ifdef SWIFT_DEBUG_CHECKS
......@@ -1421,6 +1422,10 @@ void runner_do_recv_part(struct runner *r, struct cell *c, int timer) {
error("Received un-drifted particle !");
#endif
}
/* Convert into a time */
ti_end_min = get_integer_time_end(ti_current, time_bin_min);
ti_end_max = get_integer_time_end(ti_current, time_bin_max);
}
/* Otherwise, recurse and collect. */
......@@ -1475,22 +1480,27 @@ void runner_do_recv_gpart(struct runner *r, struct cell *c, int timer) {
integertime_t ti_end_min = max_nr_timesteps;
integertime_t ti_end_max = 0;
timebin_t time_bin_min = num_time_bins;
timebin_t time_bin_max = 0;
/* If this cell is a leaf, collect the particle data. */
if (!c->split) {
/* Collect everything... */
for (size_t k = 0; k < nr_gparts; k++) {
const integertime_t ti_end =
get_integer_time_end(ti_current, gparts[k].time_bin);
ti_end_min = min(ti_end_min, ti_end);
ti_end_max = max(ti_end_max, ti_end);
if(gparts[k].time_bin == time_bin_inhibited) continue;
time_bin_min = min(time_bin_min, gparts[k].time_bin);
time_bin_max = max(time_bin_max, gparts[k].time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (gparts[k].ti_drift != ti_current)
error("Received un-drifted g-particle !");
#endif
}
/* Convert into a time */
ti_end_min = get_integer_time_end(ti_current, time_bin_min);
ti_end_max = get_integer_time_end(ti_current, time_bin_max);
}
/* Otherwise, recurse and collect. */
......@@ -1543,17 +1553,27 @@ void runner_do_recv_spart(struct runner *r, struct cell *c, int timer) {
integertime_t ti_end_min = max_nr_timesteps;
integertime_t ti_end_max = 0;
timebin_t time_bin_min = num_time_bins;
timebin_t time_bin_max = 0;
/* If this cell is a leaf, collect the particle data. */
if (!c->split) {
/* Collect everything... */
for (size_t k = 0; k < nr_sparts; k++) {
const integertime_t ti_end =
get_integer_time_end(ti_current, sparts[k].time_bin);
ti_end_min = min(ti_end_min, ti_end);
ti_end_max = max(ti_end_max, ti_end);
if(sparts[k].time_bin == time_bin_inhibited) continue;
time_bin_min = min(time_bin_min, sparts[k].time_bin);
time_bin_max = max(time_bin_max, sparts[k].time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (sparts[k].ti_drift != ti_current)
error("Received un-drifted s-particle !");
#endif
}
/* Convert into a time */
ti_end_min = get_integer_time_end(ti_current, time_bin_min);
ti_end_max = get_integer_time_end(ti_current, time_bin_max);
}
/* Otherwise, recurse and collect. */
......
......@@ -37,7 +37,8 @@ typedef char timebin_t;
/*! The maximal number of timesteps in a simulation */
#define max_nr_timesteps (1LL << (num_time_bins + 1))
#define time_bin_inactive (num_time_bins + 2)
/*! Fictious time-bin to hold inhibited particles */
#define time_bin_inhibited (num_time_bins + 2)
/**
* @brief Returns the integer time interval corresponding to a time bin
......
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