From 6d512f84674dff80793a3a88f202eddf25ccdfd7 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Sat, 25 Apr 2020 18:33:13 +0200 Subject: [PATCH] Use the new safe_checkdir() function in the distributed i/o --- src/black_holes_io.h | 3 +++ src/distributed_io.c | 12 ++++++++---- src/distributed_io.h | 9 +++------ src/engine.c | 5 ++--- src/parallel_io.h | 6 +++--- src/serial_io.h | 6 +++--- src/single_io.h | 8 ++++---- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/black_holes_io.h b/src/black_holes_io.h index bc3b1be3be..babe306560 100644 --- a/src/black_holes_io.h +++ b/src/black_holes_io.h @@ -21,6 +21,9 @@ #include "../config.h" +/* Local includes */ +#include "engine.h" + /* Load the correct star type */ #if defined(BLACK_HOLES_NONE) #include "./black_holes/Default/black_holes_io.h" diff --git a/src/distributed_io.c b/src/distributed_io.c index 93d39815eb..8a5a21f4fc 100644 --- a/src/distributed_io.c +++ b/src/distributed_io.c @@ -54,6 +54,7 @@ #include "part_type.h" #include "star_formation_io.h" #include "stars_io.h" +#include "tools.h" #include "tracers_io.h" #include "units.h" #include "velociraptor_io.h" @@ -220,16 +221,19 @@ void write_distributed_array(const struct engine* e, hid_t grp, * @brief Writes a snapshot distributed into multiple files. * * @param e The engine containing all the system. - * @param baseName The common part of the snapshot file name. * @param internal_units The #unit_system used internally * @param snapshot_units The #unit_system used in the snapshots + * @param mpi_rank The rank number of the calling MPI rank. + * @param mpi_size the number of MPI ranks. + * @param comm The communicator used by the MPI ranks. + * @param info The MPI information object. * * Creates a series of HDF5 output files (1 per MPI node) as a snapshot. * Writes the particles contained in the engine. * If such files already exist, it is erased and replaced by the new one. * The companion XMF file is also updated accordingly. */ -void write_output_distributed(struct engine* e, const char* baseName, +void write_output_distributed(struct engine* e, const struct unit_system* internal_units, const struct unit_system* snapshot_units, const int mpi_rank, const int mpi_size, @@ -317,8 +321,8 @@ void write_output_distributed(struct engine* e, const char* baseName, } /* Create the directory */ - if (mpi_rank == 0) mkdir(dirName, 0777); - MPI_Barrier(MPI_COMM_WORLD); + if (mpi_rank == 0) safe_checkdir(dirName, /*create=*/1); + MPI_Barrier(comm); /* Compute offset in the file and total number of particles */ const long long N[swift_type_count] = {Ngas_written, Ndm_written, diff --git a/src/distributed_io.h b/src/distributed_io.h index 3331c5a360..41b2740ece 100644 --- a/src/distributed_io.h +++ b/src/distributed_io.h @@ -29,13 +29,10 @@ #include <mpi.h> #endif -/* Includes. */ -#include "engine.h" -#include "io_properties.h" -#include "part.h" -#include "units.h" +struct engine; +struct unit_system; -void write_output_distributed(struct engine* e, const char* baseName, +void write_output_distributed(struct engine* e, const struct unit_system* internal_units, const struct unit_system* snapshot_units, int mpi_rank, int mpi_size, MPI_Comm comm, diff --git a/src/engine.c b/src/engine.c index c3f163c52b..487e5cdcf3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3616,9 +3616,8 @@ void engine_dump_snapshot(struct engine *e) { if (e->snapshot_distributed) { - write_output_distributed(e, snapshotBase, e->internal_units, - e->snapshot_units, e->nodeID, e->nr_nodes, - MPI_COMM_WORLD, MPI_INFO_NULL); + write_output_distributed(e, e->internal_units, e->snapshot_units, e->nodeID, + e->nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL); } else { #if defined(HAVE_PARALLEL_HDF5) diff --git a/src/parallel_io.h b/src/parallel_io.h index 6f1b397ef3..08588ee3d3 100644 --- a/src/parallel_io.h +++ b/src/parallel_io.h @@ -28,10 +28,10 @@ #include <mpi.h> /* Includes. */ -#include "engine.h" -#include "io_properties.h" #include "part.h" -#include "units.h" + +struct engine; +struct unit_system; void read_ic_parallel(char* fileName, const struct unit_system* internal_units, double dim[3], struct part** parts, struct gpart** gparts, diff --git a/src/serial_io.h b/src/serial_io.h index 02b3a22fa6..1146e5f5fb 100644 --- a/src/serial_io.h +++ b/src/serial_io.h @@ -30,10 +30,10 @@ #endif /* Includes. */ -#include "engine.h" -#include "io_properties.h" #include "part.h" -#include "units.h" + +struct engine; +struct unit_system; void read_ic_serial(char* fileName, const struct unit_system* internal_units, double dim[3], struct part** parts, struct gpart** gparts, diff --git a/src/single_io.h b/src/single_io.h index a28b06979f..c341fda920 100644 --- a/src/single_io.h +++ b/src/single_io.h @@ -24,11 +24,11 @@ #if defined(HAVE_HDF5) && !defined(WITH_MPI) -/* Includes. */ -#include "engine.h" -#include "io_properties.h" +/* Local includes */ #include "part.h" -#include "units.h" + +struct engine; +struct unit_system; void read_ic_single(const char* fileName, const struct unit_system* internal_units, double dim[3], -- GitLab