Commit 4338bd27 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Formatting....

parent 838eb3d6
...@@ -396,7 +396,7 @@ int main(int argc, char *argv[]) { ...@@ -396,7 +396,7 @@ int main(int argc, char *argv[]) {
/* Take a step. */ /* Take a step. */
engine_step(&e); engine_step(&e);
if (j == 1) break; if (j == 2) break;
if (with_outputs && j % 100 == 0) { if (with_outputs && j % 100 == 0) {
...@@ -505,7 +505,7 @@ int main(int argc, char *argv[]) { ...@@ -505,7 +505,7 @@ int main(int argc, char *argv[]) {
#endif #endif
/* Say goodbye. */ /* Say goodbye. */
if (myrank == 0) message("done."); if (myrank == 0) message("done. Bye.");
/* All is calm, all is bright. */ /* All is calm, all is bright. */
return 0; return 0;
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#define const_eta_kernel \ #define const_eta_kernel \
1.2349f /* Corresponds to 48 ngbs with the cubic spline kernel */ 1.2349f /* Corresponds to 48 ngbs with the cubic spline kernel */
#define const_delta_nwneigh 1.f #define const_delta_nwneigh 1.f
#define const_smoothing_max_iter 3 #define const_smoothing_max_iter 30
#define CUBIC_SPLINE_KERNEL #define CUBIC_SPLINE_KERNEL
/* Gravity stuff. */ /* Gravity stuff. */
......
...@@ -51,13 +51,12 @@ ...@@ -51,13 +51,12 @@
#endif #endif
#include "runner_iact_grav.h" #include "runner_iact_grav.h"
#define PRINT_PART \
#define PRINT_PART if(p->id==1000) { \ if (p->id == 1000) { \
message("p->id=%lld p->h=%f p->N_ngb=%f p->rho=%f p->t_beg=%f p->t_end=%f",\ message( \
p->id, p->h, p->density.wcount, p->rho, p->t_begin, p->t_end); \ "p->id=%lld p->h=%f p->N_ngb=%f p->rho=%f p->t_beg=%f p->t_end=%f", \
} p->id, p->h, p->density.wcount, p->rho, p->t_begin, p->t_end); \
}
/* Convert cell location to ID. */ /* Convert cell location to ID. */
#define cell_getid(cdim, i, j, k) \ #define cell_getid(cdim, i, j, k) \
...@@ -197,8 +196,8 @@ void runner_dosort(struct runner *r, struct cell *c, int flags, int clock) { ...@@ -197,8 +196,8 @@ void runner_dosort(struct runner *r, struct cell *c, int flags, int clock) {
TIMER_TIC TIMER_TIC
// message("sort!"); // message("sort!");
/* Clean-up the flags, i.e. filter out what's already been sorted. */ /* Clean-up the flags, i.e. filter out what's already been sorted. */
flags &= ~c->sorted; flags &= ~c->sorted;
if (flags == 0) return; if (flags == 0) return;
...@@ -540,7 +539,6 @@ void runner_doinit(struct runner *r, struct cell *c) { ...@@ -540,7 +539,6 @@ void runner_doinit(struct runner *r, struct cell *c) {
} }
PRINT_PART; PRINT_PART;
} }
} }
...@@ -567,7 +565,7 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -567,7 +565,7 @@ void runner_doghost(struct runner *r, struct cell *c) {
TIMER_TIC; TIMER_TIC;
//message("start"); // message("start");
/* Recurse? */ /* Recurse? */
if (c->split) { if (c->split) {
...@@ -582,7 +580,8 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -582,7 +580,8 @@ void runner_doghost(struct runner *r, struct cell *c) {
for (k = 0; k < count; k++) pid[k] = k; for (k = 0; k < count; k++) pid[k] = k;
/* While there are particles that need to be updated... */ /* While there are particles that need to be updated... */
for (num_reruns = 0; count > 0 && num_reruns < const_smoothing_max_iter; num_reruns++) { for (num_reruns = 0; count > 0 && num_reruns < const_smoothing_max_iter;
num_reruns++) {
// message("count=%d redo=%d", count, redo); // message("count=%d redo=%d", count, redo);
...@@ -613,11 +612,10 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -613,11 +612,10 @@ void runner_doghost(struct runner *r, struct cell *c) {
wcount_dh = wcount_dh =
p->density.wcount_dh * ih * (4.0f / 3.0 * M_PI * kernel_gamma3); p->density.wcount_dh * ih * (4.0f / 3.0 * M_PI * kernel_gamma3);
PRINT_PART; PRINT_PART;
//if(p->id==1000) // if(p->id==1000)
// message("wcount_dh=%f", wcount_dh); // message("wcount_dh=%f", wcount_dh);
/* If no derivative, double the smoothing length. */ /* If no derivative, double the smoothing length. */
if (wcount_dh == 0.0f) h_corr = p->h; if (wcount_dh == 0.0f) h_corr = p->h;
...@@ -637,8 +635,8 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -637,8 +635,8 @@ void runner_doghost(struct runner *r, struct cell *c) {
/* Ok, correct then */ /* Ok, correct then */
p->h += h_corr; p->h += h_corr;
//message("Not converged: wcount=%f", p->density.wcount); // message("Not converged: wcount=%f", p->density.wcount);
/* And flag for another round of fun */ /* And flag for another round of fun */
pid[redo] = pid[i]; pid[redo] = pid[i];
redo += 1; redo += 1;
...@@ -651,7 +649,7 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -651,7 +649,7 @@ void runner_doghost(struct runner *r, struct cell *c) {
continue; continue;
} }
/* We now have a particle whose smoothing length has converged */ /* We now have a particle whose smoothing length has converged */
/* Pre-compute some stuff for the balsara switch. */ /* Pre-compute some stuff for the balsara switch. */
normDiv_v = fabs(p->density.div_v / rho * ih4); normDiv_v = fabs(p->density.div_v / rho * ih4);
...@@ -708,16 +706,16 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -708,16 +706,16 @@ void runner_doghost(struct runner *r, struct cell *c) {
count = redo; count = redo;
if (count > 0) { if (count > 0) {
message("count=%d", count);fflush(stdout); // message("count=%d", count);fflush(stdout);
/* Climb up the cell hierarchy. */ /* Climb up the cell hierarchy. */
for (finger = c; finger != NULL; finger = finger->parent) { for (finger = c; finger != NULL; finger = finger->parent) {
/* Run through this cell's density interactions. */ /* Run through this cell's density interactions. */
for (struct link *l = finger->link_density; l != NULL; l = l->next) { for (struct link *l = finger->link_density; l != NULL; l = l->next) {
//message("link: %p next: %p", l, l->next); fflush(stdout); // message("link: %p next: %p", l, l->next); fflush(stdout);
/* Self-interaction? */ /* Self-interaction? */
if (l->t->type == task_type_self) if (l->t->type == task_type_self)
runner_doself_subset_density(r, finger, parts, pid, count); runner_doself_subset_density(r, finger, parts, pid, count);
...@@ -725,8 +723,8 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -725,8 +723,8 @@ void runner_doghost(struct runner *r, struct cell *c) {
/* Otherwise, pair interaction? */ /* Otherwise, pair interaction? */
else if (l->t->type == task_type_pair) { else if (l->t->type == task_type_pair) {
//message("pair"); // message("pair");
/* Left or right? */ /* Left or right? */
if (l->t->ci == finger) if (l->t->ci == finger)
runner_dopair_subset_density(r, finger, parts, pid, count, runner_dopair_subset_density(r, finger, parts, pid, count,
...@@ -740,8 +738,8 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -740,8 +738,8 @@ void runner_doghost(struct runner *r, struct cell *c) {
/* Otherwise, sub interaction? */ /* Otherwise, sub interaction? */
else if (l->t->type == task_type_sub) { else if (l->t->type == task_type_sub) {
//message("sub"); // message("sub");
/* Left or right? */ /* Left or right? */
if (l->t->ci == finger) if (l->t->ci == finger)
runner_dosub_subset_density(r, finger, parts, pid, count, runner_dosub_subset_density(r, finger, parts, pid, count,
...@@ -751,16 +749,14 @@ void runner_doghost(struct runner *r, struct cell *c) { ...@@ -751,16 +749,14 @@ void runner_doghost(struct runner *r, struct cell *c) {
l->t->ci, -1, 1); l->t->ci, -1, 1);
} }
} }
error("done"); // error("done");
} }
} }
} }
if (count)
message("Smoothing length failed to converge on %i particles.", count );
if (count)
message("Smoothing length failed to converge on %i particles.", count);
#ifdef TIMER_VERBOSE #ifdef TIMER_VERBOSE
message("runner %02i: %i parts at depth %i took %.3f ms.", r->id, c->count, message("runner %02i: %i parts at depth %i took %.3f ms.", r->id, c->count,
c->depth, ((double)TIMER_TOC(timer_doghost)) / CPU_TPS * 1000); c->depth, ((double)TIMER_TOC(timer_doghost)) / CPU_TPS * 1000);
...@@ -801,7 +797,7 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) { ...@@ -801,7 +797,7 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) {
ih = 1.0f / h; ih = 1.0f / h;
PRINT_PART; PRINT_PART;
/* Drift... */ /* Drift... */
p->x[0] += xp->v_full[0] * dt; p->x[0] += xp->v_full[0] * dt;
p->x[1] += xp->v_full[1] * dt; p->x[1] += xp->v_full[1] * dt;
...@@ -825,12 +821,12 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) { ...@@ -825,12 +821,12 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) {
u = p->u *= expf(w); u = p->u *= expf(w);
/* Predict smoothing length */ /* Predict smoothing length */
//w = p->force.h_dt * ih * dt; // w = p->force.h_dt * ih * dt;
//if (fabsf(w) < 0.01f) // if (fabsf(w) < 0.01f)
// h = p->h *= // h = p->h *=
// 1.0f + // 1.0f +
// w * (1.0f + w * (0.5f + w * (1.0f / 6.0f + 1.0f / 24.0f * w))); // w * (1.0f + w * (0.5f + w * (1.0f / 6.0f + 1.0f / 24.0f * w)));
//else // else
// h = p->h *= expf(w); // h = p->h *= expf(w);
/* Predict density */ /* Predict density */
...@@ -940,8 +936,8 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) { ...@@ -940,8 +936,8 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) {
p->t_begin = p->t_end; p->t_begin = p->t_end;
p->t_end = p->t_begin + dt; p->t_end = p->t_begin + dt;
PRINT_PART PRINT_PART
/* Kick particles in momentum space */ /* Kick particles in momentum space */
xp->v_full[0] += p->a[0] * dt; xp->v_full[0] += p->a[0] * dt;
xp->v_full[1] += p->a[1] * dt; xp->v_full[1] += p->a[1] * dt;
...@@ -1068,8 +1064,9 @@ void *runner_main(void *data) { ...@@ -1068,8 +1064,9 @@ void *runner_main(void *data) {
struct part *parts; struct part *parts;
int k, nr_parts; int k, nr_parts;
message("here");fflush(stdout); message("here");
fflush(stdout);
/* Main loop. */ /* Main loop. */
while (1) { while (1) {
...@@ -1090,8 +1087,8 @@ void *runner_main(void *data) { ...@@ -1090,8 +1087,8 @@ void *runner_main(void *data) {
t = scheduler_gettask(sched, r->qid, super); t = scheduler_gettask(sched, r->qid, super);
TIMER_TOC(timer_gettask); TIMER_TOC(timer_gettask);
//message("Got task %p", t->type); fflush(stdout); // message("Got task %p", t->type); fflush(stdout);
/* Did I get anything? */ /* Did I get anything? */
if (t == NULL) break; if (t == NULL) break;
} }
...@@ -1112,7 +1109,7 @@ void *runner_main(void *data) { ...@@ -1112,7 +1109,7 @@ void *runner_main(void *data) {
/* Different types of tasks... */ /* Different types of tasks... */
switch (t->type) { switch (t->type) {
case task_type_self: case task_type_self:
//message("self"); // message("self");
if (t->subtype == task_subtype_density) if (t->subtype == task_subtype_density)
runner_doself1_density(r, ci); runner_doself1_density(r, ci);
else if (t->subtype == task_subtype_force) else if (t->subtype == task_subtype_force)
......
...@@ -496,8 +496,8 @@ void scheduler_splittasks(struct scheduler *s) { ...@@ -496,8 +496,8 @@ void scheduler_splittasks(struct scheduler *s) {
/* Otherwise, if not spilt, stitch-up the sorting. */ /* Otherwise, if not spilt, stitch-up the sorting. */
else { else {
//message("called"); // message("called");
/* Create the sort for ci. */ /* Create the sort for ci. */
// lock_lock( &ci->lock ); // lock_lock( &ci->lock );
if (ci->sorts == NULL) if (ci->sorts == NULL)
...@@ -672,7 +672,7 @@ struct task *scheduler_addtask(struct scheduler *s, int type, int subtype, ...@@ -672,7 +672,7 @@ struct task *scheduler_addtask(struct scheduler *s, int type, int subtype,
/* Get the next free task. */ /* Get the next free task. */
ind = atomic_inc(&s->tasks_next); ind = atomic_inc(&s->tasks_next);
/* Overflow? */ /* Overflow? */
if (ind >= s->size) error("Task list overflow."); if (ind >= s->size) error("Task list overflow.");
...@@ -680,7 +680,7 @@ struct task *scheduler_addtask(struct scheduler *s, int type, int subtype, ...@@ -680,7 +680,7 @@ struct task *scheduler_addtask(struct scheduler *s, int type, int subtype,
t = &s->tasks[ind]; t = &s->tasks[ind];
if (t->type == task_type_sort) message("sort!"); if (t->type == task_type_sort) message("sort!");
/* Copy the data. */ /* Copy the data. */
t->type = type; t->type = type;
t->subtype = subtype; t->subtype = subtype;
...@@ -908,14 +908,14 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { ...@@ -908,14 +908,14 @@ void scheduler_start(struct scheduler *s, unsigned int mask) {
struct task *t, *tasks = s->tasks; struct task *t, *tasks = s->tasks;
// ticks tic; // ticks tic;
//message("begin"); // message("begin");
//fflush(stdout); // fflush(stdout);
/* Store the mask */ /* Store the mask */
s->mask = mask; s->mask = mask;
FILE* file = fopen("tasks.dat", "w"); FILE *file = fopen("tasks.dat", "w");
/* Run through the tasks and set their waits. */ /* Run through the tasks and set their waits. */
// tic = getticks(); // tic = getticks();
for (k = nr_tasks - 1; k >= 0; k--) { for (k = nr_tasks - 1; k >= 0; k--) {
...@@ -927,29 +927,32 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { ...@@ -927,29 +927,32 @@ void scheduler_start(struct scheduler *s, unsigned int mask) {
atomic_inc(&t->unlock_tasks[j]->wait); atomic_inc(&t->unlock_tasks[j]->wait);
/* if(t->unlock_tasks[j] == &tasks[9563] ) { */ /* if(t->unlock_tasks[j] == &tasks[9563] ) { */
/* message("task %d %s %s unlocking task %d %s %s\n", */ /* message("task %d %s %s unlocking task %d %s %s\n", */
/* k, taskID_names[t->type], subtaskID_names[t->subtype], */ /* k, taskID_names[t->type], subtaskID_names[t->subtype],
/* 9563, taskID_names[t->unlock_tasks[j]->type], subtaskID_names[t->unlock_tasks[j]->type]); */ */
/* 9563, taskID_names[t->unlock_tasks[j]->type],
* subtaskID_names[t->unlock_tasks[j]->type]); */
/* } */ /* } */
} }
} }
for (k = nr_tasks - 1; k >= 0; k--) { for (k = nr_tasks - 1; k >= 0; k--) {
t = &tasks[tid[k]]; t = &tasks[tid[k]];
//if (t->type == task_type_sort) // if (t->type == task_type_sort)
// message("%d %s %s %d %d %d\n", k, taskID_names[t->type], subtaskID_names[t->subtype], t->nr_unlock_tasks, t->wait, t->skip); // message("%d %s %s %d %d %d\n", k, taskID_names[t->type],
if (!((1 << t->type) & s->mask) || t->skip) continue; // subtaskID_names[t->subtype], t->nr_unlock_tasks, t->wait, t->skip);
fprintf(file, "%d %s %s %d %d\n", k, taskID_names[t->type], subtaskID_names[t->subtype], t->nr_unlock_tasks, t->wait); if (!((1 << t->type) & s->mask) || t->skip) continue;
} fprintf(file, "%d %s %s %d %d\n", k, taskID_names[t->type],
subtaskID_names[t->subtype], t->nr_unlock_tasks, t->wait);
}
// message( "waiting tasks took %.3f ms." , (double)( getticks() - tic ) / // message( "waiting tasks took %.3f ms." , (double)( getticks() - tic ) /
// CPU_TPS * 1000 ); // CPU_TPS * 1000 );
fclose(file); fclose(file);
//message("All waits set"); // message("All waits set");
fflush(stdout); fflush(stdout);
/* Don't enqueue link tasks directly. */ /* Don't enqueue link tasks directly. */
s->mask &= ~(1 << task_type_link); s->mask &= ~(1 << task_type_link);
...@@ -967,11 +970,9 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { ...@@ -967,11 +970,9 @@ void scheduler_start(struct scheduler *s, unsigned int mask) {
} }
scheduler_dump_queue(s); scheduler_dump_queue(s);
// message("Done enqueieing");fflush(stdout);
//message("Done enqueieing");fflush(stdout);
// message( "enqueueing tasks took %.3f ms." , (double)( getticks() - tic ) / // message( "enqueueing tasks took %.3f ms." , (double)( getticks() - tic ) /
// CPU_TPS * 1000 ); // CPU_TPS * 1000 );
} }
...@@ -990,11 +991,11 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { ...@@ -990,11 +991,11 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) {
int err; int err;
#endif #endif
//if(t->type == task_type_pair) { // if(t->type == task_type_pair) {
// message("Enqueuing a %s", taskID_names[t->type]); // message("Enqueuing a %s", taskID_names[t->type]);
// fflush(stdout); // fflush(stdout);
// } // }
/* Ignore skipped tasks and tasks not in the mask. */ /* Ignore skipped tasks and tasks not in the mask. */
if (t->skip || ((1 << t->type) & ~(s->mask) && t->type != task_type_link) || if (t->skip || ((1 << t->type) & ~(s->mask) && t->type != task_type_link) ||
atomic_cas(&t->rid, -1, 0) != -1) atomic_cas(&t->rid, -1, 0) != -1)
...@@ -1095,7 +1096,6 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { ...@@ -1095,7 +1096,6 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) {
struct task *scheduler_done(struct scheduler *s, struct task *t) { struct task *scheduler_done(struct scheduler *s, struct task *t) {
/* Release whatever locks this task held. */ /* Release whatever locks this task held. */
if (!t->implicit) task_unlock(t); if (!t->implicit) task_unlock(t);
...@@ -1287,48 +1287,43 @@ void scheduler_init(struct scheduler *s, struct space *space, int nr_queues, ...@@ -1287,48 +1287,43 @@ void scheduler_init(struct scheduler *s, struct space *space, int nr_queues,
s->tasks_next = 0; s->tasks_next = 0;
} }
/** /**
* @brief Print all the tasks in the queue of the scheduler * @brief Print all the tasks in the queue of the scheduler
* *
* @param s The #scheduler. * @param s The #scheduler.
*/ */
void scheduler_dump_queue(struct scheduler *s) { void scheduler_dump_queue(struct scheduler *s) {
int i,j; int i, j;
FILE* file; FILE *file;
char buffer[256]; char buffer[256];
struct queue* q; struct queue *q;
struct task* t; struct task *t;
for( i=0; i<s->nr_queues; ++i) { for (i = 0; i < s->nr_queues; ++i) {
/* Open file */
/* Open file */ sprintf(buffer, "queue_%d.dat", i);
sprintf(buffer, "queue_%d.dat", i); file = fopen(buffer, "w");
file = fopen(buffer, "w");
/* Get the queue */
/* Get the queue */ q = &s->queues[i];
q = &s->queues[i];
/* Some general info */
/* Some general info */ fprintf(file, "# Queue %d, size=%d, count=%d\n", i, q->size, q->count);
fprintf(file, "# Queue %d, size=%d, count=%d\n", i, q->size, q->count); fprintf(file, "# Index type subtype\n");
fprintf(file, "# Index type subtype\n");
for (j = 0; j < q->count; ++j) {
for (j=0; j<q->count; ++j) {
/* Get the task */
/* Get the task */ t = &q->tasks[j];
t = &q->tasks[j];
/* And print... */
/* And print... */ fprintf(file, "%d %s %s\n", j, taskID_names[t->type],
fprintf(file, "%d %s %s\n", j , taskID_names[t->type], subtaskID_names[t->subtype]); subtaskID_names[t->subtype]);
}
}
/* Be nice and clean */
fclose(file);
}
/* Be nice and clean */ }
fclose(file);
}
}
...@@ -48,9 +48,8 @@ const char *taskID_names[task_type_count] = { ...@@ -48,9 +48,8 @@ const char *taskID_names[task_type_count] = {
"ghost", "drift", "kick", "send", "recv", "link", "ghost", "drift", "kick", "send", "recv", "link",
"grav_pp", "grav_mm", "grav_up", "grav_down"}; "grav_pp", "grav_mm", "grav_up", "grav_down"};
const char *subtaskID_names[task_type_count] = { const char *subtaskID_names[task_type_count] = {"none", "density",
"none", "density", "force", "grav"}; "force", "grav"};
/** /**
* @brief Unlock the cell held by this task. * @brief Unlock the cell held by this task.
......
...@@ -37,7 +37,7 @@ void factor(int value, int *f1, int *f2) { ...@@ -37,7 +37,7 @@ void factor(int value, int *f1, int *f2) {
int j; int j;
int i; int i;
j = (int) sqrt(value); j = (int)sqrt(value);
for (i = j; i > 0; i--) { for (i = j; i > 0; i--) {