Commit 0fe21db9 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger: part of the second review

parent 919db29c
......@@ -457,7 +457,7 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
#ifdef WITH_LOGGER
if (e->policy & engine_policy_logger) {
const int logger_flag = logger_generate_flag_data(
const uint32_t logger_flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, node_id);
/* Log the particle when leaving a rank. */
......@@ -506,7 +506,7 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
#ifdef WITH_LOGGER
if (e->policy & engine_policy_logger) {
const int logger_flag = logger_generate_flag_data(
const uint32_t logger_flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, node_id);
/* Log the particle when leaving a rank. */
......@@ -593,7 +593,7 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
if ((e->policy & engine_policy_logger) &&
s->gparts[offset_gparts + k].type == swift_type_dark_matter) {
const int logger_flag = logger_generate_flag_data(
const uint32_t logger_flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, node_id);
/* Log the particle when leaving a rank. */
......@@ -826,7 +826,7 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
#ifdef WITH_LOGGER
if (e->policy & engine_policy_logger) {
const int flag = logger_generate_flag_data(logger_flag_mpi_enter,
const uint32_t flag = logger_pack_flags_and_data(logger_flag_mpi_enter,
prox->nodeID);
struct part *parts = &s->parts[offset_parts + count_parts];
......@@ -835,27 +835,22 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
struct gpart *gparts = &s->gparts[offset_gparts + count_gparts];
/* Log the gas particles */
const unsigned int mask_hydro =
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask;
logger_log_parts(e->logger, parts, xparts,
mask_hydro, prox->nr_parts_in, flag);
prox->nr_parts_in, logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the stellar particles */
const unsigned int mask_stars = logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask;
logger_log_sparts(e->logger, sparts, mask_stars,
prox->nr_sparts_in, flag);
logger_log_sparts(e->logger, sparts, prox->nr_sparts_in,
logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the gparts */
const unsigned int mask_grav =
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask;
logger_log_gparts(e->logger, gparts, mask_grav,
prox->nr_gparts_in, flag);
logger_log_gparts(e->logger, gparts, prox->nr_gparts_in,
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the bparts */
if (prox->nr_bparts_in > 0) {
......
......@@ -995,32 +995,27 @@ void engine_redistribute(struct engine *e) {
bpart_offset += b_counts[c_ind];
continue;
}
const int flag = logger_generate_flag_data(
const uint32_t flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, i);
const unsigned int mask_hydro =
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask;
/* Log the hydro parts. */
logger_log_parts(e->logger, &parts[part_offset],
&xparts[part_offset], mask_hydro,
counts[c_ind], flag);
const unsigned int mask_stars = logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask;
&xparts[part_offset], counts[c_ind],
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the stellar parts. */
logger_log_sparts(e->logger, &sparts[spart_offset], mask_stars,
s_counts[c_ind], flag);
const unsigned int mask_grav =
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask;
logger_log_sparts(e->logger, &sparts[spart_offset], s_counts[c_ind],
logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the gparts */
logger_log_gparts(e->logger, &gparts[gpart_offset], mask_grav,
g_counts[c_ind], flag);
logger_log_gparts(e->logger, &gparts[gpart_offset], g_counts[c_ind],
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the bparts */
if (b_counts[c_ind] > 0) {
......@@ -1107,32 +1102,27 @@ void engine_redistribute(struct engine *e) {
continue;
}
const int flag = logger_generate_flag_data(
const uint32_t flag = logger_pack_flags_and_data(
logger_flag_mpi_enter, i);
const unsigned int mask_hydro =
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask;
/* Log the hydro parts. */
logger_log_parts(e->logger, &parts[part_offset],
&xparts[part_offset], mask_hydro,
counts[c_ind], flag);
const unsigned int mask_stars = logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask;
&xparts[part_offset], counts[c_ind],
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the stellar parts. */
logger_log_sparts(e->logger, &sparts[spart_offset], mask_stars,
s_counts[c_ind], flag);
const unsigned int mask_grav =
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask;
logger_log_sparts(e->logger, &sparts[spart_offset], s_counts[c_ind],
logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the gparts */
logger_log_gparts(e->logger, &gparts[gpart_offset], mask_grav,
g_counts[c_ind], flag);
logger_log_gparts(e->logger, &gparts[gpart_offset], g_counts[c_ind],
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask,
flag);
/* Log the bparts */
if (b_counts[c_ind] > 0) {
......
......@@ -78,7 +78,7 @@ const struct mask_data logger_mask_data[logger_count_mask] = {
/* Particle's constants: mass (float) and ID (long long). */
{sizeof(float) + sizeof(long long), 1 << logger_consts, "consts"},
/* Flag for special cases (e.g. change of MPI rank, star formation, ...) */
{sizeof(int), 1 << logger_special_flags, "special flags"},
{sizeof(uint32_t), 1 << logger_special_flags, "special flags"},
/* Simulation time stamp: integertime and double time (e.g. scale
factor or time). */
{sizeof(integertime_t) + sizeof(double), 1 << logger_timestamp,
......@@ -222,7 +222,7 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) {
void logger_copy_part_fields(
const struct part *p, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const int special_flags) {
const uint32_t special_flags) {
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_data[logger_timestamp].mask)
......@@ -301,7 +301,7 @@ void logger_copy_part_fields(
*/
void logger_log_part(struct logger_writer *log, const struct part *p,
unsigned int mask, size_t *offset,
const int special_flags) {
const uint32_t special_flags) {
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
......@@ -328,8 +328,8 @@ void logger_log_part(struct logger_writer *log, const struct part *p,
* @param special_flags The value of the special flags.
*/
void logger_log_parts(struct logger_writer *log, const struct part *p,
struct xpart *xp, unsigned int mask, int count,
const int special_flags) {
struct xpart *xp, int count, unsigned int mask,
const uint32_t special_flags) {
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
......@@ -363,7 +363,7 @@ void logger_log_parts(struct logger_writer *log, const struct part *p,
void logger_copy_spart_fields(
const struct spart *sp, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const int special_flags) {
const uint32_t special_flags) {
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_data[logger_timestamp].mask)
......@@ -419,7 +419,7 @@ void logger_copy_spart_fields(
*/
void logger_log_spart(struct logger_writer *log, const struct spart *sp,
unsigned int mask, size_t *offset,
const int special_flags) {
const uint32_t special_flags) {
/* Start by computing the size of the message. */
......@@ -447,8 +447,8 @@ void logger_log_spart(struct logger_writer *log, const struct spart *sp,
* @param special_flags The value of the special flags.
*/
void logger_log_sparts(struct logger_writer *log, struct spart *sp,
unsigned int mask, int count,
const int special_flags) {
int count, unsigned int mask,
const uint32_t special_flags) {
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
......@@ -482,7 +482,7 @@ void logger_log_sparts(struct logger_writer *log, struct spart *sp,
void logger_copy_gpart_fields(
const struct gpart *gp, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const int special_flags) {
const uint32_t special_flags) {
#ifdef SWIFT_DEBUG_CHECKS
if (gp->id_or_neg_offset < 0) {
......@@ -550,7 +550,7 @@ void logger_copy_gpart_fields(
*/
void logger_log_gpart(struct logger_writer *log, const struct gpart *p,
unsigned int mask, size_t *offset,
const int special_flags) {
const uint32_t special_flags) {
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
......@@ -577,8 +577,8 @@ void logger_log_gpart(struct logger_writer *log, const struct gpart *p,
* @param special_flags The value of the special flags.
*/
void logger_log_gparts(struct logger_writer *log, struct gpart *p,
unsigned int mask, int count,
const int special_flags) {
int count, unsigned int mask,
const uint32_t special_flags) {
/* Start by computing the size of the message. */
const int size = logger_compute_chunk_size(mask);
......
......@@ -174,22 +174,22 @@ int logger_compute_chunk_size(unsigned int mask);
void logger_log_all(struct logger_writer *log, const struct engine *e);
void logger_log_part(struct logger_writer *log, const struct part *p,
unsigned int mask, size_t *offset,
const int special_flags);
const uint32_t special_flags);
void logger_log_parts(struct logger_writer *log, const struct part *p,
struct xpart *xp, unsigned int mask,
int count, const int special_flags);
struct xpart *xp, int count,
unsigned int mask, const uint32_t special_flags);
void logger_log_spart(struct logger_writer *log, const struct spart *p,
unsigned int mask, size_t *offset,
const int special_flags);
const uint32_t special_flags);
void logger_log_sparts(struct logger_writer *log, struct spart *sp,
unsigned int mask, int count,
const int special_flags);
int count, unsigned int mask,
const uint32_t special_flags);
void logger_log_gpart(struct logger_writer *log, const struct gpart *p,
unsigned int mask, size_t *offset,
const int special_flags);
const uint32_t special_flags);
void logger_log_gparts(struct logger_writer *log, struct gpart *gp,
unsigned int mask, int count,
const int special_flags);
int count, unsigned int mask,
const uint32_t special_flags);
void logger_init(struct logger_writer *log, struct swift_params *params);
void logger_free(struct logger_writer *log);
void logger_log_timestamp(struct logger_writer *log, integertime_t t,
......@@ -212,13 +212,13 @@ void logger_struct_restore(struct logger_writer *log, FILE *stream);
* @param flag The special flag to use.
* @param data The data to write in the .
*/
INLINE static int logger_generate_flag_data(enum logger_special_flags flag, int data) {
INLINE static uint32_t logger_pack_flags_and_data(enum logger_special_flags flag, int data) {
#ifdef SWIFT_DEBUG_CHECKS
if (flag & 0xFFFFFF00) {
error("The special flag in the logger cannot be larger than 1 byte.");
error("The special flag in the particle logger cannot be larger than 1 byte.");
}
if (data & ~0xFFFFFF) {
error("The data for the special flag in the logger cannot be larger than 3 bytes.");
error("The data for the special flag in the particle logger cannot be larger than 3 bytes.");
}
#endif
return ((uint32_t) flag << (3 * 8)) | (data & 0xFFFFFF);
......
......@@ -325,7 +325,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_consts].mask |
logger_mask_data[logger_special_flags].mask,
&xp->logger_data.last_offset,
logger_generate_flag_data(logger_flag_change_type, swift_type_stars));
logger_pack_flags_and_data(logger_flag_change_type, swift_type_stars));
#endif
/* Convert the gas particle to a star 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