Commit ab97f53e authored by lhausamm's avatar lhausamm Committed by Loic Hausammann
Browse files

Finished moving logger toward object

parent a8ca16e0
......@@ -34,4 +34,9 @@ InitialConditions:
file_name: ./sedov.hdf5
periodic: 1
smoothing_length_scaling: 3.33
# Parameters governing the logger snapshot system
Logger:
delta_step: 10 # (Optional) Update the particle log every this many updates
mmaped_buffer_size: .05 # buffer size in GB
basename: indice # Common part of the filenames
......@@ -5215,7 +5215,8 @@ 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->total_nr_parts, e->log->buffer_size);
logger_ensure_size(e->log, e->total_nr_parts, e->total_nr_gparts,
0);
#endif
/* Now, launch the calculation */
......@@ -5468,9 +5469,9 @@ void engine_step(struct engine *e) {
e->forcerebuild = 1;
#ifdef WITH_LOGGER
logger_log_timestamp(e->ti_current, &e->logger_time_offset,
e->logger_dump);
logger_ensure_size(e->total_nr_parts, e->logger_buffer_size);
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);
#endif
/* Are we drifting everything (a la Gadget/GIZMO) ? */
......@@ -6700,7 +6701,7 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params,
#if defined(WITH_LOGGER)
e->log = (struct logger *) malloc(sizeof(struct logger));
logger_init(e->log, params);
logger_init(e->log, params, e);
#endif
/* Make the space link back to the engine. */
......@@ -7310,7 +7311,7 @@ void engine_config(int restart, struct engine *e, struct swift_params *params,
}
#ifdef WITH_LOGGER
logger_write_file_header(e->log->dump, e);
logger_write_file_header(e->log, e);
#endif
/* Free the affinity stuff */
......
......@@ -100,7 +100,7 @@ void logger_write_data(struct dump *d, size_t *offset, const size_t size, void *
* @param data_type #logger_datatype to write
*/
void logger_write_general_data(struct dump *d, struct logger_const *log, size_t *offset,
void *p, char* name, size_t data_type)
const void *p, char* name, size_t data_type)
{
char *buff;
/* write name */
......@@ -366,10 +366,12 @@ void logger_log_timestamp(struct logger *log, integertime_t timestamp, size_t *o
* Check if logger parameters are large enough to write all particles
* and ensure that enough space is available in the buffer
*
* @param log The #logger
* @param total_nr_nparts total number of particle
* @param logger_buffer_size requested file size upate
*/
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) {
size_t limit, i;
struct logger_const log_const;
logger_const_init(&log_const);
......@@ -384,19 +386,27 @@ void logger_ensure_size(struct logger *log, size_t total_nr_parts) {
limit *= total_nr_parts;
if (logger_buffer_size < limit) error("Need a larger logger size");
if (log->buffer_size < limit) error("Need a larger logger size");
if (total_nr_gparts > 0)
error("Not implemented");
if (total_nr_sparts > 0)
error("Not implemented");
logger_const_free(&log_const);
dump_ensure(e->logger_dump, e->logger_buffer_size);
dump_ensure(log->dump, log->buffer_size);
}
/**
* @brief intialize the logger structure
*
* @param log The #logger
* @param params The #swift_params
* @param e The #engine
*/
void logger_init(struct logger *log, struct swift_params *params) {
void logger_init(struct logger *log, const struct swift_params *params, const struct engine *e) {
/* 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;
......@@ -412,7 +422,7 @@ void logger_init(struct logger *log, struct swift_params *params) {
struct dump *dump_file = log->dump;
dump_init(dump_file, logger_name_file, log->buffer_size);
logger_write_file_header(log, dump_file);
logger_write_file_header(log, e);
dump_ensure(dump_file, log->buffer_size);
log->timestamp_offset = 0;
}
......@@ -429,11 +439,11 @@ void logger_clean(struct logger *log) {
/**
* @brief Write a file header to a logger file
*
* @param offset Pointer to the offset of the previous log of this particle.
* @param log The #logger
* @param dump The #dump in which to log the particle data.
*
*/
void logger_write_file_header(struct dump *dump, struct engine *e) {
void logger_write_file_header(struct logger *log, const struct engine *e) {
#ifdef SWIFT_DEBUG_CHECKS
message("writing header");
......@@ -444,6 +454,7 @@ void logger_write_file_header(struct dump *dump, struct engine *e) {
size_t file_offset;
struct logger_const log_const;
struct dump *dump = log->dump;
logger_const_init(&log_const);
file_offset = dump->file_offset;
......@@ -508,8 +519,8 @@ void logger_write_file_header(struct dump *dump, struct engine *e) {
logger_const_free(&log_const);
free(name);
dump_ensure(e->logger_dump, e->logger_buffer_size);
e->logger_time_offset = 0;
dump_ensure(log->dump, log->buffer_size);
log->timestamp_offset = 0;
}
/**
......
......@@ -122,23 +122,23 @@ extern const unsigned int logger_data_size[];
/* Function prototypes. */
int logger_compute_chunk_size(unsigned int mask);
void logger_log_all(struct part *p,
const long long Np, struct dump *dump);
void logger_log_all(struct logger *log, struct engine *e);
void logger_log_part(const struct part *p, const unsigned int mask, size_t *offset,
struct dump *dump);
void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *offset,
struct dump *dump);
void logger_init(struct logger *log, const struct swift_params *params);
void logger_init(struct logger *log, const struct swift_params *params, const struct engine *e);
void logger_clean(struct logger *log);
void logger_log_timestamp(struct logger *log, integertime_t t, size_t *offset);
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_write_file_header(struct dump *dump, struct engine* e);
void logger_write_file_header(struct logger *log, const struct engine* e);
void logger_const_init(struct logger_const* log_const);
void logger_const_free(struct logger_const* log_const);
void logger_ensure_size(size_t total_nr_parts, size_t logger_buffer_size);
void logger_ensure_size(struct logger *log, size_t total_nr_parts,
size_t total_nr_gparts, size_t total_nr_sparts);
#endif /* WITH_LOGGER */
......
......@@ -81,11 +81,14 @@ 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 gpart* dmparts = NULL;
//struct spart* sparts = e->s->sparts;
static int outputCount = 0;
struct logger *log = e->log;
/* Number of unassociated gparts */
const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0;
......@@ -126,7 +129,7 @@ void write_index_single(struct engine* e, const char* baseName,
io_write_attribute(h_grp, "BoxSize", DOUBLE, e->s->dim, 3);
double dblTime = e->time;
io_write_attribute(h_grp, "Time", DOUBLE, &dblTime, 1);
io_write_attribute(h_grp, "Time Offset", UINT, &e->logger_time_offset, 1);
io_write_attribute(h_grp, "Time Offset", UINT, &log->timestamp_offset, 1);
int dimension = (int)hydro_dimension;
io_write_attribute(h_grp, "Dimension", INT, &dimension, 1);
......
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