Commit 152f4a9c authored by Matthieu Schaller's avatar Matthieu Schaller

Use clang-format-5.0 instead of clang-format-3.8 for the code's style.

parent 4669036f
......@@ -2,4 +2,5 @@
Language: Cpp
BasedOnStyle: Google
KeepEmptyLinesAtTheStartOfBlocks: true
PenaltyBreakAssignment: 2
...
The SWIFT source code is using a variation of the 'Google' formatting style.
The script 'format.sh' in the root directory applies the clang-format-3.8
The script 'format.sh' in the root directory applies the clang-format-5.0
tool with our style choices to all the SWIFT C source file. Please apply
the formatting script to the files before submitting a merge request.
......@@ -9,4 +9,4 @@ check` in the root directory. Please check that the test suite still
runs with your changes applied before submitting a merge request and add
relevant unit tests probing the correctness of new modules. An example of how
to add a test to the suite can be found by considering the tests/testGreeting
case.
\ No newline at end of file
case.
......@@ -182,6 +182,6 @@ before you can build it.
==================
The SWIFT source code uses a variation of 'Google' style. The script
'format.sh' in the root directory applies the clang-format-3.8 tool with our
'format.sh' in the root directory applies the clang-format-5.0 tool with our
style choices to all the SWIFT C source file. Please apply the formatting
script to the files before submitting a merge request.
......@@ -32,7 +32,7 @@ Contribution Guidelines
-----------------------
The SWIFT source code uses a variation of the 'Google' formatting style.
The script 'format.sh' in the root directory applies the clang-format-3.8
The script 'format.sh' in the root directory applies the clang-format-5.0
tool with our style choices to all the SWIFT C source file. Please apply
the formatting script to the files before submitting a pull request.
......
#!/bin/bash
clang-format-3.8 -style=file -i src/*.[ch] src/*/*.[ch] src/*/*/*.[ch] examples/main.c tests/*.[ch]
clang-format-5.0 -style=file -i src/*.[ch] src/*/*.[ch] src/*/*/*.[ch] examples/main.c tests/*.[ch]
......@@ -44,10 +44,9 @@ __attribute__((always_inline, const)) INLINE static float good_approx_expf(
float x) {
return 1.f +
x * (1.f +
x * (0.5f +
x * ((1.f / 6.f) +
x * ((1.f / 24.f) +
x * ((1.f / 120.f) + (1.f / 720.f) * x)))));
x * (0.5f + x * ((1.f / 6.f) +
x * ((1.f / 24.f) +
x * ((1.f / 120.f) + (1.f / 720.f) * x)))));
}
/**
......@@ -56,11 +55,9 @@ __attribute__((always_inline, const)) INLINE static float good_approx_expf(
__attribute__((always_inline, const)) INLINE static double good_approx_exp(
double x) {
return 1. +
x * (1. +
x * (0.5 +
x * ((1. / 6.) +
x * ((1. / 24.) +
x * ((1. / 120.) + (1. / 720.) * x)))));
x * (1. + x * (0.5 + x * ((1. / 6.) +
x * ((1. / 24.) +
x * ((1. / 120.) + (1. / 720.) * x)))));
}
#endif /* SWIFT_APPROX_MATH_H */
......@@ -109,8 +109,9 @@ INLINE static void chemistry_write_flavour(hid_t h_grp) {
for (int elem = 0; elem < chemistry_element_count; ++elem) {
char buffer[20];
sprintf(buffer, "Element %d", elem);
io_write_attribute_s(h_grp, buffer, chemistry_get_element_name(
(enum chemistry_element)elem));
io_write_attribute_s(
h_grp, buffer,
chemistry_get_element_name((enum chemistry_element)elem));
}
}
#endif
......
......@@ -4794,8 +4794,8 @@ void engine_step(struct engine *e) {
/* Print the number of active tasks ? */
if (e->verbose) engine_print_task_counts(e);
/* Dump local cells and active particle counts. */
/* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */
/* Dump local cells and active particle counts. */
/* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */
#ifdef SWIFT_DEBUG_CHECKS
/* Check that we have the correct total mass in the top-level multipoles */
......
......@@ -176,13 +176,13 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pm_full(
#if SELF_GRAVITY_MULTIPOLE_ORDER > 0
/* 1st order contributions */
/* 1st order contributions */
/* 1st order contributions are all 0 since the dipole is 0 */
/* 1st order contributions are all 0 since the dipole is 0 */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
#endif
......@@ -281,13 +281,13 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pm_truncated(
#if SELF_GRAVITY_MULTIPOLE_ORDER > 0
/* 1st order contributions */
/* 1st order contributions */
/* 1st order contributions are all 0 since the dipole is 0 */
/* 1st order contributions are all 0 since the dipole is 0 */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
#endif
......
......@@ -180,14 +180,14 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pm_full(
#if SELF_GRAVITY_MULTIPOLE_ORDER > 0
/* 1st order contributions */
/* 1st order contributions */
/* 1st order contributions are all 0 since the dipole is 0 */
/* 1st order contributions are all 0 since the dipole is 0 */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
/* *pot = m->M_001 * d.D_001 + m->M_010 * d.D_010 + m->M_100 * d.D_100 ; */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
/* *pot = m->M_001 * d.D_001 + m->M_010 * d.D_010 + m->M_100 * d.D_100 ; */
#endif
......@@ -292,14 +292,14 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pm_truncated(
#if SELF_GRAVITY_MULTIPOLE_ORDER > 0
/* 1st order contributions */
/* 1st order contributions */
/* 1st order contributions are all 0 since the dipole is 0 */
/* 1st order contributions are all 0 since the dipole is 0 */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
/* *pot = m->M_001 * d.D_001 + m->M_010 * d.D_010 + m->M_100 * d.D_100 ; */
/* *f_x = m->M_001 * d.D_101 + m->M_010 * d.D_110 + m->M_100 * d.D_200 ; */
/* *f_y = m->M_001 * d.D_011 + m->M_010 * d.D_020 + m->M_100 * d.D_110 ; */
/* *f_z = m->M_001 * d.D_002 + m->M_010 * d.D_011 + m->M_100 * d.D_101 ; */
/* *pot = m->M_001 * d.D_001 + m->M_010 * d.D_010 + m->M_100 * d.D_100 ; */
#endif
......
......@@ -53,9 +53,10 @@ __attribute__((always_inline)) INLINE static void kernel_grav_pot_eval(
if (u < 0.5f)
*W = -2.8f + u * u * (5.333333333333f + u * u * (6.4f * u - 9.6f));
else
*W = -3.2f + 0.066666666667f / u +
u * u * (10.666666666667f +
u * (-16.f + u * (9.6f - 2.133333333333f * u)));
*W =
-3.2f + 0.066666666667f / u +
u * u *
(10.666666666667f + u * (-16.f + u * (9.6f - 2.133333333333f * u)));
#else
/* W(u) = 3u^7 - 15u^6 + 28u^5 - 21u^4 + 7u^2 - 3 */
......
......@@ -346,7 +346,8 @@ __attribute__((always_inline)) INLINE static void kernel_eval_dWdx(
*dW_dx = dw_dx * kernel_constant * kernel_gamma_inv_dim_plus_one;
}
/* ------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------
*/
#ifdef WITH_OLD_VECTORIZATION
/**
......
......@@ -490,9 +490,10 @@ void writeArray_chunk(struct engine* e, hid_t h_data,
else
H5Sselect_none(h_filespace);
/* message("Writing %lld '%s', %zd elements = %zd bytes (int=%d) at offset
* %zd", N, props.name, N * props.dimension, N * props.dimension * typeSize, */
/* (int)(N * props.dimension * typeSize), offset); */
/* message("Writing %lld '%s', %zd elements = %zd bytes (int=%d) at offset
* %zd", N, props.name, N * props.dimension, N * props.dimension * typeSize,
*/
/* (int)(N * props.dimension * typeSize), offset); */
#ifdef IO_SPEED_MEASUREMENT
MPI_Barrier(MPI_COMM_WORLD);
......@@ -1180,8 +1181,8 @@ void write_output_parallel(struct engine* e, const char* baseName,
* broadcast from there */
MPI_Bcast(&N_total, 6, MPI_LONG_LONG_INT, mpi_size - 1, comm);
/* Now everybody konws its offset and the total number of
* particles of each type */
/* Now everybody konws its offset and the total number of
* particles of each type */
#ifdef IO_SPEED_MEASUREMENT
ticks tic = getticks();
......
......@@ -156,17 +156,17 @@ static void split_vector(struct space *s, int nregions, int *samplecells) {
}
#endif
/* METIS support
* =============
*
* METIS partitions using a multi-level k-way scheme. We support using this in
* a unweighted scheme, which works well and seems to be guaranteed, and a
* weighted by the number of particles scheme. Note METIS is optional.
*
* Repartitioning is based on METIS and uses weights determined from the times
* that cell tasks have taken. These weight the graph edges and vertices, or
* just the edges, with vertex weights from the particle counts or none.
*/
/* METIS support
* =============
*
* METIS partitions using a multi-level k-way scheme. We support using this in
* a unweighted scheme, which works well and seems to be guaranteed, and a
* weighted by the number of particles scheme. Note METIS is optional.
*
* Repartitioning is based on METIS and uses weights determined from the times
* that cell tasks have taken. These weight the graph edges and vertices, or
* just the edges, with vertex weights from the particle counts or none.
*/
#if defined(WITH_MPI) && defined(HAVE_METIS)
/**
......@@ -926,9 +926,8 @@ void partition_initial_partition(struct partition *initial_partition,
struct cell *c;
/* If we've got the wrong number of nodes, fail. */
if (nr_nodes !=
initial_partition->grid[0] * initial_partition->grid[1] *
initial_partition->grid[2])
if (nr_nodes != initial_partition->grid[0] * initial_partition->grid[1] *
initial_partition->grid[2])
error("Grid size does not match number of nodes.");
/* Run through the cells and set their nodeID. */
......@@ -937,9 +936,8 @@ void partition_initial_partition(struct partition *initial_partition,
c = &s->cells_top[k];
for (j = 0; j < 3; j++)
ind[j] = c->loc[j] / s->dim[j] * initial_partition->grid[j];
c->nodeID = ind[0] +
initial_partition->grid[0] *
(ind[1] + initial_partition->grid[1] * ind[2]);
c->nodeID = ind[0] + initial_partition->grid[0] *
(ind[1] + initial_partition->grid[1] * ind[2]);
// message("cell at [%e,%e,%e]: ind = [%i,%i,%i], nodeID = %i", c->loc[0],
// c->loc[1], c->loc[2], ind[0], ind[1], ind[2], c->nodeID);
}
......
......@@ -88,8 +88,8 @@ void proxy_cells_exch1(struct proxy *p) {
p->nodeID * proxy_tag_shift + proxy_tag_count, MPI_COMM_WORLD,
&p->req_cells_count_in);
if (err != MPI_SUCCESS) mpi_error(err, "Failed to irecv nr of pcells.");
// message( "irecv pcells count on node %i from node %i." , p->mynodeID ,
// p->nodeID ); fflush(stdout);
// message( "irecv pcells count on node %i from node %i." , p->mynodeID ,
// p->nodeID ); fflush(stdout);
#else
error("SWIFT was not compiled with MPI support.");
......@@ -113,8 +113,8 @@ void proxy_cells_exch2(struct proxy *p) {
MPI_COMM_WORLD, &p->req_cells_in);
if (err != MPI_SUCCESS) mpi_error(err, "Failed to irecv part data.");
// message( "irecv pcells (%i) on node %i from node %i." , p->size_pcells_in ,
// p->mynodeID , p->nodeID ); fflush(stdout);
// message( "irecv pcells (%i) on node %i from node %i." , p->size_pcells_in
// , p->mynodeID , p->nodeID ); fflush(stdout);
#else
error("SWIFT was not compiled with MPI support.");
......
......@@ -388,9 +388,8 @@ __attribute__((always_inline)) INLINE static void riemann_solver_solve(
pdpR = p / WR[4];
if (p > WR[4]) {
/* shockwave */
SR = vR +
aR * sqrtf(hydro_gamma_plus_one_over_two_gamma * pdpR +
hydro_gamma_minus_one_over_two_gamma);
SR = vR + aR * sqrtf(hydro_gamma_plus_one_over_two_gamma * pdpR +
hydro_gamma_minus_one_over_two_gamma);
if (SR > 0.0f) {
Whalf[0] = WR[0] * (pdpR + hydro_gamma_minus_one_over_gamma_plus_one) /
(hydro_gamma_minus_one_over_gamma_plus_one * pdpR + 1.0f);
......@@ -436,9 +435,8 @@ __attribute__((always_inline)) INLINE static void riemann_solver_solve(
pdpL = p / WL[4];
if (p > WL[4]) {
/* shockwave */
SL = vL -
aL * sqrtf(hydro_gamma_plus_one_over_two_gamma * pdpL +
hydro_gamma_minus_one_over_two_gamma);
SL = vL - aL * sqrtf(hydro_gamma_plus_one_over_two_gamma * pdpL +
hydro_gamma_minus_one_over_two_gamma);
if (SL < 0.0f) {
Whalf[0] = WL[0] * (pdpL + hydro_gamma_minus_one_over_gamma_plus_one) /
(hydro_gamma_minus_one_over_gamma_plus_one * pdpL + 1.0f);
......
......@@ -78,15 +78,13 @@ __attribute__((always_inline)) INLINE static void riemann_solve_for_flux(
all these speeds are along the interface normal, since uL and uR are */
float qL = 1.f;
if (pstar > WL[4] && WL[4] > 0.f) {
qL = sqrtf(1.f +
0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WL[4] - 1.f));
qL = sqrtf(1.f + 0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WL[4] - 1.f));
}
float qR = 1.f;
if (pstar > WR[4] && WR[4] > 0.f) {
qR = sqrtf(1.f +
0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WR[4] - 1.f));
qR = sqrtf(1.f + 0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WR[4] - 1.f));
}
const float SL = uL - aL * qL;
const float SR = uR + aR * qR;
......@@ -230,15 +228,13 @@ riemann_solve_for_middle_state_flux(const float *WL, const float *WR,
all these speeds are along the interface normal, since uL and uR are */
float qL = 1.f;
if (pstar > WL[4] && WL[4] > 0.f) {
qL = sqrtf(1.f +
0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WL[4] - 1.f));
qL = sqrtf(1.f + 0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WL[4] - 1.f));
}
float qR = 1.f;
if (pstar > WR[4] && WR[4] > 0.f) {
qR = sqrtf(1.f +
0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WR[4] - 1.f));
qR = sqrtf(1.f + 0.5f * hydro_gamma_plus_one * hydro_one_over_gamma *
(pstar / WR[4] - 1.f));
}
const float SL = uL - aL * qL;
const float SR = uR + aR * qR;
......
......@@ -827,7 +827,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) {
}
}
/* We now have a particle whose smoothing length has converged */
/* We now have a particle whose smoothing length has converged */
#ifdef EXTRA_HYDRO_LOOP
......
......@@ -238,9 +238,10 @@ void reset_particles(struct cell *c, struct hydro_space *hs,
p->conserved.momentum[2] = p->conserved.mass * p->v[2];
p->conserved.energy =
p->primitives.P / hydro_gamma_minus_one * volume +
0.5f * (p->conserved.momentum[0] * p->conserved.momentum[0] +
p->conserved.momentum[1] * p->conserved.momentum[1] +
p->conserved.momentum[2] * p->conserved.momentum[2]) /
0.5f *
(p->conserved.momentum[0] * p->conserved.momentum[0] +
p->conserved.momentum[1] * p->conserved.momentum[1] +
p->conserved.momentum[2] * p->conserved.momentum[2]) /
p->conserved.mass;
#endif
}
......@@ -325,9 +326,10 @@ struct cell *make_cell(size_t n, const double offset[3], double size, double h,
part->conserved.momentum[2] = part->conserved.mass * part->v[2];
part->conserved.energy =
part->primitives.P / hydro_gamma_minus_one * volume +
0.5f * (part->conserved.momentum[0] * part->conserved.momentum[0] +
part->conserved.momentum[1] * part->conserved.momentum[1] +
part->conserved.momentum[2] * part->conserved.momentum[2]) /
0.5f *
(part->conserved.momentum[0] * part->conserved.momentum[0] +
part->conserved.momentum[1] * part->conserved.momentum[1] +
part->conserved.momentum[2] * part->conserved.momentum[2]) /
part->conserved.mass;
#endif
......@@ -429,7 +431,7 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
#else
0.f, 0.f, 0.f
#endif
);
);
}
if (with_solution) {
......
......@@ -291,7 +291,7 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
#else
0., 0., 0., 0.
#endif
);
);
}
/* Write all other cells */
......@@ -325,7 +325,7 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
#else
0., 0., 0., 0.
#endif
);
);
}
}
}
......
......@@ -250,8 +250,9 @@ int main(int argc, char *argv[]) {
log_u += log_u_step;
if (do_output == 1)
fprintf(f, "%.6e ", A1_u[i] * units_cgs_conversion_factor(
&us, UNIT_CONV_ENERGY_PER_UNIT_MASS));
fprintf(f, "%.6e ",
A1_u[i] * units_cgs_conversion_factor(
&us, UNIT_CONV_ENERGY_PER_UNIT_MASS));
}
if (do_output == 1) fprintf(f, "\n");
......
......@@ -154,7 +154,7 @@ void dump_indv_particle_fields(char *fileName, struct part *p) {
#else
0.f, 0.f, 0.f
#endif
);
);
fclose(file);
}
......
......@@ -43,9 +43,10 @@ void test_log_parts(struct dump *d) {
size_t offset = d->count;
/* Write the full part. */
logger_log_part(&p, logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_u | logger_mask_h | logger_mask_rho |
logger_mask_consts,
logger_log_part(&p,
logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_u | logger_mask_h | logger_mask_rho |
logger_mask_consts,
&offset, d);
printf("Wrote part at offset %#016zx.\n", offset);
......@@ -112,8 +113,9 @@ void test_log_gparts(struct dump *d) {
size_t offset = d->count;
/* Write the full part. */
logger_log_gpart(&p, logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_h | logger_mask_consts,
logger_log_gpart(&p,
logger_mask_x | logger_mask_v | logger_mask_a |
logger_mask_h | logger_mask_consts,
&offset, d);
printf("Wrote gpart at offset %#016zx.\n", offset);
......
......@@ -252,7 +252,7 @@ void dump_particle_fields(char *fileName, struct cell *main_cell, int i, int j,
#else
0., 0., 0., 0.
#endif
);
);
}
fclose(file);
}
......
......@@ -82,8 +82,9 @@ double acceleration(double mass, double r, double H, double rlr) {
if (u > 1.)
acc = -mass / (r * r * r);
else
acc = -mass * (21. * u * u * u * u * u - 90. * u * u * u * u +
140. * u * u * u - 84. * u * u + 14.) /
acc = -mass *
(21. * u * u * u * u * u - 90. * u * u * u * u + 140. * u * u * u -
84. * u * u + 14.) /
(H * H * H);
return r * acc * (4. * x * S_prime(2 * x) - 2. * S(2. * x) + 2.);
......
......@@ -78,8 +78,9 @@ double acceleration(double mass, double r, double H, double rlr) {
if (u > 1.)
acc = -mass / (r * r * r);
else
acc = -mass * (21. * u * u * u * u * u - 90. * u * u * u * u +
140. * u * u * u - 84. * u * u + 14.) /
acc = -mass *
(21. * u * u * u * u * u - 90. * u * u * u * u + 140. * u * u * u -
84. * u * u + 14.) /
(H * H * H);
return r * acc * (4. * x * S_prime(2 * x) - 2. * S(2. * x) + 2.);
......
Markdown is supported
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