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

Logger: still working on the second review

parent 0fe21db9
...@@ -335,7 +335,7 @@ int main(int argc, char *argv[]) { ...@@ -335,7 +335,7 @@ int main(int argc, char *argv[]) {
#if !defined(WITH_LOGGER) #if !defined(WITH_LOGGER)
if (with_logger) { if (with_logger) {
printf("Error: the logger is not available, please compile with --enable-logger."); printf("Error: the particle logger is not available, please compile with --enable-logger.");
return 1; return 1;
} }
#endif #endif
......
...@@ -462,9 +462,9 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts, ...@@ -462,9 +462,9 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
/* Log the particle when leaving a rank. */ /* Log the particle when leaving a rank. */
logger_log_part(e->logger, &s->parts[offset_parts + k], logger_log_part(e->logger, &s->parts[offset_parts + k],
&s->xparts[offset_parts + k],
logger_masks_all_part | logger_masks_all_part |
logger_mask_data[logger_special_flags].mask, logger_mask_data[logger_special_flags].mask,
&s->xparts[offset_parts + k].logger_data.last_offset,
logger_flag); logger_flag);
} }
#endif #endif
...@@ -513,7 +513,6 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts, ...@@ -513,7 +513,6 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
logger_log_spart(e->logger, &s->sparts[offset_sparts + k], logger_log_spart(e->logger, &s->sparts[offset_sparts + k],
logger_masks_all_spart | logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask, logger_mask_data[logger_special_flags].mask,
&s->sparts[offset_parts + k].logger_data.last_offset,
logger_flag); logger_flag);
} }
#endif #endif
...@@ -600,7 +599,6 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts, ...@@ -600,7 +599,6 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
logger_log_gpart(e->logger, &s->gparts[offset_gparts + k], logger_log_gpart(e->logger, &s->gparts[offset_gparts + k],
logger_masks_all_gpart | logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask, logger_mask_data[logger_special_flags].mask,
&s->sparts[offset_parts + k].logger_data.last_offset,
logger_flag); logger_flag);
} }
#endif #endif
......
...@@ -181,10 +181,9 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) { ...@@ -181,10 +181,9 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) {
/* loop over all parts. */ /* loop over all parts. */
for (size_t i = 0; i < s->nr_parts; i++) { for (size_t i = 0; i < s->nr_parts; i++) {
logger_log_part(log, &s->parts[i], logger_masks_all_part, logger_log_part(log, &s->parts[i], &s->xparts[i],
&s->xparts[i].logger_data.last_offset, logger_masks_all_part,
/* Special flags */ 0); /* Special flags */ 0);
s->xparts[i].logger_data.steps_since_last_output = 0;
} }
/* loop over all gparts */ /* loop over all gparts */
...@@ -193,17 +192,13 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) { ...@@ -193,17 +192,13 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) {
if (s->gparts[i].type != swift_type_dark_matter) continue; if (s->gparts[i].type != swift_type_dark_matter) continue;
logger_log_gpart(log, &s->gparts[i], logger_masks_all_gpart, logger_log_gpart(log, &s->gparts[i], logger_masks_all_gpart,
&s->gparts[i].logger_data.last_offset,
/* Special flags */ 0); /* Special flags */ 0);
s->gparts[i].logger_data.steps_since_last_output = 0;
} }
/* loop over all sparts */ /* loop over all sparts */
for (size_t i = 0; i < s->nr_sparts; i++) { for (size_t i = 0; i < s->nr_sparts; i++) {
logger_log_spart(log, &s->sparts[i], logger_masks_all_spart, logger_log_spart(log, &s->sparts[i], logger_masks_all_spart,
&s->sparts[i].logger_data.last_offset,
/* Special flags */ 0); /* Special flags */ 0);
s->sparts[i].logger_data.steps_since_last_output = 0;
} }
if (e->total_nr_bparts > 0) error("Not implemented"); if (e->total_nr_bparts > 0) error("Not implemented");
...@@ -294,28 +289,16 @@ void logger_copy_part_fields( ...@@ -294,28 +289,16 @@ void logger_copy_part_fields(
* *
* @param log The #logger_writer * @param log The #logger_writer
* @param p The #part to dump. * @param p The #part to dump.
* @param xp The #xpart to dump.
* @param mask The mask of the data 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 special_flags The value of the special flag. * @param special_flags The value of the special flag.
*/ */
void logger_log_part(struct logger_writer *log, const struct part *p, void logger_log_part(struct logger_writer *log, const struct part *p,
unsigned int mask, size_t *offset, struct xpart *xp, unsigned int mask,
const uint32_t special_flags) { const uint32_t special_flags) {
/* Start by computing the size of the message. */ logger_log_parts(log, p, xp, /* count */ 1, mask,
const int size = logger_compute_chunk_size(mask);
/* Allocate a chunk of memory in the dump of the right size. */
size_t offset_new;
char *buff = (char *)dump_get(&log->dump, size, &offset_new);
/* Copy everything into the buffer */
logger_copy_part_fields(p, mask, offset, offset_new, buff,
special_flags); special_flags);
/* Update the log message offset. */
*offset = offset_new;
} }
/** /**
...@@ -413,28 +396,13 @@ void logger_copy_spart_fields( ...@@ -413,28 +396,13 @@ void logger_copy_spart_fields(
* @param log The #logger_writer * @param log The #logger_writer
* @param sp The #spart to dump. * @param sp The #spart to dump.
* @param mask The mask of the data to dump. * @param mask The mask of the data to dump.
* @param offset Pointer to the offset of the previous log of this particle;
* @param special_flags The value of the special flag. * @param special_flags The value of the special flag.
* (return) offset of this log.
*/ */
void logger_log_spart(struct logger_writer *log, const struct spart *sp, void logger_log_spart(struct logger_writer *log, struct spart *sp,
unsigned int mask, size_t *offset, unsigned int mask, const uint32_t special_flags) {
const uint32_t special_flags) {
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
/* Allocate a chunk of memory in the dump of the right size. */
size_t offset_new;
char *buff = (char *)dump_get(&log->dump, size, &offset_new);
/* Copy the fields into the buffer. */ logger_log_sparts(log, sp, /* count */ 1, mask,
logger_copy_spart_fields(sp, mask, offset, offset_new, buff,
special_flags); special_flags);
/* Update the log message offset. */
*offset = offset_new;
} }
/** /**
...@@ -544,27 +512,11 @@ void logger_copy_gpart_fields( ...@@ -544,27 +512,11 @@ void logger_copy_gpart_fields(
* @param log The #logger_writer * @param log The #logger_writer
* @param p The #gpart to dump. * @param p The #gpart to dump.
* @param mask The mask of the data 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 special_flags The value of the special flags. * @param special_flags The value of the special flags.
*/ */
void logger_log_gpart(struct logger_writer *log, const struct gpart *p, void logger_log_gpart(struct logger_writer *log, struct gpart *p,
unsigned int mask, size_t *offset, unsigned int mask, const uint32_t special_flags) {
const uint32_t special_flags) { logger_log_gparts(log, p, /* count */ 1, mask, special_flags);
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
/* Allocate a chunk of memory in the dump of the right size. */
size_t offset_new;
char *buff = (char *)dump_get(&log->dump, size, &offset_new);
/* Copy everything into the buffer */
logger_copy_gpart_fields(p, mask, offset, offset_new, buff,
special_flags);
/* Update the log message offset. */
*offset = offset_new;
} }
/** /**
......
...@@ -173,20 +173,18 @@ struct logger_part_data { ...@@ -173,20 +173,18 @@ struct logger_part_data {
int logger_compute_chunk_size(unsigned int mask); int logger_compute_chunk_size(unsigned int mask);
void logger_log_all(struct logger_writer *log, const struct engine *e); void logger_log_all(struct logger_writer *log, const struct engine *e);
void logger_log_part(struct logger_writer *log, const struct part *p, void logger_log_part(struct logger_writer *log, const struct part *p,
unsigned int mask, size_t *offset, struct xpart *xp, unsigned int mask,
const uint32_t special_flags); const uint32_t special_flags);
void logger_log_parts(struct logger_writer *log, const struct part *p, void logger_log_parts(struct logger_writer *log, const struct part *p,
struct xpart *xp, int count, struct xpart *xp, int count,
unsigned int mask, const uint32_t special_flags); unsigned int mask, const uint32_t special_flags);
void logger_log_spart(struct logger_writer *log, const struct spart *p, void logger_log_spart(struct logger_writer *log, struct spart *p,
unsigned int mask, size_t *offset, unsigned int mask, const uint32_t special_flags);
const uint32_t special_flags);
void logger_log_sparts(struct logger_writer *log, struct spart *sp, void logger_log_sparts(struct logger_writer *log, struct spart *sp,
int count, unsigned int mask, int count, unsigned int mask,
const uint32_t special_flags); const uint32_t special_flags);
void logger_log_gpart(struct logger_writer *log, const struct gpart *p, void logger_log_gpart(struct logger_writer *log, struct gpart *p,
unsigned int mask, size_t *offset, unsigned int mask, const uint32_t special_flags);
const uint32_t special_flags);
void logger_log_gparts(struct logger_writer *log, struct gpart *gp, void logger_log_gparts(struct logger_writer *log, struct gpart *gp,
int count, unsigned int mask, int count, unsigned int mask,
const uint32_t special_flags); const uint32_t special_flags);
......
...@@ -315,7 +315,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { ...@@ -315,7 +315,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
/* Write the particle */ /* Write the particle */
/* Logs all the fields request by the user */ /* Logs all the fields request by the user */
// TODO select only the requested fields // TODO select only the requested fields
logger_log_part(e->logger, p, logger_log_part(e->logger, p, xp,
logger_mask_data[logger_x].mask | logger_mask_data[logger_x].mask |
logger_mask_data[logger_v].mask | logger_mask_data[logger_v].mask |
logger_mask_data[logger_a].mask | logger_mask_data[logger_a].mask |
...@@ -324,7 +324,6 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { ...@@ -324,7 +324,6 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_rho].mask | logger_mask_data[logger_rho].mask |
logger_mask_data[logger_consts].mask | logger_mask_data[logger_consts].mask |
logger_mask_data[logger_special_flags].mask, logger_mask_data[logger_special_flags].mask,
&xp->logger_data.last_offset,
logger_pack_flags_and_data(logger_flag_change_type, swift_type_stars)); logger_pack_flags_and_data(logger_flag_change_type, swift_type_stars));
#endif #endif
...@@ -354,11 +353,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { ...@@ -354,11 +353,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_x].mask | logger_mask_data[logger_x].mask |
logger_mask_data[logger_v].mask | logger_mask_data[logger_v].mask |
logger_mask_data[logger_consts].mask, logger_mask_data[logger_consts].mask,
&sp->logger_data.last_offset,
/* special flags */ 0); /* special flags */ 0);
/* Set counter back to zero */
sp->logger_data.steps_since_last_output = 0;
#endif #endif
} }
} }
...@@ -610,6 +605,10 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) { ...@@ -610,6 +605,10 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
const int gcount = c->grav.count; const int gcount = c->grav.count;
const int scount = c->stars.count; const int scount = c->stars.count;
if (c->black_holes.count != 0) {
error("Black holes are not implemented in the logger.");
}
/* Anything to do here? */ /* Anything to do here? */
if (!cell_is_active_hydro(c, e) && !cell_is_active_gravity(c, e) && if (!cell_is_active_hydro(c, e) && !cell_is_active_gravity(c, e) &&
!cell_is_active_stars(c, e)) !cell_is_active_stars(c, e))
...@@ -634,7 +633,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) { ...@@ -634,7 +633,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
if (logger_should_write(&xp->logger_data, e->logger)) { if (logger_should_write(&xp->logger_data, e->logger)) {
/* Write particle */ /* Write particle */
/* Currently writing everything, should adapt it through time */ /* Currently writing everything, should adapt it through time */
logger_log_part(e->logger, p, logger_log_part(e->logger, p, xp,
logger_mask_data[logger_x].mask | logger_mask_data[logger_x].mask |
logger_mask_data[logger_v].mask | logger_mask_data[logger_v].mask |
logger_mask_data[logger_a].mask | logger_mask_data[logger_a].mask |
...@@ -642,11 +641,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) { ...@@ -642,11 +641,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_h].mask | logger_mask_data[logger_h].mask |
logger_mask_data[logger_rho].mask | logger_mask_data[logger_rho].mask |
logger_mask_data[logger_consts].mask, logger_mask_data[logger_consts].mask,
&xp->logger_data.last_offset,
/* special flags */ 0); /* special flags */ 0);
/* Set counter back to zero */
xp->logger_data.steps_since_last_output = 0;
} else } else
/* Update counter */ /* Update counter */
xp->logger_data.steps_since_last_output += 1; xp->logger_data.steps_since_last_output += 1;
...@@ -673,11 +668,8 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) { ...@@ -673,11 +668,8 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_v].mask | logger_mask_data[logger_v].mask |
logger_mask_data[logger_a].mask | logger_mask_data[logger_a].mask |
logger_mask_data[logger_consts].mask, logger_mask_data[logger_consts].mask,
&gp->logger_data.last_offset,
/* Special flags */ 0); /* Special flags */ 0);
/* Set counter back to zero */
gp->logger_data.steps_since_last_output = 0;
} else } else
/* Update counter */ /* Update counter */
gp->logger_data.steps_since_last_output += 1; gp->logger_data.steps_since_last_output += 1;
...@@ -700,11 +692,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) { ...@@ -700,11 +692,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_x].mask | logger_mask_data[logger_x].mask |
logger_mask_data[logger_v].mask | logger_mask_data[logger_v].mask |
logger_mask_data[logger_consts].mask, logger_mask_data[logger_consts].mask,
&sp->logger_data.last_offset,
/* Special flags */ 0); /* Special flags */ 0);
/* Set counter back to zero */
sp->logger_data.steps_since_last_output = 0;
} else } else
/* Update counter */ /* Update counter */
sp->logger_data.steps_since_last_output += 1; sp->logger_data.steps_since_last_output += 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