Commit 261f9327 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'number_of_links' into 'master'

Correct number of links in engine_maketasks()

Correctly count the number of cell->task links required and only create the necessary number given the engine policy.

This fixes a bug reported by @lhausammann when testing a simple hydro + self-gravity box. 

It will also (very marginally) reduce the memory footprint in the purely hydro cases.

See merge request !361
parents 4e5a2ecc 080200da
......@@ -2417,17 +2417,31 @@ void engine_maketasks(struct engine *e) {
/* Split the tasks. */
scheduler_splittasks(sched);
/* Allocate the list of cell-task links. The maximum number of links is the
* number of cells (s->tot_cells) times the number of neighbours (26) times
* the number of interaction types, so 26 * 3 (density, force, grav) pairs
* and 4 (density, force, grav, ext_grav) self.
*/
/* Free the old list of cell-task links. */
if (e->links != NULL) free(e->links);
e->size_links = 0;
/* The maximum number of links is the
* number of cells (s->tot_cells) times the number of neighbours (26) times
* the number of interaction types, so 26 * 2 (density, force) pairs
* and 2 (density, force) self.
*/
#ifdef EXTRA_HYDRO_LOOP
e->size_links = s->tot_cells * (26 * 4 + 4);
const int hydro_tasks_per_cell = 27 * 3;
#else
e->size_links = s->tot_cells * (26 * 3 + 4);
const int hydro_tasks_per_cell = 27 * 2;
#endif
const int self_grav_tasks_per_cell = 27 * 2;
const int ext_grav_tasks_per_cell = 1;
if (e->policy & engine_policy_hydro)
e->size_links += s->tot_cells * hydro_tasks_per_cell;
if (e->policy & engine_policy_external_gravity)
e->size_links += s->tot_cells * ext_grav_tasks_per_cell;
if (e->policy & engine_policy_self_gravity)
e->size_links += s->tot_cells * self_grav_tasks_per_cell;
/* Allocate the new list */
if ((e->links = malloc(sizeof(struct link) * e->size_links)) == NULL)
error("Failed to allocate cell-task links.");
e->nr_links = 0;
......
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