diff --git a/src/drift.h b/src/drift.h index 05b09bb7910e8cddaf9fb24bb248f120f9db9eea..932e956d8c9f9c8b1cb5afdbff33f99bc79c180d 100644 --- a/src/drift.h +++ b/src/drift.h @@ -37,7 +37,8 @@ * @param ti_current Integer end of time-step */ __attribute__((always_inline)) INLINE static void drift_gpart( - struct gpart* gp, float dt, double timeBase, int ti_old, int ti_current) { + struct gpart *restrict gp, float dt, double timeBase, int ti_old, + int ti_current) { /* Drift... */ gp->x[0] += gp->v_full[0] * dt; gp->x[1] += gp->v_full[1] * dt; @@ -60,8 +61,8 @@ __attribute__((always_inline)) INLINE static void drift_gpart( * @param ti_current Integer end of time-step */ __attribute__((always_inline)) INLINE static void drift_part( - struct part* p, struct xpart* xp, float dt, double timeBase, int ti_old, - int ti_current) { + struct part *restrict p, struct xpart *restrict xp, float dt, + double timeBase, int ti_old, int ti_current) { /* Useful quantity */ const float h_inv = 1.0f / p->h; diff --git a/src/hydro/Default/hydro.h b/src/hydro/Default/hydro.h index a09920235eedcc6c997c1407d7f6c63d8f7a630f..b832333377f37e33a99eb0b9fdb7cb15d1233d0b 100644 --- a/src/hydro/Default/hydro.h +++ b/src/hydro/Default/hydro.h @@ -28,8 +28,8 @@ * */ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( - const struct part* p, const struct xpart* xp, - const struct hydro_props* hydro_properties) { + const struct part *restrict p, const struct xpart *restrict xp, + const struct hydro_props *restrict hydro_properties) { const float CFL_condition = hydro_properties->CFL_condition; @@ -55,7 +55,7 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( * @param xp The extended particle data to act upon */ __attribute__((always_inline)) INLINE static void hydro_first_init_part( - struct part* p, struct xpart* xp) {} + struct part *restrict p, struct xpart *restrict xp) {} /** * @brief Prepares a particle for the density calculation. @@ -66,7 +66,7 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_init_part( - struct part* p) { + struct part *restrict p) { p->density.wcount = 0.f; p->density.wcount_dh = 0.f; p->rho = 0.f; @@ -87,7 +87,7 @@ __attribute__((always_inline)) INLINE static void hydro_init_part( * @param time The current time */ __attribute__((always_inline)) INLINE static void hydro_end_density( - struct part* p, float time) { + struct part *restrict p, float time) { /* Some smoothing length multiples. */ const float h = p->h; @@ -122,7 +122,8 @@ __attribute__((always_inline)) INLINE static void hydro_end_density( * @param time The current time */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( - struct part* p, struct xpart* xp, int ti_current, double timeBase) { + struct part *restrict p, struct xpart *restrict xp, int ti_current, + double timeBase) { /* Some smoothing length multiples. */ const float h = p->h; @@ -171,7 +172,7 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( - struct part* p) { + struct part *restrict p) { /* Reset the acceleration. */ p->a_hydro[0] = 0.0f; @@ -194,7 +195,8 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * @param timeBase The minimal time-step size */ __attribute__((always_inline)) INLINE static void hydro_predict_extra( - struct part* p, struct xpart* xp, int t0, int t1, double timeBase) { + struct part *restrict p, struct xpart *restrict xp, int t0, int t1, + double timeBase) { float u, w; const float dt = (t1 - t0) * timeBase; @@ -218,7 +220,7 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_end_force( - struct part* p) {} + struct part *restrict p) {} /** * @brief Kick the additional variables @@ -229,17 +231,18 @@ __attribute__((always_inline)) INLINE static void hydro_end_force( * @param half_dt The half time-step for this kick */ __attribute__((always_inline)) INLINE static void hydro_kick_extra( - struct part* p, struct xpart* xp, float dt, float half_dt) {} + struct part *restrict p, struct xpart *restrict xp, float dt, + float half_dt) {} /** - * @brief Converts hydro quantity of a particle + * @brief Converts hydro quantity of a particle at the start of a run * * Requires the density to be known * * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( - struct part* p) {} + struct part *restrict p) {} /** * @brief Returns the internal energy of a particle @@ -248,7 +251,7 @@ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( * @param dt Time since the last kick */ __attribute__((always_inline)) INLINE static float hydro_get_internal_energy( - const struct part* p, float dt) { + const struct part *restrict p, float dt) { return p->u; } diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h index 7789d4a80db6b37003fcbff92e5f8b42b1ca5ff3..a523fbb99f469004562fb7194d0c3825e9cd1857 100644 --- a/src/hydro/Gadget2/hydro.h +++ b/src/hydro/Gadget2/hydro.h @@ -27,8 +27,8 @@ * */ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( - const struct part* p, const struct xpart* xp, - const struct hydro_props* hydro_properties) { + const struct part *restrict p, const struct xpart *restrict xp, + const struct hydro_props *restrict hydro_properties) { const float CFL_condition = hydro_properties->CFL_condition; @@ -49,7 +49,7 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( * @param xp The extended particle data to act upon */ __attribute__((always_inline)) INLINE static void hydro_first_init_part( - struct part* p, struct xpart* xp) {} + struct part *restrict p, struct xpart *restrict xp) {} /** * @brief Prepares a particle for the density calculation. @@ -60,7 +60,7 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_init_part( - struct part* p) { + struct part *restrict p) { p->density.wcount = 0.f; p->density.wcount_dh = 0.f; p->rho = 0.f; @@ -81,7 +81,7 @@ __attribute__((always_inline)) INLINE static void hydro_init_part( * @param ti_current The current time (on the integer timeline) */ __attribute__((always_inline)) INLINE static void hydro_end_density( - struct part* p, int ti_current) { + struct part *restrict p, int ti_current) { /* Some smoothing length multiples. */ const float h = p->h; @@ -125,7 +125,8 @@ __attribute__((always_inline)) INLINE static void hydro_end_density( * @param timeBase The minimal time-step size */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( - struct part* p, struct xpart* xp, int ti_current, double timeBase) { + struct part *restrict p, struct xpart *restrict xp, int ti_current, + double timeBase) { /* Compute the norm of the curl */ p->force.curl_v = sqrtf(p->density.rot_v[0] * p->density.rot_v[0] + @@ -149,7 +150,7 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( - struct part* p) { + struct part *restrict p) { /* Reset the acceleration. */ p->a_hydro[0] = 0.0f; @@ -175,7 +176,8 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * @param timeBase The minimal time-step size */ __attribute__((always_inline)) INLINE static void hydro_predict_extra( - struct part* p, struct xpart* xp, int t0, int t1, double timeBase) { + struct part *restrict p, const struct xpart *restrict xp, int t0, int t1, + double timeBase) { /* Drift the pressure */ const float dt_entr = (t1 - (p->ti_begin + p->ti_end) / 2) * timeBase; @@ -194,7 +196,7 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_end_force( - struct part* p) { + struct part *restrict p) { p->entropy_dt *= hydro_gamma_minus_one * pow_minus_gamma_minus_one(p->rho); } @@ -208,7 +210,8 @@ __attribute__((always_inline)) INLINE static void hydro_end_force( * @param half_dt The half time-step for this kick */ __attribute__((always_inline)) INLINE static void hydro_kick_extra( - struct part* p, struct xpart* xp, float dt, float half_dt) { + struct part *restrict p, struct xpart *restrict xp, float dt, + float half_dt) { /* Do not decrease the entropy (temperature) by more than a factor of 2*/ const float entropy_change = p->entropy_dt * dt; @@ -223,14 +226,14 @@ __attribute__((always_inline)) INLINE static void hydro_kick_extra( } /** - * @brief Converts hydro quantity of a particle + * @brief Converts hydro quantity of a particle at the start of a run * * Requires the density to be known * * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( - struct part* p) { + struct part *restrict p) { p->entropy = hydro_gamma_minus_one * p->entropy * pow_minus_gamma_minus_one(p->rho); @@ -243,7 +246,7 @@ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( * @param dt Time since the last kick */ __attribute__((always_inline)) INLINE static float hydro_get_internal_energy( - const struct part* p, float dt) { + const struct part *restrict p, float dt) { const float entropy = p->entropy + p->entropy_dt * dt; diff --git a/src/hydro/Minimal/hydro.h b/src/hydro/Minimal/hydro.h index 848de3b5de8b916c35a3c6da7e414fd9a35d966b..87daae2bc43f671aa9549058bb8168c0af91ad5c 100644 --- a/src/hydro/Minimal/hydro.h +++ b/src/hydro/Minimal/hydro.h @@ -32,8 +32,8 @@ * */ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( - const struct part* p, const struct xpart* xp, - const struct hydro_props* hydro_properties) { + const struct part *restrict p, const struct xpart *restrict xp, + const struct hydro_props *restrict hydro_properties) { const float CFL_condition = hydro_properties->CFL_condition; @@ -55,7 +55,7 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( * @param xp The extended particle data to act upon */ __attribute__((always_inline)) INLINE static void hydro_first_init_part( - struct part* p, struct xpart* xp) { + struct part *restrict p, struct xpart *restrict xp) { xp->u_full = p->u; } @@ -70,7 +70,7 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_init_part( - struct part* p) { + struct part *restrict p) { p->density.wcount = 0.f; p->density.wcount_dh = 0.f; p->rho = 0.f; @@ -90,7 +90,7 @@ __attribute__((always_inline)) INLINE static void hydro_init_part( * @param time The current time */ __attribute__((always_inline)) INLINE static void hydro_end_density( - struct part* p, float time) { + struct part *restrict p, float time) { /* Some smoothing length multiples. */ const float h = p->h; @@ -131,7 +131,8 @@ __attribute__((always_inline)) INLINE static void hydro_end_density( * @param timeBase The minimal time-step size */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( - struct part* p, struct xpart* xp, int ti_current, double timeBase) { + struct part *restrict p, struct xpart *restrict xp, int ti_current, + double timeBase) { p->force.pressure = p->rho * p->u * hydro_gamma_minus_one; } @@ -145,7 +146,7 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( - struct part* p) { + struct part *restrict p) { /* Reset the acceleration. */ p->a_hydro[0] = 0.0f; @@ -171,7 +172,8 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * @param timeBase The minimal time-step size */ __attribute__((always_inline)) INLINE static void hydro_predict_extra( - struct part* p, struct xpart* xp, int t0, int t1, double timeBase) { + struct part *restrict p, const struct xpart *restrict xp, int t0, int t1, + double timeBase) { p->u = xp->u_full; @@ -189,7 +191,7 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_end_force( - struct part* p) {} + struct part *restrict p) {} /** * @brief Kick the additional variables @@ -203,7 +205,8 @@ __attribute__((always_inline)) INLINE static void hydro_end_force( * @param half_dt The half time-step for this kick */ __attribute__((always_inline)) INLINE static void hydro_kick_extra( - struct part* p, struct xpart* xp, float dt, float half_dt) { + struct part *restrict p, struct xpart *restrict xp, float dt, + float half_dt) { /* Kick in momentum space */ xp->u_full += p->u_dt * dt; @@ -223,7 +226,7 @@ __attribute__((always_inline)) INLINE static void hydro_kick_extra( * @param p The particle to act upon */ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( - struct part* p) {} + struct part *restrict p) {} /** * @brief Returns the internal energy of a particle @@ -236,7 +239,7 @@ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( * @param dt Time since the last kick */ __attribute__((always_inline)) INLINE static float hydro_get_internal_energy( - const struct part* p, float dt) { + const struct part *restrict p, float dt) { return p->u; } diff --git a/src/kick.h b/src/kick.h index df3bd4cc6ce9819d0b65640db51d2ed20a7d59fe..2cf50ca00ebe738a194d54fbd0142ed7e525b947 100644 --- a/src/kick.h +++ b/src/kick.h @@ -33,9 +33,8 @@ * @param new_dti The (integer) time-step for this kick. * @param timeBase The minimal allowed time-step size. */ -__attribute__((always_inline)) INLINE static void kick_gpart(struct gpart* gp, - int new_dti, - double timeBase) { +__attribute__((always_inline)) INLINE static void kick_gpart( + struct gpart *restrict gp, int new_dti, double timeBase) { /* Compute the time step for this kick */ const int ti_start = (gp->ti_begin + gp->ti_end) / 2; @@ -64,10 +63,9 @@ __attribute__((always_inline)) INLINE static void kick_gpart(struct gpart* gp, * @param new_dti The (integer) time-step for this kick. * @param timeBase The minimal allowed time-step size. */ -__attribute__((always_inline)) INLINE static void kick_part(struct part* p, - struct xpart* xp, - int new_dti, - double timeBase) { +__attribute__((always_inline)) INLINE static void kick_part( + struct part *restrict p, struct xpart *restrict xp, int new_dti, + double timeBase) { /* Compute the time step for this kick */ const int ti_start = (p->ti_begin + p->ti_end) / 2; diff --git a/src/runner.c b/src/runner.c index a0b8c51cfabf830afd685a210bd78d3f98af62f0..ae8a33f8b6f62ad0e89e78bc04f60c965c88cd93 100644 --- a/src/runner.c +++ b/src/runner.c @@ -119,7 +119,7 @@ void runner_do_grav_external(struct runner *r, struct cell *c, int timer) { for (int i = 0; i < gcount; i++) { /* Get a direct pointer on the part. */ - struct gpart *const g = &gparts[i]; + struct gpart *restrict g = &gparts[i]; /* Is this part within the time step? */ if (g->ti_end <= ti_current) { @@ -371,8 +371,8 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int clock) { */ void runner_do_init(struct runner *r, struct cell *c, int timer) { - struct part *const parts = c->parts; - struct gpart *const gparts = c->gparts; + struct part *restrict parts = c->parts; + struct gpart *restrict gparts = c->gparts; const int count = c->count; const int gcount = c->gcount; const int ti_current = r->e->ti_current; @@ -390,7 +390,7 @@ void runner_do_init(struct runner *r, struct cell *c, int timer) { for (int i = 0; i < count; i++) { /* Get a direct pointer on the part. */ - struct part *const p = &parts[i]; + struct part *restrict p = &parts[i]; if (p->ti_end <= ti_current) { @@ -403,7 +403,7 @@ void runner_do_init(struct runner *r, struct cell *c, int timer) { for (int i = 0; i < gcount; i++) { /* Get a direct pointer on the part. */ - struct gpart *const gp = &gparts[i]; + struct gpart *restrict gp = &gparts[i]; if (gp->ti_end <= ti_current) { @@ -588,9 +588,9 @@ void runner_do_drift(struct runner *r, struct cell *c, int timer) { const double dt = (r->e->ti_current - r->e->ti_old) * timeBase; const int ti_old = r->e->ti_old; const int ti_current = r->e->ti_current; - struct part *const parts = c->parts; - struct xpart *const xparts = c->xparts; - struct gpart *const gparts = c->gparts; + struct part *restrict parts = c->parts; + struct xpart *restrict xparts = c->xparts; + struct gpart *restrict gparts = c->gparts; float dx_max = 0.f, dx2_max = 0.f, h_max = 0.f; double e_kin = 0.0, e_int = 0.0, e_pot = 0.0, mass = 0.0; @@ -611,7 +611,7 @@ void runner_do_drift(struct runner *r, struct cell *c, int timer) { for (size_t k = 0; k < nr_gparts; k++) { /* Get a handle on the gpart. */ - struct gpart *const gp = &gparts[k]; + struct gpart *restrict gp = &gparts[k]; /* Drift... */ drift_gpart(gp, dt, timeBase, ti_old, ti_current); @@ -628,8 +628,8 @@ void runner_do_drift(struct runner *r, struct cell *c, int timer) { for (size_t k = 0; k < nr_parts; k++) { /* Get a handle on the part. */ - struct part *const p = &parts[k]; - struct xpart *const xp = &xparts[k]; + struct part *restrict p = &parts[k]; + struct xpart *restrict xp = &xparts[k]; /* Drift... */ drift_part(p, xp, dt, timeBase, ti_old, ti_current); @@ -684,7 +684,7 @@ void runner_do_drift(struct runner *r, struct cell *c, int timer) { if (c->progeny[k] != NULL) { /* Recurse */ - struct cell *cp = c->progeny[k]; + struct cell *restrict cp = c->progeny[k]; runner_do_drift(r, cp, 0); /* Collect */ @@ -734,9 +734,9 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) { const double timeBase = r->e->timeBase; const int count = c->count; const int gcount = c->gcount; - struct part *const parts = c->parts; - struct xpart *const xparts = c->xparts; - struct gpart *const gparts = c->gparts; + struct part *restrict parts = c->parts; + struct xpart *restrict xparts = c->xparts; + struct gpart *restrict gparts = c->gparts; int updated = 0, g_updated = 0; int ti_end_min = max_nr_timesteps, ti_end_max = 0; @@ -757,7 +757,7 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) { for (int k = 0; k < gcount; k++) { /* Get a handle on the part. */ - struct gpart *const gp = &gparts[k]; + struct gpart *restrict gp = &gparts[k]; /* If the g-particle has no counterpart */ if (gp->id_or_neg_offset > 0) { @@ -783,8 +783,8 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) { for (int k = 0; k < count; k++) { /* Get a handle on the part. */ - struct part *const p = &parts[k]; - struct xpart *const xp = &xparts[k]; + struct part *restrict p = &parts[k]; + struct xpart *restrict xp = &xparts[k]; /* First, finish the force loop */ p->h_dt *= p->h * 0.333333333f; @@ -812,7 +812,7 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) { /* Loop over the progeny. */ for (int k = 0; k < 8; k++) if (c->progeny[k] != NULL) { - struct cell *const cp = c->progeny[k]; + struct cell *restrict cp = c->progeny[k]; /* Recurse */ runner_do_kick_fixdt(r, cp, 0); @@ -849,9 +849,9 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) { const int ti_current = r->e->ti_current; const int count = c->count; const int gcount = c->gcount; - struct part *const parts = c->parts; - struct xpart *const xparts = c->xparts; - struct gpart *const gparts = c->gparts; + struct part *restrict parts = c->parts; + struct xpart *restrict xparts = c->xparts; + struct gpart *restrict gparts = c->gparts; int updated = 0, g_updated = 0; int ti_end_min = max_nr_timesteps, ti_end_max = 0; @@ -869,7 +869,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) { for (int k = 0; k < gcount; k++) { /* Get a handle on the part. */ - struct gpart *const gp = &gparts[k]; + struct gpart *restrict gp = &gparts[k]; /* If the g-particle has no counterpart and needs to be kicked */ if (gp->id_or_neg_offset > 0) { @@ -901,8 +901,8 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) { for (int k = 0; k < count; k++) { /* Get a handle on the part. */ - struct part *const p = &parts[k]; - struct xpart *const xp = &xparts[k]; + struct part *restrict p = &parts[k]; + struct xpart *restrict xp = &xparts[k]; /* If particle needs to be kicked */ if (p->ti_end <= ti_current) { @@ -937,7 +937,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) { /* Loop over the progeny. */ for (int k = 0; k < 8; k++) if (c->progeny[k] != NULL) { - struct cell *const cp = c->progeny[k]; + struct cell *restrict cp = c->progeny[k]; /* Recurse */ runner_do_kick(r, cp, 0); @@ -968,8 +968,8 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) { */ void runner_do_recv_cell(struct runner *r, struct cell *c, int timer) { - const struct part *const parts = c->parts; - const struct gpart *const gparts = c->gparts; + const struct part *restrict parts = c->parts; + const struct gpart *restrict gparts = c->gparts; const size_t nr_parts = c->count; const size_t nr_gparts = c->gcount; // const int ti_current = r->e->ti_current; diff --git a/src/timestep.h b/src/timestep.h index 1674958812d1f9e72eb618a9cb026befd610d06d..b4da4cdbaf5b082bd5c5890ca6305dd1dd952781 100644 --- a/src/timestep.h +++ b/src/timestep.h @@ -66,7 +66,7 @@ __attribute__((always_inline)) INLINE static int get_integer_timestep( * @param e The #engine (used to get some constants). */ __attribute__((always_inline)) INLINE static int get_gpart_timestep( - const struct gpart *gp, const struct engine *e) { + const struct gpart *restrict gp, const struct engine *restrict e) { const float new_dt_external = gravity_compute_timestep_external( e->external_potential, e->physical_constants, gp); @@ -94,7 +94,8 @@ __attribute__((always_inline)) INLINE static int get_gpart_timestep( * @param e The #engine (used to get some constants). */ __attribute__((always_inline)) INLINE static int get_part_timestep( - const struct part *p, const struct xpart *xp, const struct engine *e) { + const struct part *restrict p, const struct xpart *restrict xp, + const struct engine *restrict e) { /* Compute the next timestep (hydro condition) */ const float new_dt_hydro = hydro_compute_timestep(p, xp, e->hydro_properties);