Commit e295df53 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'master' into add_particles

parents fc928650 7cfaacbe
......@@ -59,10 +59,10 @@ Scheduler:
cell_sub_size_self_hydro: 32000 # (Optional) Maximal number of interactions per sub-self hydro task (this is the default value).
cell_sub_size_pair_grav: 256000000 # (Optional) Maximal number of interactions per sub-pair gravity task (this is the default value).
cell_sub_size_self_grav: 32000 # (Optional) Maximal number of interactions per sub-self gravity task (this is the default value).
cell_sub_size_pair_stars: 256000000 # (Optional) Maximal number of interactions per sub-pair stars task (this is the default value).
cell_sub_size_self_stars: 32000 # (Optional) Maximal number of interactions per sub-self stars task (this is the default value).
cell_sub_size_pair_stars: 256000000 # (Optional) Maximal number of interactions per sub-pair stars task (this is the default value).
cell_sub_size_self_stars: 32000 # (Optional) Maximal number of interactions per sub-self stars task (this is the default value).
cell_split_size: 400 # (Optional) Maximal number of particles per cell (this is the default value).
cell_subdepth_grav: 2 # (Optional) Maximal depth the gravity tasks can be pushed down (this is the default value).
cell_subdepth_diff_grav: 4 # (Optional) Maximal depth difference between leaves and a cell that gravity tasks can be pushed down to (this is the default value).
max_top_level_cells: 12 # (Optional) Maximal number of top-level cells in any dimension. The number of top-level cells will be the cube of this (this is the default value).
tasks_per_cell: 0 # (Optional) The average number of tasks per cell. If not large enough the simulation will fail (means guess...).
mpi_message_limit: 4096 # (Optional) Maximum MPI task message size to send non-buffered, KB.
......
......@@ -190,6 +190,7 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc,
pc->hydro.count = c->hydro.count;
pc->grav.count = c->grav.count;
pc->stars.count = c->stars.count;
pc->maxdepth = c->maxdepth;
/* Copy the Multipole related information */
if (with_gravity) {
......@@ -292,6 +293,8 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c,
c->hydro.count = pc->hydro.count;
c->grav.count = pc->grav.count;
c->stars.count = pc->stars.count;
c->maxdepth = pc->maxdepth;
#ifdef SWIFT_DEBUG_CHECKS
c->cellID = pc->cellID;
#endif
......@@ -1626,6 +1629,8 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) {
/* Mark this cell for drifting. */
c->grav.do_drift = 1;
if (c->grav.drift_out != NULL) scheduler_activate(s, c->grav.drift_out);
/* Set the do_grav_sub_drifts all the way up and activate the super drift
if this has not yet been done. */
if (c == c->grav.super) {
......@@ -1639,6 +1644,11 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) {
parent != NULL && !parent->grav.do_sub_drift;
parent = parent->parent) {
parent->grav.do_sub_drift = 1;
if (parent->grav.drift_out) {
scheduler_activate(s, parent->grav.drift_out);
}
if (parent == c->grav.super) {
#ifdef SWIFT_DEBUG_CHECKS
if (parent->grav.drift == NULL)
......@@ -2909,16 +2919,18 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) {
if (c->kick2 != NULL) scheduler_activate(s, c->kick2);
if (c->timestep != NULL) scheduler_activate(s, c->timestep);
if (c->end_force != NULL) scheduler_activate(s, c->end_force);
if ((e->policy & engine_policy_cooling) && c->hydro.cooling != NULL)
scheduler_activate(s, c->hydro.cooling);
if ((e->policy & engine_policy_star_formation) &&
c->hydro.star_formation != NULL)
scheduler_activate(s, c->hydro.star_formation);
if (c->grav.down != NULL) scheduler_activate(s, c->grav.down);
if (c->grav.down_in != NULL) scheduler_activate(s, c->grav.down_in);
if (c->grav.mesh != NULL) scheduler_activate(s, c->grav.mesh);
if (c->grav.long_range != NULL) scheduler_activate(s, c->grav.long_range);
if (c->logger != NULL) scheduler_activate(s, c->logger);
/* Subgrid tasks */
if ((e->policy & engine_policy_cooling) && c->hydro.cooling != NULL)
scheduler_activate(s, c->hydro.cooling);
if ((e->policy & engine_policy_star_formation) &&
c->hydro.star_formation != NULL)
scheduler_activate(s, c->hydro.star_formation);
}
return rebuild;
......
......@@ -149,6 +149,9 @@ struct pcell {
} stars;
/*! Maximal depth in that part of the tree */
int maxdepth;
/*! Relative indices of the cell's progeny. */
int progeny[8];
......@@ -336,7 +339,7 @@ struct cell {
/*! Do any of this cell's sub-cells need to be sorted? */
char do_sub_sort;
#ifdef SWIFT_DEBUG_CHECKS
#ifdef SWIFT_DEBUG_CHECKS
/*! Last (integer) time the cell's sort arrays were updated. */
integertime_t ti_sort;
......@@ -361,6 +364,9 @@ struct cell {
/*! The drift task for gparts */
struct task *drift;
/*! Implicit task (going up- and down the tree) for the #gpart drifts */
struct task *drift_out;
/*! Linked list of the tasks computing this cell's gravity forces. */
struct link *grav;
......@@ -815,8 +821,8 @@ __attribute__((always_inline)) INLINE static int cell_can_split_self_stars_task(
__attribute__((always_inline)) INLINE static int
cell_can_split_pair_gravity_task(const struct cell *c) {
/* Is the cell split ? */
return c->split && c->depth < space_subdepth_grav;
/* Is the cell split and still far from the leaves ? */
return c->split && ((c->maxdepth - c->depth) > space_subdepth_diff_grav);
}
/**
......@@ -828,8 +834,8 @@ cell_can_split_pair_gravity_task(const struct cell *c) {
__attribute__((always_inline)) INLINE static int
cell_can_split_self_gravity_task(const struct cell *c) {
/* Is the cell split ? */
return c->split && c->depth < space_subdepth_grav;
/* Is the cell split and still far from the leaves ? */
return c->split && ((c->maxdepth - c->depth) > space_subdepth_diff_grav);
}
/**
......
......@@ -1044,6 +1044,8 @@ void engine_repartition_trigger(struct engine *e) {
#ifdef WITH_MPI
const ticks tic = getticks();
/* Do nothing if there have not been enough steps since the last
* repartition, don't want to repeat this too often or immediately after
* a repartition step. Also nothing to do when requested. */
......@@ -1112,6 +1114,10 @@ void engine_repartition_trigger(struct engine *e) {
/* We always reset CPU time for next check, unless it will not be used. */
if (e->reparttype->type != REPART_NONE)
e->cputime_last_step = clocks_get_cputime_used();
if (e->verbose)
message("took %.3f %s", clocks_from_ticks(getticks() - tic),
clocks_getunit());
#endif
}
......@@ -1591,6 +1597,8 @@ void engine_exchange_top_multipoles(struct engine *e) {
#ifdef WITH_MPI
ticks tic = getticks();
#ifdef SWIFT_DEBUG_CHECKS
for (int i = 0; i < e->s->nr_cells; ++i) {
const struct gravity_tensors *m = &e->s->multipoles_top[i];
......@@ -1654,6 +1662,9 @@ void engine_exchange_top_multipoles(struct engine *e) {
counter, e->total_nr_gparts);
#endif
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
#else
error("SWIFT was not compiled with MPI support.");
#endif
......@@ -1991,6 +2002,8 @@ void engine_rebuild(struct engine *e, int repartitioned,
/* Re-build the space. */
space_rebuild(e->s, repartitioned, e->verbose);
const ticks tic2 = getticks();
/* Update the global counters of particles */
long long num_particles[3] = {
(long long)(e->s->nr_parts - e->s->nr_extra_parts),
......@@ -2009,6 +2022,10 @@ void engine_rebuild(struct engine *e, int repartitioned,
e->nr_inhibited_gparts = 0;
e->nr_inhibited_sparts = 0;
if (e->verbose)
message("updating particle counts took %.3f %s.",
clocks_from_ticks(getticks() - tic2), clocks_getunit());
/* Re-compute the mesh forces */
if ((e->policy & engine_policy_self_gravity) && e->s->periodic)
pm_mesh_compute_potential(e->mesh, e->s, &e->threadpool, e->verbose);
......@@ -3872,6 +3889,8 @@ void engine_makeproxies(struct engine *e) {
void engine_split(struct engine *e, struct partition *initial_partition) {
#ifdef WITH_MPI
const ticks tic = getticks();
struct space *s = e->s;
/* Do the initial partition of the cells. */
......@@ -3952,6 +3971,10 @@ void engine_split(struct engine *e, struct partition *initial_partition) {
s->nr_sparts, e->verbose);
#endif
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
#else
error("SWIFT was not compiled with MPI support.");
#endif
......@@ -5125,6 +5148,8 @@ void engine_init_output_lists(struct engine *e, struct swift_params *params) {
*/
void engine_recompute_displacement_constraint(struct engine *e) {
const ticks tic = getticks();
/* Get the cosmological information */
const struct cosmology *cosmo = e->cosmology;
const float Om = cosmo->Omega_m;
......@@ -5237,6 +5262,10 @@ void engine_recompute_displacement_constraint(struct engine *e) {
if (e->verbose)
message("max_dt_RMS_displacement = %e", e->dt_max_RMS_displacement);
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
}
/**
......
......@@ -462,6 +462,7 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
c->end_force = scheduler_addtask(s, task_type_end_force,
task_subtype_none, 0, 0, c, NULL);
/* Subgrid tasks */
if (is_with_cooling) {
c->hydro.cooling = scheduler_addtask(s, task_type_cooling,
......@@ -485,13 +486,13 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
} else {
scheduler_addunlock(s, c->kick2, c->timestep);
}
scheduler_addunlock(s, c->timestep, c->kick1);
#if defined(WITH_LOGGER)
scheduler_addunlock(s, c->kick1, c->logger);
#endif
}
} else { /* We are above the super-cell so need to go deeper */
/* Recurse. */
......@@ -544,6 +545,8 @@ void engine_make_hierarchical_tasks_gravity(struct engine *e, struct cell *c) {
task_subtype_none, 0, 0, c, NULL);
/* Implicit tasks for the up and down passes */
c->grav.drift_out = scheduler_addtask(s, task_type_drift_gpart_out,
task_subtype_none, 0, 1, c, NULL);
c->grav.init_out = scheduler_addtask(s, task_type_init_grav_out,
task_subtype_none, 0, 1, c, NULL);
c->grav.down_in = scheduler_addtask(s, task_type_grav_down_in,
......@@ -562,19 +565,24 @@ void engine_make_hierarchical_tasks_gravity(struct engine *e, struct cell *c) {
/* Link in the implicit tasks */
scheduler_addunlock(s, c->grav.init, c->grav.init_out);
scheduler_addunlock(s, c->grav.drift, c->grav.drift_out);
scheduler_addunlock(s, c->grav.down_in, c->grav.down);
}
}
}
/* We are below the super-cell but not below the maximal splitting depth */
else if (c->grav.super != NULL && c->depth < space_subdepth_grav) {
else if ((c->grav.super != NULL) &&
((c->maxdepth - c->depth) >= space_subdepth_diff_grav)) {
/* Local tasks only... */
if (c->nodeID == e->nodeID) {
if (is_self_gravity) {
c->grav.drift_out = scheduler_addtask(s, task_type_drift_gpart_out,
task_subtype_none, 0, 1, c, NULL);
c->grav.init_out = scheduler_addtask(s, task_type_init_grav_out,
task_subtype_none, 0, 1, c, NULL);
......@@ -582,13 +590,14 @@ void engine_make_hierarchical_tasks_gravity(struct engine *e, struct cell *c) {
task_subtype_none, 0, 1, c, NULL);
scheduler_addunlock(s, c->parent->grav.init_out, c->grav.init_out);
scheduler_addunlock(s, c->parent->grav.drift_out, c->grav.drift_out);
scheduler_addunlock(s, c->grav.down_in, c->parent->grav.down_in);
}
}
}
/* Recurse but not below the maximal splitting depth */
if (c->split && c->depth <= space_subdepth_grav)
if (c->split && ((c->maxdepth - c->depth) >= space_subdepth_diff_grav))
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_make_hierarchical_tasks_gravity(e, c->progeny[k]);
......@@ -1128,7 +1137,7 @@ void engine_link_gravity_tasks(struct engine *e) {
/* drift ---+-> gravity --> grav_down */
/* init --/ */
scheduler_addunlock(sched, ci->grav.super->grav.drift, t);
scheduler_addunlock(sched, ci_parent->grav.drift_out, t);
scheduler_addunlock(sched, ci_parent->grav.init_out, t);
scheduler_addunlock(sched, t, ci_parent->grav.down_in);
}
......@@ -1152,7 +1161,7 @@ void engine_link_gravity_tasks(struct engine *e) {
/* drift ---+-> gravity --> grav_down */
/* init --/ */
scheduler_addunlock(sched, ci->grav.super->grav.drift, t);
scheduler_addunlock(sched, ci_parent->grav.drift_out, t);
scheduler_addunlock(sched, ci_parent->grav.init_out, t);
scheduler_addunlock(sched, t, ci_parent->grav.down_in);
}
......@@ -1160,10 +1169,8 @@ void engine_link_gravity_tasks(struct engine *e) {
/* drift ---+-> gravity --> grav_down */
/* init --/ */
if (ci->grav.super != cj->grav.super) /* Avoid double unlock */
scheduler_addunlock(sched, cj->grav.super->grav.drift, t);
if (ci_parent != cj_parent) { /* Avoid double unlock */
scheduler_addunlock(sched, cj_parent->grav.drift_out, t);
scheduler_addunlock(sched, cj_parent->grav.init_out, t);
scheduler_addunlock(sched, t, cj_parent->grav.down_in);
}
......@@ -1178,7 +1185,7 @@ void engine_link_gravity_tasks(struct engine *e) {
#endif
/* drift ---+-> gravity --> grav_down */
/* init --/ */
scheduler_addunlock(sched, ci->grav.super->grav.drift, t);
scheduler_addunlock(sched, ci_parent->grav.drift_out, t);
scheduler_addunlock(sched, ci_parent->grav.init_out, t);
scheduler_addunlock(sched, t, ci_parent->grav.down_in);
}
......@@ -1203,7 +1210,7 @@ void engine_link_gravity_tasks(struct engine *e) {
/* drift ---+-> gravity --> grav_down */
/* init --/ */
scheduler_addunlock(sched, ci->grav.super->grav.drift, t);
scheduler_addunlock(sched, ci_parent->grav.drift_out, t);
scheduler_addunlock(sched, ci_parent->grav.init_out, t);
scheduler_addunlock(sched, t, ci_parent->grav.down_in);
}
......@@ -1211,10 +1218,8 @@ void engine_link_gravity_tasks(struct engine *e) {
/* drift ---+-> gravity --> grav_down */
/* init --/ */
if (ci->grav.super != cj->grav.super) /* Avoid double unlock */
scheduler_addunlock(sched, cj->grav.super->grav.drift, t);
if (ci_parent != cj_parent) { /* Avoid double unlock */
scheduler_addunlock(sched, cj_parent->grav.drift_out, t);
scheduler_addunlock(sched, cj_parent->grav.init_out, t);
scheduler_addunlock(sched, t, cj_parent->grav.down_in);
}
......
......@@ -261,6 +261,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
}
}
/* Gravity */
if ((t_subtype == task_subtype_grav) &&
((ci_active_gravity && ci_nodeID == nodeID) ||
(cj_active_gravity && cj_nodeID == nodeID))) {
......@@ -474,6 +475,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
t_type == task_type_grav_long_range ||
t_type == task_type_init_grav ||
t_type == task_type_init_grav_out ||
t_type == task_type_drift_gpart_out ||
t_type == task_type_grav_down_in) {
if (cell_is_active_gravity(t->ci, e)) scheduler_activate(s, t);
}
......
......@@ -21,6 +21,7 @@
#include "../config.h"
/* Some standard headers. */
#include <math.h>
#include <string.h>
/* This object's header. */
......
......@@ -1353,7 +1353,7 @@ static void runner_do_unskip_gravity(struct cell *c, struct engine *e) {
if (!cell_is_active_gravity(c, e)) return;
/* Recurse */
if (c->split && c->depth < space_subdepth_grav) {
if (c->split && ((c->maxdepth - c->depth) >= space_subdepth_diff_grav)) {
for (int k = 0; k < 8; k++) {
if (c->progeny[k] != NULL) {
struct cell *cp = c->progeny[k];
......
......@@ -68,7 +68,7 @@ int space_subsize_pair_grav = space_subsize_pair_grav_default;
int space_subsize_self_grav = space_subsize_self_grav_default;
int space_subsize_pair_stars = space_subsize_pair_stars_default;
int space_subsize_self_stars = space_subsize_self_stars_default;
int space_subdepth_grav = space_subdepth_grav_default;
int space_subdepth_diff_grav = space_subdepth_diff_grav_default;
int space_maxsize = space_maxsize_default;
/*! Number of extra #part we allocate memory for per top-level cell */
......@@ -523,6 +523,14 @@ void space_regrid(struct space *s, int verbose) {
c->grav.ti_old_multipole = ti_current;
#ifdef WITH_MPI
c->mpi.tag = -1;
c->mpi.hydro.recv_xv = NULL;
c->mpi.hydro.recv_rho = NULL;
c->mpi.hydro.recv_gradient = NULL;
c->mpi.hydro.send_xv = NULL;
c->mpi.hydro.send_rho = NULL;
c->mpi.hydro.send_gradient = NULL;
c->mpi.grav.recv = NULL;
c->mpi.grav.send = NULL;
#endif // WITH_MPI
if (s->with_self_gravity) c->grav.multipole = &s->multipoles_top[cid];
#ifdef SWIFT_DEBUG_CHECKS
......@@ -3693,13 +3701,14 @@ void space_init(struct space *s, struct swift_params *params,
space_subsize_self_stars_default);
space_splitsize = parser_get_opt_param_int(
params, "Scheduler:cell_split_size", space_splitsize_default);
space_subdepth_grav = parser_get_opt_param_int(
params, "Scheduler:cell_subdepth_grav", space_subdepth_grav_default);
space_subdepth_diff_grav =
parser_get_opt_param_int(params, "Scheduler:cell_subdepth_diff_grav",
space_subdepth_diff_grav_default);
if (verbose) {
message("max_size set to %d split_size set to %d", space_maxsize,
space_splitsize);
message("subdepth_grav set to %d", space_subdepth_grav);
message("subdepth_grav set to %d", space_subdepth_diff_grav);
message("sub_size_pair_hydro set to %d, sub_size_self_hydro set to %d",
space_subsize_pair_hydro, space_subsize_self_hydro);
message("sub_size_pair_grav set to %d, sub_size_self_grav set to %d",
......
......@@ -54,7 +54,7 @@ struct cosmology;
#define space_subsize_self_grav_default 32000
#define space_subsize_pair_stars_default 256000000
#define space_subsize_self_stars_default 32000
#define space_subdepth_grav_default 2
#define space_subdepth_diff_grav_default 4
#define space_max_top_level_cells_default 12
#define space_stretch 1.10f
#define space_maxreldx 0.1f
......@@ -71,7 +71,7 @@ extern int space_subsize_pair_grav;
extern int space_subsize_self_grav;
extern int space_subsize_pair_stars;
extern int space_subsize_self_stars;
extern int space_subdepth_grav;
extern int space_subdepth_diff_grav;
extern int space_extra_parts;
extern int space_extra_gparts;
extern int space_extra_sparts;
......
......@@ -21,6 +21,7 @@
#include "../config.h"
/* Some standard headers. */
#include <math.h>
#include <string.h>
/* MPI headers. */
......@@ -136,7 +137,7 @@ void stats_collect_part_mapper(void *map_data, int nr_parts, void *extra_data) {
/* Get the particle */
const struct part *p = &parts[k];
const struct xpart *xp = &xparts[k];
const struct gpart *gp = (p->gpart != NULL) ? gp = p->gpart : NULL;
const struct gpart *gp = p->gpart;
/* Get useful time variables */
const integertime_t ti_beg =
......
......@@ -47,18 +47,39 @@
#include "lock.h"
/* Task type names. */
const char *taskID_names[task_type_count] = {
"none", "sort", "self",
"pair", "sub_self", "sub_pair",
"init_grav", "init_grav_out", "ghost_in",
"ghost", "ghost_out", "extra_ghost",
"drift_part", "drift_gpart", "end_force",
"kick1", "kick2", "timestep",
"send", "recv", "grav_long_range",
"grav_mm", "grav_down_in", "grav_down",
"grav_mesh", "cooling", "star_formation",
"sourceterms", "logger", "stars_ghost_in",
"stars_ghost", "stars_ghost_out"};
const char *taskID_names[task_type_count] = {"none",
"sort",
"self",
"pair",
"sub_self",
"sub_pair",
"init_grav",
"init_grav_out",
"ghost_in",
"ghost",
"ghost_out",
"extra_ghost",
"drift_part",
"drift_gpart",
"drift_gpart_out",
"end_force",
"kick1",
"kick2",
"timestep",
"send",
"recv",
"grav_long_range",
"grav_mm",
"grav_down_in",
"grav_down",
"grav_mesh",
"cooling",
"star_formation",
"sourceterms",
"logger",
"stars_ghost_in",
"stars_ghost",
"stars_ghost_out"};
/* Sub-task type names. */
const char *subtaskID_names[task_subtype_count] = {
......@@ -390,8 +411,10 @@ int task_lock(struct task *t) {
char buff[MPI_MAX_ERROR_STRING];
int len;
MPI_Error_string(err, buff, &len);
error("Failed to test request on send/recv task (tag=%lld, %s).",
t->flags, buff);
error(
"Failed to test request on send/recv task (type=%s/%s tag=%lld, "
"%s).",
taskID_names[t->type], subtaskID_names[t->subtype], t->flags, buff);
}
return res;
#else
......
......@@ -53,6 +53,7 @@ enum task_types {
task_type_extra_ghost,
task_type_drift_part,
task_type_drift_gpart,
task_type_drift_gpart_out, /* Implicit */
task_type_end_force,
task_type_kick1,
task_type_kick2,
......
......@@ -77,6 +77,7 @@ TASKTYPES = [
"extra_ghost",
"drift_part",
"drift_gpart",
"drift_gpart_out",
"end_force",
"kick1",
"kick2",
......
......@@ -41,7 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import matplotlib
matplotlib.use("Agg")
import matplotlib.collections as collections
import matplotlib.ticker as plticker
......@@ -163,6 +162,7 @@ TASKTYPES = [
"extra_ghost",
"drift_part",
"drift_gpart",
"drift_gpart_out",
"end_force",
"kick1",
"kick2",
......
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