Commit 59b0f1e9 authored by Loic Hausammann's avatar Loic Hausammann Committed by Matthieu Schaller
Browse files

Logger restart

parent 55ce5d4b
......@@ -158,4 +158,27 @@ void dump_init(struct dump *d, const char *filename, size_t size) {
d->page_mask = page_mask;
}
/**
* @brief Restart a file dump.
*
* @param d The #dump to restart.
* @param filename The fully qualified name of the file in which to dump,
* note that it will be overwritten.
*/
void dump_restart(struct dump *d, const char *filename) {
/* Create the output file.
The option O_RDWR seems to be required by mmap.
*/
if ((d->fd = open(filename, O_RDWR, 0660)) == -1) {
error("Failed to open dump file '%s' (%s).", filename, strerror(errno));
}
/* Map memory to the created file. */
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));
}
}
#endif
......@@ -51,6 +51,7 @@ struct dump {
/* Function prototypes. */
void dump_init(struct dump *d, const char *filename, size_t size);
void dump_restart(struct dump *d, const char *filename);
void dump_ensure(struct dump *d, size_t required_size, size_t increase_size);
void dump_sync(struct dump *d);
void dump_close(struct dump *d);
......
......@@ -4196,8 +4196,10 @@ void engine_config(int restart, int fof, struct engine *e,
}
#ifdef WITH_LOGGER
/* Write the particle logger header */
logger_write_file_header(e->logger);
if (!restart) {
/* Write the particle logger header */
logger_write_file_header(e->logger);
}
#endif
/* Initialise the structure finder */
......@@ -4794,6 +4796,10 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
if (e->output_list_stats)
output_list_struct_dump(e->output_list_stats, stream);
if (e->output_list_stf) output_list_struct_dump(e->output_list_stf, stream);
#ifdef WITH_LOGGER
logger_struct_dump(e->logger, stream);
#endif
}
/**
......@@ -4938,6 +4944,13 @@ void engine_struct_restore(struct engine *e, FILE *stream) {
e->output_list_stf = output_list_stf;
}
#ifdef WITH_LOGGER
struct logger_writer *log =
(struct logger_writer *)malloc(sizeof(struct logger_writer));
logger_struct_restore(log, stream);
e->logger = log;
#endif
#ifdef EOS_PLANETARY
eos_init(&eos, e->physical_constants, e->snapshot_units, e->parameter_file);
#endif
......
......@@ -836,6 +836,37 @@ int logger_read_timestamp(unsigned long long int *t, double *time,
return mask;
}
/**
* @brief Write a swift_params struct to the given FILE as a stream of bytes.
*
* @param log the struct
* @param stream the file stream
*/
void logger_struct_dump(const struct logger_writer *log, FILE *stream) {
restart_write_blocks((void *)log, sizeof(struct logger_writer), 1, stream,
"logger", "logger");
}
/**
* @brief Restore a logger struct from the given FILE as a stream of
* bytes.
*
* @param logger the struct
* @param stream the file stream
*/
void logger_struct_restore(struct logger_writer *log, FILE *stream) {
/* Read the block */
restart_read_blocks((void *)log, sizeof(struct logger_writer), 1, stream,
NULL, "logger");
/* generate dump filename */
char logger_name_file[PARSER_MAX_LINE_SIZE];
strcpy(logger_name_file, log->base_name);
strcat(logger_name_file, ".dump");
dump_restart(&log->dump, logger_name_file);
}
#endif /* WITH_LOGGER */
#endif /* HAVE_POSIX_FALLOCATE */
......@@ -176,6 +176,8 @@ 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, double *time,
size_t *offset, const char *buff);
void logger_struct_dump(const struct logger_writer *log, FILE *stream);
void logger_struct_restore(struct logger_writer *log, FILE *stream);
/**
* @brief Initialize the logger data for a particle.
......
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