Commit ae1c3f5a authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Format

parent 8145ecbb
......@@ -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.
*/
......
......@@ -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,11 +232,10 @@ 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 */
......@@ -5215,8 +5213,7 @@ 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 */
......@@ -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) ? */
......@@ -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,7 +7161,8 @@ 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 "
message(
"WARNING: There is currently no way of predicting the output "
"size, please use it carefully");
#endif
......
......@@ -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;
......
......@@ -188,7 +188,6 @@ INLINE static void hydro_write_particles(const struct part* parts,
#endif
}
/**
* @brief Specifies which particle fields to write to a dataset
*
......@@ -199,8 +198,7 @@ INLINE static void hydro_write_particles(const struct part* parts,
* 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
......
......@@ -24,10 +24,10 @@
#ifdef WITH_LOGGER
/* Some standard headers. */
#include <hdf5.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <hdf5.h>
/* This object's header. */
#include "logger.h"
......@@ -35,21 +35,16 @@
/* Local headers. */
#include "atomic.h"
#include "dump.h"
#include "engine.h"
#include "error.h"
#include "part.h"
#include "units.h"
#include "engine.h"
char logger_version[logger_version_size] = "0.1";
const unsigned int logger_datatype_size[logger_data_count] = {
sizeof(int),
sizeof(float),
sizeof(double),
sizeof(char),
sizeof(long long),
1,
sizeof(int), sizeof(float), sizeof(double),
sizeof(char), sizeof(long long), 1,
};
/**
......@@ -62,7 +57,8 @@ const unsigned int logger_datatype_size[logger_data_count] = {
*
* @return updated buff
*/
char *logger_write_chunk_header(char *buff, const unsigned int *mask, const size_t *offset, const size_t offset_new) {
char *logger_write_chunk_header(char *buff, const unsigned int *mask,
const size_t *offset, const size_t offset_new) {
/* write mask */
memcpy(buff, mask, logger_mask_size);
buff += logger_mask_size;
......@@ -83,8 +79,8 @@ char *logger_write_chunk_header(char *buff, const unsigned int *mask, const size
* @param size number of bytes to write
* @param p pointer to the data
*/
void logger_write_data(struct dump *d, size_t *offset, size_t size, const void * p)
{
void logger_write_data(struct dump *d, size_t *offset, size_t size,
const void *p) {
/* get buffer */
char *buff = dump_get(d, size, offset);
......@@ -105,9 +101,10 @@ void logger_write_data(struct dump *d, size_t *offset, size_t size, const void *
* @param name Label of the parameter (should be smaller than log->name)
* @param data_type #logger_datatype to write
*/
void logger_write_general_data(struct dump *d, const struct logger_parameters *params, size_t *offset,
const void *p, char* name, size_t data_type)
{
void logger_write_general_data(struct dump *d,
const struct logger_parameters *params,
size_t *offset, const void *p, char *name,
size_t data_type) {
/* write name */
logger_write_data(d, offset, params->label_size, name);
......@@ -115,8 +112,7 @@ void logger_write_general_data(struct dump *d, const struct logger_parameters *p
logger_write_data(d, offset, params->data_type_size, &data_type);
/* write value */
if (data_type >= logger_data_count)
error("Not implemented");
if (data_type >= logger_data_count) error("Not implemented");
size_t size = logger_datatype_size[data_type];
logger_write_data(d, offset, size, p);
......@@ -190,18 +186,17 @@ void logger_log_all(struct logger *log, const struct engine *e) {
logger_mask_consts;
/* loop over all parts */
for(long long i=0; i < e->total_nr_parts; i++) {
logger_log_part(log, &s->parts[i], mask, &s->xparts[i].logger_data.last_offset);
for (long long i = 0; i < e->total_nr_parts; i++) {
logger_log_part(log, &s->parts[i], mask,
&s->xparts[i].logger_data.last_offset);
s->xparts[i].logger_data.last_output = 0;
}
/* loop over all gparts */
if (e->total_nr_gparts > 0)
error("Not implemented");
if (e->total_nr_gparts > 0) error("Not implemented");
/* loop over all sparts */
// TODO
}
/**
......@@ -210,9 +205,11 @@ void logger_log_all(struct logger *log, const struct engine *e) {
* @param log The #logger
* @param p The #part to dump.
* @param mask The mask of the data to dump.
* @param offset Pointer to the offset of the previous log of this particle; (return) offset of this log.
* @param offset Pointer to the offset of the previous log of this particle;
* (return) offset of this log.
*/
void logger_log_part(struct logger *log, const struct part *p, unsigned int mask, size_t *offset) {
void logger_log_part(struct logger *log, const struct part *p,
unsigned int mask, size_t *offset) {
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_timestamp)
......@@ -286,9 +283,11 @@ void logger_log_part(struct logger *log, const struct part *p, unsigned int mask
* @param log The #logger
* @param p The #gpart to dump.
* @param mask The mask of the data to dump.
* @param offset Pointer to the offset of the previous log of this particle; (return) offset of this log.
* @param offset Pointer to the offset of the previous log of this particle;
* (return) offset of this log.
*/
void logger_log_gpart(struct logger *log, const struct gpart *p, unsigned int mask, size_t *offset) {
void logger_log_gpart(struct logger *log, const struct gpart *p,
unsigned int mask, size_t *offset) {
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_timestamp)
......@@ -343,9 +342,11 @@ void logger_log_gpart(struct logger *log, const struct gpart *p, unsigned int ma
*
* @param log The #logger
* @param timestamp time to write
* @param offset Pointer to the offset of the previous log of this particle; (return) offset of this log.
* @param offset Pointer to the offset of the previous log of this particle;
* (return) offset of this log.
*/
void logger_log_timestamp(struct logger *log, integertime_t timestamp, size_t *offset) {
void logger_log_timestamp(struct logger *log, integertime_t timestamp,
size_t *offset) {
struct dump *dump = log->dump;
/* Start by computing the size of the message. */
......@@ -366,7 +367,6 @@ void logger_log_timestamp(struct logger *log, integertime_t timestamp, size_t *o
*offset = offset_new;
}
/**
* @brief Ensure that the buffer is large enough for a step.
*
......@@ -378,8 +378,7 @@ void logger_log_timestamp(struct logger *log, integertime_t timestamp, size_t *o
* @param total_nr_gparts total number of gpart
* @param total_nr_sparts total number of spart
*/
void logger_ensure_size(
struct logger *log, size_t total_nr_parts,
void logger_ensure_size(struct logger *log, size_t total_nr_parts,
size_t total_nr_gparts, size_t total_nr_sparts) {
struct logger_parameters *log_params = log->params;
......@@ -387,7 +386,7 @@ void logger_ensure_size(
/* count part memory */
size_t limit = log_params->offset_size + log_params->mask_size;
for(size_t i=0; i < log_params->nber_mask; i++) {
for (size_t i = 0; i < log_params->nber_mask; i++) {
if (log_params->masks[i] != logger_mask_timestamp)
limit += log_params->masks_data_size[i];
}
......@@ -401,12 +400,10 @@ void logger_ensure_size(
}
/* count gpart memory */
if (total_nr_gparts > 0)
error("Not implemented");
if (total_nr_gparts > 0) error("Not implemented");
/* count spart memory */
if (total_nr_sparts > 0)
error("Not implemented");
if (total_nr_sparts > 0) error("Not implemented");
/* ensure enough space in dump */
dump_ensure(log->dump, log->buffer_size);
......@@ -418,11 +415,13 @@ void logger_ensure_size(
* @param log The #logger
* @param params The #swift_params
*/
void logger_init(struct logger *log, const struct swift_params *params) {
void logger_init(struct logger *log, struct swift_params *params) {
/* read parameters */
log->delta_step = parser_get_param_int(params, "Logger:delta_step");
log->buffer_size = parser_get_param_float(params, "Logger:mmaped_buffer_size") * 1e9;
log->buffer_scale = parser_get_opt_param_float(params, "Logger:buffer_scale", 1.2);
log->buffer_size =
parser_get_param_float(params, "Logger:mmaped_buffer_size") * 1e9;
log->buffer_scale =
parser_get_opt_param_float(params, "Logger:buffer_scale", 1.2);
parser_get_param_string(params, "Logger:basename", log->base_name);
/* set initial value of parameters */
......@@ -434,7 +433,8 @@ void logger_init(struct logger *log, const struct swift_params *params) {
strcat(logger_name_file, ".dump");
/* init parameters */
log->params = (struct logger_parameters*) malloc(sizeof(struct logger_parameters));
log->params =
(struct logger_parameters *)malloc(sizeof(struct logger_parameters));
logger_parameters_init(log->params);
/* init dump */
......@@ -445,7 +445,6 @@ void logger_init(struct logger *log, const struct swift_params *params) {
/* ensure enough place in dump */
dump_ensure(dump_file, log->buffer_size);
}
/**
......@@ -475,46 +474,56 @@ void logger_write_file_header(struct logger *log, const struct engine *e) {
size_t file_offset = dump->file_offset;
if (file_offset != 0)
error("The logger is not empty."
error(
"The logger is not empty."
"This function should be called before writing anything in the logger");
/* Write version information */
logger_write_data(dump, &file_offset, logger_version_size, &logger_version);
/* write number of bytes used for the offsets */
logger_write_data(dump, &file_offset, logger_header_number_size, &log_params.offset_size);
logger_write_data(dump, &file_offset, logger_header_number_size,
&log_params.offset_size);
/* write offset direction */
int reversed = 0;
logger_write_data(dump, &file_offset, logger_datatype_size[logger_data_bool], &reversed);
logger_write_data(dump, &file_offset, logger_datatype_size[logger_data_bool],
&reversed);
/* will write the offset of the first particle here */
char *skip_header = dump_get(dump, log_params.offset_size, &file_offset);
/* write number of bytes used for names */
logger_write_data(dump, &file_offset, logger_header_number_size, &log_params.label_size);
logger_write_data(dump, &file_offset, logger_header_number_size,
&log_params.label_size);
/* write number of bytes used for numbers */
logger_write_data(dump, &file_offset, logger_header_number_size, &log_params.number_size);
logger_write_data(dump, &file_offset, logger_header_number_size,
&log_params.number_size);
/* write number of bytes used for masks */
logger_write_data(dump, &file_offset, logger_header_number_size, &log_params.mask_size);
logger_write_data(dump, &file_offset, logger_header_number_size,
&log_params.mask_size);
/* write number of masks */
logger_write_data(dump, &file_offset, log_params.number_size, &log_params.nber_mask);
logger_write_data(dump, &file_offset, log_params.number_size,
&log_params.nber_mask);
/* write masks */
// loop over all mask type
for(size_t i=0; i<log_params.nber_mask; i++) {
for (size_t i = 0; i < log_params.nber_mask; i++) {
// mask name
size_t j = i * log_params.label_size;
logger_write_data(dump, &file_offset, log_params.label_size, &log_params.masks_name[j]);
logger_write_data(dump, &file_offset, log_params.label_size,
&log_params.masks_name[j]);
// mask
logger_write_data(dump, &file_offset, log_params.mask_size, &log_params.masks[i]);
logger_write_data(dump, &file_offset, log_params.mask_size,
&log_params.masks[i]);
// mask size
logger_write_data(dump, &file_offset, log_params.number_size, &log_params.masks_data_size[i]);
logger_write_data(dump, &file_offset, log_params.number_size,
&log_params.masks_data_size[i]);
}
/* write mask data */
......@@ -544,7 +553,7 @@ void logger_write_file_header(struct logger *log, const struct engine *e) {
*
* @param log_params #logger_parameters to initialize
*/
void logger_parameters_init(struct logger_parameters* log_params) {
void logger_parameters_init(struct logger_parameters *log_params) {
/* set parameters */
log_params->label_size = 20;
log_params->offset_size = 7;
......@@ -555,7 +564,7 @@ void logger_parameters_init(struct logger_parameters* log_params) {
log_params->nber_mask = 8;
/* set masks array */
log_params->masks = malloc(sizeof(size_t)*log_params->nber_mask);
log_params->masks = malloc(sizeof(size_t) * log_params->nber_mask);
log_params->masks[0] = logger_mask_x;
log_params->masks[1] = logger_mask_v;
log_params->masks[2] = logger_mask_a;
......@@ -615,7 +624,6 @@ void logger_parameters_init(struct logger_parameters* log_params) {
log_params->masks_data_size[7] = sizeof(integertime_t);
// todo masks_type
}
/**
......@@ -623,13 +631,12 @@ void logger_parameters_init(struct logger_parameters* log_params) {
*
* @param log_params The #logger_parameters
*/
void logger_parameters_clean(struct logger_parameters* log_params) {
void logger_parameters_clean(struct logger_parameters *log_params) {
free(log_params->masks);
free(log_params->masks_name);
free(log_params->masks_data_size);
}
/**
* @brief read chunk header
*
......@@ -640,7 +647,8 @@ void logger_parameters_clean(struct logger_parameters* log_params) {
*
* @return Number of bytes read
*/
__attribute__((always_inline)) INLINE static int logger_read_chunk_header(const char *buff, unsigned int *mask, size_t *offset, size_t cur_offset) {
__attribute__((always_inline)) INLINE static int logger_read_chunk_header(
const char *buff, unsigned int *mask, size_t *offset, size_t cur_offset) {
memcpy(mask, buff, logger_mask_size);
buff += logger_mask_size;
......@@ -824,4 +832,3 @@ int logger_read_timestamp(unsigned long long int *t, size_t *offset,
#endif /* WITH_LOGGER */
#endif /* HAVE_POSIX_FALLOCATE */
......@@ -130,10 +130,8 @@ struct logger_parameters {
/* label of each mask */
char *masks_name;
};
/* structure containing global data */
struct logger {
/* Number of particle steps between dumping a chunk of data */
......@@ -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);
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,9 +63,9 @@
* @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.
*
......@@ -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 */
......@@ -256,10 +263,10 @@ void write_index_single(struct engine* e, const char* baseName,
error("TODO");
break;
case swift_type_star:
case swift_type_stars:
N = Nstars;
error("TODO");
//star_write_index(sparts, list, &num_fields);
// 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..."); */
......
......@@ -29,6 +29,7 @@
/* Includes. */
#include "engine.h"
#include "io_properties.h"
#include "part.h"
#include "units.h"
......
......@@ -2506,7 +2506,6 @@ void *runner_main(void *data) {
t->ti_run = e->ti_current;