diff --git a/examples/main.c b/examples/main.c index e385f173d4b96a2a0a69ff508871e200034bd4b7..b01ace59007fb9917488eac1a47df9263db4e6a6 100644 --- a/examples/main.c +++ b/examples/main.c @@ -397,7 +397,7 @@ int main(int argc, char *argv[]) { /* Take a step. */ engine_step(&e); - if (j == 5) break; + if (j == 1) break; if (with_outputs && j % 100 == 0) { diff --git a/src/engine.c b/src/engine.c index 42fce5dbbeb2afd3794e5e3e262b4fd4acb87b71..830cf6e9c9105d1caf098c92eb4b627fd2abcaf3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2009,8 +2009,6 @@ if ( e->nodeID == 0 ) scheduler_print_tasks(&e->sched, "tasks_after.dat"); - error("done step"); - TIMER_TOC(timer_runners); TIMER_TOC2(timer_step); diff --git a/src/runner.c b/src/runner.c index 54f3dab561e435a0666f38b28c3f02b784aac13e..77e50c87792ba8012d07b16c1f390985af3dc3d9 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1193,30 +1193,7 @@ void *runner_main(void *data) { space_split(e->s, t->ci); break; case task_type_rewait: - - - - for (struct task *t2 = (struct task *)t->ci; - t2 != (struct task *)t->cj; t2++) { - if(store == NULL && t2->type==task_type_pair && t2->subtype==task_subtype_density) { - message("\n"); - message("Checking task %s-%s address: %p", taskID_names[t2->type], subtaskID_names[t2->subtype], t2); - store = t2; - } - for (int k = 0; k < t2->nr_unlock_tasks; k++) { - if(t2->type == task_type_sort && t2->flags == 0) continue; - atomic_inc(&t2->unlock_tasks[k]->wait); - - struct task *t3=t2->unlock_tasks[k]; - if (t3 == store) { - message("Unlocked by task %s-%s address: %p" , taskID_names[t2->type], subtaskID_names[t2->subtype], t2); - } - - } - } - - - + task_do_rewait(t); break; default: error("Unknown task type."); diff --git a/src/runner_iact_legacy.h b/src/runner_iact_legacy.h index 79157e9284e12e66cb1083dc8c865eb39198af16..bd868b63bb946eaa836ea562e3cca21193c7bf89 100644 --- a/src/runner_iact_legacy.h +++ b/src/runner_iact_legacy.h @@ -26,9 +26,8 @@ #include "part.h" #include "vector.h" -/* #define PRINT_PARTS \ */ -/* void; */ -/*if (pi->id == 1000) { \ +#define PRINT_PARTS \ +if (pi->id == 1000) { \ message( \ "pi->id=%lld pi->h=%f pi->N_ngb=%f pi->rho=%f pi->t_beg=%f pi->t_end=%f pos=[%f %f %f]", \ pi->id, pi->h, pi->density.wcount, pi->rho, pi->t_begin, pi->t_end, pi->x[0], pi->x[1], pi->x[2]); \ @@ -39,7 +38,6 @@ pj->id, pj->h, pj->density.wcount, pj->rho, pj->t_begin, pj->t_end, pj->x[0], pj->x[1], pj->x[2]); \ }\ fflush(stdout); -*/ /** @@ -74,7 +72,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_density( float dv[3], curlvr[3]; int k; - //PRINT_PARTS; + PRINT_PARTS; /* Get the masses. */ mi = pi->mass; @@ -250,7 +248,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density( float dv[3], curlvr[3]; int k; - //PRINT_PARTS; + PRINT_PARTS; /* Get the masses. */ mj = pj->mass; diff --git a/src/scheduler.c b/src/scheduler.c index 341a681ddcd12922b4409241ea48fd967c311f2b..084b8f3626f833ea5ba84da1e71b1c3a7e9bc720 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -983,13 +983,21 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { ? s->size - s->nr_tasks : s->nr_queues; - const int waiting_old = - s->waiting; // Remember that engine_launch may fiddle with this value. + /* Remember that engine_launch may fiddle with this value. */ + const int waiting_old = s->waiting; + + /* We are going to use the task structure in a modified way to pass information + to the task. Don't do this at home ! + - ci and cj will give the range of tasks to which the waits will be applied + - the flags will be used to transfer the mask + - the rest is unused. + */ for (int k = 0; k < num_rewait_tasks; k++) { rewait_tasks[k].type = task_type_rewait; rewait_tasks[k].ci = (struct cell *)&s->tasks[k * nr_tasks / s->nr_queues]; rewait_tasks[k].cj = (struct cell *)&s->tasks[(k + 1) * nr_tasks / s->nr_queues]; + rewait_tasks[k].flags = s->mask; rewait_tasks[k].skip = 0; rewait_tasks[k].wait = 0; rewait_tasks[k].rid = -1; diff --git a/src/task.c b/src/task.c index b65bfd21fd194a21533df2b41a57ca84c16ad26f..afb93720fca7b7f916feded6de39820de2b87a1d 100644 --- a/src/task.c +++ b/src/task.c @@ -41,6 +41,8 @@ #include "error.h" #include "lock.h" +struct task *store; + /* Task type names. */ const char *taskID_names[task_type_count] = { "none", "sort", "self", "pair", "sub", "init", @@ -267,3 +269,41 @@ void task_print_mask(unsigned int mask) { printf(" %s=%s", taskID_names[k], (mask & (1 << k)) ? "yes" : "no"); printf(" ]\n"); } + + +void task_do_rewait(struct task *t) { + + const unsigned int mask = t->flags; + + for (struct task *t2 = (struct task *)t->ci; t2 != (struct task *)t->cj; t2++) { + + if( t2->skip ) continue; + + /* Skip tasks not in the mask */ + if( !((1<<t2->type) & mask) ) continue; + + /* Skip sort tasks that have already been performed */ + if(t2->type == task_type_sort && t2->flags == 0) continue; + + if(store == NULL && t2->type==task_type_pair && t2->subtype==task_subtype_density) { + message("\n"); + message("Checking task %s-%s address: %p", taskID_names[t2->type], subtaskID_names[t2->subtype], t2); + store = t2; + } + + for (int k = 0; k < t2->nr_unlock_tasks; k++) { + + struct task *t3=t2->unlock_tasks[k]; + + atomic_inc(&t3->wait); + + if (t3 == store) { + message("Unlocked by task %s-%s address: %p" , taskID_names[t2->type], subtaskID_names[t2->subtype], t2); + } + + } + } + + + +} diff --git a/src/task.h b/src/task.h index fbeed3a7a47ee6e2e180ae48dd8e0eb1029fb868..8f633a640ef7457a28713fe3fa3f182232d137de 100644 --- a/src/task.h +++ b/src/task.h @@ -95,5 +95,6 @@ void task_addunlock(struct task *ta, struct task *tb); void task_unlock(struct task *t); int task_lock(struct task *t); void task_print_mask(unsigned int mask); +void task_do_rewait(struct task *t); #endif /* SWIFT_TASK_H */