Commit 9f88b224 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Force compiler to report shadowed variables. Removed all shadowed variables....

Force compiler to report shadowed variables. Removed all shadowed variables. Added the function scheduler_activate_send() to simplify the unskipping of MPI sends.
parent bbc990c1
......@@ -602,10 +602,10 @@ if test "$enable_warn" != "no"; then
# We will do this by hand instead and only default to the macro for unknown compilers
case "$ax_cv_c_compiler_vendor" in
gnu | clang)
CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter"
CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wshadow"
;;
intel)
CFLAGS="$CFLAGS -w2 -Wunused-variable"
CFLAGS="$CFLAGS -w2 -Wunused-variable -Wshadow"
;;
*)
AX_CFLAGS_WARN_ALL
......
......@@ -1917,46 +1917,28 @@ int cell_unskip_tasks(struct cell *c, struct scheduler *s) {
/* If the foreign cell is active, we want its ti_end values. */
if (cell_is_active(ci, e)) scheduler_activate(s, ci->recv_ti);
/* Look for the local cell cj's send tasks. */
/* Is the foreign cell active and will need stuff from us? */
if (cell_is_active(ci, e)) {
struct link *l = NULL;
for (l = cj->send_xv; l != NULL && l->t->cj->nodeID != ci->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_xv task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, cj->send_xv, ci->nodeID);
/* Drift the cell which will be sent; note that not all sent
particles will be drifted, only those that are needed. */
cell_activate_drift_part(cj, s);
/* If the local cell is also active, more stuff will be needed. */
if (cell_is_active(cj, e)) {
struct link *l = NULL;
for (l = cj->send_rho; l != NULL && l->t->cj->nodeID != ci->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_rho task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, cj->send_rho, ci->nodeID);
#ifdef EXTRA_HYDRO_LOOP
for (l = cj->send_gradient;
l != NULL && l->t->cj->nodeID != ci->nodeID; l = l->next)
;
if (l == NULL) error("Missing link to send_gradient task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, cj->send_gradient, ci->nodeID);
#endif
}
}
/* If the local cell is active, send its ti_end values. */
if (cell_is_active(cj, e)) {
struct link *l = NULL;
for (l = cj->send_ti; l != NULL && l->t->cj->nodeID != ci->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_ti task.");
scheduler_activate(s, l->t);
}
if (cell_is_active(cj, e))
scheduler_activate_send(s, cj->send_ti, ci->nodeID);
} else if (cj->nodeID != engine_rank) {
......@@ -1974,47 +1956,29 @@ int cell_unskip_tasks(struct cell *c, struct scheduler *s) {
/* If the foreign cell is active, we want its ti_end values. */
if (cell_is_active(cj, e)) scheduler_activate(s, cj->recv_ti);
/* Look for the local cell ci's send tasks. */
/* Is the foreign cell active and will need stuff from us? */
if (cell_is_active(cj, e)) {
struct link *l = NULL;
for (l = ci->send_xv; l != NULL && l->t->cj->nodeID != cj->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_xv task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, ci->send_xv, cj->nodeID);
/* Drift the cell which will be sent; note that not all sent
particles will be drifted, only those that are needed. */
cell_activate_drift_part(ci, s);
/* If the local cell is also active, more stuff will be needed. */
if (cell_is_active(ci, e)) {
struct link *l = NULL;
for (l = ci->send_rho; l != NULL && l->t->cj->nodeID != cj->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_rho task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, ci->send_rho, cj->nodeID);
#ifdef EXTRA_HYDRO_LOOP
for (l = ci->send_gradient;
l != NULL && l->t->cj->nodeID != cj->nodeID; l = l->next)
;
if (l == NULL) error("Missing link to send_gradient task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, ci->send_gradient, cj->nodeID);
#endif
}
}
/* If the local cell is active, send its ti_end values. */
if (cell_is_active(ci, e)) {
struct link *l = NULL;
for (l = ci->send_ti; l != NULL && l->t->cj->nodeID != cj->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_ti task.");
scheduler_activate(s, l->t);
}
if (cell_is_active(ci, e))
scheduler_activate_send(s, ci->send_ti, cj->nodeID);
}
#endif
}
......
......@@ -708,11 +708,11 @@ void engine_redistribute(struct engine *e) {
size_t total = 0, g_total = 0, s_total = 0;
size_t unmoved = 0, g_unmoved = 0, s_unmoved = 0;
for (int p = 0, r = 0; p < nr_nodes; p++) {
for (int s = 0; s < nr_nodes; s++) {
for (int n = 0; n < nr_nodes; n++) {
total += counts[r];
g_total += g_counts[r];
s_total += s_counts[r];
if (p == s) {
if (p == n) {
unmoved += counts[r];
g_unmoved += g_counts[r];
s_unmoved += s_counts[r];
......@@ -2754,47 +2754,30 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
/* If the foreign cell is active, we want its ti_end values. */
if (cell_is_active(ci, e)) scheduler_activate(s, ci->recv_ti);
/* Look for the local cell cj's send tasks. */
/* Is the foreign cell active and will need stuff from us? */
if (cell_is_active(ci, e)) {
struct link *l = NULL;
for (l = cj->send_xv; l != NULL && l->t->cj->nodeID != ci->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_xv task.");
scheduler_activate(s, l->t);
struct link *l =
scheduler_activate_send(s, cj->send_xv, ci->nodeID);
/* Drift the cell which will be sent at the level at which it is
sent, i.e. drift the cell specified in the send task (l->t)
itself. */
cell_activate_drift_part(l->t->ci, s);
/* If the local cell is also active, more stuff will be needed. */
if (cell_is_active(cj, e)) {
struct link *l = NULL;
for (l = cj->send_rho;
l != NULL && l->t->cj->nodeID != ci->nodeID; l = l->next)
;
if (l == NULL) error("Missing link to send_rho task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, cj->send_rho, ci->nodeID);
#ifdef EXTRA_HYDRO_LOOP
for (l = cj->send_gradient;
l != NULL && l->t->cj->nodeID != ci->nodeID; l = l->next)
;
if (l == NULL) error("Missing link to send_gradient task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, cj->send_gradient, ci->nodeID);
#endif
}
}
/* If the local cell is active, send its ti_end values. */
if (cell_is_active(cj, e)) {
struct link *l = NULL;
for (l = cj->send_ti; l != NULL && l->t->cj->nodeID != ci->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_ti task.");
scheduler_activate(s, l->t);
}
if (cell_is_active(cj, e))
scheduler_activate_send(s, cj->send_ti, ci->nodeID);
} else if (cj->nodeID != engine_rank) {
......@@ -2812,48 +2795,31 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
/* If the foreign cell is active, we want its ti_end values. */
if (cell_is_active(cj, e)) scheduler_activate(s, cj->recv_ti);
/* Look for the local cell ci's send tasks. */
/* Is the foreign cell active and will need stuff from us? */
if (cell_is_active(cj, e)) {
struct link *l = NULL;
for (l = ci->send_xv; l != NULL && l->t->cj->nodeID != cj->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_xv task.");
scheduler_activate(s, l->t);
struct link *l =
scheduler_activate_send(s, ci->send_xv, cj->nodeID);
/* Drift the cell which will be sent at the level at which it is
sent, i.e. drift the cell specified in the send task (l->t)
itself. */
cell_activate_drift_part(l->t->ci, s);
/* If the local cell is also active, more stuff will be needed. */
if (cell_is_active(ci, e)) {
struct link *l = NULL;
for (l = ci->send_rho;
l != NULL && l->t->cj->nodeID != cj->nodeID; l = l->next)
;
if (l == NULL) error("Missing link to send_rho task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, ci->send_rho, cj->nodeID);
#ifdef EXTRA_HYDRO_LOOP
for (l = ci->send_gradient;
l != NULL && l->t->cj->nodeID != cj->nodeID; l = l->next)
;
if (l == NULL) error("Missing link to send_gradient task.");
scheduler_activate(s, l->t);
scheduler_activate_send(s, ci->send_gradient, cj->nodeID);
#endif
}
}
/* If the local cell is active, send its ti_end values. */
if (cell_is_active(ci, e)) {
struct link *l = NULL;
for (l = ci->send_ti; l != NULL && l->t->cj->nodeID != cj->nodeID;
l = l->next)
;
if (l == NULL) error("Missing link to send_ti task.");
scheduler_activate(s, l->t);
}
if (cell_is_active(ci, e))
scheduler_activate_send(s, ci->send_ti, cj->nodeID);
}
#endif
}
......
......@@ -95,7 +95,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pp_truncated(
} else {
const float r = r2 * r_inv;
const float ui = r * h_inv;
float W_ij;
......
......@@ -1612,83 +1612,87 @@ __attribute__((always_inline)) INLINE void voronoi_intersect(
continue;
}
if (c->orders[v] == 2) {
int j = voronoi_get_edge(c, v, 0);
int k = voronoi_get_edge(c, v, 1);
int b = voronoi_get_edgeindex(c, v, 1);
int l = 0;
safewhile(l < c->orders[j] && voronoi_get_edge(c, j, l) != k) { ++l; }
if (l == c->orders[j]) {
int jj = voronoi_get_edge(c, v, 0);
int kk = voronoi_get_edge(c, v, 1);
int bb = voronoi_get_edgeindex(c, v, 1);
int ll = 0;
safewhile(ll < c->orders[jj] && voronoi_get_edge(c, jj, ll) != kk) {
++ll;
}
if (ll == c->orders[jj]) {
int a = voronoi_get_edgeindex(c, v, 0);
/* j and k are not joined together. Replace their edges pointing to v
with a new edge pointing from j to k */
voronoi_set_edge(c, j, a, k);
voronoi_set_edgeindex(c, j, a, b);
voronoi_set_edge(c, k, b, j);
voronoi_set_edgeindex(c, k, b, a);
/* jj and kk are not joined together. Replace their edges pointing to v
with a new edge pointing from jj to kk */
voronoi_set_edge(c, jj, a, k);
voronoi_set_edgeindex(c, jj, a, bb);
voronoi_set_edge(c, kk, bb, jj);
voronoi_set_edgeindex(c, kk, bb, a);
/* no new elements added to the stack: decrease the counter */
--low_order_index;
} else {
/* just remove the edges from j to v and from k to v: create two new
/* just remove the edges from jj to v and from kk to v: create two new
vertices */
/* vertex j */
/* vertex jj */
vindex = c->nvert;
++c->nvert;
c->vertices[3 * vindex] = c->vertices[3 * j];
c->vertices[3 * vindex + 1] = c->vertices[3 * j + 1];
c->vertices[3 * vindex + 2] = c->vertices[3 * j + 2];
c->orders[vindex] = c->orders[j] - 1;
c->vertices[3 * vindex] = c->vertices[3 * jj];
c->vertices[3 * vindex + 1] = c->vertices[3 * jj + 1];
c->vertices[3 * vindex + 2] = c->vertices[3 * jj + 2];
c->orders[vindex] = c->orders[jj] - 1;
c->offsets[vindex] = c->offsets[vindex - 1] + c->orders[vindex - 1];
int m = 0;
for (int n = 0; n < c->orders[j]; ++n) {
int l = voronoi_get_edge(c, j, n);
if (l != v) {
for (int n = 0; n < c->orders[jj]; ++n) {
int lll = voronoi_get_edge(c, jj, n);
if (lll != v) {
/* make a new edge */
voronoi_set_edge(c, vindex, m, l);
voronoi_set_edgeindex(c, vindex, m, voronoi_get_edgeindex(c, j, n));
voronoi_set_edge(c, vindex, m, lll);
voronoi_set_edgeindex(c, vindex, m,
voronoi_get_edgeindex(c, jj, n));
/* update the other vertex */
voronoi_set_edge(c, l, voronoi_get_edgeindex(c, j, n), vindex);
voronoi_set_edgeindex(c, l, voronoi_get_edgeindex(c, j, n), m);
voronoi_set_edge(c, lll, voronoi_get_edgeindex(c, jj, n), vindex);
voronoi_set_edgeindex(c, lll, voronoi_get_edgeindex(c, jj, n), m);
/* copy ngb information */
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, j, n));
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, jj, n));
++m;
}
/* remove the old vertex */
voronoi_set_edge(c, j, n, -1);
voronoi_set_edgeindex(c, j, n, -1);
voronoi_set_edge(c, jj, n, -1);
voronoi_set_edgeindex(c, jj, n, -1);
}
/* vertex k */
/* vertex kk */
vindex = c->nvert;
++c->nvert;
c->vertices[3 * vindex] = c->vertices[3 * k];
c->vertices[3 * vindex + 1] = c->vertices[3 * k + 1];
c->vertices[3 * vindex + 2] = c->vertices[3 * k + 2];
c->orders[vindex] = c->orders[k] - 1;
c->vertices[3 * vindex] = c->vertices[3 * kk];
c->vertices[3 * vindex + 1] = c->vertices[3 * kk + 1];
c->vertices[3 * vindex + 2] = c->vertices[3 * kk + 2];
c->orders[vindex] = c->orders[kk] - 1;
c->offsets[vindex] = c->offsets[vindex - 1] + c->orders[vindex - 1];
m = 0;
for (int n = 0; n < c->orders[k]; ++n) {
int l = voronoi_get_edge(c, k, n);
if (l != v) {
for (int n = 0; n < c->orders[kk]; ++n) {
int lll = voronoi_get_edge(c, kk, n);
if (lll != v) {
/* make a new edge */
voronoi_set_edge(c, vindex, m, l);
voronoi_set_edgeindex(c, vindex, m, voronoi_get_edgeindex(c, k, n));
voronoi_set_edge(c, vindex, m, lll);
voronoi_set_edgeindex(c, vindex, m,
voronoi_get_edgeindex(c, kk, n));
/* update the other vertex */
voronoi_set_edge(c, l, voronoi_get_edgeindex(c, k, n), vindex);
voronoi_set_edgeindex(c, l, voronoi_get_edgeindex(c, k, n), m);
voronoi_set_edge(c, lll, voronoi_get_edgeindex(c, kk, n), vindex);
voronoi_set_edgeindex(c, lll, voronoi_get_edgeindex(c, kk, n), m);
/* copy ngb information */
/* this one is special: we copy the ngb corresponding to the
deleted edge and skip the one after that */
if (n == b + 1) {
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, k, b));
if (n == bb + 1) {
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, kk, bb));
} else {
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, k, n));
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, kk, n));
}
++m;
}
/* remove the old vertex */
voronoi_set_edge(c, k, n, -1);
voronoi_set_edgeindex(c, k, n, -1);
voronoi_set_edge(c, kk, n, -1);
voronoi_set_edgeindex(c, kk, n, -1);
}
/* check if j or k has become an order 2 vertex */
/* check if jj or kk has become an order 2 vertex */
/* if they have become an order 1 vertex, they were already an order 2
vertex, and they should already be in the list... */
if (c->orders[vindex] == 2) {
......@@ -1716,32 +1720,32 @@ __attribute__((always_inline)) INLINE void voronoi_intersect(
voronoi_set_edge(c, v, 1, -1);
voronoi_set_edgeindex(c, v, 1, -1);
} else if (c->orders[v] == 1) {
int j = voronoi_get_edge(c, v, 0);
int jj = voronoi_get_edge(c, v, 0);
/* we have to remove the edge between j and v. We create a new vertex */
vindex = c->nvert;
++c->nvert;
c->vertices[3 * vindex] = c->vertices[3 * j];
c->vertices[3 * vindex + 1] = c->vertices[3 * j + 1];
c->vertices[3 * vindex + 2] = c->vertices[3 * j + 2];
c->vertices[3 * vindex] = c->vertices[3 * jj];
c->vertices[3 * vindex + 1] = c->vertices[3 * jj + 1];
c->vertices[3 * vindex + 2] = c->vertices[3 * jj + 2];
c->orders[vindex] = c->orders[j] - 1;
c->offsets[vindex] = c->offsets[vindex - 1] + c->orders[vindex - 1];
int m = 0;
for (int k = 0; k < c->orders[j]; ++k) {
int l = voronoi_get_edge(c, j, k);
if (l != v) {
for (int kk = 0; kk < c->orders[j]; ++kk) {
int ll = voronoi_get_edge(c, jj, kk);
if (ll != v) {
/* make a new edge */
voronoi_set_edge(c, vindex, m, l);
voronoi_set_edgeindex(c, vindex, m, voronoi_get_edgeindex(c, j, k));
voronoi_set_edge(c, vindex, m, ll);
voronoi_set_edgeindex(c, vindex, m, voronoi_get_edgeindex(c, jj, kk));
/* update the other vertex */
voronoi_set_edge(c, l, voronoi_get_edgeindex(c, j, k), vindex);
voronoi_set_edgeindex(c, l, voronoi_get_edgeindex(c, j, k), m);
voronoi_set_edge(c, ll, voronoi_get_edgeindex(c, jj, kk), vindex);
voronoi_set_edgeindex(c, ll, voronoi_get_edgeindex(c, jj, kk), m);
/* copy ngb information */
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, j, k));
voronoi_set_ngb(c, vindex, m, voronoi_get_ngb(c, jj, kk));
++m;
}
/* remove the old vertex */
voronoi_set_edge(c, j, k, -1);
voronoi_set_edgeindex(c, j, k, -1);
voronoi_set_edge(c, jj, kk, -1);
voronoi_set_edgeindex(c, jj, kk, -1);
}
/* if the new vertex is a new order 2 vertex, add it to the stack */
if (c->orders[vindex] == 2) {
......
......@@ -43,4 +43,32 @@
_a > _b ? _a : _b; \
})
/**
* @brief Minimum of three numbers
*
* This macro evaluates its arguments exactly once.
*/
#define min3(x, y, z) \
({ \
const __typeof__(x) _x = (x); \
const __typeof__(y) _y = (y); \
const __typeof__(z) _z = (z); \
const __typeof__(x) _temp = min(_x, _y); \
min(_temp, _z); \
})
/**
* @brief Maximum of three numbers
*
* This macro evaluates its arguments exactly once.
*/
#define max3(x, y, z) \
({ \
const __typeof__(x) _x = (x); \
const __typeof__(y) _y = (y); \
const __typeof__(z) _z = (z); \
const __typeof__(x) _temp = max(_x, _y); \
max(_temp, _z); \
})
#endif /* SWIFT_MINMAX_H */
......@@ -989,11 +989,11 @@ INLINE static int gravity_multipole_equal(const struct gravity_tensors *ga,
*
* Corresponds to equation (28c).
*
* @param m The #multipole (content will be overwritten).
* @param multi The #multipole (content will be overwritten).
* @param gparts The #gpart.
* @param gcount The number of particles.
*/
INLINE static void gravity_P2M(struct gravity_tensors *m,
INLINE static void gravity_P2M(struct gravity_tensors *multi,
const struct gpart *gparts, int gcount) {
/* Temporary variables */
......@@ -1153,96 +1153,96 @@ INLINE static void gravity_P2M(struct gravity_tensors *m,
#endif
/* Store the data on the multipole. */
m->m_pole.M_000 = mass;
m->r_max = sqrt(r_max2);
m->CoM[0] = com[0];
m->CoM[1] = com[1];
m->CoM[2] = com[2];
m->m_pole.vel[0] = vel[0];
m->m_pole.vel[1] = vel[1];
m->m_pole.vel[2] = vel[2];
multi->m_pole.M_000 = mass;
multi->r_max = sqrt(r_max2);
multi->CoM[0] = com[0];
multi->CoM[1] = com[1];
multi->CoM[2] = com[2];
multi->m_pole.vel[0] = vel[0];
multi->m_pole.vel[1] = vel[1];
multi->m_pole.vel[2] = vel[2];
#if SELF_GRAVITY_MULTIPOLE_ORDER > 0
/* 1st order terms */
m->m_pole.M_100 = M_100;
m->m_pole.M_010 = M_010;
m->m_pole.M_001 = M_001;
multi->m_pole.M_100 = M_100;
multi->m_pole.M_010 = M_010;
multi->m_pole.M_001 = M_001;
#endif
#if SELF_GRAVITY_MULTIPOLE_ORDER > 1
/* 2nd order terms */
m->m_pole.M_200 = M_200;
m->m_pole.M_020 = M_020;
m->m_pole.M_002 = M_002;
m->m_pole.M_110 = M_110;
m->m_pole.M_101 = M_101;
m->m_pole.M_011 = M_011;
multi->m_pole.M_200 = M_200;
multi->m_pole.M_020 = M_020;
multi->m_pole.M_002 = M_002;
multi->m_pole.M_110 = M_110;
multi->m_pole.M_101 = M_101;
multi->m_pole.M_011 = M_011;
#endif
#if SELF_GRAVITY_MULTIPOLE_ORDER > 2
/* 3rd order terms */
m->m_pole.M_300 = M_300;
m->m_pole.M_030 = M_030;
m->m_pole.M_003 = M_003;
m->m_pole.M_210 = M_210;
m->m_pole.M_201 = M_201;
m->m_pole.M_120 = M_120;
m->m_pole.M_021 = M_021;
m->m_pole.M_102 = M_102;
m->m_pole.M_012 = M_012;
m->m_pole.M_111 = M_111;
multi->m_pole.M_300 = M_300;
multi->m_pole.M_030 = M_030;
multi->m_pole.M_003 = M_003;
multi->m_pole.M_210 = M_210;
multi->m_pole.M_201 = M_201;
multi->m_pole.M_120 = M_120;
multi->m_pole.M_021 = M_021;
multi->m_pole.M_102 = M_102;
multi->m_pole.M_012 = M_012;
multi->m_pole.M_111 = M_111;
#endif
#if SELF_GRAVITY_MULTIPOLE_ORDER > 3
/* 4th order terms */
m->m_pole.M_400 = M_400;
m->m_pole.M_040 = M_040;
m->m_pole.M_004 = M_004;
m->m_pole.M_310 = M_310;
m->m_pole.M_301 = M_301;
m->m_pole.M_130 = M_130;
m->m_pole.M_031 = M_031;
m->m_pole.M_103 = M_103;
m->m_pole.M_013 = M_013;
m->m_pole.M_220 = M_220;
m->m_pole.M_202 = M_202;
m->m_pole.M_022 = M_022;
m->m_pole.M_211 = M_211;
m->m_pole.M_121 = M_121;
m->m_pole.M_112 = M_112;
multi->m_pole.M_400 = M_400;
multi->m_pole.M_040 = M_040;
multi->m_pole.M_004 = M_004;
multi->m_pole.M_310 = M_310;
multi->m_pole.M_301 = M_301;