Commit 561825dd authored by Loic Hausammann's avatar Loic Hausammann
Browse files

The stellar ghost compiles

parent 83d7c5fc
......@@ -282,6 +282,15 @@ struct cell {
/*! Task propagating the multipole to the particles */
struct task *grav_down;
/*! Dependency implicit task for the star ghost (in->ghost->out)*/
struct task *star_ghost_in;
/*! Dependency implicit task for the star ghost (in->ghost->out)*/
struct task *star_ghost_out;
/*! The star ghost task itself */
struct task *star_ghost;
/*! Task for cooling */
struct task *cooling;
......
......@@ -83,6 +83,7 @@
#include "sort_part.h"
#include "sourceterms.h"
#include "statistics.h"
#include "stars_io.h"
#include "timers.h"
#include "tools.h"
#include "units.h"
......@@ -148,6 +149,29 @@ void engine_addlink(struct engine *e, struct link **l, struct task *t) {
res->next = atomic_swap(l, res);
}
/**
* @brief Recursively add non-implicit star ghost tasks to a cell hierarchy.
*/
void engine_add_star_ghosts(struct engine *e, struct cell *c, struct task *star_ghost_in,
struct task *star_ghost_out) {
/* If we have reached the leaf OR have to few particles to play with*/
if (!c->split || c->scount < engine_max_sparts_per_ghost) {
/* Add the ghost task and its dependencies */
struct scheduler *s = &e->sched;
c->star_ghost =
scheduler_addtask(s, task_type_star_ghost, task_subtype_none, 0, 0, c, NULL);
scheduler_addunlock(s, star_ghost_in, c->star_ghost);
scheduler_addunlock(s, c->star_ghost, star_ghost_out);
} else {
/* Keep recursing */
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_add_star_ghosts(e, c->progeny[k], star_ghost_in, star_ghost_out);
}
}
/**
* @brief Recursively add non-implicit ghost tasks to a cell hierarchy.
*/
......@@ -389,6 +413,48 @@ void engine_make_hierarchical_tasks_gravity(struct engine *e, struct cell *c) {
engine_make_hierarchical_tasks_gravity(e, c->progeny[k]);
}
/**
* @brief Generate the stars hierarchical tasks for a hierarchy of cells -
* i.e. all the O(Npart) tasks -- star version
*
* Tasks are only created here. The dependencies will be added later on.
*
* Note that there is no need to recurse below the super-cell. Note also
* that we only add tasks if the relevant particles are present in the cell.
*
* @param e The #engine.
* @param c The #cell.
*/
void engine_make_hierarchical_tasks_stars(struct engine *e, struct cell *c) {
struct scheduler *s = &e->sched;
/* Are we in a super-cell ? */
if (c->super_hydro == c) {
/* Local tasks only... */
if (c->nodeID == e->nodeID) {
/* Generate the ghost tasks. */
c->star_ghost_in =
scheduler_addtask(s, task_type_star_ghost_in, task_subtype_none, 0,
/* implicit = */ 1, c, NULL);
c->star_ghost_out =
scheduler_addtask(s, task_type_star_ghost_out, task_subtype_none, 0,
/* implicit = */ 1, c, NULL);
engine_add_star_ghosts(e, c, c->star_ghost_in, c->star_ghost_out);
}
} else { /* We are above the super-cell so need to go deeper */
/* Recurse. */
if (c->split)
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_make_hierarchical_tasks_stars(e, c->progeny[k]);
}
}
void engine_make_hierarchical_tasks_mapper(void *map_data, int num_elements,
void *extra_data) {
struct engine *e = (struct engine *)extra_data;
......@@ -396,6 +462,7 @@ void engine_make_hierarchical_tasks_mapper(void *map_data, int num_elements,
const int is_with_self_gravity = (e->policy & engine_policy_self_gravity);
const int is_with_external_gravity =
(e->policy & engine_policy_external_gravity);
const int is_with_stars = (e->policy & engine_policy_stars);
for (int ind = 0; ind < num_elements; ind++) {
struct cell *c = &((struct cell *)map_data)[ind];
......@@ -406,6 +473,8 @@ void engine_make_hierarchical_tasks_mapper(void *map_data, int num_elements,
/* And the gravity stuff */
if (is_with_self_gravity || is_with_external_gravity)
engine_make_hierarchical_tasks_gravity(e, c);
if (is_with_stars)
engine_make_hierarchical_tasks_stars(e, c);
}
}
......@@ -2876,7 +2945,22 @@ static inline void engine_make_hydro_loops_dependencies(struct scheduler *sched,
scheduler_addunlock(sched, c->super_hydro->ghost_out, force);
}
#endif
/**
* @brief Creates the dependency network for the stars tasks of a given cell.
*
* @param sched The #scheduler.
* @param density The density task to link.
* @param c The cell.
*/
static inline void engine_make_stars_loops_dependencies(struct scheduler *sched,
struct task *density,
struct cell *c) {
/* density loop --> ghost */
scheduler_addunlock(sched, density, c->super_hydro->star_ghost_in);
}
/**
* @brief Duplicates the first hydro loop and construct all the
* dependencies for the hydro part
......@@ -2887,13 +2971,14 @@ static inline void engine_make_hydro_loops_dependencies(struct scheduler *sched,
* With all the relevant tasks for a given cell available, we construct
* all the dependencies for that cell.
*/
void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
void engine_make_extra_loop_tasks_mapper(void *map_data, int num_elements,
void *extra_data) {
struct engine *e = (struct engine *)extra_data;
struct scheduler *sched = &e->sched;
const int nodeID = e->nodeID;
const int with_cooling = (e->policy & engine_policy_cooling);
const int with_stars = (e->policy & engine_policy_stars);
for (int ind = 0; ind < num_elements; ind++) {
struct task *t = &((struct task *)map_data)[ind];
......@@ -2923,6 +3008,8 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
/* Now, build all the dependencies for the hydro */
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t3, t->ci->super->end_force);
#else
......@@ -2934,7 +3021,8 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
engine_addlink(e, &t->ci->force, t2);
/* Now, build all the dependencies for the hydro */
engine_make_hydro_loops_dependencies(sched, t, t2, t->ci, with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t2, t->ci->super->end_force);
#endif
}
......@@ -2970,12 +3058,18 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
if (t->ci->nodeID == nodeID) {
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t3, t->ci->super->end_force);
}
if (t->cj->nodeID == nodeID) {
if (t->ci->super_hydro != t->cj->super_hydro)
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->cj,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
if (t->ci->super != t->cj->super)
scheduler_addunlock(sched, t3, t->cj->super->end_force);
}
......@@ -2994,12 +3088,16 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
/* that are local and are not descendant of the same super_hydro-cells */
if (t->ci->nodeID == nodeID) {
engine_make_hydro_loops_dependencies(sched, t, t2, t->ci, with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t2, t->ci->super->end_force);
}
if (t->cj->nodeID == nodeID) {
if (t->ci->super_hydro != t->cj->super_hydro)
engine_make_hydro_loops_dependencies(sched, t, t2, t->cj,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
if (t->ci->super != t->cj->super)
scheduler_addunlock(sched, t2, t->cj->super->end_force);
}
......@@ -3035,6 +3133,8 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
if (t->ci->nodeID == nodeID) {
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t3, t->ci->super->end_force);
}
......@@ -3051,6 +3151,8 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
/* that are local and are not descendant of the same super_hydro-cells */
if (t->ci->nodeID == nodeID) {
engine_make_hydro_loops_dependencies(sched, t, t2, t->ci, with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t2, t->ci->super->end_force);
}
#endif
......@@ -3091,12 +3193,16 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
if (t->ci->nodeID == nodeID) {
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t3, t->ci->super->end_force);
}
if (t->cj->nodeID == nodeID) {
if (t->ci->super_hydro != t->cj->super_hydro)
engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->cj,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
if (t->ci->super != t->cj->super)
scheduler_addunlock(sched, t3, t->cj->super->end_force);
}
......@@ -3115,12 +3221,16 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
/* that are local and are not descendant of the same super_hydro-cells */
if (t->ci->nodeID == nodeID) {
engine_make_hydro_loops_dependencies(sched, t, t2, t->ci, with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t2, t->ci->super->end_force);
}
if (t->cj->nodeID == nodeID) {
if (t->ci->super_hydro != t->cj->super_hydro)
engine_make_hydro_loops_dependencies(sched, t, t2, t->cj,
with_cooling);
if (with_stars)
engine_make_stars_loops_dependencies(sched, t, t->ci);
if (t->ci->super != t->cj->super)
scheduler_addunlock(sched, t2, t->cj->super->end_force);
}
......
......@@ -97,6 +97,7 @@ enum engine_step_properties {
#define engine_default_energy_file_name "energy"
#define engine_default_timesteps_file_name "timesteps"
#define engine_max_parts_per_ghost 1000
#define engine_max_sparts_per_ghost 1000
/**
* @brief The rank of the engine as a global variable (for messages).
......@@ -394,7 +395,8 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params,
const struct unit_system *internal_units,
const struct phys_const *physical_constants,
struct cosmology *cosmo, const struct hydro_props *hydro,
struct gravity_props *gravity, struct pm_mesh *mesh,
struct gravity_props *gravity, const struct stars_props *stars,
struct pm_mesh *mesh,
const struct external_potential *potential,
const struct cooling_function_data *cooling_func,
const struct chemistry_global_data *chemistry,
......
......@@ -147,7 +147,6 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
struct spart *restrict sparts = c->sparts;
const struct engine *e = r->e;
const struct space *s = e->s;
const struct cosmology *cosmo = e->cosmology;
const struct stars_props *stars_properties = e->stars_properties;
const float star_h_max = e->stars_properties->h_max;
......@@ -171,7 +170,7 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
/* Init the list of active particles that have to be updated. */
int *sid = NULL;
if ((sid = (int *)malloc(sizeof(int) * c->scount)) == NULL)
error("Can't allocate memory for pid.");
error("Can't allocate memory for sid.");
for (int k = 0; k < c->scount; k++)
if (spart_is_active(&sparts[k], e)) {
sid[count] = k;
......@@ -303,23 +302,23 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
/* Self-interaction? */
if (l->t->type == task_type_self)
runner_doself_subset_star_density(r, finger, parts, pid, count);
runner_doself_subset_branch_star_density(r, finger, sparts, sid, count);
/* Otherwise, pair interaction? */
else if (l->t->type == task_type_pair) {
/* Left or right? */
if (l->t->ci == finger)
runner_dopair_subset_star_density(r, finger, parts, pid,
runner_dopair_subset_branch_star_density(r, finger, sparts, sid,
count, l->t->cj);
else
runner_dopair_subset_star_density(r, finger, parts, pid,
runner_dopair_subset_branch_star_density(r, finger, sparts, sid,
count, l->t->ci);
}
/* Otherwise, sub-self interaction? */
else if (l->t->type == task_type_sub_self)
runner_dosub_subset_density(r, finger, parts, pid, count, NULL,
runner_dosub_subset_star_density(r, finger, sparts, sid, count, NULL,
-1, 1);
/* Otherwise, sub-pair interaction? */
......@@ -327,10 +326,10 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
/* Left or right? */
if (l->t->ci == finger)
runner_dosub_subset_density(r, finger, parts, pid, count,
runner_dosub_subset_star_density(r, finger, sparts, sid, count,
l->t->cj, -1, 1);
else
runner_dosub_subset_density(r, finger, parts, pid, count,
runner_dosub_subset_star_density(r, finger, sparts, sid, count,
l->t->ci, -1, 1);
}
}
......
This diff is collapsed.
......@@ -1525,6 +1525,7 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) {
break;
case task_type_sort:
case task_type_ghost:
case task_type_star_ghost:
case task_type_drift_part:
qid = t->ci->super_hydro->owner;
break;
......
......@@ -33,7 +33,7 @@ INLINE static void star_read_particles(struct spart* sparts,
struct io_props* list, int* num_fields) {
/* Say how much we want to read */
*num_fields = 4;
*num_fields = 5;
/* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
......@@ -44,6 +44,8 @@ INLINE static void star_read_particles(struct spart* sparts,
sparts, mass);
list[3] = io_make_input_field("ParticleIDs", LONGLONG, 1, COMPULSORY,
UNIT_CONV_NO_UNITS, sparts, id);
list[4] = io_make_input_field("SmoothingLength", FLOAT, 1, COMPULSORY,
UNIT_CONV_LENGTH, sparts, h);
}
/**
......@@ -58,7 +60,7 @@ INLINE static void star_write_particles(const struct spart* sparts,
int* num_fields) {
/* Say how much we want to read */
*num_fields = 4;
*num_fields = 5;
/* List what we want to read */
list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH,
......@@ -69,6 +71,8 @@ INLINE static void star_write_particles(const struct spart* sparts,
io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass);
list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS,
sparts, id);
list[4] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH,
sparts, h);
}
/**
......@@ -122,7 +126,7 @@ INLINE static void stars_props_init(struct stars_props *sp,
*
* @param p The #stars_props.
*/
void stars_props_print(const struct stars_props *sp) {
INLINE static void stars_props_print(const struct stars_props *sp) {
/* Now stars */
message("Stars kernel: %s with eta=%f (%.2f neighbours).", kernel_name,
......@@ -144,7 +148,7 @@ void stars_props_print(const struct stars_props *sp) {
}
#if defined(HAVE_HDF5)
void stars_props_print_snapshot(hid_t h_grpstars, const struct stars_props *sp) {
INLINE static void stars_props_print_snapshot(hid_t h_grpstars, const struct stars_props *sp) {
io_write_attribute_s(h_grpstars, "Kernel function", kernel_name);
io_write_attribute_f(h_grpstars, "Kernel target N_ngb", sp->target_neighbours);
......@@ -167,7 +171,7 @@ void stars_props_print_snapshot(hid_t h_grpstars, const struct stars_props *sp)
* @param p the struct
* @param stream the file stream
*/
void stars_props_struct_dump(const struct stars_props *p, FILE *stream) {
INLINE static void stars_props_struct_dump(const struct stars_props *p, FILE *stream) {
restart_write_blocks((void *)p, sizeof(struct stars_props), 1, stream,
"starsprops", "stars props");
}
......@@ -179,7 +183,7 @@ void stars_props_struct_dump(const struct stars_props *p, FILE *stream) {
* @param p the struct
* @param stream the file stream
*/
void stars_props_struct_restore(const struct stars_props *p, FILE *stream) {
INLINE static void stars_props_struct_restore(const struct stars_props *p, FILE *stream) {
restart_read_blocks((void *)p, sizeof(struct stars_props), 1, stream, NULL,
"stars props");
}
......
......@@ -66,6 +66,8 @@
#include "single_io.h"
#include "sourceterms.h"
#include "space.h"
#include "stars.h"
#include "stars_io.h"
#include "task.h"
#include "threadpool.h"
#include "timeline.h"
......
......@@ -48,15 +48,16 @@
/* 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", "sourceterms"};
"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", "sourceterms",
"star_ghost_in", "star_ghost", "star_ghost_out"};
/* Sub-task type names. */
const char *subtaskID_names[task_subtype_count] = {
......
......@@ -66,6 +66,9 @@ enum task_types {
task_type_grav_mesh,
task_type_cooling,
task_type_sourceterms,
task_type_star_ghost_in,
task_type_star_ghost,
task_type_star_ghost_out,
task_type_count
} __attribute__((packed));
......
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