Skip to content
Snippets Groups Projects
Commit a0b8277f authored by James Willis's avatar James Willis
Browse files

Removed verbose output and added the ability to apply a random perturbation in h for each particle.

parent f8ec2ed4
No related branches found
No related tags found
1 merge request!348Fix pair vec
...@@ -30,11 +30,8 @@ ...@@ -30,11 +30,8 @@
/* Local headers. */ /* Local headers. */
#include "swift.h" #include "swift.h"
#define ACC_THRESHOLD 1e-5
#if defined(WITH_VECTORIZATION) #if defined(WITH_VECTORIZATION)
#define DOSELF1 runner_doself1_density_vec #define DOSELF1 runner_doself1_density_vec
//#define DOPAIR1 runner_dopair1_density_vec
#define DOPAIR1 runner_dopair1_branch_density #define DOPAIR1 runner_dopair1_branch_density
#define DOSELF1_NAME "runner_doself1_density_vec" #define DOSELF1_NAME "runner_doself1_density_vec"
#define DOPAIR1_NAME "runner_dopair1_density_vec" #define DOPAIR1_NAME "runner_dopair1_density_vec"
...@@ -74,9 +71,10 @@ enum velocity_types { ...@@ -74,9 +71,10 @@ enum velocity_types {
*/ */
struct cell *make_cell(size_t n, double *offset, double size, double h, struct cell *make_cell(size_t n, double *offset, double size, double h,
double density, long long *partId, double pert, double density, long long *partId, double pert,
enum velocity_types vel) { enum velocity_types vel, double h_pert) {
const size_t count = n * n * n; const size_t count = n * n * n;
const double volume = size * size * size; const double volume = size * size * size;
float h_max = 0.f;
struct cell *cell = malloc(sizeof(struct cell)); struct cell *cell = malloc(sizeof(struct cell));
bzero(cell, sizeof(struct cell)); bzero(cell, sizeof(struct cell));
...@@ -122,7 +120,11 @@ struct cell *make_cell(size_t n, double *offset, double size, double h, ...@@ -122,7 +120,11 @@ struct cell *make_cell(size_t n, double *offset, double size, double h,
part->v[2] = 0.f; part->v[2] = 0.f;
break; break;
} }
part->h = size * h / (float)n; if(h_pert)
part->h = size * h * random_uniform(1.f,1.1f) / (float)n;
else
part->h = size * h / (float)n;
h_max = fmax(h_max, part->h);
part->id = ++(*partId); part->id = ++(*partId);
#if defined(GIZMO_SPH) || defined(SHADOWFAX_SPH) #if defined(GIZMO_SPH) || defined(SHADOWFAX_SPH)
...@@ -157,7 +159,7 @@ struct cell *make_cell(size_t n, double *offset, double size, double h, ...@@ -157,7 +159,7 @@ struct cell *make_cell(size_t n, double *offset, double size, double h,
/* Cell properties */ /* Cell properties */
cell->split = 0; cell->split = 0;
cell->h_max = size * h / (float)n; cell->h_max = h_max;
cell->count = count; cell->count = count;
cell->dx_max_part = 0.; cell->dx_max_part = 0.;
cell->dx_max_sort = 0.; cell->dx_max_sort = 0.;
...@@ -289,27 +291,6 @@ void dump_particle_fields(char *fileName, struct cell *main_cell, ...@@ -289,27 +291,6 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
fclose(file); fclose(file);
} }
/**
* @brief Compares the vectorised result against
* the serial result of the interaction.
*
* @param serial_parts Particle array that has been interacted serially
* @param vec_parts Particle array to be interacted using vectors
* @param count No. of particles that have been interacted
* @param threshold Level of accuracy needed
*
* @return Non-zero value if difference found, 0 otherwise
*/
int check_results(struct part *serial_parts, struct part *vec_parts, int count,
double threshold) {
int result = 0;
for (int i = 0; i < count; i++)
result += compare_particles(serial_parts[i], vec_parts[i], threshold);
return result;
}
/* Just a forward declaration... */ /* Just a forward declaration... */
void runner_doself1_density(struct runner *r, struct cell *ci); void runner_doself1_density(struct runner *r, struct cell *ci);
void runner_doself1_density_vec(struct runner *r, struct cell *ci); void runner_doself1_density_vec(struct runner *r, struct cell *ci);
...@@ -321,8 +302,7 @@ int main(int argc, char *argv[]) { ...@@ -321,8 +302,7 @@ int main(int argc, char *argv[]) {
engine_pin(); engine_pin();
size_t runs = 0, particles = 0; size_t runs = 0, particles = 0;
double h = 1.23485, size = 1., rho = 1.; double h = 1.23485, size = 1., rho = 1.;
double perturbation = 0.; double perturbation = 0., h_pert = 0.;
double threshold = ACC_THRESHOLD;
char outputFileNameExtension[200] = ""; char outputFileNameExtension[200] = "";
char outputFileName[200] = ""; char outputFileName[200] = "";
enum velocity_types vel = velocity_zero; enum velocity_types vel = velocity_zero;
...@@ -338,11 +318,14 @@ int main(int argc, char *argv[]) { ...@@ -338,11 +318,14 @@ int main(int argc, char *argv[]) {
srand(0); srand(0);
char c; char c;
while ((c = getopt(argc, argv, "m:s:h:n:r:t:d:f:v:a:")) != -1) { while ((c = getopt(argc, argv, "m:s:h:p:n:r:t:d:f:v:")) != -1) {
switch (c) { switch (c) {
case 'h': case 'h':
sscanf(optarg, "%lf", &h); sscanf(optarg, "%lf", &h);
break; break;
case 'p':
sscanf(optarg, "%lf", &h_pert);
break;
case 's': case 's':
sscanf(optarg, "%lf", &size); sscanf(optarg, "%lf", &size);
break; break;
...@@ -364,9 +347,6 @@ int main(int argc, char *argv[]) { ...@@ -364,9 +347,6 @@ int main(int argc, char *argv[]) {
case 'v': case 'v':
sscanf(optarg, "%d", (int *)&vel); sscanf(optarg, "%d", (int *)&vel);
break; break;
case 'a':
sscanf(optarg, "%lf", &threshold);
break;
case '?': case '?':
error("Unknown option."); error("Unknown option.");
break; break;
...@@ -381,6 +361,7 @@ int main(int argc, char *argv[]) { ...@@ -381,6 +361,7 @@ int main(int argc, char *argv[]) {
"runner_doself1_density()." "runner_doself1_density()."
"\n\nOptions:" "\n\nOptions:"
"\n-h DISTANCE=1.2348 - Smoothing length in units of <x>" "\n-h DISTANCE=1.2348 - Smoothing length in units of <x>"
"\n-p - Random fractional change in h, h=h*random(1,p)"
"\n-m rho - Physical density in the cell" "\n-m rho - Physical density in the cell"
"\n-s size - Physical size of the cell" "\n-s size - Physical size of the cell"
"\n-d pert - Perturbation to apply to the particles [0,1[" "\n-d pert - Perturbation to apply to the particles [0,1["
...@@ -435,7 +416,7 @@ int main(int argc, char *argv[]) { ...@@ -435,7 +416,7 @@ int main(int argc, char *argv[]) {
for (int k = 0; k < 3; ++k) { for (int k = 0; k < 3; ++k) {
double offset[3] = {i * size, j * size, k * size}; double offset[3] = {i * size, j * size, k * size};
cells[i * 9 + j * 3 + k] = make_cell(particles, offset, size, h, rho, cells[i * 9 + j * 3 + k] = make_cell(particles, offset, size, h, rho,
&partId, perturbation, vel); &partId, perturbation, vel, h_pert);
runner_do_drift_part(&runner, cells[i * 9 + j * 3 + k], 0); runner_do_drift_part(&runner, cells[i * 9 + j * 3 + k], 0);
...@@ -503,10 +484,6 @@ int main(int argc, char *argv[]) { ...@@ -503,10 +484,6 @@ int main(int argc, char *argv[]) {
} }
} }
/* Store the vectorised particle results. */
struct part vec_parts[main_cell->count];
for (int i = 0; i < main_cell->count; i++) vec_parts[i] = main_cell->parts[i];
/* Output timing */ /* Output timing */
ticks corner_time = timings[0] + timings[2] + timings[6] + timings[8] + ticks corner_time = timings[0] + timings[2] + timings[6] + timings[8] +
timings[18] + timings[20] + timings[24] + timings[26]; timings[18] + timings[20] + timings[24] + timings[26];
...@@ -551,10 +528,6 @@ int main(int argc, char *argv[]) { ...@@ -551,10 +528,6 @@ int main(int argc, char *argv[]) {
sprintf(outputFileName, "brute_force_27_%s.dat", outputFileNameExtension); sprintf(outputFileName, "brute_force_27_%s.dat", outputFileNameExtension);
dump_particle_fields(outputFileName, main_cell, cells); dump_particle_fields(outputFileName, main_cell, cells);
/* Check serial results against the vectorised results. */
if (check_results(main_cell->parts, vec_parts, main_cell->count, threshold))
message("Differences found...");
/* Output timing */ /* Output timing */
message("Brute force calculation took : %15lli ticks.", toc - tic); message("Brute force calculation took : %15lli ticks.", toc - tic);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment