Commit ae1c3f5a authored by Loic Hausammann's avatar Loic Hausammann

Format

parent 8145ecbb
......@@ -1006,7 +1006,7 @@ int main(int argc, char *argv[]) {
/* Initialise the particles */
engine_init_particles(&e, flag_entropy_ICs, clean_smoothing_length_values);
/* Write the state of the system before starting time integration. */
/* Write the state of the system before starting time integration. */
#ifdef WITH_LOGGER
logger_ensure_size(e.log, e.total_nr_parts, e.total_nr_gparts, 0);
logger_log_all(e.log, &e);
......
......@@ -279,9 +279,6 @@ struct cell {
/*! Values of h_max before the drifts, used for sub-cell tasks. */
float h_max_old;
/*! The logger task */
struct task *logger;
/*! The task to compute time-steps */
struct task *timestep;
......@@ -556,6 +553,9 @@ struct cell {
/*! Task for source terms */
struct task *sourceterms;
/*! The logger task */
struct task *logger;
/*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
float dmin;
......
......@@ -49,14 +49,12 @@
void *dump_get(struct dump *d, size_t count, size_t *offset) {
size_t local_offset = atomic_add(&d->count, count);
#ifdef SWIFT_DEBUG_CHECKS
if (d->count > d->size)
error("A new dump file should have been created.");
if (d->count > d->size) error("A new dump file should have been created.");
#endif
*offset = local_offset + d->file_offset;
return (char *)d->data + local_offset;
}
/**
* @brief Ensure that at least size bytes are available in the #dump.
*/
......@@ -86,7 +84,7 @@ void dump_ensure(struct dump *d, size_t size) {
if ((d->data = mmap(NULL, d->size, PROT_WRITE, MAP_SHARED, d->fd,
d->file_offset)) == MAP_FAILED) {
error("Failed to allocate map of size %zi bytes (%s).", d->size,
strerror(errno));
strerror(errno));
}
}
......
......@@ -115,8 +115,7 @@ const char *engine_policy_names[] = {"none",
"structure finding",
"star formation",
"feedback",
"logger"
};
"logger"};
/** The rank of the engine as a global variable (for messages). */
int engine_rank;
......@@ -233,10 +232,9 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
c, NULL);
#if defined(WITH_LOGGER)
c->logger = scheduler_addtask(s, task_type_logger, task_subtype_none, 0, 0,
c, NULL);
c->logger = scheduler_addtask(s, task_type_logger, task_subtype_none, 0,
0, c, NULL);
#endif
c->kick2 = scheduler_addtask(s, task_type_kick2, task_subtype_none, 0, 0,
c, NULL);
......@@ -277,7 +275,7 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
#if defined(WITH_LOGGER)
scheduler_addunlock(s, c->kick1, c->logger);
#endif
}
}
} else { /* We are above the super-cell so need to go deeper */
......@@ -4260,7 +4258,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
/* logger tasks ? */
else if (t->type == task_type_logger) {
if (cell_is_active_hydro(t->ci, e) || cell_is_active_gravity(t->ci, e))
scheduler_activate(s, t);
scheduler_activate(s, t);
}
/* Gravity stuff ? */
......@@ -5215,10 +5213,9 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
#ifdef WITH_LOGGER
logger_log_timestamp(e->log, e->ti_current, &e->log->timestamp_offset);
logger_ensure_size(e->log, e->total_nr_parts, e->total_nr_gparts,
0);
logger_ensure_size(e->log, e->total_nr_parts, e->total_nr_gparts, 0);
#endif
/* Now, launch the calculation */
TIMER_TIC;
engine_launch(e);
......@@ -5470,8 +5467,7 @@ void engine_step(struct engine *e) {
#ifdef WITH_LOGGER
logger_log_timestamp(e->log, e->ti_current, &e->log->timestamp_offset);
logger_ensure_size(e->log, e->total_nr_parts, e->total_nr_gparts,
0);
logger_ensure_size(e->log, e->total_nr_parts, e->total_nr_gparts, 0);
#endif
/* Are we drifting everything (a la Gadget/GIZMO) ? */
......@@ -5625,9 +5621,9 @@ void engine_check_for_dumps(struct engine *e) {
/* Dump everything */
engine_print_stats(e);
#ifdef WITH_LOGGER
engine_dump_index(e);
engine_dump_index(e);
#else
engine_dump_snapshot(e);
engine_dump_snapshot(e);
#endif
} else if (e->ti_next_stats < e->ti_next_snapshot) {
......@@ -5659,9 +5655,9 @@ void engine_check_for_dumps(struct engine *e) {
/* Dump snapshot */
#ifdef WITH_LOGGER
engine_dump_index(e);
engine_dump_index(e);
#else
engine_dump_snapshot(e);
engine_dump_snapshot(e);
#endif
} else if (e->ti_next_stats > e->ti_next_snapshot) {
......@@ -5681,9 +5677,9 @@ void engine_check_for_dumps(struct engine *e) {
/* Dump snapshot */
#ifdef WITH_LOGGER
engine_dump_index(e);
engine_dump_index(e);
#else
engine_dump_snapshot(e);
engine_dump_snapshot(e);
#endif
/* Let's fake that we are at the stats dump time */
......@@ -6484,8 +6480,8 @@ void engine_dump_snapshot(struct engine *e) {
MPI_INFO_NULL);
#endif
#else
write_output_single(e, e->snapshot_base_name, e->internal_units,
e->snapshot_units);
write_output_single(e, e->snapshot_base_name, e->internal_units,
e->snapshot_units);
#endif
#endif
......@@ -6524,7 +6520,7 @@ void engine_dump_index(struct engine *e) {
/* Dump... */
write_index_single(e, e->log->base_name, e->internal_units,
e->snapshot_units);
e->snapshot_units);
e->dump_snapshot = 0;
......@@ -6702,9 +6698,8 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params,
e->last_repartition = 0;
#endif
#if defined(WITH_LOGGER)
e->log = (struct logger *) malloc(sizeof(struct logger));
e->log = (struct logger *)malloc(sizeof(struct logger));
logger_init(e->log, params);
#endif
......@@ -7166,8 +7161,9 @@ void engine_config(int restart, struct engine *e, struct swift_params *params,
#if defined(WITH_LOGGER)
if (e->nodeID == 0)
message("WARNING: There is currently no way of predicting the output "
"size, please use it carefully");
message(
"WARNING: There is currently no way of predicting the output "
"size, please use it carefully");
#endif
/* Find the time of the first snapshot output */
......
......@@ -28,7 +28,6 @@
#include "kernel_gravity.h"
#include "minmax.h"
/**
* @brief Returns the mass of a particle
*
......@@ -147,7 +146,6 @@ __attribute__((always_inline)) INLINE static void gravity_init_gpart(
gp->a_grav[0] = 0.f;
gp->a_grav[1] = 0.f;
gp->a_grav[2] = 0.f;
gp->last_output = SHRT_MAX;
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gp->potential_PM = 0.f;
......
......@@ -788,7 +788,7 @@ hydro_set_init_internal_energy(struct part *p, float u_init) {
__attribute__((always_inline)) INLINE static int xpart_should_write(
const struct xpart *xp, const struct engine *e) {
return (xp->logger_data.last_output > e->log->delta_step);
return (xp->logger_data.last_output > e->log->delta_step);
}
#endif
......
......@@ -188,19 +188,17 @@ INLINE static void hydro_write_particles(const struct part* parts,
#endif
}
/**
* @brief Specifies which particle fields to write to a dataset
*
* @param parts The particle array.
* @param list The list of i/o properties to write.
* @param num_fields The number of i/o fields to write.
*
*
* In this version, we only want the ids and the offset.
*/
__attribute__((always_inline)) INLINE static void hydro_write_index(
const struct part* parts, const struct xpart* xparts,
struct io_props* list,
const struct part* parts, const struct xpart* xparts, struct io_props* list,
int* num_fields) {
#ifdef WITH_LOGGER
......@@ -210,15 +208,13 @@ __attribute__((always_inline)) INLINE static void hydro_write_index(
list[0] = io_make_output_field("ParticleIDs", ULONGLONG, 1,
UNIT_CONV_NO_UNITS, parts, id);
list[1] = io_make_output_field("Offset", ULONGLONG, 1,
UNIT_CONV_NO_UNITS, xparts, logger_data.last_offset);
list[1] = io_make_output_field("Offset", ULONGLONG, 1, UNIT_CONV_NO_UNITS,
xparts, logger_data.last_offset);
#else
error("Cannot write index without logger");
#endif
}
/**
* @brief Writes the current model of SPH to the file
* @param h_grpsph The HDF5 group in which to write
......
This diff is collapsed.
......@@ -118,7 +118,7 @@ struct logger_parameters {
/* size of a data type in bytes */
size_t data_type_size;
/* number of different mask */
size_t nber_mask;
......@@ -127,20 +127,18 @@ struct logger_parameters {
/* data size of each mask */
size_t *masks_data_size;
/* label of each mask */
char *masks_name;
};
/* structure containing global data */
struct logger {
/* Number of particle steps between dumping a chunk of data */
short int delta_step;
/* Logger basename */
char base_name[LOGGER_STRING_LENGTH];
char base_name[LOGGER_STRING_LENGTH];
/* File name of the dump file */
struct dump *dump;
......@@ -168,8 +166,7 @@ struct logger_part_data {
size_t last_offset;
};
INLINE static void logger_part_data_init(
struct logger_part_data *logger ) {
INLINE static void logger_part_data_init(struct logger_part_data *logger) {
logger->last_offset = 0;
logger->last_output = SHRT_MAX;
}
......@@ -189,22 +186,24 @@ extern const unsigned int logger_datatype_size[];
/* Function prototypes. */
int logger_compute_chunk_size(unsigned int mask);
void logger_log_all(struct logger *log, const struct engine *e);
void logger_log_part(struct logger *log, const struct part *p, unsigned int mask, size_t *offset);
void logger_log_gpart(struct logger *log, const struct gpart *p, unsigned int mask, size_t *offset);
void logger_init(struct logger *log, const struct swift_params *params);
void logger_log_part(struct logger *log, const struct part *p,
unsigned int mask, size_t *offset);
void logger_log_gpart(struct logger *log, const struct gpart *p,
unsigned int mask, size_t *offset);
void logger_init(struct logger *log, struct swift_params *params);
void logger_clean(struct logger *log);
void logger_log_timestamp(struct logger *log, integertime_t t, size_t *offset);
void logger_ensure_size(struct logger *log, size_t total_nr_parts,
size_t total_nr_gparts, size_t total_nr_sparts);
void logger_write_file_header(struct logger *log, const struct engine* e);
size_t total_nr_gparts, size_t total_nr_sparts);
void logger_write_file_header(struct logger *log, const struct engine *e);
int logger_read_part(struct part *p, size_t *offset, const char *buff);
int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff);
int logger_read_timestamp(unsigned long long int *t, size_t *offset,
const char *buff);
void logger_parameters_init(struct logger_parameters* log_params);
void logger_parameters_clean(struct logger_parameters* log_params);
void logger_parameters_init(struct logger_parameters *log_params);
void logger_parameters_clean(struct logger_parameters *log_params);
#endif /* WITH_LOGGER */
......
......@@ -63,16 +63,16 @@
* @param internal_units The #unit_system used internally
* @param snapshot_units The #unit_system used in the snapshots
*
* Creates an HDF5 output file and writes the offset and id of particles contained
* in the engine. If such a file already exists, it is erased and replaced
* by the new one.
* Creates an HDF5 output file and writes the offset and id of particles
* contained in the engine. If such a file already exists, it is erased and
* replaced by the new one.
*
* Calls #error() if an error occurs.
*
*/
void write_index_single(struct engine* e, const char* baseName,
const struct unit_system* internal_units,
const struct unit_system* snapshot_units) {
const struct unit_system* internal_units,
const struct unit_system* snapshot_units) {
hid_t h_file = 0, h_grp = 0;
const size_t Ngas = e->s->nr_parts;
......@@ -81,13 +81,13 @@ void write_index_single(struct engine* e, const char* baseName,
int periodic = e->s->periodic;
int numFiles = 1;
struct part* parts = e->s->parts;
struct xpart *xparts = e->s->xparts;
//struct gpart* gparts = e->s->gparts;
struct xpart* xparts = e->s->xparts;
// struct gpart* gparts = e->s->gparts;
struct gpart* dmparts = NULL;
//struct spart* sparts = e->s->sparts;
// struct spart* sparts = e->s->sparts;
static int outputCount = 0;
struct logger *log = e->log;
struct logger* log = e->log;
/* Number of unassociated gparts */
const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0;
......@@ -182,7 +182,14 @@ void write_index_single(struct engine* e, const char* baseName,
h_grp =
H5Gcreate(h_file, "/Parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if (h_grp < 0) error("Error while creating parameters group");
parser_write_params_to_hdf5(e->parameter_file, h_grp);
parser_write_params_to_hdf5(e->parameter_file, h_grp, 1);
H5Gclose(h_grp);
/* Print the runtime unused parameters */
h_grp = H5Gcreate(h_file, "/UnusedParameters", H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
if (h_grp < 0) error("Error while creating parameters group");
parser_write_params_to_hdf5(e->parameter_file, h_grp, 0);
H5Gclose(h_grp);
/* Print the system of Units used in the spashot */
......@@ -249,17 +256,17 @@ void write_index_single(struct engine* e, const char* baseName,
case swift_type_gas:
N = Ngas;
hydro_write_index(parts, xparts, list, &num_fields);
hydro_write_index(parts, xparts, list, &num_fields);
break;
case swift_type_dark_matter:
error("TODO");
break;
case swift_type_star:
error("TODO");
break;
case swift_type_stars:
N = Nstars;
error("TODO");
//star_write_index(sparts, list, &num_fields);
error("TODO");
// star_write_index(sparts, list, &num_fields);
break;
default:
......@@ -279,7 +286,6 @@ void write_index_single(struct engine* e, const char* baseName,
/* Close particle group */
H5Gclose(h_grp);
}
/* message("Done writing particles..."); */
......
......@@ -30,8 +30,8 @@
#include "units.h"
void write_index_single(struct engine* e, const char* baseName,
const struct unit_system* internal_units,
const struct unit_system* snapshot_units);
const struct unit_system* internal_units,
const struct unit_system* snapshot_units);
#endif
#endif /* SWIFT_LOGGER_IO_H */
......@@ -29,6 +29,7 @@
/* Includes. */
#include "engine.h"
#include "io_properties.h"
#include "part.h"
#include "units.h"
......
......@@ -899,7 +899,7 @@ void runner_do_init_grav(struct runner *r, struct cell *c, int timer) {
* @param timer Are we timing this ?
*/
void runner_do_extra_ghost(struct runner *r, struct cell *c, int timer) {
#ifdef EXTRA_HYDRO_LOOP
struct part *restrict parts = c->hydro.parts;
......@@ -2506,7 +2506,6 @@ void *runner_main(void *data) {
t->ti_run = e->ti_current;
#endif
/* Different types of tasks... */
switch (t->type) {
case task_type_self:
......@@ -2613,8 +2612,8 @@ void *runner_main(void *data) {
runner_do_end_force(r, ci, 1);
break;
case task_type_logger:
runner_do_logger(r, ci, 1);
break;
runner_do_logger(r, ci, 1);
break;
case task_type_timestep:
runner_do_timestep(r, ci, 1);
break;
......@@ -2694,7 +2693,6 @@ void *runner_main(void *data) {
return NULL;
}
/**
* @brief Write the required particles through the logger.
*
......@@ -2708,13 +2706,12 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
TIMER_TIC;
const struct engine *e = r->e;
struct part *restrict parts = c->parts;
struct xpart *restrict xparts = c->xparts;
const int count = c->count;
struct part *restrict parts = c->hydro.parts;
struct xpart *restrict xparts = c->hydro.xparts;
const int count = c->hydro.count;
/* Anything to do here? */
if (!cell_is_starting_hydro(c, e) && !cell_is_starting_gravity(c, e))
return;
if (!cell_is_starting_hydro(c, e) && !cell_is_starting_gravity(c, e)) return;
/* Recurse? */
if (c->split) {
......@@ -2732,35 +2729,30 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
/* If particle needs to be kicked */
if (part_is_starting(p, e)) {
if (xpart_should_write(xp, e))
{
/* Write particle */
logger_log_part(e->log, p, logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_u | logger_mask_h | logger_mask_rho |
logger_mask_consts,
&xp->logger_data.last_offset);
//message("Offset: %lu", p->last_offset);
/* Set counter back to zero */
xp->logger_data.last_output = 0;
}
else
/* Update counter */
xp->logger_data.last_output += 1;
if (xpart_should_write(xp, e)) {
/* Write particle */
logger_log_part(e->log, p,
logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_u | logger_mask_h | logger_mask_rho |
logger_mask_consts,
&xp->logger_data.last_offset);
// message("Offset: %lu", p->last_offset);
/* Set counter back to zero */
xp->logger_data.last_output = 0;
} else
/* Update counter */
xp->logger_data.last_output += 1;
}
}
}
if (c->gcount > 0)
error("gparts not implemented");
if (c->grav.count > 0) error("gparts not implemented");
if (c->stars.count > 0) error("sparts not implemented");
if (c->scount > 0)
error("sparts not implemented");
if (timer) TIMER_TOC(timer_logger);
#else
error("Logger disabled, please enable it during configuration");
#endif
}
......@@ -314,7 +314,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
/* Write XMF description for this data set */
if (xmfFile != NULL)
xmf_write_line(xmfFile, fileName, partTypeGroupName, props.name, N,
props.dimension, props.type);
props.dimension, props.type);
/* Write unit conversion factors for this data set */
char buffer[FIELD_BUFFER_SIZE];
......@@ -995,5 +995,4 @@ void write_output_single(struct engine* e, const char* baseName,
e->snapshot_output_count++;
}
#endif /* HAVE_HDF5 */
......@@ -47,19 +47,38 @@
#include "lock.h"
/* Task type names. */
const char *taskID_names[task_type_count] = {
"none", "sort", "self",
"pair", "sub_self", "sub_pair",
"init_grav", "init_grav_out", "ghost_in",
"ghost", "ghost_out", "extra_ghost",
"drift_part", "drift_gpart", "end_force",
"kick1", "kick2", "timestep",
"send", "recv", "grav_long_range",
"grav_mm", "grav_down_in", "grav_down",
"grav_mesh", "cooling", "star_formation",
"sourceterms", "stars_ghost_in", "stars_ghost",
"stars_ghost_out","logger"
};
const char *taskID_names[task_type_count] = {"none",
"sort",
"self",
"pair",
"sub_self",
"sub_pair",
"init_grav",
"init_grav_out",
"ghost_in",
"ghost",
"ghost_out",
"extra_ghost",
"drift_part",
"drift_gpart",
"end_force",
"kick1",
"kick2",
"timestep",
"send",
"recv",
"grav_long_range",
"grav_mm",
"grav_down_in",
"grav_down",
"grav_mesh",
"cooling",
"star_formation",
"sourceterms",
"stars_ghost_in",
"stars_ghost",
"stars_ghost_out",
"logger"};
/* Sub-task type names. */
const char *subtaskID_names[task_subtype_count] = {
......
......@@ -35,67 +35,65 @@
ticks timers[timer_count];
/* Timer names. */
const char* timers_names[timer_count] = {
"none",
"prepare",
"init",
"init_grav",
"drift_part",
"drift_gpart",
"kick1",
"kick2",
"timestep",
"endforce",
"dosort",
"doself_density",
"doself_gradient",
"doself_force",
"doself_grav_pp",
"dopair_density",
"dopair_gradient",
"dopair_force",
"dopair_grav_mm",
"dopair_grav_pp",
"dograv_external",
"dograv_down",
"dograv_mesh",
"dograv_top_level",
"dograv_long_range",
"dosource",
"dosub_self_density",
"dosub_self_gradient",
"dosub_self_force",
"dosub_self_grav",
"dosub_pair_density",
"dosub_pair_gradient",
"dosub_pair_force",
"dosub_pair_grav",
"doself_subset",
"dopair_subset",
"dopair_subset_naive",
"dosub_subset",
"do_ghost",
"do_extra_ghost",
"dorecv_part",
"dorecv_gpart",
"dorecv_spart",
"do_cooling",
"do_star_formation",
"gettask",
"qget",
"qsteal",
"locktree",
"runners",
"step",
"doself_stars_density",
"dopair_stars_density",
"do_stars_ghost",
"doself_subset_stars_density",
"dopair_subset_stars_density",
"dosubpair_stars_density",
"dosub_self_stars_density",
"logger"
};
const char* timers_names[timer_count] = {"none",
"prepare",
"init",
"init_grav",
"drift_part",
"drift_gpart",
"kick1",
"kick2",
"timestep",
"endforce",
"dosort",
"doself_density",
"doself_gradient",
"doself_force",
"doself_grav_pp",
"dopair_density",
"dopair_gradient",
"dopair_force",
"dopair_grav_mm",
"dopair_grav_pp",
"dograv_external",
"dograv_down",
"dograv_mesh",
"dograv_top_level",
"dograv_long_range",
"dosource",
"dosub_self_density",
"dosub_self_gradient",
"dosub_self_force",
"dosub_self_grav",
"dosub_pair_density",
"dosub_pair_gradient",
"dosub_pair_force",
"dosub_pair_grav",
"doself_subset",
"dopair_subset",
"dopair_subset_naive",
"dosub_subset",
"do_ghost",
"do_extra_ghost",
"dorecv_part",
"dorecv_gpart",
"dorecv_spart",
"do_cooling",
"do_star_formation",
"gettask",
"qget",
"qsteal",
"locktree",
"runners",
"step",
"doself_stars_density",
"dopair_stars_density",
"do_stars_ghost",
"doself_subset_stars_density",
"dopair_subset_stars_density",
"dosubpair_stars_density",
"dosub_self_stars_density",
"logger"};
/* File to store the timers */
static FILE