Commit c6b36c04 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Memory leak fix and code formatting.

parent bef902ad
......@@ -1393,13 +1393,15 @@ int main(int argc, char *argv[]) {
if ((e.output_list_snapshots && e.output_list_snapshots->final_step_dump) ||
!e.output_list_snapshots) {
#ifdef HAVE_VELOCIRAPTOR
if (with_structure_finding && e.snapshot_invoke_stf && !e.stf_this_timestep)
velociraptor_invoke(&e, /*linked_with_snap=*/1);
if (with_structure_finding && e.snapshot_invoke_stf &&
!e.stf_this_timestep)
velociraptor_invoke(&e, /*linked_with_snap=*/1);
#endif
engine_dump_snapshot(&e);
#ifdef HAVE_VELOCIRAPTOR
if (with_structure_finding && e.snapshot_invoke_stf && !e.stf_this_timestep)
free(e.s->gpart_group_data);
if (with_structure_finding && e.snapshot_invoke_stf &&
e.s->gpart_group_data)
swift_free("gpart_group_data", e.s->gpart_group_data);
#endif
}
......
......@@ -2209,7 +2209,6 @@ void engine_step(struct engine *e) {
e->step += 1;
engine_current_step = e->step;
e->step_props = engine_step_prop_none;
e->stf_this_timestep = 0;
/* When restarting, move everyone to the current time. */
if (e->restarting) engine_drift_all(e, /*drift_mpole=*/1);
......@@ -2389,6 +2388,7 @@ void engine_check_for_dumps(struct engine *e) {
* before the next time-step */
enum output_type type = output_none;
integertime_t ti_output = max_nr_timesteps;
e->stf_this_timestep = 0;
/* Save some statistics ? */
if (e->ti_end_min > e->ti_next_stats && e->ti_next_stats > 0) {
......@@ -2462,7 +2462,7 @@ void engine_check_for_dumps(struct engine *e) {
#endif
/* Free the memory allocated for VELOCIraptor i/o. */
if (with_stf && e->snapshot_invoke_stf && !e->stf_this_timestep) {
if (with_stf && e->snapshot_invoke_stf && e->s->gpart_group_data) {
#ifdef HAVE_VELOCIRAPTOR
swift_free("gpart_group_data", e->s->gpart_group_data);
e->s->gpart_group_data = NULL;
......
......@@ -479,7 +479,7 @@ struct engine {
char run_name[PARSER_MAX_LINE_SIZE];
/* Has there been an stf this timestep? */
int stf_this_timestep;
char stf_this_timestep;
};
/* Function prototypes, engine.c. */
......
......@@ -1073,14 +1073,13 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6],
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
(int)round(e->time));
else
if (e->snapshot_invoke_stf) {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
else if (e->snapshot_invoke_stf) {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->stf_output_count);
} else {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
}
} else {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
}
/* Open HDF5 file with the chosen parameters */
hid_t h_file = H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
......@@ -1454,14 +1453,13 @@ void write_output_parallel(struct engine* e, const char* baseName,
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
(int)round(e->time));
else
if (e->snapshot_invoke_stf) {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->stf_output_count);
} else {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
}
else if (e->snapshot_invoke_stf) {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->stf_output_count);
} else {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
}
/* Now write the top-level cell structure */
hid_t h_file_cells = 0, h_grp_cells = 0;
......
......@@ -918,14 +918,13 @@ void write_output_serial(struct engine* e, const char* baseName,
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
(int)round(e->time));
else
if (e->snapshot_invoke_stf) {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->stf_output_count);
} else {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
}
else if (e->snapshot_invoke_stf) {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->stf_output_count);
} else {
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
}
/* Compute offset in the file and total number of particles */
size_t N[swift_type_count] = {Ngas_written, Ndm_written,
......
......@@ -647,6 +647,7 @@ void velociraptor_invoke(struct engine *e, const int linked_with_snap) {
/* Record we have ran stf this timestep */
e->stf_this_timestep = 1;
#else
error("SWIFT not configure to run with VELOCIraptor.");
#endif /* HAVE_VELOCIRAPTOR */
......
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