Skip to content
Snippets Groups Projects

Implement counter of jumps

Merged Loic Hausammann requested to merge log_number_jumps into master
1 file
+ 37
4
Compare changes
  • Side-by-side
  • Inline
+ 37
4
@@ -393,6 +393,7 @@ void csds_reader_get_number_particles(struct csds_reader *reader,
* @param field_wanted The field to read.
* @param output Pointers to the output array
* @param type The #part_type.
* @param number_jumps The number of jumps done in order to find the particle.
*
* @return Is the particle removed from the logfile?
*/
@@ -401,10 +402,12 @@ int csds_reader_read_field(struct csds_reader *reader, double time,
enum csds_reader_type interp_type,
const size_t offset_last_full_record,
const struct field_information *field_wanted,
void *output, enum part_type type) {
void *output, enum part_type type,
int *number_jumps) {
const struct header *h = &reader->log.header;
size_t offset = offset_last_full_record;
*number_jumps = 0;
/* Check if the offsets are correct. */
if (offset > offset_time) {
@@ -423,6 +426,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time,
no need to check if the field is found.
*/
while (offset < offset_time) {
*number_jumps += 1;
/* Read the particle. */
csds_loader_io_read_mask(reader->log.log.map + offset, &mask, &h_offset);
@@ -660,6 +664,9 @@ struct extra_data_read_all {
/*! The current position in the output arrays. */
size_t current_output;
/*! The number of jumps done in order to find the particles */
long int total_number_jumps;
};
/**
@@ -715,6 +722,7 @@ void csds_reader_read_all_particles_single_type_mapper(void *map_data,
}
/* Read the particles */
long int total_number_jumps = 0;
for (int i = 0; i < num_elements; i++) {
/* Get the next index. */
@@ -739,15 +747,18 @@ void csds_reader_read_all_particles_single_type_mapper(void *map_data,
for (int field = 0; field < n_fields_wanted; field++) {
/* Read the field. */
int number_jumps = 0;
particle_removed = csds_reader_read_field(
reader, time, reader->time.time_offset, interp_type, offset,
fields_wanted[field], output_tmp[field], type);
fields_wanted[field], output_tmp[field], type, &number_jumps);
/* Should we continue to read the fields of this particle? */
if (particle_removed) {
i--;
break;
}
total_number_jumps += number_jumps;
}
/* Write the particle into the output if it was not removed */
@@ -771,6 +782,10 @@ void csds_reader_read_all_particles_single_type_mapper(void *map_data,
free(output_tmp[i]);
}
free(output_tmp);
/* Write the number of jumps */
__atomic_add_fetch(&data_tp->total_number_jumps, total_number_jumps,
__ATOMIC_RELAXED);
}
/**
@@ -813,7 +828,8 @@ void csds_reader_read_all_particles_single_type(
n_part,
type,
/* current_index */ 0,
/* current_output */ 0};
/* current_output */ 0,
/* total_number_jumps */ 0};
/* Create the threadpool */
struct threadpool tp;
@@ -828,6 +844,13 @@ void csds_reader_read_all_particles_single_type(
error("The reader was not able to find all the expected particles.");
}
/* Print the number of jumps if required */
if (reader->verbose > 1 || reader->verbose == CSDS_VERBOSE_TIMERS) {
float avg = (float)extra.total_number_jumps /
(float)(n_fields_wanted * n_part[type]);
message("Average number of jumps for %s: %.1f", part_type_names[type], avg);
}
/* Free the memory */
threadpool_clean(&tp);
free(fields_info_wanted);
@@ -930,6 +953,7 @@ void csds_reader_read_particles_from_ids_single_type(
n_fields_wanted, type);
/* Read the particles */
size_t total_number_jumps = 0;
for (size_t i = 0; i < n_part[type]; i++) {
/* Get the offset */
@@ -952,9 +976,10 @@ void csds_reader_read_particles_from_ids_single_type(
(i + prev_npart) * fields_info_wanted[field]->field.size;
/* Read the field. */
int number_jumps = 0;
int particle_removed = csds_reader_read_field(
reader, time, reader->time.time_offset, interp_type, offset,
fields_info_wanted[field], output_single, type);
fields_info_wanted[field], output_single, type, &number_jumps);
/* Is the particle still present? */
if (particle_removed) {
@@ -963,9 +988,17 @@ void csds_reader_read_particles_from_ids_single_type(
i -= 1;
break;
}
total_number_jumps += number_jumps;
}
}
/* Print the number of jumps if required */
if (reader->verbose > 1 || reader->verbose == CSDS_VERBOSE_TIMERS) {
float avg =
(float)total_number_jumps / (float)(n_fields_wanted * n_part[type]);
message("Average number of jumps for %s: %.1f", part_type_names[type], avg);
}
/* Free the memory */
free(fields_info_wanted);
}
Loading