From 6b58e85ac542f77f464d7f493bc4601c8f82a84d Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Sun, 6 Jan 2019 17:27:06 +0100 Subject: [PATCH] Split the tasks before allocating the links. --- src/engine_maketasks.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c index 9ada090730..9aea036b7f 100644 --- a/src/engine_maketasks.c +++ b/src/engine_maketasks.c @@ -2068,20 +2068,6 @@ void engine_maketasks(struct engine *e) { if (e->sched.nr_tasks == 0 && (s->nr_gparts > 0 || s->nr_parts > 0)) error("We have particles but no hydro or gravity tasks were created."); - /* Free the old list of cell-task links. */ - if (e->links != NULL) free(e->links); - e->size_links = e->sched.nr_tasks * e->links_per_tasks; - - /* Make sure that we have space for more links than last time. */ - if (e->size_links < e->nr_links * engine_rebuild_link_alloc_margin) - e->size_links = e->nr_links * engine_rebuild_link_alloc_margin; - - /* Allocate the new link list */ - if ((e->links = (struct link *)malloc(sizeof(struct link) * e->size_links)) == - NULL) - error("Failed to allocate cell-task links."); - e->nr_links = 0; - tic2 = getticks(); /* Split the tasks. */ @@ -2099,6 +2085,20 @@ void engine_maketasks(struct engine *e) { } #endif + /* Free the old list of cell-task links. */ + if (e->links != NULL) free(e->links); + e->size_links = e->sched.nr_tasks * e->links_per_tasks; + + /* Make sure that we have space for more links than last time. */ + if (e->size_links < e->nr_links * engine_rebuild_link_alloc_margin) + e->size_links = e->nr_links * engine_rebuild_link_alloc_margin; + + /* Allocate the new link list */ + if ((e->links = (struct link *)malloc(sizeof(struct link) * e->size_links)) == + NULL) + error("Failed to allocate cell-task links."); + e->nr_links = 0; + tic2 = getticks(); /* Count the number of tasks associated with each cell and -- GitLab