From 169f8aa682e13091dc393956a7d6d9c6d99b687d Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Sat, 20 Aug 2016 00:12:03 +0100 Subject: [PATCH] Code formatting, threadpool documentation, threadpool memory cleaning. --- src/engine.c | 1 + src/hydro/Gadget2/hydro_iact.h | 4 ++-- src/runner.c | 8 ++++---- src/serial_io.c | 4 ++-- src/threadpool.c | 12 +++++++++++- src/threadpool.h | 1 + src/timestep.h | 8 +++++--- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/engine.c b/src/engine.c index a626e611bc..4eb3126d86 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3349,4 +3349,5 @@ void engine_clean(struct engine *e) { free(e->links); scheduler_clean(&e->sched); space_clean(e->s); + threadpool_clean(&e->threadpool); } diff --git a/src/hydro/Gadget2/hydro_iact.h b/src/hydro/Gadget2/hydro_iact.h index bec6b004a4..0108e0663c 100644 --- a/src/hydro/Gadget2/hydro_iact.h +++ b/src/hydro/Gadget2/hydro_iact.h @@ -432,7 +432,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_force( const float balsara_j = pj->force.balsara; /* Are the particles moving towards each others ? */ - const float omega_ij = (dvdr < 0.f) ? dvdr: 0.f; + const float omega_ij = (dvdr < 0.f) ? dvdr : 0.f; const float mu_ij = fac_mu * r_inv * omega_ij; /* This is 0 or negative */ /* Signal velocity */ @@ -707,7 +707,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force( const float balsara_j = pj->force.balsara; /* Are the particles moving towards each others ? */ - const float omega_ij = (dvdr < 0.f) ? dvdr: 0.f; + const float omega_ij = (dvdr < 0.f) ? dvdr : 0.f; const float mu_ij = fac_mu * r_inv * omega_ij; /* This is 0 or negative */ /* Signal velocity */ diff --git a/src/runner.c b/src/runner.c index c9c2ef69f4..018f1f082e 100644 --- a/src/runner.c +++ b/src/runner.c @@ -487,8 +487,8 @@ void runner_do_ghost(struct runner *r, struct cell *c) { h_corr = (target_wcount - p->density.wcount) / p->density.wcount_dh; /* Truncate to the range [ -p->h/2 , p->h ]. */ - h_corr = (h_corr < p->h) ? h_corr : p->h; - h_corr = (h_corr > -0.5f * p->h) ? h_corr : -0.5f * p->h; + h_corr = (h_corr < p->h) ? h_corr : p->h; + h_corr = (h_corr > -0.5f * p->h) ? h_corr : -0.5f * p->h; } /* Did we get the right number density? */ @@ -622,7 +622,7 @@ static void runner_do_drift(struct cell *c, struct engine *e) { const float dx2 = gp->x_diff[0] * gp->x_diff[0] + gp->x_diff[1] * gp->x_diff[1] + gp->x_diff[2] * gp->x_diff[2]; - dx2_max = (dx2_max > dx2) ? dx2_max : dx2; + dx2_max = (dx2_max > dx2) ? dx2_max : dx2; } /* Loop over all the particles in the cell (more work for these !) */ @@ -640,7 +640,7 @@ static void runner_do_drift(struct cell *c, struct engine *e) { const float dx2 = xp->x_diff[0] * xp->x_diff[0] + xp->x_diff[1] * xp->x_diff[1] + xp->x_diff[2] * xp->x_diff[2]; - dx2_max = (dx2_max > dx2) ? dx2_max : dx2; + dx2_max = (dx2_max > dx2) ? dx2_max : dx2; /* Maximal smoothing length */ h_max = (h_max > p->h) ? h_max : p->h; diff --git a/src/serial_io.c b/src/serial_io.c index 83f1f35746..d0618ea93e 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -225,11 +225,11 @@ void prepareArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile, } /* Impose data compression */ - if(e->snapshotCompression > 0) { + if (e->snapshotCompression > 0) { h_err = H5Pset_deflate(h_prop, e->snapshotCompression); if (h_err < 0) { error("Error while setting compression options for field '%s'.", - props.name); + props.name); } } diff --git a/src/threadpool.c b/src/threadpool.c index 795fa4d557..4ef75954b3 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -71,6 +71,12 @@ void *threadpool_runner(void *data) { } } +/** + * @brief Initialises the #threadpool with a given number of threads. + * + * @param tp The #threadpool. + * @param num_threads The number of threads. + */ void threadpool_init(struct threadpool *tp, int num_threads) { /* Initialize the thread counters. */ @@ -126,7 +132,6 @@ void threadpool_init(struct threadpool *tp, int num_threads) { * @param extra_data Addtitional pointer that will be passed to the mapping * function, may contain additional data. */ - void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, void *map_data, size_t N, int stride, int chunk, void *extra_data) { @@ -154,3 +159,8 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, } pthread_mutex_unlock(&tp->thread_mutex); } + +/** + * @brief Frees up the memory allocated for this #threadpool. + */ +void threadpool_clean(struct threadpool *tp) { free(tp->threads); } diff --git a/src/threadpool.h b/src/threadpool.h index e07a0613c0..76aa0c1196 100644 --- a/src/threadpool.h +++ b/src/threadpool.h @@ -57,5 +57,6 @@ void threadpool_init(struct threadpool *tp, int num_threads); void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, void *map_data, size_t N, int stride, int chunk, void *extra_data); +void threadpool_clean(struct threadpool *tp); #endif /* SWIFT_THREADPOOL_H */ diff --git a/src/timestep.h b/src/timestep.h index 582f10a658..d92f88d064 100644 --- a/src/timestep.h +++ b/src/timestep.h @@ -74,7 +74,8 @@ __attribute__((always_inline)) INLINE static int get_gpart_timestep( /* gravity_compute_timestep_self(e->physical_constants, gp); */ const float new_dt_self = FLT_MAX; // MATTHIEU - float new_dt = (new_dt_external < new_dt_self) ? new_dt_external : new_dt_self; + float new_dt = + (new_dt_external < new_dt_self) ? new_dt_external : new_dt_self; /* Limit timestep within the allowed range */ new_dt = (new_dt < e->dt_max) ? new_dt : e->dt_max; @@ -111,11 +112,12 @@ __attribute__((always_inline)) INLINE static int get_part_timestep( /* gravity_compute_timestep_self(e->physical_constants, p->gpart); */ const float new_dt_self = FLT_MAX; // MATTHIEU - new_dt_grav = (new_dt_external < new_dt_self) ? new_dt_external : new_dt_self; + new_dt_grav = + (new_dt_external < new_dt_self) ? new_dt_external : new_dt_self; } /* Final time-step is minimum of hydro and gravity */ - float new_dt = (new_dt_hydro < new_dt_grav) ? new_dt_hydro: new_dt_grav; + float new_dt = (new_dt_hydro < new_dt_grav) ? new_dt_hydro : new_dt_grav; /* Limit change in h */ const float dt_h_change = -- GitLab