diff --git a/examples/main.c b/examples/main.c index b816039e73795a6e1e338f1f0a020b0b7cc2b810..3b2b976d94374ce44f74cd92dea8f7d594610e95 100644 --- a/examples/main.c +++ b/examples/main.c @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) { /* Make sure messages are stamped with the correct rank and step. */ engine_rank = myrank; - engine_cstep = 0; + engine_current_step = 0; if ((res = MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN)) != MPI_SUCCESS) @@ -1049,7 +1049,6 @@ int main(int argc, char *argv[]) { } #endif - /* Main simulation loop */ /* ==================== */ int force_stop = 0, resubmit = 0; @@ -1097,7 +1096,7 @@ int main(int argc, char *argv[]) { task_dump_stats(dumpfile, &e, /* header = */ 0, /* allranks = */ 1); } - /* Dump memory use report if collected. */ + /* Dump memory use report if collected. */ #ifdef SWIFT_MEMUSE_REPORTS { char dumpfile[40]; diff --git a/src/engine.c b/src/engine.c index 9481f653efaa0758acf92bedbf30472e9b11d639..db5368a4e6667bb3af4097416dfc955d54b821de 100644 --- a/src/engine.c +++ b/src/engine.c @@ -123,7 +123,7 @@ const char *engine_policy_names[] = {"none", int engine_rank; /** The current step of the engine as a global variable (for messages). */ -int engine_cstep; +int engine_current_step; /** * @brief Data collected from the cells at the end of a time-step @@ -182,15 +182,15 @@ void engine_addlink(struct engine *e, struct link **l, struct task *t) { * @result new particle data constructed from all the exchanges with the * given alignment. */ -static void *engine_do_redistribute(const char * label, int *counts, char *parts, +static void *engine_do_redistribute(const char *label, int *counts, char *parts, size_t new_nr_parts, size_t sizeofparts, size_t alignsize, MPI_Datatype mpi_type, int nr_nodes, int nodeID) { /* Allocate a new particle array with some extra margin */ char *parts_new = NULL; - if (swift_memalign(label, - (void **)&parts_new, alignsize, + if (swift_memalign( + label, (void **)&parts_new, alignsize, sizeofparts * new_nr_parts * engine_redistribute_alloc_margin) != 0) error("Failed to allocate new particle data."); @@ -865,34 +865,34 @@ void engine_redistribute(struct engine *e) { * under control. */ /* SPH particles. */ - void *new_parts = engine_do_redistribute("parts", - counts, (char *)s->parts, nr_parts_new, sizeof(struct part), part_align, - part_mpi_type, nr_nodes, nodeID); + void *new_parts = engine_do_redistribute( + "parts", counts, (char *)s->parts, nr_parts_new, sizeof(struct part), + part_align, part_mpi_type, nr_nodes, nodeID); swift_free("parts", s->parts); s->parts = (struct part *)new_parts; s->nr_parts = nr_parts_new; s->size_parts = engine_redistribute_alloc_margin * nr_parts_new; /* Extra SPH particle properties. */ - new_parts = engine_do_redistribute("xparts", counts, (char *)s->xparts, nr_parts_new, - sizeof(struct xpart), xpart_align, - xpart_mpi_type, nr_nodes, nodeID); + new_parts = engine_do_redistribute( + "xparts", counts, (char *)s->xparts, nr_parts_new, sizeof(struct xpart), + xpart_align, xpart_mpi_type, nr_nodes, nodeID); swift_free("xparts", s->xparts); s->xparts = (struct xpart *)new_parts; /* Gravity particles. */ - new_parts = engine_do_redistribute("gparts", g_counts, (char *)s->gparts, nr_gparts_new, - sizeof(struct gpart), gpart_align, - gpart_mpi_type, nr_nodes, nodeID); + new_parts = engine_do_redistribute( + "gparts", g_counts, (char *)s->gparts, nr_gparts_new, + sizeof(struct gpart), gpart_align, gpart_mpi_type, nr_nodes, nodeID); swift_free("gparts", s->gparts); s->gparts = (struct gpart *)new_parts; s->nr_gparts = nr_gparts_new; s->size_gparts = engine_redistribute_alloc_margin * nr_gparts_new; /* Star particles. */ - new_parts = engine_do_redistribute("sparts", s_counts, (char *)s->sparts, nr_sparts_new, - sizeof(struct spart), spart_align, - spart_mpi_type, nr_nodes, nodeID); + new_parts = engine_do_redistribute( + "sparts", s_counts, (char *)s->sparts, nr_sparts_new, + sizeof(struct spart), spart_align, spart_mpi_type, nr_nodes, nodeID); swift_free("sparts", s->sparts); s->sparts = (struct spart *)new_parts; s->nr_sparts = nr_sparts_new; @@ -1661,12 +1661,14 @@ void engine_exchange_proxy_multipoles(struct engine *e) { /* Allocate the buffers for the packed data */ struct gravity_tensors *buffer_send = NULL; - if (swift_memalign("send_gravity_tensors", (void **)&buffer_send, SWIFT_CACHE_ALIGNMENT, + if (swift_memalign("send_gravity_tensors", (void **)&buffer_send, + SWIFT_CACHE_ALIGNMENT, count_send_cells * sizeof(struct gravity_tensors)) != 0) error("Unable to allocate memory for multipole transactions"); struct gravity_tensors *buffer_recv = NULL; - if (swift_memalign("recv_gravity_tensors", (void **)&buffer_recv, SWIFT_CACHE_ALIGNMENT, + if (swift_memalign("recv_gravity_tensors", (void **)&buffer_recv, + SWIFT_CACHE_ALIGNMENT, count_recv_cells * sizeof(struct gravity_tensors)) != 0) error("Unable to allocate memory for multipole transactions"); @@ -1827,7 +1829,8 @@ void engine_allocate_foreign_particles(struct engine *e) { /* Allocate space for the foreign particles we will receive */ if (count_parts_in > s->size_parts_foreign) { - if (s->parts_foreign != NULL) swift_free("sparts_foreign", s->parts_foreign); + if (s->parts_foreign != NULL) + swift_free("sparts_foreign", s->parts_foreign); s->size_parts_foreign = engine_foreign_alloc_margin * count_parts_in; if (swift_memalign("parts_foreign", (void **)&s->parts_foreign, part_align, sizeof(struct part) * s->size_parts_foreign) != 0) @@ -1836,18 +1839,22 @@ void engine_allocate_foreign_particles(struct engine *e) { /* Allocate space for the foreign particles we will receive */ if (count_gparts_in > s->size_gparts_foreign) { - if (s->gparts_foreign != NULL) swift_free("gparts_foreign", s->gparts_foreign); + if (s->gparts_foreign != NULL) + swift_free("gparts_foreign", s->gparts_foreign); s->size_gparts_foreign = engine_foreign_alloc_margin * count_gparts_in; - if (swift_memalign("gparts_foreign", (void **)&s->gparts_foreign, gpart_align, + if (swift_memalign("gparts_foreign", (void **)&s->gparts_foreign, + gpart_align, sizeof(struct gpart) * s->size_gparts_foreign) != 0) error("Failed to allocate foreign gpart data."); } /* Allocate space for the foreign particles we will receive */ if (count_sparts_in > s->size_sparts_foreign) { - if (s->sparts_foreign != NULL) swift_free("sparts_foreign", s->sparts_foreign); + if (s->sparts_foreign != NULL) + swift_free("sparts_foreign", s->sparts_foreign); s->size_sparts_foreign = engine_foreign_alloc_margin * count_sparts_in; - if (swift_memalign("sparts_foreign", (void **)&s->sparts_foreign, spart_align, + if (swift_memalign("sparts_foreign", (void **)&s->sparts_foreign, + spart_align, sizeof(struct spart) * s->size_sparts_foreign) != 0) error("Failed to allocate foreign spart data."); } @@ -3115,7 +3122,7 @@ void engine_step(struct engine *e) { e->max_active_bin = get_max_active_bin(e->ti_end_min); e->min_active_bin = get_min_active_bin(e->ti_current, e->ti_old); e->step += 1; - engine_cstep = e->step; + engine_current_step = e->step; e->step_props = engine_step_prop_none; /* When restarting, move everyone to the current time. */ diff --git a/src/engine.h b/src/engine.h index 95adae81c99e2036f9e519bbea8c2212e22e56db..16edf7dd2437478d6876272debd197aaeaeba378 100644 --- a/src/engine.h +++ b/src/engine.h @@ -117,7 +117,7 @@ extern int engine_rank; /** * @brief The current step as a global variable (for messages). */ -extern int engine_cstep; +extern int engine_current_step; /* Data structure for the engine. */ struct engine { diff --git a/src/memuse.c b/src/memuse.c index 10a90e9180c36ac1ebb85ea685edc577e406a4ca..02b5334c6921faf22c2dfbc5169380370c436504 100644 --- a/src/memuse.c +++ b/src/memuse.c @@ -44,7 +44,7 @@ /* Also recorded in logger. */ extern int engine_rank; -extern int engine_cstep; +extern int engine_current_step; /* Entry for logger of memory allocations and deallocations in a step. */ #define MEMUSE_MAXLAB 64 @@ -74,60 +74,74 @@ struct memuse_log_entry { /* The log of allocations and frees. */ static struct memuse_log_entry *memuse_log = NULL; -static size_t log_size = 0; -static size_t log_count = 0; -static size_t log_done = 0; +static volatile size_t memuse_log_size = 0; +static volatile size_t memuse_log_count = 0; +static volatile size_t memuse_log_done = 0; #define MEMUSE_INITLOG 1000000 -static void log_reallocate(size_t ind) { +static void memuse_log_reallocate(size_t ind) { if (ind == 0) { /* Need to perform initialization. Be generous. */ - if ((memuse_log = (struct memuse_log_entry *) - malloc(sizeof(struct memuse_log_entry) * MEMUSE_INITLOG)) == NULL) + if ((memuse_log = (struct memuse_log_entry *)malloc( + sizeof(struct memuse_log_entry) * MEMUSE_INITLOG)) == NULL) error("Failed to allocate memuse log."); /* Last action. */ - log_size = MEMUSE_INITLOG; + memuse_log_size = MEMUSE_INITLOG; } else { struct memuse_log_entry *new_log; - if ((new_log = (struct memuse_log_entry *) - malloc(sizeof(struct memuse_log_entry) * log_size * 2)) == NULL) + if ((new_log = (struct memuse_log_entry *)malloc( + sizeof(struct memuse_log_entry) * memuse_log_size * 2)) == NULL) error("Failed to re-allocate memuse log."); /* Wait for all writes to the old buffer to complete. */ - while (log_done < log_size); + while (memuse_log_done < memuse_log_size) + ; /* Copy to new buffer. */ - memcpy(new_log, memuse_log, sizeof(struct memuse_log_entry) * log_count); + memcpy(new_log, memuse_log, + sizeof(struct memuse_log_entry) * memuse_log_count); free(memuse_log); memuse_log = new_log; /* Last action. */ - log_size *= 2; + memuse_log_size *= 2; } } -static void log_allocation(const char *label, void *ptr, int allocated, +/** + * @brief Log an allocation or deallocation of memory. + * + * @param label the label associated with the memory. + * @param ptr the memory pointer. + * @param allocated whether this is an allocation or deallocation. + * @param size the size in byte of memory allocated, set to 0 when + * deallocating. + */ +void memuse_log_allocation(const char *label, void *ptr, int allocated, size_t size) { - size_t ind = atomic_inc(&log_count); - if (ind == log_size) log_reallocate(ind); + size_t ind = atomic_inc(&memuse_log_count); + + /* If we are at the current size we need more space. */ + if (ind == memuse_log_size) memuse_log_reallocate(ind); /* Other threads wait for space. */ - while (ind > log_size); + while (ind > memuse_log_size) + ; /* Record the log. */ memuse_log[ind].rank = engine_rank; - memuse_log[ind].step = engine_cstep; + memuse_log[ind].step = engine_current_step; memuse_log[ind].allocated = allocated; memuse_log[ind].size = size; memuse_log[ind].ptr = ptr; strncpy(memuse_log[ind].label, label, MEMUSE_MAXLAB); memuse_log[ind].label[MEMUSE_MAXLAB] = '\0'; memuse_log[ind].tic = getticks(); - atomic_inc(&log_done); + atomic_inc(&memuse_log_done); } /** @@ -136,7 +150,7 @@ static void log_allocation(const char *label, void *ptr, int allocated, void memuse_log_dump(const char *filename) { /* Skip if nothing allocated this step. */ - if (log_count == 0) return; + if (memuse_log_count == 0) return; /* Open the output file. */ FILE *fd; @@ -148,14 +162,14 @@ void memuse_log_dump(const char *filename) { fprintf(fd, "# cpufreq: %lld\n", clocks_get_cpufreq()); fprintf(fd, "# tic adr rank step allocated label size\n"); - for (size_t k = 0; k < log_count; k++) { + for (size_t k = 0; k < memuse_log_count; k++) { fprintf(fd, "%lld %p %d %d %d %s %zd\n", memuse_log[k].tic, memuse_log[k].ptr, memuse_log[k].rank, memuse_log[k].step, memuse_log[k].allocated, memuse_log[k].label, memuse_log[k].size); } /* Clear the log. */ - log_count = 0; + memuse_log_count = 0; /* Close the file. */ fflush(fd); @@ -164,43 +178,6 @@ void memuse_log_dump(const char *filename) { #endif /* SWIFT_MEMUSE_REPORTS */ -/** - * @brief allocate aligned memory. The use and results are the same as the - * posix_memalign function. - * - * @param label a symbolic label for the memory, i.e. "parts". - * @param memptr pointer to the allocated memory. - * @param alignment alignment boundary. - * @param size the quantity of bytes to allocate. - * @result zero on success, otherwise an error code. - */ -int swift_memalign(const char *label, void **memptr, size_t alignment, - size_t size) { - int result = posix_memalign(memptr, alignment, size); - -#ifdef SWIFT_MEMUSE_REPORTS - if (result == 0) log_allocation(label, *memptr, 1, size); -#endif - return result; -} - -/** - * @brief free aligned memory. The use and results are the same as the - * free function. - * - * @param label a symbolic label for the memory, i.e. "parts", should match - * call used to allocate the memory. - * @param ptr pointer to the allocated memory. - */ -void swift_free(const char *label, void *ptr) { - free(ptr); - -#ifdef SWIFT_MEMUSE_REPORTS - log_allocation(label, ptr, 0, 0); -#endif - return; -} - /** * @brief parse the process /proc/self/statm file to get the process * memory use (in KB). Top field in (). @@ -274,14 +251,16 @@ const char *memuse_process(int inmb) { memuse_use(&size, &resident, &shared, &text, &data, &library, &dirty); if (inmb) { - snprintf(buffer, 256, - "VIRT = %.3f SHR = %.3f CODE = %.3f DATA = %.3f " - "RES = %.3f (MB)", size/1024.0, shared/1024.0, - text/1024.0, data/1024.0, resident/1024.0); + snprintf(buffer, 256, + "VIRT = %.3f SHR = %.3f CODE = %.3f DATA = %.3f " + "RES = %.3f (MB)", + size / 1024.0, shared / 1024.0, text / 1024.0, data / 1024.0, + resident / 1024.0); } else { - snprintf(buffer, 256, - "VIRT = %ld SHR = %ld CODE = %ld DATA = %ld " - "RES = %ld (KB)", size, shared, text, data, resident); + snprintf(buffer, 256, + "VIRT = %ld SHR = %ld CODE = %ld DATA = %ld " + "RES = %ld (KB)", + size, shared, text, data, resident); } return buffer; } diff --git a/src/memuse.h b/src/memuse.h index 8e9c2ec8dbacf009e04093652ffdca4a76acac19..334e84a4cecc6d6aabfad77bc632b91b2ff5f098 100644 --- a/src/memuse.h +++ b/src/memuse.h @@ -22,17 +22,56 @@ /* Config parameters. */ #include "../config.h" -/* Public API. */ -int swift_memalign(const char *label, void **memptr, size_t alignment, - size_t size); -void swift_free(const char *label, void *ptr); +/* Includes. */ +#include <stdlib.h> +/* API. */ void memuse_use(long *size, long *resident, long *shared, long *text, long *data, long *library, long *dirty); const char *memuse_process(int inmb); #ifdef SWIFT_MEMUSE_REPORTS void memuse_log_dump(const char *filename); +void memuse_log_allocation(const char *label, void *ptr, int allocated, + size_t size); #endif +/** + * @brief allocate aligned memory. The use and results are the same as the + * posix_memalign function. + * + * @param label a symbolic label for the memory, i.e. "parts". + * @param memptr pointer to the allocated memory. + * @param alignment alignment boundary. + * @param size the quantity of bytes to allocate. + * @result zero on success, otherwise an error code. + */ +__attribute__((always_inline)) inline int swift_memalign(const char *label, + void **memptr, + size_t alignment, + size_t size) { + int result = posix_memalign(memptr, alignment, size); +#ifdef SWIFT_MEMUSE_REPORTS + if (result == 0) memuse_log_allocation(label, *memptr, 1, size); +#endif + return result; +} + +/** + * @brief free aligned memory. The use and results are the same as the + * free function. + * + * @param label a symbolic label for the memory, i.e. "parts", should match + * call used to allocate the memory. + * @param ptr pointer to the allocated memory. + */ +__attribute__((always_inline)) inline void swift_free(const char *label, + void *ptr) { + free(ptr); +#ifdef SWIFT_MEMUSE_REPORTS + memuse_log_allocation(label, ptr, 0, 0); +#endif + return; +} + #endif /* SWIFT_MEMUSE_H */ diff --git a/src/parallel_io.c b/src/parallel_io.c index 5091497b435ea01fa484819721cd91fe342f21e7..d83a4c566ffdc2624c536731e799ce44df0971c0 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1488,10 +1488,12 @@ void write_output_parallel(struct engine* e, const char* baseName, Nparticles = Ngas_written; /* Allocate temporary arrays */ - if (swift_memalign("parts_written", (void**)&parts_written, part_align, + if (swift_memalign("parts_written", (void**)&parts_written, + part_align, Ngas_written * sizeof(struct part)) != 0) error("Error while allocating temporart memory for parts"); - if (swift_memalign("xparts_written", (void**)&xparts_written, xpart_align, + if (swift_memalign("xparts_written", (void**)&xparts_written, + xpart_align, Ngas_written * sizeof(struct xpart)) != 0) error("Error while allocating temporart memory for xparts"); @@ -1536,13 +1538,15 @@ void write_output_parallel(struct engine* e, const char* baseName, Nparticles = Ndm_written; /* Allocate temporary array */ - if (swift_memalign("gparts_written", (void**)&gparts_written, gpart_align, + if (swift_memalign("gparts_written", (void**)&gparts_written, + gpart_align, Ndm_written * sizeof(struct gpart)) != 0) error("Error while allocating temporart memory for gparts"); if (with_stf) { - if (swift_memalign("gpart_group_written", - (void**)&gpart_group_data_written, gpart_align, + if (swift_memalign( + "gpart_group_written", (void**)&gpart_group_data_written, + gpart_align, Ndm_written * sizeof(struct velociraptor_gpart_data)) != 0) error( "Error while allocating temporart memory for gparts STF " @@ -1583,7 +1587,8 @@ void write_output_parallel(struct engine* e, const char* baseName, Nparticles = Nstars_written; /* Allocate temporary arrays */ - if (swift_memalign("sparts_written", (void**)&sparts_written, spart_align, + if (swift_memalign("sparts_written", (void**)&sparts_written, + spart_align, Nstars_written * sizeof(struct spart)) != 0) error("Error while allocating temporart memory for sparts"); @@ -1626,7 +1631,8 @@ void write_output_parallel(struct engine* e, const char* baseName, if (parts_written) swift_free("parts_written", parts_written); if (xparts_written) swift_free("xparts_written", xparts_written); if (gparts_written) swift_free("gparts_written", gparts_written); - if (gpart_group_data_written) swift_free("gpart_group_written", gpart_group_data_written); + if (gpart_group_data_written) + swift_free("gpart_group_written", gpart_group_data_written); if (sparts_written) swift_free("sparts_written", sparts_written); #ifdef IO_SPEED_MEASUREMENT diff --git a/src/proxy.c b/src/proxy.c index a2e1817aa364dc6220a7428caf9d97e9e1ee4772..6de044f4009173182da0bee41ae6c1d9d2ccb0d6 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -206,7 +206,8 @@ void proxy_cells_exchange_first(struct proxy *p) { /* Allocate and fill the pcell buffer. */ if (p->pcells_out != NULL) swift_free("pcells_out", p->pcells_out); - if (swift_memalign("pcells_out", (void **)&p->pcells_out, SWIFT_STRUCT_ALIGNMENT, + if (swift_memalign("pcells_out", (void **)&p->pcells_out, + SWIFT_STRUCT_ALIGNMENT, sizeof(struct pcell) * p->size_pcells_out) != 0) error("Failed to allocate pcell_out buffer."); @@ -253,7 +254,8 @@ void proxy_cells_exchange_second(struct proxy *p) { /* Re-allocate the pcell_in buffer. */ if (p->pcells_in != NULL) swift_free("pcells_in", p->pcells_in); - if (swift_memalign("pcells_in", (void **)&p->pcells_in, SWIFT_STRUCT_ALIGNMENT, + if (swift_memalign("pcells_in", (void **)&p->pcells_in, + SWIFT_STRUCT_ALIGNMENT, sizeof(struct pcell) * p->size_pcells_in) != 0) error("Failed to allocate pcell_in buffer."); diff --git a/src/serial_io.c b/src/serial_io.c index 234a77d3b94b727126817e70871434820f1b7db5..1f1ba013175f42094144f846b0053d2259ba2e3c 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1133,10 +1133,12 @@ void write_output_serial(struct engine* e, const char* baseName, Nparticles = Ngas_written; /* Allocate temporary arrays */ - if (swift_memalign("parts_written", (void**)&parts_written, part_align, + if (swift_memalign("parts_written", (void**)&parts_written, + part_align, Ngas_written * sizeof(struct part)) != 0) error("Error while allocating temporart memory for parts"); - if (swift_memalign("xparts_written", (void**)&xparts_written, xpart_align, + if (swift_memalign("xparts_written", (void**)&xparts_written, + xpart_align, Ngas_written * sizeof(struct xpart)) != 0) error("Error while allocating temporart memory for xparts"); @@ -1182,12 +1184,14 @@ void write_output_serial(struct engine* e, const char* baseName, Nparticles = Ndm_written; /* Allocate temporary array */ - if (swift_memalign("gparts_written", (void**)&gparts_written, gpart_align, + if (swift_memalign("gparts_written", (void**)&gparts_written, + gpart_align, Ndm_written * sizeof(struct gpart)) != 0) error("Error while allocating temporart memory for gparts"); if (with_stf) { - if (swift_memalign("gpart_group_written", + if (swift_memalign( + "gpart_group_written", (void**)&gpart_group_data_written, gpart_align, Ndm_written * sizeof(struct velociraptor_gpart_data)) != 0) @@ -1230,7 +1234,8 @@ void write_output_serial(struct engine* e, const char* baseName, Nparticles = Nstars_written; /* Allocate temporary arrays */ - if (swift_memalign("sparts_written", (void**)&sparts_written, spart_align, + if (swift_memalign("sparts_written", (void**)&sparts_written, + spart_align, Nstars_written * sizeof(struct spart)) != 0) error("Error while allocating temporart memory for sparts"); @@ -1274,8 +1279,8 @@ void write_output_serial(struct engine* e, const char* baseName, if (parts_written) swift_free("parts_written", parts_written); if (xparts_written) swift_free("xparts_written", xparts_written); if (gparts_written) swift_free("gparts_written", gparts_written); - if (gpart_group_data_written) swift_free("gpart_group_written", - gpart_group_data_written); + if (gpart_group_data_written) + swift_free("gpart_group_written", gpart_group_data_written); if (sparts_written) swift_free("sparts_written", sparts_written); /* Close particle group */ diff --git a/src/single_io.c b/src/single_io.c index 531a3f5663480178ebf0cd9dc806fd2e26e30527..5264403cc9a919f1a9dbdfcec87692ef32b28b5c 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -936,10 +936,12 @@ void write_output_single(struct engine* e, const char* baseName, N = Ngas_written; /* Allocate temporary arrays */ - if (swift_memalign("parts_written", (void**)&parts_written, part_align, + if (swift_memalign("parts_written", (void**)&parts_written, + part_align, Ngas_written * sizeof(struct part)) != 0) error("Error while allocating temporart memory for parts"); - if (swift_memalign("xparts_written", (void**)&xparts_written, xpart_align, + if (swift_memalign("xparts_written", (void**)&xparts_written, + xpart_align, Ngas_written * sizeof(struct xpart)) != 0) error("Error while allocating temporart memory for xparts"); @@ -984,13 +986,15 @@ void write_output_single(struct engine* e, const char* baseName, N = Ndm_written; /* Allocate temporary array */ - if (swift_memalign("gparts_written", (void**)&gparts_written, gpart_align, + if (swift_memalign("gparts_written", (void**)&gparts_written, + gpart_align, Ndm_written * sizeof(struct gpart)) != 0) error("Error while allocating temporart memory for gparts"); if (with_stf) { - if (swift_memalign("gpart_group_written", - (void**)&gpart_group_data_written, gpart_align, + if (swift_memalign( + "gpart_group_written", (void**)&gpart_group_data_written, + gpart_align, Ndm_written * sizeof(struct velociraptor_gpart_data)) != 0) error( "Error while allocating temporart memory for gparts STF " @@ -1029,7 +1033,8 @@ void write_output_single(struct engine* e, const char* baseName, N = Nstars_written; /* Allocate temporary arrays */ - if (swift_memalign("sparts_written", (void**)&sparts_written, spart_align, + if (swift_memalign("sparts_written", (void**)&sparts_written, + spart_align, Nstars_written * sizeof(struct spart)) != 0) error("Error while allocating temporart memory for sparts"); @@ -1072,7 +1077,8 @@ void write_output_single(struct engine* e, const char* baseName, if (parts_written) swift_free("parts_written", parts_written); if (xparts_written) swift_free("xparts_written", xparts_written); if (gparts_written) swift_free("gparts_written", gparts_written); - if (gpart_group_data_written) swift_free("gpart_group_written", gpart_group_data_written); + if (gpart_group_data_written) + swift_free("gpart_group_written", gpart_group_data_written); if (sparts_written) swift_free("sparts_written", sparts_written); /* Close particle group */ diff --git a/src/space.c b/src/space.c index 6f45423c66e75f711b029e654344cec9553cff15..bbe889e2cd7a98d8bff68ae753d560a7fcc39e16 100644 --- a/src/space.c +++ b/src/space.c @@ -452,7 +452,8 @@ void space_regrid(struct space *s, int verbose) { swift_free("local_cells_with_tasks_top", s->local_cells_with_tasks_top); swift_free("local_cells_top", s->local_cells_top); swift_free("cells_with_particles_top", s->cells_with_particles_top); - swift_free("local_cells_with_particles_top", s->local_cells_with_particles_top); + swift_free("local_cells_with_particles_top", + s->local_cells_with_particles_top); swift_free("cells_top", s->cells_top); swift_free("multipoles_top", s->multipoles_top); } @@ -479,32 +480,36 @@ void space_regrid(struct space *s, int verbose) { /* Allocate the multipoles for the top-level cells. */ if (s->with_self_gravity) { - if (swift_memalign("multipoles_top", (void **)&s->multipoles_top, multipole_align, + if (swift_memalign("multipoles_top", (void **)&s->multipoles_top, + multipole_align, s->nr_cells * sizeof(struct gravity_tensors)) != 0) error("Failed to allocate top-level multipoles."); bzero(s->multipoles_top, s->nr_cells * sizeof(struct gravity_tensors)); } /* Allocate the indices of local cells */ - if (swift_memalign("local_cells_top", (void **)&s->local_cells_top, SWIFT_STRUCT_ALIGNMENT, - s->nr_cells * sizeof(int)) != 0) + if (swift_memalign("local_cells_top", (void **)&s->local_cells_top, + SWIFT_STRUCT_ALIGNMENT, s->nr_cells * sizeof(int)) != 0) error("Failed to allocate indices of local top-level cells."); bzero(s->local_cells_top, s->nr_cells * sizeof(int)); /* Allocate the indices of local cells with tasks */ - if (swift_memalign("local_cells_with_tasks_top",(void **)&s->local_cells_with_tasks_top, + if (swift_memalign("local_cells_with_tasks_top", + (void **)&s->local_cells_with_tasks_top, SWIFT_STRUCT_ALIGNMENT, s->nr_cells * sizeof(int)) != 0) error("Failed to allocate indices of local top-level cells with tasks."); bzero(s->local_cells_with_tasks_top, s->nr_cells * sizeof(int)); /* Allocate the indices of cells with particles */ - if (swift_memalign("cells_with_particles_top",(void **)&s->cells_with_particles_top, + if (swift_memalign("cells_with_particles_top", + (void **)&s->cells_with_particles_top, SWIFT_STRUCT_ALIGNMENT, s->nr_cells * sizeof(int)) != 0) error("Failed to allocate indices of top-level cells with particles."); bzero(s->cells_with_particles_top, s->nr_cells * sizeof(int)); /* Allocate the indices of local cells with particles */ - if (swift_memalign("local_cells_with_particles_top",(void **)&s->local_cells_with_particles_top, + if (swift_memalign("local_cells_with_particles_top", + (void **)&s->local_cells_with_particles_top, SWIFT_STRUCT_ALIGNMENT, s->nr_cells * sizeof(int)) != 0) error( "Failed to allocate indices of local top-level cells with " @@ -3183,8 +3188,8 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) { /* Is the multipole buffer empty? */ if (s->with_self_gravity && s->multipoles_sub == NULL) { - if (swift_memalign("multipoles_sub", - (void **)&s->multipoles_sub, multipole_align, + if (swift_memalign( + "multipoles_sub", (void **)&s->multipoles_sub, multipole_align, space_cellallocchunk * sizeof(struct gravity_tensors)) != 0) error("Failed to allocate more multipoles."); @@ -3953,7 +3958,7 @@ void space_init(struct space *s, struct swift_params *params, /* Allocate the extra parts array for the gas particles. */ if (Npart > 0) { - if (swift_memalign("xparts", (void **)&s->xparts, xpart_align, + if (swift_memalign("xparts", (void **)&s->xparts, xpart_align, Npart * sizeof(struct xpart)) != 0) error("Failed to allocate xparts."); bzero(s->xparts, Npart * sizeof(struct xpart)); @@ -4419,7 +4424,8 @@ void space_clean(struct space *s) { swift_free("local_cells_top", s->local_cells_top); swift_free("local_cells_with_tasks_top", s->local_cells_with_tasks_top); swift_free("cells_with_particles_top", s->cells_with_particles_top); - swift_free("local_cells_with_particles_top", s->local_cells_with_particles_top); + swift_free("local_cells_with_particles_top", + s->local_cells_with_particles_top); swift_free("parts", s->parts); swift_free("xparts", s->xparts); swift_free("gparts", s->gparts); diff --git a/tools/process_memuse.py b/tools/process_memuse.py index 87e83ead313112962bef067aa7f09cf8993b9895..8744320992101254db9b551bd09a528badf8711c 100755 --- a/tools/process_memuse.py +++ b/tools/process_memuse.py @@ -3,9 +3,8 @@ Usage: process_memuse.py output.dat -Parse the output of a run of SWIFT to convert the memuse output dumps -into a timeseries of memory use. Also outputs use in memory per labelled -type. +Parse the output of a run of SWIFT to convert the memuse output dumps into a +timeseries of memory use. Also outputs use in memory per labelled type. This file is part of SWIFT. Copyright (c) 2019 Peter W. Draper (p.w.draper@durham.ac.uk) @@ -59,7 +58,7 @@ with open(sys.argv[1]) as infile: memuse[adr] = [size] labels[adr] = label else: - memuse[adr] = memuse[adr].append(size) + memuse[adr].append(size) else: # Free, locate allocation. if adr in memuse: