From c47a27bf041e03c9e0c89259b820a517d1e1f424 Mon Sep 17 00:00:00 2001
From: Aidan Chalk <aidan.chalk@stfc.ac.uk>
Date: Thu, 22 Nov 2018 17:21:33 +0000
Subject: [PATCH] Threadpoolized version of numa_helper function

---
 src/numa_helper.c | 15 +++++++++++++++
 src/numa_helper.h |  1 +
 src/space.c       |  7 ++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/numa_helper.c b/src/numa_helper.c
index 5f9fa9011f..6057ae3efb 100644
--- a/src/numa_helper.c
+++ b/src/numa_helper.c
@@ -43,6 +43,21 @@
 #include "cell.h"
 
 
+/**
+ * @brief threadpool mapping function for hydro parts NUMA movement.
+ * 
+ *
+ */
+void swiftnuma_cell_move_hydro_parts_threadpool_map(void *map_data, int num_elements, void *extra_data){
+
+  struct cell *cells = (struct cell *) map_data;
+  int32_t *nodes = (int32_t *)extra_data;
+
+  for(int32_t i = 0; i < num_elements; i++){
+    swiftnuma_cell_move_hydro_parts(&cells[i], nodes[i], 1);
+  }
+
+}
 
 /**
  * @brief Move a cell structure's hydro parts into a single NUMA region.
diff --git a/src/numa_helper.h b/src/numa_helper.h
index 68912b8589..a1803ff7f8 100644
--- a/src/numa_helper.h
+++ b/src/numa_helper.h
@@ -22,6 +22,7 @@
 #include <stdint.h>
 #include "cell.h"
 
+void swiftnuma_cell_move_hydro_parts_threadpool_map(void *map_data, int num_elements, void *extra_data);
 void swiftnuma_cell_move_hydro_parts(struct cell *c, int32_t node, int32_t verbose);
 
 #endif
diff --git a/src/space.c b/src/space.c
index 6ff5677532..24d878b313 100644
--- a/src/space.c
+++ b/src/space.c
@@ -1169,10 +1169,15 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) {
   /* Move pages for each cell's particles to be in a single NUMA region.*/
   //TODO This doesn't make use of NUMA information yet so just assumes we have 2 domains...
     int32_t numanode = 0;
+    int32_t *nodes = malloc(sizeof(int32_t) * s->nr_cells);
     for(int32_t i = 0; i < s->nr_cells; i++){
       if( i > s->nr_cells/2) numanode=1;
-      swiftnuma_cell_move_hydro_parts(&cells_top[i],numanode,1);
+      nodes[i] = numanode;
+//      swiftnuma_cell_move_hydro_parts(&cells_top[i],numanode,1);
     }
+    threadpool_map(s->e->tp, &swiftnuma_cell_move_hydro_parts_threadpool_map, s->c, s->nr_cells,
+                      sizeof(struct cell), 0, nodes);
+    free(nodes);
 #endif
 
   if (verbose)
-- 
GitLab