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

Start rewriting logger

parent 7736f0f2
...@@ -1009,9 +1009,8 @@ int main(int argc, char *argv[]) { ...@@ -1009,9 +1009,8 @@ int main(int argc, char *argv[]) {
/* Write the state of the system before starting time integration. */ /* Write the state of the system before starting time integration. */
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
engine_dump_index(&e); engine_dump_index(&e);
#else
engine_dump_snapshot(&e);
#endif #endif
engine_dump_snapshot(&e);
engine_print_stats(&e); engine_print_stats(&e);
/* Is there a dump before the end of the first time-step? */ /* Is there a dump before the end of the first time-step? */
......
...@@ -5214,8 +5214,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs, ...@@ -5214,8 +5214,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
space_init_sparts(s, e->verbose); space_init_sparts(s, e->verbose);
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
logger_log_timestamp(e->ti_old, &e->logger_time_offset, logger_write_timestamp(e->log);
e->logger_dump);
logger_ensure_size(e->total_nr_parts, e->logger_buffer_size); logger_ensure_size(e->total_nr_parts, e->logger_buffer_size);
#endif #endif
...@@ -5468,12 +5467,10 @@ void engine_step(struct engine *e) { ...@@ -5468,12 +5467,10 @@ void engine_step(struct engine *e) {
((double)e->total_nr_gparts) * e->gravity_properties->rebuild_frequency)) ((double)e->total_nr_gparts) * e->gravity_properties->rebuild_frequency))
e->forcerebuild = 1; e->forcerebuild = 1;
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
logger_log_timestamp(e->ti_current, &e->logger_time_offset, logger_log_timestamp(e->ti_current, &e->logger_time_offset,
e->logger_dump); e->logger_dump);
logger_ensure_size(e->total_nr_parts, e->logger_buffer_size); logger_ensure_size(e->total_nr_parts, e->logger_buffer_size);
dump_ensure(e->logger_dump, e->logger_buffer_size);
#endif #endif
/* Are we drifting everything (a la Gadget/GIZMO) ? */ /* Are we drifting everything (a la Gadget/GIZMO) ? */
...@@ -6521,8 +6518,8 @@ void engine_dump_index(struct engine *e) { ...@@ -6521,8 +6518,8 @@ void engine_dump_index(struct engine *e) {
#endif #endif
/* Dump... */ /* Dump... */
write_index_single(e, e->loggerBaseName, e->internal_units, write_index_single(e, e->loggerBaseName, e->internal_units,
e->snapshotUnits); e->snapshotUnits);
e->dump_snapshot = 0; e->dump_snapshot = 0;
...@@ -6702,22 +6699,8 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, ...@@ -6702,22 +6699,8 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params,
#if defined(WITH_LOGGER) #if defined(WITH_LOGGER)
/* Logger params */ e->log = (struct logger *) malloc(sizeof(struct logger));
char logger_name_file[PARSER_MAX_LINE_SIZE]; logger_init(e->log);
e->logger_max_steps = parser_get_opt_param_int(params, "Snapshots:logger_max_steps", 10);
e->logger_size = parser_get_param_float(params, "Snapshots:logger_size") * 1e6;
/* generate dump filename */
strcpy(logger_name_file, e->snapshotBaseName);
strcat(logger_name_file, ".dump");
/* init dump */
e->logger_dump = malloc(sizeof(struct dump));
struct dump *dump_file = e->logger_dump;
dump_init(dump_file, logger_name_file, e->logger_size);
logger_write_file_header(dump_file, e);
dump_ensure(dump_file, e->logger_size);
e->logger_time_offset = 0;
#endif #endif
/* Make the space link back to the engine. */ /* Make the space link back to the engine. */
...@@ -7327,11 +7310,7 @@ void engine_config(int restart, struct engine *e, struct swift_params *params, ...@@ -7327,11 +7310,7 @@ void engine_config(int restart, struct engine *e, struct swift_params *params,
} }
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
if (e->nodeID == 0)
message("Expected output of over 9000\n Should write a real message...");
logger_write_file_header(e->logger_dump, e); logger_write_file_header(e->logger_dump, e);
dump_ensure(e->logger_dump, e->logger_buffer_size);
e->logger_time_offset = 0;
#endif #endif
/* Free the affinity stuff */ /* Free the affinity stuff */
...@@ -7754,8 +7733,8 @@ void engine_clean(struct engine *e) { ...@@ -7754,8 +7733,8 @@ void engine_clean(struct engine *e) {
free(e->links); free(e->links);
free(e->cell_loc); free(e->cell_loc);
#if defined(WITH_LOGGER) #if defined(WITH_LOGGER)
dump_close(e->logger_dump); logger_clean(e->log);
free(e->logger_dump); free(e->log);
#endif #endif
scheduler_clean(&e->sched); scheduler_clean(&e->sched);
space_clean(e->s); space_clean(e->s);
......
...@@ -313,20 +313,8 @@ struct engine { ...@@ -313,20 +313,8 @@ struct engine {
int forcerepart; int forcerepart;
struct repartition *reparttype; struct repartition *reparttype;
/* Number of particle steps between dumping a chunk of data */ #ifdef WITH_LOGGER
short int logger_max_steps; struct logger *log;
/* Logger basename */
char loggerBaseName[PARSER_MAX_LINE_SIZE];
/* File name of the dump file */
struct dump *logger_dump;
/* timestamp offset for logger*/
size_t logger_time_offset;
/* Size of the dump file */
size_t logger_buffer_size;
#endif #endif
/* Need to dump a snapshot ? */ /* Need to dump a snapshot ? */
......
...@@ -753,8 +753,8 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part( ...@@ -753,8 +753,8 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part(
xp->entropy_full = p->entropy; xp->entropy_full = p->entropy;
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
p->last_offset = 0; xp->logger.last_offset = 0;
xp->last_output = SHRT_MAX; xp->logger.last_output = SHRT_MAX;
#endif #endif
hydro_reset_acceleration(p); hydro_reset_acceleration(p);
...@@ -789,7 +789,7 @@ hydro_set_init_internal_energy(struct part *p, float u_init) { ...@@ -789,7 +789,7 @@ hydro_set_init_internal_energy(struct part *p, float u_init) {
__attribute__((always_inline)) INLINE static int xpart_should_write( __attribute__((always_inline)) INLINE static int xpart_should_write(
const struct xpart *xp, const struct engine *e) { const struct xpart *xp, const struct engine *e) {
return (xp->last_output > e->logger_max_steps); return (xp->logger.last_output > e->log->delta_step);
} }
#endif #endif
......
...@@ -198,8 +198,9 @@ INLINE static void hydro_write_particles(const struct part* parts, ...@@ -198,8 +198,9 @@ INLINE static void hydro_write_particles(const struct part* parts,
* *
* In this version, we only want the ids and the offset. * In this version, we only want the ids and the offset.
*/ */
void hydro_write_index(struct part* parts, struct io_props* list, __attribute__((always_inline)) INLINE static void hydro_write_index(
int* num_fields) { struct part* parts, struct io_props* list,
int* num_fields) {
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
*num_fields = 2; *num_fields = 2;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "cooling_struct.h" #include "cooling_struct.h"
#include "logger_struct.h"
/* Extra particle data not needed during the SPH loops over neighbours. */ /* Extra particle data not needed during the SPH loops over neighbours. */
struct xpart { struct xpart {
...@@ -56,8 +57,7 @@ struct xpart { ...@@ -56,8 +57,7 @@ struct xpart {
struct cooling_xpart_data cooling_data; struct cooling_xpart_data cooling_data;
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
/* Number of particle updates since last output */ struct logger_part_data logger;
short int last_output;
#endif #endif
} SWIFT_STRUCT_ALIGN; } SWIFT_STRUCT_ALIGN;
...@@ -95,11 +95,6 @@ struct part { ...@@ -95,11 +95,6 @@ struct part {
/* Entropy time derivative */ /* Entropy time derivative */
float entropy_dt; float entropy_dt;
#ifdef WITH_LOGGER
/* offset of last particle log entry */
size_t last_offset;
#endif
union { union {
struct { struct {
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
char LOGGER_VERSION[LOGGER_VERSION_SIZE] = "0.1"; char LOGGER_VERSION[LOGGER_VERSION_SIZE] = "0.1";
const unsigned int logger_data_size[logger_data_count] = { const unsigned int logger_data_size[logger_data_count] = {
sizeof(int), sizeof(int),
sizeof(float), sizeof(float),
...@@ -72,7 +73,6 @@ char *logger_write_chunk_header(char *buff, const unsigned int *mask, const size ...@@ -72,7 +73,6 @@ char *logger_write_chunk_header(char *buff, const unsigned int *mask, const size
return buff; return buff;
} }
/** /**
* @brief write a data to the file * @brief write a data to the file
* *
...@@ -177,19 +177,22 @@ int logger_compute_chunk_size(unsigned int mask) { ...@@ -177,19 +177,22 @@ int logger_compute_chunk_size(unsigned int mask) {
/** /**
* @brief log all particles * @brief log all particles
* *
* This function update the last_offset in #part * @param log The #logger
* * @param e The #engine
* @param p List of all the #part to log
* @param Np Number of particle to log
* @param dump The #dump in which to log the particle data
*/ */
void logger_log_all(struct part *p, const long long Np, struct dump *dump) { void logger_log_all(struct logger *log, struct engine *e) {
struct space *s = e->s;
const unsigned int mask = logger_mask_x | logger_mask_v | logger_mask_a | const unsigned int mask = logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_u | logger_mask_h | logger_mask_rho | logger_mask_u | logger_mask_h | logger_mask_rho |
logger_mask_consts; logger_mask_consts;
for(long long i=0; i < Np; i++) {
logger_log_part(&p[i], mask, &p[i].last_offset, dump); for(long long i=0; i < e->total_nr_parts; i++) {
logger_log_part(&s->parts[i], mask, &s->xparts[i].logger.last_offset, log->dump);
} }
if (e->total_nr_gparts > 0)
error("Not implemented");
} }
/** /**
...@@ -331,12 +334,13 @@ void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *of ...@@ -331,12 +334,13 @@ void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *of
/** /**
* @brief write a timestamp * @brief write a timestamp
* *
* @param log The #logger
* @param timestamp time to write * @param timestamp time to write
* @param offset In: previous offset, out: offset of this chunk * @param offset In: previous offset, out: offset of this chunk
* @param dump #dump file
*/ */
void logger_log_timestamp(integertime_t timestamp, size_t *offset, void logger_log_timestamp(struct logger *log, integertime_t timestamp, size_t *offset) {
struct dump *dump) { struct dump *dump = log->dump;
/* Start by computing the size of the message. */ /* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(logger_mask_timestamp); const int size = logger_compute_chunk_size(logger_mask_timestamp);
...@@ -357,12 +361,15 @@ void logger_log_timestamp(integertime_t timestamp, size_t *offset, ...@@ -357,12 +361,15 @@ void logger_log_timestamp(integertime_t timestamp, size_t *offset,
/** /**
* @brief ensure that the input parameter logger size is large enough * @brief ensure that the buffer is large enough
*
* Check if logger parameters are large enough to write all particles
* and ensure that enough space is available in the buffer
* *
* @param total_nr_nparts total number of particle * @param total_nr_nparts total number of particle
* @param logger_buffer_size requested file size upate * @param logger_buffer_size requested file size upate
*/ */
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 limit, i; size_t limit, i;
struct logger_const log_const; struct logger_const log_const;
logger_const_init(&log_const); logger_const_init(&log_const);
...@@ -380,6 +387,43 @@ void logger_ensure_size(size_t total_nr_parts, size_t logger_buffer_size) { ...@@ -380,6 +387,43 @@ void logger_ensure_size(size_t total_nr_parts, size_t logger_buffer_size) {
if (logger_buffer_size < limit) error("Need a larger logger size"); if (logger_buffer_size < limit) error("Need a larger logger size");
logger_const_free(&log_const); logger_const_free(&log_const);
dump_ensure(e->logger_dump, e->logger_buffer_size);
}
/**
* @brief intialize the logger structure
*
* @param log The #logger
*/
void logger_init(struct logger *log) {
/* 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;
parser_get_param_string(params, "Logger:basename", log->base_name);
/* generate dump filename */
char logger_name_file[PARSER_MAX_LINE_SIZE];
strcpy(logger_name_file, log->base_name);
strcat(logger_name_file, ".dump");
/* init dump */
log->dump = malloc(sizeof(struct dump));
struct dump *dump_file = log->dump;
dump_init(dump_file, logger_name_file, log->buffer_size);
logger_write_file_header(log, dump_file);
dump_ensure(dump_file, log->buffer_size);
log->timestamp_offset = 0;
}
/**
* @brief Close dump file and desallocate memory
*
* @param log The #logger
*/
void logger_clean(struct logger *log) {
dump_close(log->dump);
} }
/** /**
...@@ -453,8 +497,8 @@ void logger_write_file_header(struct dump *dump, struct engine *e) { ...@@ -453,8 +497,8 @@ void logger_write_file_header(struct dump *dump, struct engine *e) {
/* Write data */ /* Write data */
char *name = malloc(sizeof(char) * log_const.name); char *name = malloc(sizeof(char) * log_const.name);
strcpy(name, "timeBase"); strcpy(name, "time_base");
logger_write_general_data(dump, &log_const, &file_offset, &e->timeBase, logger_write_general_data(dump, &log_const, &file_offset, &e->time_base,
name, logger_data_double); name, logger_data_double);
/* last step: write first offset */ /* last step: write first offset */
...@@ -463,6 +507,9 @@ void logger_write_file_header(struct dump *dump, struct engine *e) { ...@@ -463,6 +507,9 @@ void logger_write_file_header(struct dump *dump, struct engine *e) {
/* free memory */ /* free memory */
logger_const_free(&log_const); logger_const_free(&log_const);
free(name); free(name);
dump_ensure(e->logger_dump, e->logger_buffer_size);
e->logger_time_offset = 0;
} }
/** /**
......
...@@ -22,10 +22,11 @@ ...@@ -22,10 +22,11 @@
#ifdef WITH_LOGGER #ifdef WITH_LOGGER
/* Includes. */ /* Includes. */
#include "common_io.h"
#include "engine.h"
#include "logger_struct.h"
#include "part.h" #include "part.h"
#include "units.h" #include "units.h"
#include "engine.h"
#include "common_io.h"
/* Forward declaration */ /* Forward declaration */
struct dump; struct dump;
...@@ -94,6 +95,7 @@ struct dump; ...@@ -94,6 +95,7 @@ struct dump;
extern char LOGGER_VERSION[LOGGER_VERSION_SIZE]; extern char LOGGER_VERSION[LOGGER_VERSION_SIZE];
struct logger_const { struct logger_const {
size_t name; // labels size size_t name; // labels size
size_t offset; // offset size size_t offset; // offset size
......
...@@ -29,18 +29,6 @@ ...@@ -29,18 +29,6 @@
#include "part.h" #include "part.h"
#include "units.h" #include "units.h"
void read_ic_single(char* fileName, const struct unit_system* internal_units,
double dim[3], struct part** parts, struct gpart** gparts,
struct spart** sparts, size_t* Ngas, size_t* Ndm,
size_t* Nstars, int* periodic, int* flag_entropy,
int with_hydro, int with_gravity, int with_stars,
int nr_threads, int dry_run);
void write_output_single(struct engine* e, const char* baseName,
const struct unit_system* internal_units,
const struct unit_system* snapshot_units);
void write_index_single(struct engine* e, const char* baseName, void write_index_single(struct engine* e, const char* baseName,
const struct unit_system* internal_units, const struct unit_system* internal_units,
const struct unit_system* snapshot_units); const struct unit_system* snapshot_units);
......
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2017 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#ifndef SWIFT_LOGGER_STRUCT_H
#define SWIFT_LOGGER_STRUCT_H
#ifdef WITH_LOGGER
#define LOGGER_STRING_LENGTH 200
#include "dump.h"
/* 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];
/* File name of the dump file */
struct dump *dump;
/* timestamp offset for logger*/
size_t timestamp_offset;
/* size of the buffer */
size_t buffer_size;
} SWIFT_STRUCT_ALIGN;
/* required structure for each particle type */
struct logger_part_data {
/* Number of particle updates since last output */
short int last_output;
/* offset of last particle log entry */
size_t last_offset;
};
#endif // WITH_LOGGER
#endif // SWIFT_LOGGER_STRUCT_H
...@@ -312,8 +312,9 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName, ...@@ -312,8 +312,9 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
if (h_err < 0) error("Error while writing data array '%s'.", props.name); if (h_err < 0) error("Error while writing data array '%s'.", props.name);
/* Write XMF description for this data set */ /* Write XMF description for this data set */
xmf_write_line(xmfFile, fileName, partTypeGroupName, props.name, N, if (xmfFile != NULL)
props.dimension, props.type); xmf_write_line(xmfFile, fileName, partTypeGroupName, props.name, N,
props.dimension, props.type);
/* Write unit conversion factors for this data set */ /* Write unit conversion factors for this data set */
char buffer[FIELD_BUFFER_SIZE]; char buffer[FIELD_BUFFER_SIZE];
......
...@@ -43,14 +43,12 @@ void write_output_single(struct engine* e, const char* baseName, ...@@ -43,14 +43,12 @@ void write_output_single(struct engine* e, const char* baseName,
const struct unit_system* internal_units, const struct unit_system* internal_units,
const struct unit_system* snapshot_units); const struct unit_system* snapshot_units);
void write_index_single(struct engine* e, const char* baseName,
const struct unit_system* internal_units,
const struct unit_system* snapshot_units);
void writeArray(const struct engine* e, hid_t grp, char* fileName, void writeArray(const struct engine* e, hid_t grp, char* fileName,
FILE* xmfFile, char* partTypeGroupName, FILE* xmfFile, char* partTypeGroupName,
const struct io_props props, size_t N, const struct io_props props, size_t N,
const struct unit_system* internal_units, const struct unit_system* internal_units,
const struct unit_system* snapshot_units); const struct unit_system* snapshot_units);
#endif // HAVE_HDF5 && !WITH_MPI
#endif /* SWIFT_SINGLE_IO_H */ #endif /* SWIFT_SINGLE_IO_H */
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