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

Add support for swift_malloc and implement for some large looking allocations

parent 39bc5a65
......@@ -1815,14 +1815,14 @@ void cell_clean(struct cell *c) {
/* Hydro */
for (int i = 0; i < 13; i++)
if (c->hydro.sort[i] != NULL) {
free(c->hydro.sort[i]);
swift_free("hydro.sorts", c->hydro.sort[i]);
c->hydro.sort[i] = NULL;
}
/* Stars */
for (int i = 0; i < 13; i++)
if (c->stars.sort[i] != NULL) {
free(c->stars.sort[i]);
swift_free("stars.sort", c->stars.sort[i]);
c->stars.sort[i] = NULL;
}
......@@ -4299,7 +4299,7 @@ void cell_clear_stars_sort_flags(struct cell *c, const int is_super) {
#endif
for (int i = 0; i < 13; i++) {
free(c->stars.sort[i]);
swift_free("stars.sort", c->stars.sort[i]);
}
}
......
......@@ -632,7 +632,7 @@ void engine_redistribute(struct engine *e) {
error("Failed to allocate counts temporary buffer.");
int *dest;
if ((dest = (int *)malloc(sizeof(int) * nr_parts)) == NULL)
if ((dest = (int *)swift_malloc("dest", sizeof(int) * nr_parts)) == NULL)
error("Failed to allocate dest temporary buffer.");
/* Simple index of node IDs, used for mappers over nodes. */
......@@ -695,7 +695,7 @@ void engine_redistribute(struct engine *e) {
threadpool_map(&e->threadpool, engine_redistribute_savelink_mapper_part,
nodes, nr_nodes, sizeof(int), 0, &savelink_data);
}
free(dest);
swift_free("dest", dest);
/* Get destination of each s-particle */
int *s_counts;
......@@ -703,7 +703,7 @@ void engine_redistribute(struct engine *e) {
error("Failed to allocate s_counts temporary buffer.");
int *s_dest;
if ((s_dest = (int *)malloc(sizeof(int) * nr_sparts)) == NULL)
if ((s_dest = (int *)swift_malloc("s_dest", sizeof(int) * nr_sparts)) == NULL)
error("Failed to allocate s_dest temporary buffer.");
redist_data.counts = s_counts;
......@@ -753,7 +753,7 @@ void engine_redistribute(struct engine *e) {
threadpool_map(&e->threadpool, engine_redistribute_savelink_mapper_spart,
nodes, nr_nodes, sizeof(int), 0, &savelink_data);
}
free(s_dest);
swift_free("s_dest", s_dest);
/* Get destination of each g-particle */
int *g_counts;
......@@ -761,7 +761,7 @@ void engine_redistribute(struct engine *e) {
error("Failed to allocate g_gcount temporary buffer.");
int *g_dest;
if ((g_dest = (int *)malloc(sizeof(int) * nr_gparts)) == NULL)
if ((g_dest = (int *)swift_malloc("g_dest", sizeof(int) * nr_gparts)) == NULL)
error("Failed to allocate g_dest temporary buffer.");
redist_data.counts = g_counts;
......@@ -801,7 +801,7 @@ void engine_redistribute(struct engine *e) {
}
#endif
free(g_dest);
swift_free("g_dest", g_dest);
/* Get all the counts from all the nodes. */
if (MPI_Allreduce(MPI_IN_PLACE, counts, nr_nodes * nr_nodes, MPI_INT, MPI_SUM,
......@@ -4005,7 +4005,8 @@ void engine_collect_stars_counter(struct engine *e) {
}
/* Get all sparticles */
struct spart *sparts = (struct spart *)malloc(total * sizeof(struct spart));
struct spart *sparts =
(struct spart *)swift_malloc("sparts", total * sizeof(struct spart));
err = MPI_Allgatherv(e->s->sparts_foreign, e->s->nr_sparts_foreign,
spart_mpi_type, sparts, n_sparts_int, displs,
spart_mpi_type, MPI_COMM_WORLD);
......@@ -5392,7 +5393,7 @@ void engine_clean(struct engine *e) {
output_list_clean(&e->output_list_stats);
output_list_clean(&e->output_list_stf);
free(e->links);
swift_free("links", e->links);
#if defined(WITH_LOGGER)
logger_clean(e->logger);
free(e->logger);
......
......@@ -2289,7 +2289,7 @@ void engine_maketasks(struct engine *e) {
#endif
/* Free the old list of cell-task links. */
if (e->links != NULL) free(e->links);
if (e->links != NULL) swift_free("links", 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. */
......@@ -2297,8 +2297,8 @@ void engine_maketasks(struct engine *e) {
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)
if ((e->links = (struct link *)swift_malloc(
"links", sizeof(struct link) * e->size_links)) == NULL)
error("Failed to allocate cell-task links.");
e->nr_links = 0;
......
......@@ -34,11 +34,16 @@ const char *memuse_process(int inmb);
void memuse_log_dump(const char *filename);
void memuse_log_allocation(const char *label, void *ptr, int allocated,
size_t size);
#else
/* No-op when not reporting. */
#define memuse_log_allocation(label, ptr, allocated, size)
#endif
/**
* @brief allocate aligned memory. The use and results are the same as the
* posix_memalign function.
* posix_memalign function. This function should be used for any
* significant allocations and consistently labelled.
*
* @param label a symbolic label for the memory, i.e. "parts".
* @param memptr pointer to the allocated memory.
......@@ -57,12 +62,32 @@ __attribute__((always_inline)) inline int swift_memalign(const char *label,
return result;
}
/**
* @brief allocate memory. The use and results are the same as the
* malloc function. This function should be used for any
* _significant_ allocations and consistently labelled.
* Do not use this function for small or high frequency
* allocations in production code.
*
* @param label a symbolic label for the memory, i.e. "parts".
* @param size the quantity of bytes to allocate.
* @result pointer to the allocated memory or NULL on failure.
*/
__attribute__((always_inline)) inline void *swift_malloc(const char *label,
size_t size) {
void *memptr = malloc(size);
#ifdef SWIFT_MEMUSE_REPORTS
if (memptr != NULL) memuse_log_allocation(label, memptr, 1, size);
#endif
return memptr;
}
/**
* @brief free aligned memory. The use and results are the same as the
* free function.
* free function. The label should match a prior call to swift_memalign
* or swift_malloc.
*
* @param label a symbolic label for the memory, i.e. "parts", should match
* call used to allocate the memory.
* @param label a symbolic label for the memory, i.e. "parts".
* @param ptr pointer to the allocated memory.
*/
__attribute__((always_inline)) inline void swift_free(const char *label,
......
......@@ -389,6 +389,8 @@ void pm_mesh_compute_potential(struct pm_mesh* mesh, const struct space* s,
(fftw_complex*)fftw_malloc(sizeof(fftw_complex) * N * N * (N_half + 1));
if (frho == NULL)
error("Error allocating memory for transform of density mesh");
memuse_log_allocation("fftw_frho", frho, 1,
sizeof(fftw_complex) * N * N * (N_half + 1));
/* Prepare the FFT library */
fftw_plan forward_plan = fftw_plan_dft_r2c_3d(
......@@ -537,6 +539,7 @@ void pm_mesh_compute_potential(struct pm_mesh* mesh, const struct space* s,
/* Clean-up the mess */
fftw_destroy_plan(forward_plan);
fftw_destroy_plan(inverse_plan);
memuse_log_allocation("fftw_frho", frho, 0, 0);
fftw_free(frho);
#else
......@@ -636,6 +639,9 @@ void pm_mesh_init(struct pm_mesh* mesh, const struct gravity_props* props,
mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N);
if (mesh->potential == NULL)
error("Error allocating memory for the long-range gravity mesh.");
memuse_log_allocation("fftw_mesh.potential", mesh->potential, 1,
sizeof(double) * N * N * N);
#else
error("No FFTW library found. Cannot compute periodic long-range forces.");
#endif
......@@ -674,7 +680,10 @@ void pm_mesh_clean(struct pm_mesh* mesh) {
fftw_cleanup_threads();
#endif
if (mesh->potential) free(mesh->potential);
if (mesh->potential) {
memuse_log_allocation("fftw_mesh.potential", mesh->potential, 0, 0);
free(mesh->potential);
}
mesh->potential = 0;
}
......@@ -718,6 +727,8 @@ void pm_mesh_struct_restore(struct pm_mesh* mesh, FILE* stream) {
mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N);
if (mesh->potential == NULL)
error("Error allocating memory for the long-range gravity mesh.");
memuse_log_allocation("fftw_mesh.potential", mesh->potential, 1,
sizeof(double) * N * N * N);
#else
error("No FFTW library found. Cannot compute periodic long-range forces.");
#endif
......
......@@ -473,7 +473,7 @@ void writeArray_chunk(struct engine* e, hid_t h_data,
/* Allocate temporary buffer */
void* temp = NULL;
if (swift_memalign("temp", (void**)&temp, IO_BUFFER_ALIGNMENT,
if (swift_memalign("writetemp", (void**)&temp, IO_BUFFER_ALIGNMENT,
num_elements * typeSize) != 0)
error("Unable to allocate temporary i/o buffer");
......@@ -557,7 +557,7 @@ void writeArray_chunk(struct engine* e, hid_t h_data,
#endif
/* Free and close everything */
swift_free("temp", temp);
swift_free("writetemp", temp);
H5Sclose(h_memspace);
H5Sclose(h_filespace);
}
......
......@@ -650,30 +650,30 @@ void proxy_parts_exchange_second(struct proxy *p) {
do {
p->size_parts_in *= proxy_buffgrow;
} while (p->nr_parts_in > p->size_parts_in);
free(p->parts_in);
free(p->xparts_in);
if ((p->parts_in = (struct part *)malloc(sizeof(struct part) *
p->size_parts_in)) == NULL ||
(p->xparts_in = (struct xpart *)malloc(sizeof(struct xpart) *
p->size_parts_in)) == NULL)
swift_free("parts_in", p->parts_in);
swift_free("xparts_in", p->xparts_in);
if ((p->parts_in = (struct part *)swift_malloc(
"parts_in", sizeof(struct part) * p->size_parts_in)) == NULL ||
(p->xparts_in = (struct xpart *)swift_malloc(
"xparts_in", sizeof(struct xpart) * p->size_parts_in)) == NULL)
error("Failed to re-allocate parts_in buffers.");
}
if (p->nr_gparts_in > p->size_gparts_in) {
do {
p->size_gparts_in *= proxy_buffgrow;
} while (p->nr_gparts_in > p->size_gparts_in);
free(p->gparts_in);
if ((p->gparts_in = (struct gpart *)malloc(sizeof(struct gpart) *
p->size_gparts_in)) == NULL)
swift_free("gparts_in", p->gparts_in);
if ((p->gparts_in = (struct gpart *)swift_malloc(
"gparts_in", sizeof(struct gpart) * p->size_gparts_in)) == NULL)
error("Failed to re-allocate gparts_in buffers.");
}
if (p->nr_sparts_in > p->size_sparts_in) {
do {
p->size_sparts_in *= proxy_buffgrow;
} while (p->nr_sparts_in > p->size_sparts_in);
free(p->sparts_in);
if ((p->sparts_in = (struct spart *)malloc(sizeof(struct spart) *
p->size_sparts_in)) == NULL)
swift_free("sparts_in", p->sparts_in);
if ((p->sparts_in = (struct spart *)swift_malloc(
"sparts_in", sizeof(struct spart) * p->size_sparts_in)) == NULL)
error("Failed to re-allocate sparts_in buffers.");
}
......@@ -729,15 +729,15 @@ void proxy_parts_load(struct proxy *p, const struct part *parts,
} while (p->nr_parts_out + N > p->size_parts_out);
struct part *tp = NULL;
struct xpart *txp = NULL;
if ((tp = (struct part *)malloc(sizeof(struct part) * p->size_parts_out)) ==
NULL ||
(txp = (struct xpart *)malloc(sizeof(struct xpart) *
p->size_parts_out)) == NULL)
if ((tp = (struct part *)swift_malloc(
"parts_out", sizeof(struct part) * p->size_parts_out)) == NULL ||
(txp = (struct xpart *)swift_malloc(
"xparts_out", sizeof(struct xpart) * p->size_parts_out)) == NULL)
error("Failed to re-allocate parts_out buffers.");
memcpy(tp, p->parts_out, sizeof(struct part) * p->nr_parts_out);
memcpy(txp, p->xparts_out, sizeof(struct xpart) * p->nr_parts_out);
free(p->parts_out);
free(p->xparts_out);
swift_free("parts_out", p->parts_out);
swift_free("xparts_out", p->xparts_out);
p->parts_out = tp;
p->xparts_out = txp;
}
......@@ -765,11 +765,11 @@ void proxy_gparts_load(struct proxy *p, const struct gpart *gparts, int N) {
p->size_gparts_out *= proxy_buffgrow;
} while (p->nr_gparts_out + N > p->size_gparts_out);
struct gpart *tp;
if ((tp = (struct gpart *)malloc(sizeof(struct gpart) *
p->size_gparts_out)) == NULL)
if ((tp = (struct gpart *)swift_malloc(
"gparts_out", sizeof(struct gpart) * p->size_gparts_out)) == NULL)
error("Failed to re-allocate gparts_out buffers.");
memcpy(tp, p->gparts_out, sizeof(struct gpart) * p->nr_gparts_out);
free(p->gparts_out);
swift_free("gparts_out", p->gparts_out);
p->gparts_out = tp;
}
......@@ -795,11 +795,11 @@ void proxy_sparts_load(struct proxy *p, const struct spart *sparts, int N) {
p->size_sparts_out *= proxy_buffgrow;
} while (p->nr_sparts_out + N > p->size_sparts_out);
struct spart *tp;
if ((tp = (struct spart *)malloc(sizeof(struct spart) *
p->size_sparts_out)) == NULL)
if ((tp = (struct spart *)swift_malloc(
"sparts_out", sizeof(struct spart) * p->size_sparts_out)) == NULL)
error("Failed to re-allocate sparts_out buffers.");
memcpy(tp, p->sparts_out, sizeof(struct spart) * p->nr_sparts_out);
free(p->sparts_out);
swift_free("sparts_out", p->sparts_out);
p->sparts_out = tp;
}
......@@ -848,19 +848,19 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
/* Allocate the part send and receive buffers, if needed. */
if (p->parts_in == NULL) {
p->size_parts_in = proxy_buffinit;
if ((p->parts_in = (struct part *)malloc(sizeof(struct part) *
p->size_parts_in)) == NULL ||
(p->xparts_in = (struct xpart *)malloc(sizeof(struct xpart) *
p->size_parts_in)) == NULL)
if ((p->parts_in = (struct part *)swift_malloc(
"parts_in", sizeof(struct part) * p->size_parts_in)) == NULL ||
(p->xparts_in = (struct xpart *)swift_malloc(
"xparts_in", sizeof(struct xpart) * p->size_parts_in)) == NULL)
error("Failed to allocate parts_in buffers.");
}
p->nr_parts_in = 0;
if (p->parts_out == NULL) {
p->size_parts_out = proxy_buffinit;
if ((p->parts_out = (struct part *)malloc(sizeof(struct part) *
p->size_parts_out)) == NULL ||
(p->xparts_out = (struct xpart *)malloc(sizeof(struct xpart) *
p->size_parts_out)) == NULL)
if ((p->parts_out = (struct part *)swift_malloc(
"parts_out", sizeof(struct part) * p->size_parts_out)) == NULL ||
(p->xparts_out = (struct xpart *)swift_malloc(
"xparts_out", sizeof(struct xpart) * p->size_parts_out)) == NULL)
error("Failed to allocate parts_out buffers.");
}
p->nr_parts_out = 0;
......@@ -868,15 +868,15 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
/* Allocate the gpart send and receive buffers, if needed. */
if (p->gparts_in == NULL) {
p->size_gparts_in = proxy_buffinit;
if ((p->gparts_in = (struct gpart *)malloc(sizeof(struct gpart) *
p->size_gparts_in)) == NULL)
if ((p->gparts_in = (struct gpart *)swift_malloc(
"gparts_in", sizeof(struct gpart) * p->size_gparts_in)) == NULL)
error("Failed to allocate gparts_in buffers.");
}
p->nr_gparts_in = 0;
if (p->gparts_out == NULL) {
p->size_gparts_out = proxy_buffinit;
if ((p->gparts_out = (struct gpart *)malloc(sizeof(struct gpart) *
p->size_gparts_out)) == NULL)
if ((p->gparts_out = (struct gpart *)swift_malloc(
"gparts_out", sizeof(struct gpart) * p->size_gparts_out)) == NULL)
error("Failed to allocate gparts_out buffers.");
}
p->nr_gparts_out = 0;
......@@ -884,15 +884,15 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
/* Allocate the spart send and receive buffers, if needed. */
if (p->sparts_in == NULL) {
p->size_sparts_in = proxy_buffinit;
if ((p->sparts_in = (struct spart *)malloc(sizeof(struct spart) *
p->size_sparts_in)) == NULL)
if ((p->sparts_in = (struct spart *)swift_malloc(
"sparts_in", sizeof(struct spart) * p->size_sparts_in)) == NULL)
error("Failed to allocate sparts_in buffers.");
}
p->nr_sparts_in = 0;
if (p->sparts_out == NULL) {
p->size_sparts_out = proxy_buffinit;
if ((p->sparts_out = (struct spart *)malloc(sizeof(struct spart) *
p->size_sparts_out)) == NULL)
if ((p->sparts_out = (struct spart *)swift_malloc(
"sparts_out", sizeof(struct spart) * p->size_sparts_out)) == NULL)
error("Failed to allocate sparts_out buffers.");
}
p->nr_sparts_out = 0;
......
......@@ -816,8 +816,9 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flags,
/* start by allocating the entry arrays in the requested dimensions. */
for (int j = 0; j < 13; j++) {
if ((flags & (1 << j)) && c->hydro.sort[j] == NULL) {
if ((c->hydro.sort[j] = (struct entry *)malloc(sizeof(struct entry) *
(count + 1))) == NULL)
if ((c->hydro.sort[j] = (struct entry *)
swift_malloc("hydro.sort", sizeof(struct entry) *
(count + 1))) == NULL)
error("Failed to allocate sort memory.");
}
}
......@@ -1041,8 +1042,8 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags,
/* start by allocating the entry arrays in the requested dimensions. */
for (int j = 0; j < 13; j++) {
if ((flags & (1 << j)) && c->stars.sort[j] == NULL) {
if ((c->stars.sort[j] = (struct entry *)malloc(sizeof(struct entry) *
(count + 1))) == NULL)
if ((c->stars.sort[j] = (struct entry *)swift_malloc(
"stars.sort", sizeof(struct entry) * (count + 1))) == NULL)
error("Failed to allocate sort memory.");
}
}
......
......@@ -68,9 +68,10 @@ static void scheduler_extend_unlocks(struct scheduler *s) {
/* Allocate the new buffer. */
const int size_unlocks_new = s->size_unlocks * 2;
struct task **unlocks_new =
(struct task **)malloc(sizeof(struct task *) * size_unlocks_new);
int *unlock_ind_new = (int *)malloc(sizeof(int) * size_unlocks_new);
struct task **unlocks_new = (struct task **)swift_malloc(
"unlocks", sizeof(struct task *) * size_unlocks_new);
int *unlock_ind_new =
(int *)swift_malloc("unlock_ind", sizeof(int) * size_unlocks_new);
if (unlocks_new == NULL || unlock_ind_new == NULL)
error("Failed to re-allocate unlocks.");
......@@ -1322,7 +1323,8 @@ void scheduler_set_unlocks(struct scheduler *s) {
/* Store the counts for each task. */
short int *counts;
if ((counts = (short int *)malloc(sizeof(short int) * s->nr_tasks)) == NULL)
if ((counts = (short int *)swift_malloc(
"counts", sizeof(short int) * s->nr_tasks)) == NULL)
error("Failed to allocate temporary counts array.");
bzero(counts, sizeof(short int) * s->nr_tasks);
for (int k = 0; k < s->nr_unlocks; k++) {
......@@ -1340,7 +1342,8 @@ void scheduler_set_unlocks(struct scheduler *s) {
/* Compute the offset for each unlock block. */
int *offsets;
if ((offsets = (int *)malloc(sizeof(int) * (s->nr_tasks + 1))) == NULL)
if ((offsets = (int *)swift_malloc("offsets",
sizeof(int) * (s->nr_tasks + 1))) == NULL)
error("Failed to allocate temporary offsets array.");
offsets[0] = 0;
for (int k = 0; k < s->nr_tasks; k++) {
......@@ -1354,8 +1357,8 @@ void scheduler_set_unlocks(struct scheduler *s) {
/* Create and fill a temporary array with the sorted unlocks. */
struct task **unlocks;
if ((unlocks = (struct task **)malloc(sizeof(struct task *) *
s->size_unlocks)) == NULL)
if ((unlocks = (struct task **)swift_malloc(
"unlocks", sizeof(struct task *) * s->size_unlocks)) == NULL)
error("Failed to allocate temporary unlocks array.");
for (int k = 0; k < s->nr_unlocks; k++) {
const int ind = s->unlock_ind[k];
......@@ -1396,8 +1399,8 @@ void scheduler_set_unlocks(struct scheduler *s) {
#endif
/* Clean up. */
free(counts);
free(offsets);
swift_free("counts", counts);
swift_free("offsets", offsets);
}
/**
......@@ -1483,10 +1486,12 @@ void scheduler_reset(struct scheduler *s, int size) {
size * sizeof(struct task)) != 0)
error("Failed to allocate task array.");
if ((s->tasks_ind = (int *)malloc(sizeof(int) * size)) == NULL)
if ((s->tasks_ind = (int *)swift_malloc("tasks_ind", sizeof(int) * size)) ==
NULL)
error("Failed to allocate task lists.");
if ((s->tid_active = (int *)malloc(sizeof(int) * size)) == NULL)
if ((s->tid_active =
(int *)swift_malloc("tid_active", sizeof(int) * size)) == NULL)
error("Failed to allocate aactive task lists.");
}
......@@ -2161,10 +2166,11 @@ void scheduler_init(struct scheduler *s, struct space *space, int nr_tasks,
error("Failed to initialize sleep barrier.");
/* Init the unlocks. */
if ((s->unlocks = (struct task **)malloc(
sizeof(struct task *) * scheduler_init_nr_unlocks)) == NULL ||
(s->unlock_ind =
(int *)malloc(sizeof(int) * scheduler_init_nr_unlocks)) == NULL)
if ((s->unlocks = (struct task **)swift_malloc(
"unlocks", sizeof(struct task *) * scheduler_init_nr_unlocks)) ==
NULL ||
(s->unlock_ind = (int *)swift_malloc(
"unlock_ind", sizeof(int) * scheduler_init_nr_unlocks)) == NULL)
error("Failed to allocate unlocks.");
s->nr_unlocks = 0;
s->size_unlocks = scheduler_init_nr_unlocks;
......
......@@ -365,7 +365,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
/* Allocate temporary buffer */
void* temp = NULL;
if (swift_memalign("temp", (void**)&temp, IO_BUFFER_ALIGNMENT,
if (swift_memalign("writetemp", (void**)&temp, IO_BUFFER_ALIGNMENT,
num_elements * typeSize) != 0)
error("Unable to allocate temporary i/o buffer");
......@@ -416,7 +416,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
if (h_err < 0) error("Error while writing data array '%s'.", props.name);
/* Free and close everything */
swift_free("temp", temp);
swift_free("writetemp", temp);
H5Dclose(h_data);
H5Sclose(h_memspace);
H5Sclose(h_filespace);
......
......@@ -241,7 +241,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
/* Allocate temporary buffer */
void* temp = NULL;
if (swift_memalign("temp", (void**)&temp, IO_BUFFER_ALIGNMENT,
if (swift_memalign("writetemp", (void**)&temp, IO_BUFFER_ALIGNMENT,
num_elements * typeSize) != 0)
error("Unable to allocate temporary i/o buffer");
......@@ -333,7 +333,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
io_write_attribute_s(h_data, "Conversion factor", buffer);
/* Free and close everything */
free(temp);
swift_free("writetemp", temp);
H5Pclose(h_prop);
H5Dclose(h_data);
H5Sclose(h_space);
......
......@@ -261,13 +261,14 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements,
#endif
if (s->with_self_gravity)
bzero(c->grav.multipole, sizeof(struct gravity_tensors));
for (int i = 0; i < 13; i++) {
if (c->hydro.sort[i] != NULL) {
free(c->hydro.sort[i]);
swift_free("hydro.sort", c->hydro.sort[i]);
c->hydro.sort[i] = NULL;
}
if (c->stars.sort[i] != NULL) {
free(c->stars.sort[i]);
swift_free("stars.sort", c->stars.sort[i]);
c->stars.sort[i] = NULL;
}
}
......@@ -416,7 +417,8 @@ void space_regrid(struct space *s, int verbose) {
oldwidth[1] = s->width[1];
oldwidth[2] = s->width[2];
if ((oldnodeIDs = (int *)malloc(sizeof(int) * s->nr_cells)) == NULL)
if ((oldnodeIDs =
(int *)swift_malloc("nodeIDs", sizeof(int) * s->nr_cells)) == NULL)
error("Failed to allocate temporary nodeIDs.");
int cid = 0;
......@@ -609,7 +611,7 @@ void space_regrid(struct space *s, int verbose) {
engine_makeproxies(s->e);
/* Finished with these. */
free(oldnodeIDs);
swift_free("nodeIDs", oldnodeIDs);
} else if (no_regrid && s->e != NULL) {
/* If we have created the top-levels cells and not done an initial
......@@ -1033,16 +1035,19 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) {
/* Allocate arrays to store the indices of the cells where particles
belong. We allocate extra space to allow for particles we may
receive from other nodes */
int *h_index = (int *)malloc(sizeof(int) * h_index_size);
int *g_index = (int *)malloc(sizeof(int) * g_index_size);
int *s_index = (int *)malloc(sizeof(int) * s_index_size);
int *h_index = (int *)swift_malloc("h_index", sizeof(int) * h_index_size);
int *g_index = (int *)swift_malloc("g_index", sizeof(int) * g_index_size);
int *s_index = (int *)swift_malloc("s_index", sizeof(int) * s_index_size);
if (h_index == NULL || g_index == NULL || s_index == NULL)
error("Failed to allocate temporary particle indices.");
/* Allocate counters of particles that will land in each cell */
int *cell_part_counts = (int *)malloc(sizeof(int) * s->nr_cells);
int *cell_gpart_counts = (int *)malloc(sizeof(int) * s->nr_cells);
int *cell_spart_counts = (int *)malloc(sizeof(int) * s->nr_cells);