Commit 7c6a2f2c authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'no_specific_counters' into 'master'

No specific counters and leaner cell structure.

Implements #225 and #227.

While re-packing of the cell structure I have made the following changes:

- All the depth-related things are now chars. Depth beyond 256 is ridiculous.
- All the binary things (e.g. c->split) are now chars.
- The number of tasks associated with a cell is a short int.
- The hold locks are now chars. @nnrw56 that's the only part I worry about. Any objection to this ?

In combination with the removal of the statistics, the cell structure has gone from 576 bytes to 416 bytes. Might help with the memory bandwidth. 

All fields are now individually documented using Doxygen.

See merge request !270
parents 183c658f 3334941d
......@@ -757,16 +757,9 @@ void cell_convert_hydro(struct cell *c, void *data) {
*/
void cell_clean_links(struct cell *c, void *data) {
c->density = NULL;
c->nr_density = 0;
c->gradient = NULL;
c->nr_gradient = 0;
c->force = NULL;
c->nr_force = 0;
c->grav = NULL;
c->nr_grav = 0;
}
/**
......
......@@ -79,127 +79,191 @@ struct pcell {
} SWIFT_STRUCT_ALIGN;
/* Structure to store the data of a single cell. */
/**
* @brief Cell within the tree structure.
*
* Contains particles, links to tasks, a multipole object and counters.
*/
struct cell {
/* The cell location on the grid. */
/*! This cell's multipole. */
struct multipole multipole;
/*! The cell location on the grid. */
double loc[3];
/* The cell dimensions. */
/*! The cell dimensions. */
double width[3];
/* Max smoothing length in this cell. */
/*! Max smoothing length in this cell. */
double h_max;
/* Minimum and maximum end of time step in this cell. */
int ti_end_min, ti_end_max;
/* Last time the cell's content was drifted forward in time. */
int ti_old;
/* Minimum dimension, i.e. smallest edge of this cell. */
float dmin;
/* Maximum slack allowed for particle movement. */
float slack;
/* Maximum particle movement in this cell since last construction. */
float dx_max;
/* The depth of this cell in the tree. */
int depth, split, maxdepth;
/* Nr of parts. */
int count, gcount;
/*! Linking pointer for "memory management". */
struct cell *next;
/* Pointers to the particle data. */
/*! Pointer to the #part data. */
struct part *parts;
/* Pointers to the extra particle data. */
/*! Pointer to the #xpart data. */
struct xpart *xparts;
/* Pointers to the gravity particle data. */
/*! Pointer to the #gpart data. */
struct gpart *gparts;
/* Pointers for the sorted indices. */
/*! Pointer for the sorted indices. */
struct entry *sort;
unsigned int sorted;
/* Pointers to the next level of cells. */
/*! Pointers to the next level of cells. */
struct cell *progeny[8];
/* Parent cell. */
/*! Parent cell. */
struct cell *parent;
/* Super cell, i.e. the highest-level supercell that has pair/self tasks */
/*! Super cell, i.e. the highest-level parent cell that has pair/self tasks */
struct cell *super;
/* The task computing this cell's sorts. */
/*! The task computing this cell's sorts. */
struct task *sorts;
int sortsize;
/* The tasks computing this cell's density. */
struct link *density, *gradient, *force, *grav;
int nr_density, nr_gradient, nr_force, nr_grav;
/*! Linked list of the tasks computing this cell's hydro density. */
struct link *density;
/* The hierarchical tasks. */
struct task *extra_ghost, *ghost, *init, *kick;
/* Linked list of the tasks computing this cell's hydro gradients. */
struct link *gradient;
#ifdef WITH_MPI
/*! Linked list of the tasks computing this cell's hydro forces. */
struct link *force;
/* Task receiving data. */
struct task *recv_xv, *recv_rho, *recv_gradient, *recv_ti;
/*! Linked list of the tasks computing this cell's gravity forces. */
struct link *grav;
/* Task send data. */
struct link *send_xv, *send_rho, *send_gradient, *send_ti;
/*! The initialistation task */
struct task *init;
#endif
/*! The ghost task */
struct task *ghost;
/*! The extra ghost task for complex hydro schemes */
struct task *extra_ghost;
/*! The kick task */
struct task *kick;
/*! Task constructing the multipole from the particles */
struct task *grav_up;
/* Tasks for gravity tree. */
struct task *grav_up, *grav_down;
/*! Task propagating the multipole to the particles */
struct task *grav_down;
/* Task for cooling */
/*! Task for cooling */
struct task *cooling;
/* Task for source terms */
/*! Task for source terms */
struct task *sourceterms;
/* Number of tasks that are associated with this cell. */
int nr_tasks;
#ifdef WITH_MPI
/* Is the data of this cell being used in a sub-cell? */
int hold, ghold;
/* Task receiving data (positions). */
struct task *recv_xv;
/* Spin lock for various uses. */
swift_lock_type lock, glock;
/* Task receiving data (density). */
struct task *recv_rho;
/* ID of the previous owner, e.g. runner. */
int owner;
/* Task receiving data (gradient). */
struct task *recv_gradient;
/* Number of particles updated in this cell. */
int updated, g_updated;
/* Task receiving data (time-step). */
struct task *recv_ti;
/* Linking pointer for "memory management". */
struct cell *next;
/* Linked list for sending data (positions). */
struct link *send_xv;
/* This cell's multipole. */
struct multipole multipole;
/* Linked list for sending data (density). */
struct link *send_rho;
/* ID of the node this cell lives on. */
int nodeID;
/* Linked list for sending data (gradient). */
struct link *send_gradient;
#ifdef WITH_MPI
/* Linked list for sending data (time-step). */
struct link *send_ti;
/* Bit mask of the proxies this cell is registered with. */
/*! Bit mask of the proxies this cell is registered with. */
unsigned long long int sendto;
/* Pointer to this cell's packed representation. */
/*! Pointer to this cell's packed representation. */
struct pcell *pcell;
/*! Size of the packed representation */
int pcell_size;
/*! MPI tag associated with this cell */
int tag;
#endif
/*! Minimum end of (integer) time step in this cell. */
int ti_end_min;
/*! Maximum end of (integer) time step in this cell. */
int ti_end_max;
/*! Last (integer) time the cell's content was drifted forward in time. */
int ti_old;
/*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
float dmin;
/*! Maximum particle movement in this cell since last construction. */
float dx_max;
/*! Nr of #part in this cell. */
int count;
/*! Nr of #gpart in this cell. */
int gcount;
/*! The size of the sort array */
int sortsize;
/*! Bit-mask indicating the sorted directions */
unsigned int sorted;
/*! Spin lock for various uses (#part case). */
swift_lock_type lock;
/*! Spin lock for various uses (#gpart case). */
swift_lock_type glock;
/*! ID of the previous owner, e.g. runner. */
int owner;
/*! Number of #part updated in this cell. */
int updated;
/*! Number of #gpart updated in this cell. */
int g_updated;
/*! ID of the node this cell lives on. */
int nodeID;
/*! Is the #part data of this cell being used in a sub-cell? */
int hold;
/*! Is the #gpart data of this cell being used in a sub-cell? */
int ghold;
/*! Number of tasks that are associated with this cell. */
short int nr_tasks;
/*! The depth of this cell in the tree. */
char depth;
/*! Is this cell split ? */
char split;
/*! The maximal depth of this cell and its progenies */
char maxdepth;
} SWIFT_STRUCT_ALIGN;
/* Convert cell location to ID. */
......
......@@ -1359,15 +1359,12 @@ void engine_count_and_link_tasks(struct engine *e) {
atomic_inc(&ci->nr_tasks);
if (t->subtype == task_subtype_density) {
engine_addlink(e, &ci->density, t);
atomic_inc(&ci->nr_density);
}
if (t->subtype == task_subtype_grav) {
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
}
if (t->subtype == task_subtype_external_grav) {
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
}
/* Link pair tasks to cells. */
......@@ -1376,15 +1373,11 @@ void engine_count_and_link_tasks(struct engine *e) {
atomic_inc(&cj->nr_tasks);
if (t->subtype == task_subtype_density) {
engine_addlink(e, &ci->density, t);
atomic_inc(&ci->nr_density);
engine_addlink(e, &cj->density, t);
atomic_inc(&cj->nr_density);
}
if (t->subtype == task_subtype_grav) {
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
engine_addlink(e, &cj->grav, t);
atomic_inc(&cj->nr_grav);
}
/* Link sub-self tasks to cells. */
......@@ -1392,15 +1385,12 @@ void engine_count_and_link_tasks(struct engine *e) {
atomic_inc(&ci->nr_tasks);
if (t->subtype == task_subtype_density) {
engine_addlink(e, &ci->density, t);
atomic_inc(&ci->nr_density);
}
if (t->subtype == task_subtype_grav) {
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
}
if (t->subtype == task_subtype_external_grav) {
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
}
/* Link sub-pair tasks to cells. */
......@@ -1409,22 +1399,16 @@ void engine_count_and_link_tasks(struct engine *e) {
atomic_inc(&cj->nr_tasks);
if (t->subtype == task_subtype_density) {
engine_addlink(e, &ci->density, t);
atomic_inc(&ci->nr_density);
engine_addlink(e, &cj->density, t);
atomic_inc(&cj->nr_density);
}
if (t->subtype == task_subtype_grav) {
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
engine_addlink(e, &cj->grav, t);
atomic_inc(&cj->nr_grav);
}
if (t->subtype == task_subtype_external_grav) {
error("Found a sub-pair/external-gravity task...");
engine_addlink(e, &ci->grav, t);
atomic_inc(&ci->nr_grav);
engine_addlink(e, &cj->grav, t);
atomic_inc(&cj->nr_grav);
}
}
}
......@@ -1650,9 +1634,7 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loops and the cell */
engine_addlink(e, &t->ci->gradient, t2);
atomic_inc(&t->ci->nr_gradient);
engine_addlink(e, &t->ci->force, t3);
atomic_inc(&t->ci->nr_force);
/* Now, build all the dependencies for the hydro */
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci);
......@@ -1665,7 +1647,6 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and the cell */
engine_addlink(e, &t->ci->force, t2);
atomic_inc(&t->ci->nr_force);
/* Now, build all the dependencies for the hydro */
engine_make_hydro_loops_dependencies(sched, t, t2, t->ci);
......@@ -1684,13 +1665,9 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and both cells */
engine_addlink(e, &t->ci->gradient, t2);
atomic_inc(&t->ci->nr_gradient);
engine_addlink(e, &t->cj->gradient, t2);
atomic_inc(&t->cj->nr_gradient);
engine_addlink(e, &t->ci->force, t3);
atomic_inc(&t->ci->nr_force);
engine_addlink(e, &t->cj->force, t3);
atomic_inc(&t->cj->nr_force);
/* Now, build all the dependencies for the hydro for the cells */
/* that are local and are not descendant of the same super-cells */
......@@ -1709,9 +1686,7 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and both cells */
engine_addlink(e, &t->ci->force, t2);
atomic_inc(&t->ci->nr_force);
engine_addlink(e, &t->cj->force, t2);
atomic_inc(&t->cj->nr_force);
/* Now, build all the dependencies for the hydro for the cells */
/* that are local and are not descendant of the same super-cells */
......@@ -1742,9 +1717,7 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and the cell */
engine_addlink(e, &t->ci->gradient, t2);
atomic_inc(&t->ci->nr_gradient);
engine_addlink(e, &t->ci->force, t3);
atomic_inc(&t->ci->nr_force);
/* Now, build all the dependencies for the hydro for the cells */
/* that are local and are not descendant of the same super-cells */
......@@ -1760,7 +1733,6 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and the cell */
engine_addlink(e, &t->ci->force, t2);
atomic_inc(&t->ci->nr_force);
/* Now, build all the dependencies for the hydro for the cells */
/* that are local and are not descendant of the same super-cells */
......@@ -1786,13 +1758,9 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and both cells */
engine_addlink(e, &t->ci->gradient, t2);
atomic_inc(&t->ci->nr_gradient);
engine_addlink(e, &t->cj->gradient, t2);
atomic_inc(&t->cj->nr_gradient);
engine_addlink(e, &t->ci->force, t3);
atomic_inc(&t->ci->nr_force);
engine_addlink(e, &t->cj->force, t3);
atomic_inc(&t->cj->nr_force);
/* Now, build all the dependencies for the hydro for the cells */
/* that are local and are not descendant of the same super-cells */
......@@ -1811,9 +1779,7 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
/* Add the link between the new loop and both cells */
engine_addlink(e, &t->ci->force, t2);
atomic_inc(&t->ci->nr_force);
engine_addlink(e, &t->cj->force, t2);
atomic_inc(&t->cj->nr_force);
/* Now, build all the dependencies for the hydro for the cells */
/* that are local and are not descendant of the same super-cells */
......
......@@ -392,10 +392,6 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
space_rebuild_recycle(s, &s->cells_top[k]);
s->cells_top[k].sorts = NULL;
s->cells_top[k].nr_tasks = 0;
s->cells_top[k].nr_density = 0;
s->cells_top[k].nr_gradient = 0;
s->cells_top[k].nr_force = 0;
s->cells_top[k].nr_grav = 0;
s->cells_top[k].density = NULL;
s->cells_top[k].gradient = NULL;
s->cells_top[k].force = NULL;
......@@ -1444,6 +1440,7 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) {
const int count = c->count;
const int gcount = c->gcount;
const int depth = c->depth;
int maxdepth = 0;
float h_max = 0.0f;
int ti_end_min = max_nr_timesteps, ti_end_max = 0;
......@@ -1453,8 +1450,8 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) {
struct xpart *xparts = c->xparts;
/* Check the depth. */
while (c->depth > (maxdepth = s->maxdepth)) {
atomic_cas(&s->maxdepth, maxdepth, c->depth);
while (depth > (maxdepth = s->maxdepth)) {
atomic_cas(&s->maxdepth, maxdepth, depth);
}
/* If the depth is too large, we have a problem and should stop. */
......
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