Commit 87e54c49 authored by Loic Hausammann's avatar Loic Hausammann

logger: add double time inside timestamp

parent 1ac99176
......@@ -2683,7 +2683,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
#ifdef WITH_LOGGER
/* Mark the first time step in the particle logger file. */
logger_log_timestamp(e->logger, e->ti_current, &e->logger->timestamp_offset);
logger_log_timestamp(e->logger, e->ti_current, e->time, &e->logger->timestamp_offset);
/* Make sure that we have enough space in the particle logger file
* to store the particles in current time step. */
logger_ensure_size(e->logger, e->total_nr_parts, e->total_nr_gparts, 0);
......@@ -2940,7 +2940,7 @@ void engine_step(struct engine *e) {
#ifdef WITH_LOGGER
/* Mark the current time step in the particle logger file. */
logger_log_timestamp(e->logger, e->ti_current, &e->logger->timestamp_offset);
logger_log_timestamp(e->logger, e->ti_current, e->time, &e->logger->timestamp_offset);
/* Make sure that we have enough space in the particle logger file
* to store the particles in current time step. */
logger_ensure_size(e->logger, e->total_nr_parts, e->total_nr_gparts, 0);
......
......@@ -161,6 +161,7 @@ int logger_compute_chunk_size(unsigned int mask) {
/* A timestamp consists of an unsigned long long int. */
size += sizeof(unsigned long long int);
size += sizeof(double);
} else {
......@@ -369,11 +370,12 @@ void logger_log_gpart(struct logger *log, const struct gpart *p,
*
* @param log The #logger
* @param timestamp time to write
* @param time time or scale factor
* @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) {
double time, size_t *offset) {
struct dump *dump = log->dump;
/* Start by computing the size of the message. */
......@@ -389,6 +391,10 @@ void logger_log_timestamp(struct logger *log, integertime_t timestamp,
/* Store the timestamp. */
memcpy(buff, &timestamp, sizeof(integertime_t));
buff += sizeof(integertime_t);
/* Store the time */
memcpy(buff, &time, sizeof(double));
/* Update the log message offset. */
*offset = offset_new;
......@@ -634,7 +640,7 @@ void logger_parameters_init(struct logger_parameters *log_params) {
log_params->masks_data_size[4] = sizeof(float);
log_params->masks_data_size[5] = sizeof(float);
log_params->masks_data_size[6] = sizeof(float) + sizeof(long long);
log_params->masks_data_size[7] = sizeof(integertime_t);
log_params->masks_data_size[7] = sizeof(integertime_t) + sizeof(double);
/* Compute the size of a chunk if all the mask are activated */
log_params->total_size = logger_offset_size + logger_mask_size;
......@@ -824,7 +830,7 @@ int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff) {
*
* @return The mask containing the values read.
*/
int logger_read_timestamp(unsigned long long int *t, size_t *offset,
int logger_read_timestamp(unsigned long long int *t, double *time, size_t *offset,
const char *buff) {
/* Jump to the offset. */
......@@ -845,6 +851,10 @@ int logger_read_timestamp(unsigned long long int *t, size_t *offset,
/* Copy the timestamp value from the buffer. */
memcpy(t, buff, sizeof(unsigned long long int));
buff += sizeof(unsigned long long int);
/* Copy the timestamp value from the buffer. */
memcpy(time, buff, sizeof(unsigned long long int));
/* Finally, return the mask of the values we just read. */
return mask;
......
......@@ -172,14 +172,14 @@ 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_log_timestamp(struct logger *log, integertime_t t, double time, 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);
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,
int logger_read_timestamp(unsigned long long int *t, double *time, size_t *offset,
const char *buff);
void logger_parameters_init(struct logger_parameters *log_params);
......
......@@ -178,50 +178,68 @@ void test_log_timestamps(struct logger *log) {
/* The timestamp to log. */
unsigned long long int t = 10;
double time = 0.1;
/* Start with an offset at the end of the dump. */
size_t offset = d->count;
/* Log three consecutive timestamps. */
logger_log_timestamp(log, t, &offset);
logger_log_timestamp(log, t, time, &offset);
printf("Logged timestamp %020llu at offset %#016zx.\n", t, offset);
t += 10;
logger_log_timestamp(log, t, &offset);
time = 0.2;
logger_log_timestamp(log, t, time, &offset);
printf("Logged timestamp %020llu at offset %#016zx.\n", t, offset);
t += 10;
logger_log_timestamp(log, t, &offset);
time = 0.3;
logger_log_timestamp(log, t, time, &offset);
printf("Logged timestamp %020llu at offset %#016zx.\n", t, offset);
/* Recover the three timestamps. */
size_t offset_old = offset;
t = 0;
int mask = logger_read_timestamp(&t, &offset, (const char *)d->data);
time = 0;
int mask = logger_read_timestamp(&t, &time, &offset, (const char *)d->data);
printf("Recovered timestamp %020llu at offset %#016zx with mask %#04x.\n", t,
offset_old, mask);
if (t != 30) {
printf("FAIL: could not recover correct timestamp.\n");
abort();
}
if (time != 0.3) {
printf("FAIL: could not recover correct time %g.\n", time);
abort();
}
offset_old = offset;
t = 0;
mask = logger_read_timestamp(&t, &offset, (const char *)d->data);
time = 0;
mask = logger_read_timestamp(&t, &time, &offset, (const char *)d->data);
printf("Recovered timestamp %020llu at offset %#016zx with mask %#04x.\n", t,
offset_old, mask);
if (t != 20) {
printf("FAIL: could not recover correct timestamp.\n");
abort();
}
if (time != 0.2) {
printf("FAIL: could not recover correct time.\n");
abort();
}
offset_old = offset;
t = 0;
mask = logger_read_timestamp(&t, &offset, (const char *)d->data);
time = 0;
mask = logger_read_timestamp(&t, &time, &offset, (const char *)d->data);
printf("Recovered timestamp %020llu at offset %#016zx with mask %#04x.\n", t,
offset_old, mask);
if (t != 10) {
printf("FAIL: could not recover correct timestamp.\n");
abort();
}
if (time != 0.1) {
printf("FAIL: could not recover correct time.\n");
abort();
}
}
int main(int argc, char *argv[]) {
......
Markdown is supported
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