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

Format

parent eb83729b
......@@ -253,8 +253,8 @@ int main(int argc, char *argv[]) {
"Overwrite the CPU "
"frequency (Hz) to be used for time measurements.",
NULL, 0, 0),
OPT_BOOLEAN(0, "logger", &with_logger,
"Run with the particle logger.", NULL, 0, 0),
OPT_BOOLEAN(0, "logger", &with_logger, "Run with the particle logger.",
NULL, 0, 0),
OPT_INTEGER('n', "steps", &nsteps,
"Execute a fixed number of time steps. When unset use the "
"time_end parameter to stop.",
......@@ -335,7 +335,9 @@ int main(int argc, char *argv[]) {
#if !defined(WITH_LOGGER)
if (with_logger) {
printf("Error: the particle logger is not available, please compile with --enable-logger.");
printf(
"Error: the particle logger is not available, please compile with "
"--enable-logger.");
return 1;
}
#endif
......
......@@ -123,8 +123,7 @@ const char *engine_policy_names[] = {"none",
"fof search",
"time-step limiter",
"time-step sync",
"logger"
};
"logger"};
/** The rank of the engine as a global variable (for messages). */
int engine_rank;
......@@ -457,14 +456,13 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
#ifdef WITH_LOGGER
if (e->policy & engine_policy_logger) {
const uint32_t logger_flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, node_id);
const uint32_t logger_flag =
logger_pack_flags_and_data(logger_flag_mpi_exit, node_id);
/* Log the particle when leaving a rank. */
logger_log_part(e->logger, &s->parts[offset_parts + k],
&s->xparts[offset_parts + k],
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
logger_log_part(
e->logger, &s->parts[offset_parts + k], &s->xparts[offset_parts + k],
logger_masks_all_part | logger_mask_data[logger_special_flags].mask,
logger_flag);
}
#endif
......@@ -506,13 +504,13 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
#ifdef WITH_LOGGER
if (e->policy & engine_policy_logger) {
const uint32_t logger_flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, node_id);
const uint32_t logger_flag =
logger_pack_flags_and_data(logger_flag_mpi_exit, node_id);
/* Log the particle when leaving a rank. */
logger_log_spart(e->logger, &s->sparts[offset_sparts + k],
logger_masks_all_spart |
logger_mask_data[logger_special_flags].mask,
logger_log_spart(
e->logger, &s->sparts[offset_sparts + k],
logger_masks_all_spart | logger_mask_data[logger_special_flags].mask,
logger_flag);
}
#endif
......@@ -592,13 +590,13 @@ 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 uint32_t logger_flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, node_id);
const uint32_t logger_flag =
logger_pack_flags_and_data(logger_flag_mpi_exit, node_id);
/* Log the particle when leaving a rank. */
logger_log_gpart(e->logger, &s->gparts[offset_gparts + k],
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask,
logger_log_gpart(
e->logger, &s->gparts[offset_gparts + k],
logger_masks_all_gpart | logger_mask_data[logger_special_flags].mask,
logger_flag);
}
#endif
......@@ -824,8 +822,8 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
#ifdef WITH_LOGGER
if (e->policy & engine_policy_logger) {
const uint32_t flag = logger_pack_flags_and_data(logger_flag_mpi_enter,
prox->nodeID);
const uint32_t flag =
logger_pack_flags_and_data(logger_flag_mpi_enter, prox->nodeID);
struct part *parts = &s->parts[offset_parts + count_parts];
struct xpart *xparts = &s->xparts[offset_parts + count_parts];
......@@ -833,9 +831,9 @@ 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 */
logger_log_parts(e->logger, parts, xparts,
prox->nr_parts_in, logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
logger_log_parts(
e->logger, parts, xparts, prox->nr_parts_in,
logger_masks_all_part | logger_mask_data[logger_special_flags].mask,
flag);
/* Log the stellar particles */
......
......@@ -867,8 +867,7 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
/* Create a variable in order to avoid to many ifdef */
kick2_or_logger = c->logger;
}
else {
} else {
kick2_or_logger = c->kick2;
}
#else
......@@ -1186,8 +1185,7 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c,
#ifdef WITH_LOGGER
if (with_logger) {
scheduler_addunlock(s, c->super->logger, c->stars.stars_in);
}
else {
} else {
scheduler_addunlock(s, c->super->kick2, c->stars.stars_in);
}
#else
......@@ -1223,10 +1221,11 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c,
#ifdef WITH_LOGGER
if (with_logger) {
scheduler_addunlock(s, c->super->logger, c->black_holes.black_holes_in);
}
else {
scheduler_addunlock(s, c->super->kick2, c->black_holes.black_holes_in);
scheduler_addunlock(s, c->super->logger,
c->black_holes.black_holes_in);
} else {
scheduler_addunlock(s, c->super->kick2,
c->black_holes.black_holes_in);
}
#else
scheduler_addunlock(s, c->super->kick2, c->black_holes.black_holes_in);
......
......@@ -984,7 +984,7 @@ void engine_redistribute(struct engine *e) {
size_t gpart_offset = 0;
size_t bpart_offset = 0;
for(int i = 0; i < nr_nodes; i++) {
for (int i = 0; i < nr_nodes; i++) {
const size_t c_ind = engine_rank * nr_nodes + i;
/* No need to log the local particles. */
......@@ -995,26 +995,24 @@ void engine_redistribute(struct engine *e) {
bpart_offset += b_counts[c_ind];
continue;
}
const uint32_t flag = logger_pack_flags_and_data(
logger_flag_mpi_exit, i);
const uint32_t flag = logger_pack_flags_and_data(logger_flag_mpi_exit, i);
/* Log the hydro parts. */
logger_log_parts(e->logger, &parts[part_offset],
&xparts[part_offset], counts[c_ind],
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
logger_log_parts(
e->logger, &parts[part_offset], &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], s_counts[c_ind],
logger_masks_all_spart |
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], g_counts[c_ind],
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask,
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 */
......@@ -1090,7 +1088,7 @@ void engine_redistribute(struct engine *e) {
size_t gpart_offset = 0;
size_t bpart_offset = 0;
for(int i = 0; i < nr_nodes; i++) {
for (int i = 0; i < nr_nodes; i++) {
const size_t c_ind = i * nr_nodes + engine_rank;
/* No need to log the local particles. */
......@@ -1102,26 +1100,25 @@ void engine_redistribute(struct engine *e) {
continue;
}
const uint32_t flag = logger_pack_flags_and_data(
logger_flag_mpi_enter, i);
const uint32_t flag =
logger_pack_flags_and_data(logger_flag_mpi_enter, i);
/* Log the hydro parts. */
logger_log_parts(e->logger, &parts[part_offset],
&xparts[part_offset], counts[c_ind],
logger_masks_all_part |
logger_mask_data[logger_special_flags].mask,
logger_log_parts(
e->logger, &parts[part_offset], &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], s_counts[c_ind],
logger_masks_all_spart |
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], g_counts[c_ind],
logger_masks_all_gpart |
logger_mask_data[logger_special_flags].mask,
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 */
......
......@@ -181,8 +181,7 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) {
/* loop over all parts. */
for (size_t i = 0; i < s->nr_parts; i++) {
logger_log_part(log, &s->parts[i], &s->xparts[i],
logger_masks_all_part,
logger_log_part(log, &s->parts[i], &s->xparts[i], logger_masks_all_part,
/* Special flags */ 0);
}
......@@ -214,8 +213,7 @@ void logger_log_all(struct logger_writer *log, const struct engine *e) {
* @param buff The buffer to use when writing.
* @param special_flags The data for the special flags.
*/
void logger_copy_part_fields(
const struct part *p, unsigned int mask,
void logger_copy_part_fields(const struct part *p, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const uint32_t special_flags) {
......@@ -281,7 +279,6 @@ void logger_copy_part_fields(
memcpy(buff, &special_flags, logger_mask_data[logger_special_flags].size);
buff += logger_mask_data[logger_special_flags].size;
}
}
/**
......@@ -297,8 +294,7 @@ void logger_log_part(struct logger_writer *log, const struct part *p,
struct xpart *xp, unsigned int mask,
const uint32_t special_flags) {
logger_log_parts(log, p, xp, /* count */ 1, mask,
special_flags);
logger_log_parts(log, p, xp, /* count */ 1, mask, special_flags);
}
/**
......@@ -320,7 +316,7 @@ void logger_log_parts(struct logger_writer *log, const struct part *p,
size_t offset_new;
char *buff = (char *)dump_get(&log->dump, count * size, &offset_new);
for(int i = 0; i < count; i++) {
for (int i = 0; i < count; i++) {
/* Copy everything into the buffer */
logger_copy_part_fields(&p[i], mask, &xp[i].logger_data.last_offset,
offset_new, buff, special_flags);
......@@ -343,8 +339,7 @@ void logger_log_parts(struct logger_writer *log, const struct part *p,
* @param buff The buffer to use when writing.
* @param special_flags The data for the special flags.
*/
void logger_copy_spart_fields(
const struct spart *sp, unsigned int mask,
void logger_copy_spart_fields(const struct spart *sp, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const uint32_t special_flags) {
......@@ -401,8 +396,7 @@ void logger_copy_spart_fields(
void logger_log_spart(struct logger_writer *log, struct spart *sp,
unsigned int mask, const uint32_t special_flags) {
logger_log_sparts(log, sp, /* count */ 1, mask,
special_flags);
logger_log_sparts(log, sp, /* count */ 1, mask, special_flags);
}
/**
......@@ -414,9 +408,8 @@ void logger_log_spart(struct logger_writer *log, struct spart *sp,
* @param count The number of particle to dump.
* @param special_flags The value of the special flags.
*/
void logger_log_sparts(struct logger_writer *log, struct spart *sp,
int count, unsigned int mask,
const uint32_t special_flags) {
void logger_log_sparts(struct logger_writer *log, struct spart *sp, 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);
......@@ -424,7 +417,7 @@ void logger_log_sparts(struct logger_writer *log, struct spart *sp,
size_t offset_new;
char *buff = (char *)dump_get(&log->dump, count * size, &offset_new);
for(int i = 0; i < count; i++) {
for (int i = 0; i < count; i++) {
/* Copy everything into the buffer */
logger_copy_spart_fields(&sp[i], mask, &sp[i].logger_data.last_offset,
offset_new, buff, special_flags);
......@@ -447,8 +440,7 @@ void logger_log_sparts(struct logger_writer *log, struct spart *sp,
* @param buff The buffer to use when writing.
* @param special_flags The data of the special flag.
*/
void logger_copy_gpart_fields(
const struct gpart *gp, unsigned int mask,
void logger_copy_gpart_fields(const struct gpart *gp, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const uint32_t special_flags) {
......@@ -503,7 +495,6 @@ void logger_copy_gpart_fields(
memcpy(buff, &special_flags, logger_mask_data[logger_special_flags].size);
buff += logger_mask_data[logger_special_flags].size;
}
}
/**
......@@ -528,9 +519,8 @@ void logger_log_gpart(struct logger_writer *log, struct gpart *p,
* @param count The number of particle to dump.
* @param special_flags The value of the special flags.
*/
void logger_log_gparts(struct logger_writer *log, struct gpart *p,
int count, unsigned int mask,
const uint32_t special_flags) {
void logger_log_gparts(struct logger_writer *log, struct gpart *p, 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);
......@@ -538,7 +528,7 @@ void logger_log_gparts(struct logger_writer *log, struct gpart *p,
size_t offset_new;
char *buff = (char *)dump_get(&log->dump, count * size, &offset_new);
for(int i = 0; i < count; i++) {
for (int i = 0; i < count; i++) {
/* Log only the dark matter */
if (p[i].type != swift_type_dark_matter) continue;
......@@ -945,7 +935,6 @@ 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.
*
......@@ -957,7 +946,6 @@ void logger_struct_dump(const struct logger_writer *log, FILE *stream) {
"logger", "logger");
}
/**
* @brief Restore a logger struct from the given FILE as a stream of
* bytes.
......
......@@ -94,18 +94,19 @@ enum logger_masks_number {
/* Defines some mask for logging all the fields */
enum logger_masks_all {
logger_masks_all_part = (1 << logger_x) | (1 << logger_v) |
(1 << logger_a) | (1 << logger_u) | (1 << logger_h) | (1 << logger_rho) |
(1 << logger_consts),
logger_masks_all_gpart = (1 << logger_x) | (1 << logger_v) |
(1 << logger_a) | (1 << logger_consts),
logger_masks_all_spart = (1 << logger_x) | (1 << logger_v) |
logger_masks_all_part = (1 << logger_x) | (1 << logger_v) | (1 << logger_a) |
(1 << logger_u) | (1 << logger_h) |
(1 << logger_rho) | (1 << logger_consts),
logger_masks_all_gpart = (1 << logger_x) | (1 << logger_v) | (1 << logger_a) |
(1 << logger_consts),
logger_masks_all_spart =
(1 << logger_x) | (1 << logger_v) | (1 << logger_consts),
} __attribute__((packed));
enum logger_special_flags {
logger_flag_change_type = 1, /* Flag for a change of particle type */
logger_flag_mpi_enter, /* Flag for a particle received from another MPI rank */
logger_flag_mpi_enter, /* Flag for a particle received from another MPI rank
*/
logger_flag_mpi_exit, /* Flag for a particle sent to another MPI rank */
logger_flag_delete, /* Flag for a deleted particle */
logger_flag_create, /* Flag for a created particle */
......@@ -176,18 +177,16 @@ void logger_log_part(struct logger_writer *log, const struct part *p,
struct xpart *xp, unsigned int mask,
const uint32_t special_flags);
void logger_log_parts(struct logger_writer *log, const struct part *p,
struct xpart *xp, int count,
unsigned int mask, const uint32_t special_flags);
struct xpart *xp, int count, unsigned int mask,
const uint32_t special_flags);
void logger_log_spart(struct logger_writer *log, struct spart *p,
unsigned int mask, const uint32_t special_flags);
void logger_log_sparts(struct logger_writer *log, struct spart *sp,
int count, unsigned int mask,
const uint32_t special_flags);
void logger_log_sparts(struct logger_writer *log, struct spart *sp, int count,
unsigned int mask, const uint32_t special_flags);
void logger_log_gpart(struct logger_writer *log, struct gpart *p,
unsigned int mask, const uint32_t special_flags);
void logger_log_gparts(struct logger_writer *log, struct gpart *gp,
int count, unsigned int mask,
const uint32_t special_flags);
void logger_log_gparts(struct logger_writer *log, struct gpart *gp, 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,
......@@ -203,23 +202,27 @@ int logger_read_timestamp(unsigned long long int *t, double *time,
void logger_struct_dump(const struct logger_writer *log, FILE *stream);
void logger_struct_restore(struct logger_writer *log, FILE *stream);
/**
* @brief Generate the data for the special flags.
*
* @param flag The special flag to use.
* @param data The data to write in the .
*/
INLINE static uint32_t logger_pack_flags_and_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 particle 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 particle 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);
return ((uint32_t)flag << (3 * 8)) | (data & 0xFFFFFF);
}
/**
......
......@@ -324,7 +324,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
logger_mask_data[logger_rho].mask |
logger_mask_data[logger_consts].mask |
logger_mask_data[logger_special_flags].mask,
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
/* 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