Commit 2dc8a2e7 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

Merge branch 'clang_compiler' into 'master'

Small changes for clang compatibility

I have made some minor changes (mostly to space.c) so that the code now compiles out of the box with the clang compiler. 

The main change is the removal of nested functions in space.c. They have been replaced by static functions.

See merge request !32

Former-commit-id: 2cd4eaf9f37f79fa04271b6dec78c8be321d5262
parents b46e36d3 327ab075
......@@ -32,8 +32,17 @@ or:
to use an Intel compiler. The main "programs" can be found in the "examples/"
directory.
SWIFT has been successfully built and tested with the following compilers:
- GCC 4.8.x
- Intel ICC 15.0.x
- clang 3.4.x
More recent versions and slightly older ones should also be able to
built the software.
By default an attempt to choose suitable set of optimizing compiler flags
will be made, targetted for the host machine of the build. If this doesn't
will be made, targeted for the host machine of the build. If this doesn't
work or the binaries will for another architecture then you can stop the
selection of flags using:
......@@ -64,7 +73,7 @@ SWIFT currently requires a compiler with OpenMP support.
Dependencies
============
SWIFT depends on a number of thirdparty libraries that should be available
SWIFT depends on a number of third party libraries that should be available
before you can build it.
......
......@@ -447,15 +447,7 @@ void kernel_dump ( int N ) {
}
void gravity_dump ( float r_max , int N ) {
int k;
float x, w;
float x4[4] = {0.0f,0.0f,0.0f,0.0f};
float w4[4] = {0.0f,0.0f,0.0f,0.0f};
// float dw_dx4[4] __attribute__ ((aligned (16)));
float gadget ( float r ) {
float gadget ( float r ) {
float fac, h_inv, u, r2 = r*r;
if ( r >= const_epsilon )
fac = 1.0f / (r2 * r);
......@@ -469,7 +461,16 @@ void gravity_dump ( float r_max , int N ) {
38.4 * u * u - 10.666666666667 * u * u * u - 0.066666666667 / (u * u * u));
}
return const_G * fac;
}
}
void gravity_dump ( float r_max , int N ) {
int k;
float x, w;
float x4[4] = {0.0f,0.0f,0.0f,0.0f};
float w4[4] = {0.0f,0.0f,0.0f,0.0f};
// float dw_dx4[4] __attribute__ ((aligned (16)));
for ( k = 1 ; k <= N ; k++ ) {
x = (r_max * k) / N;
......
......@@ -23,6 +23,7 @@
/* Some standard headers. */
#include <float.h>
#include <limits.h>
#include <stdlib.h>
/* MPI headers. */
#ifdef WITH_MPI
......
......@@ -18,7 +18,7 @@
*
******************************************************************************/
#ifndef SWIFT_RUNNER_IACT_LEGACY_H
#define SWIFT_RUNNER_IACT_LECAGY_H
#define SWIFT_RUNNER_IACT_LEGACY_H
/* Includes. */
#include "const.h"
......
......@@ -25,6 +25,7 @@
#include <limits.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
/* MPI headers. */
#ifdef WITH_MPI
......@@ -488,7 +489,7 @@ void parts_sort(struct part *parts, struct xpart *xparts, int *ind, int N,
volatile int ready;
};
struct qstack *qstack;
int qstack_size = 2 * (max - min) + 10;
unsigned int qstack_size = 2 * (max - min) + 10;
volatile unsigned int first, last, waiting;
int pivot;
......@@ -777,22 +778,19 @@ void space_map_clearsort(struct cell *c, void *data) {
}
}
/**
* @brief Map a function to all particles in a aspace.
* @brief Map a function to all particles in a cell recursively.
*
* @param s The #space we are working in.
* @param c The #cell we are working in.
* @param fun Function pointer to apply on the cells.
* @param data Data passed to the function fun.
*/
void space_map_parts(struct space *s,
static void rec_map_parts(struct cell * c,
void (*fun)(struct part *p, struct cell *c, void *data),
void *data) {
int cid = 0;
void rec_map(struct cell * c) {
int k;
/* No progeny? */
......@@ -802,50 +800,78 @@ void space_map_parts(struct space *s,
/* Otherwise, recurse. */
else
for (k = 0; k < 8; k++)
if (c->progeny[k] != NULL) rec_map(c->progeny[k]);
}
/* Call the recursive function on all higher-level cells. */
for (cid = 0; cid < s->nr_cells; cid++) rec_map(&s->cells[cid]);
if (c->progeny[k] != NULL) rec_map_parts(c->progeny[k], fun, data);
}
/**
* @brief Map a function to all particles in a aspace.
* @brief Map a function to all particles in a space.
*
* @param s The #space we are working in.
* @param full Map to all cells, including cells with sub-cells.
* @param fun Function pointer to apply on the cells.
* @param data Data passed to the function fun.
*/
void space_map_cells_post(struct space *s, int full,
void (*fun)(struct cell *c, void *data), void *data) {
void space_map_parts(struct space *s,
void (*fun)(struct part *p, struct cell *c, void *data),
void *data) {
int cid = 0;
void rec_map(struct cell * c) {
/* Call the recursive function on all higher-level cells. */
for (cid = 0; cid < s->nr_cells; cid++) rec_map_parts(&s->cells[cid], fun, data);
}
/**
* @brief Map a function to all particles in a cell recursively.
*
* @param c The #cell we are working in.
* @param full Map to all cells, including cells with sub-cells.
* @param fun Function pointer to apply on the cells.
* @param data Data passed to the function fun.
*/
static void rec_map_cells_post(struct cell * c, int full,
void (*fun)(struct cell *c, void *data),
void *data) {
int k;
/* Recurse. */
if (c->split)
for (k = 0; k < 8; k++)
if (c->progeny[k] != NULL) rec_map(c->progeny[k]);
if (c->progeny[k] != NULL) rec_map_cells_post(c->progeny[k], full, fun, data);
/* No progeny? */
if (full || !c->split) fun(c, data);
}
}
/**
* @brief Map a function to all particles in a space.
*
* @param s The #space we are working in.
* @param full Map to all cells, including cells with sub-cells.
* @param fun Function pointer to apply on the cells.
* @param data Data passed to the function fun.
*/
void space_map_cells_post(struct space *s, int full,
void (*fun)(struct cell *c, void *data),
void *data) {
int cid = 0;
/* Call the recursive function on all higher-level cells. */
for (cid = 0; cid < s->nr_cells; cid++) rec_map(&s->cells[cid]);
for (cid = 0; cid < s->nr_cells; cid++) rec_map_cells_post(&s->cells[cid], full, fun, data);
}
void space_map_cells_pre(struct space *s, int full,
void (*fun)(struct cell *c, void *data), void *data) {
int cid = 0;
void rec_map(struct cell * c) {
static void rec_map_cells_pre(struct cell * c, int full,
void (*fun)(struct cell *c, void *data),
void *data) {
int k;
......@@ -855,13 +881,22 @@ void space_map_cells_pre(struct space *s, int full,
/* Recurse. */
if (c->split)
for (k = 0; k < 8; k++)
if (c->progeny[k] != NULL) rec_map(c->progeny[k]);
}
if (c->progeny[k] != NULL) rec_map_cells_pre(c->progeny[k], full, fun, data);
}
void space_map_cells_pre(struct space *s, int full,
void (*fun)(struct cell *c, void *data),
void *data) {
int cid = 0;
/* Call the recursive function on all higher-level cells. */
for (cid = 0; cid < s->nr_cells; cid++) rec_map(&s->cells[cid]);
for (cid = 0; cid < s->nr_cells; cid++) rec_map_cells_pre(&s->cells[cid], full, fun, data);
}
/**
* @brief Split cells that contain too many particles.
*
......
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