Commit 68c5af52 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Collect the sum of the part/gpart/spart velocity norms as well.

parent d77b7603
......@@ -37,14 +37,13 @@
/**
* @brief Atomic min operation on floats.
*/
__attribute__((always_inline)) INLINE void atomic_min_f(volatile float* x,
float y) {
__attribute__((always_inline)) INLINE static void atomic_min_f(
volatile float* x, float y) {
float test, new;
float old = *x;
do {
test = old;
new = min(old, y);
if (new == old) return;
old = atomic_cas((int*)x, test, new);
} while (test != old);
}
......@@ -52,14 +51,13 @@ __attribute__((always_inline)) INLINE void atomic_min_f(volatile float* x,
/**
* @brief Atomic max operation on floats.
*/
__attribute__((always_inline)) INLINE void atomic_max_f(volatile float* x,
float y) {
__attribute__((always_inline)) INLINE static void atomic_max_f(
volatile float* x, float y) {
float test, new;
float old = *x;
do {
test = old;
new = max(old, y);
if (new == old) return;
old = atomic_cas((int*)x, test, new);
} while (test != old);
}
......@@ -67,14 +65,13 @@ __attribute__((always_inline)) INLINE void atomic_max_f(volatile float* x,
/**
* @brief Atomic add operation on floats.
*/
__attribute__((always_inline)) INLINE void atomic_add_f(volatile float* x,
float y) {
__attribute__((always_inline)) INLINE static void atomic_add_f(
volatile float* x, float y) {
float test, new;
float old = *x;
do {
test = old;
new = old + y;
if (new == old) return;
old = atomic_cas((int*)x, test, new);
} while (test != old);
}
......
......@@ -1087,8 +1087,9 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
if (cell_counts == NULL)
error("Failed to allocate temporary cell count buffer.");
/* Init the local minimal part mass */
/* Init the local collectors */
float min_mass = FLT_MAX;
float sum_vel_norm = 0.f;
/* Loop over the parts. */
for (int k = 0; k < nr_parts; k++) {
......@@ -1125,6 +1126,9 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
/* Compute minimal mass */
min_mass = min(min_mass, hydro_get_mass(p));
/* Compute sum of velocity norm */
sum_vel_norm += p->v[0] * p->v[0] + p->v[1] * p->v[1] + p->v[2] * p->v[2];
/* Update the position */
p->x[0] = pos_x;
p->x[1] = pos_y;
......@@ -1136,8 +1140,9 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
if (cell_counts[k]) atomic_add(&data->cell_counts[k], cell_counts[k]);
free(cell_counts);
/* Write back thee minimal part mass */
/* Write back the minimal part mass and velocity sum */
atomic_min_f(&s->min_part_mass, min_mass);
atomic_add_f(&s->sum_part_vel_norm, sum_vel_norm);
}
/**
......@@ -1170,8 +1175,9 @@ void space_gparts_get_cell_index_mapper(void *map_data, int nr_gparts,
if (cell_counts == NULL)
error("Failed to allocate temporary cell count buffer.");
/* Init the local minimal part mass */
/* Init the local collectors */
float min_mass = FLT_MAX;
float sum_vel_norm = 0.f;
for (int k = 0; k < nr_gparts; k++) {
......@@ -1205,7 +1211,12 @@ void space_gparts_get_cell_index_mapper(void *map_data, int nr_gparts,
#endif
/* Compute minimal mass */
if (gp->type == swift_type_dark_matter) min_mass = min(min_mass, gp->mass);
if (gp->type == swift_type_dark_matter) {
min_mass = min(min_mass, gp->mass);
sum_vel_norm += gp->v_full[0] * gp->v_full[0] +
gp->v_full[1] * gp->v_full[1] +
gp->v_full[2] * gp->v_full[2];
}
/* Update the position */
gp->x[0] = pos_x;
......@@ -1218,8 +1229,9 @@ void space_gparts_get_cell_index_mapper(void *map_data, int nr_gparts,
if (cell_counts[k]) atomic_add(&data->cell_counts[k], cell_counts[k]);
free(cell_counts);
/* Write back thee minimal part mass */
/* Write back the minimal part mass and velocity sum */
atomic_min_f(&s->min_gpart_mass, min_mass);
atomic_add_f(&s->sum_gpart_vel_norm, sum_vel_norm);
}
/**
......@@ -1252,8 +1264,9 @@ void space_sparts_get_cell_index_mapper(void *map_data, int nr_sparts,
if (cell_counts == NULL)
error("Failed to allocate temporary cell count buffer.");
/* Init the local minimal part mass */
/* Init the local collectors */
float min_mass = FLT_MAX;
float sum_vel_norm = 0.f;
for (int k = 0; k < nr_sparts; k++) {
......@@ -1289,6 +1302,10 @@ void space_sparts_get_cell_index_mapper(void *map_data, int nr_sparts,
/* Compute minimal mass */
min_mass = min(min_mass, sp->mass);
/* Compute sum of velocity norm */
sum_vel_norm +=
sp->v[0] * sp->v[0] + sp->v[1] * sp->v[1] + sp->v[2] * sp->v[2];
/* Update the position */
sp->x[0] = pos_x;
sp->x[1] = pos_y;
......@@ -1300,8 +1317,9 @@ void space_sparts_get_cell_index_mapper(void *map_data, int nr_sparts,
if (cell_counts[k]) atomic_add(&data->cell_counts[k], cell_counts[k]);
free(cell_counts);
/* Write back thee minimal part mass */
/* Write back the minimal part mass and velocity sum */
atomic_min_f(&s->min_spart_mass, min_mass);
atomic_add_f(&s->sum_spart_vel_norm, sum_vel_norm);
}
/**
......@@ -1320,8 +1338,9 @@ void space_parts_get_cell_index(struct space *s, int *ind, int *cell_counts,
const ticks tic = getticks();
/* Re-set the minimal mass */
/* Re-set the counters */
s->min_part_mass = FLT_MAX;
s->sum_part_vel_norm = 0.f;
/* Pack the extra information */
struct index_data data;
......@@ -1354,8 +1373,9 @@ void space_gparts_get_cell_index(struct space *s, int *gind, int *cell_counts,
const ticks tic = getticks();
/* Re-set the minimal mass */
/* Re-set the counters */
s->min_gpart_mass = FLT_MAX;
s->sum_gpart_vel_norm = 0.f;
/* Pack the extra information */
struct index_data data;
......@@ -1388,8 +1408,9 @@ void space_sparts_get_cell_index(struct space *s, int *sind, int *cell_counts,
const ticks tic = getticks();
/* Re-set the minimal mass */
/* Re-set the counters */
s->min_spart_mass = FLT_MAX;
s->sum_spart_vel_norm = 0.f;
/* Pack the extra information */
struct index_data data;
......@@ -2685,6 +2706,12 @@ void space_init(struct space *s, const struct swift_params *params,
s->nr_sparts = Nspart;
s->size_sparts = Nspart;
s->sparts = sparts;
s->min_part_mass = FLT_MAX;
s->min_gpart_mass = FLT_MAX;
s->min_spart_mass = FLT_MAX;
s->sum_part_vel_norm = 0.f;
s->sum_gpart_vel_norm = 0.f;
s->sum_spart_vel_norm = 0.f;
s->nr_queues = 1; /* Temporary value until engine construction */
/* Are we generating gas from the DM-only ICs? */
......
......@@ -155,6 +155,15 @@ struct space {
/*! Minimal mass of all the #spart */
float min_spart_mass;
/*! Sum of the norm of the velocity of all the #part */
float sum_part_vel_norm;
/*! Sum of the norm of the velocity of all the dark-matter #gpart */
float sum_gpart_vel_norm;
/*! Sum of the norm of the velocity of all the #spart */
float sum_spart_vel_norm;
/*! General-purpose lock for this space. */
swift_lock_type lock;
......
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