diff --git a/src/engine.c b/src/engine.c index 8bedfbc5bfa55dce226c345a9736b3cb028cdce4..42fce5dbbeb2afd3794e5e3e262b4fd4acb87b71 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1323,41 +1323,41 @@ int engine_marktasks(struct engine *e) { struct cell *ci, *cj; // ticks tic = getticks(); - /* Much less to do here if we're on a fixed time-step. */ - if (!(e->policy & engine_policy_multistep)) { + /* /\* Much less to do here if we're on a fixed time-step. *\/ */ + /* if (!(e->policy & engine_policy_multistep)) { */ - /* Run through the tasks and mark as skip or not. */ - for (k = 0; k < nr_tasks; k++) { + /* /\* Run through the tasks and mark as skip or not. *\/ */ + /* for (k = 0; k < nr_tasks; k++) { */ - /* Get a handle on the kth task. */ - t = &tasks[ind[k]]; + /* /\* Get a handle on the kth task. *\/ */ + /* t = &tasks[ind[k]]; */ - /* Pair? */ - if (t->type == task_type_pair || - (t->type == task_type_sub && t->cj != NULL)) { + /* /\* Pair? *\/ */ + /* if (t->type == task_type_pair || */ + /* (t->type == task_type_sub && t->cj != NULL)) { */ - /* Local pointers. */ - ci = t->ci; - cj = t->cj; + /* /\* Local pointers. *\/ */ + /* ci = t->ci; */ + /* cj = t->cj; */ - /* Too much particle movement? */ - if (t->tight && - (fmaxf(ci->h_max, cj->h_max) + ci->dx_max + cj->dx_max > cj->dmin || - ci->dx_max > space_maxreldx * ci->h_max || - cj->dx_max > space_maxreldx * cj->h_max)) - return 1; + /* /\* Too much particle movement? *\/ */ + /* if (t->tight && */ + /* (fmaxf(ci->h_max, cj->h_max) + ci->dx_max + cj->dx_max > cj->dmin || */ + /* ci->dx_max > space_maxreldx * ci->h_max || */ + /* cj->dx_max > space_maxreldx * cj->h_max)) */ + /* return 1; */ - } + /* } */ - /* Sort? */ - else if (t->type == task_type_sort) { + /* /\* Sort? *\/ */ + /* else if (t->type == task_type_sort) { */ - /* If all the sorts have been done, make this task implicit. */ - if (!(t->flags & (t->flags ^ t->ci->sorted))) t->implicit = 1; - } - } + /* /\* If all the sorts have been done, make this task implicit. *\/ */ + /* if (!(t->flags & (t->flags ^ t->ci->sorted))) t->implicit = 1; */ + /* } */ + /* } */ - } else { + /* } else { */ /* Run through the tasks and mark as skip or not. */ for (k = 0; k < nr_tasks; k++) { @@ -1432,7 +1432,7 @@ int engine_marktasks(struct engine *e) { else if (t->type == task_type_none) t->skip = 1; } - } + //} // message( "took %.3f ms." , (double)(getticks() - tic)/CPU_TPS*1000 ); @@ -1841,15 +1841,15 @@ void engine_init_particles(struct engine *e) { engine_prepare(e); - engine_print(e); + //engine_print(e); // engine_maketasks(e); - engine_print(e); + //engine_print(e); engine_marktasks(e); - engine_print(e); + //engine_print(e); fflush(stdout); message("Engine prepared"); @@ -1990,7 +1990,7 @@ if ( e->nodeID == 0 ) /* Prepare the space. */ engine_prepare(e); - // engine_maketasks(e); + //engine_maketasks(e); // engine_marktasks(e); @@ -2002,14 +2002,14 @@ if ( e->nodeID == 0 ) TIMER_TIC; engine_launch(e, e->nr_threads, (1 << task_type_sort) | (1 << task_type_self) | - (1 << task_type_pair) | (1 << task_type_sub) | - (1 << task_type_init) | (1 << task_type_ghost) | - (1 << task_type_kick) | (1 << task_type_send) | - (1 << task_type_recv)); + (1 << task_type_pair) | (1 << task_type_sub) | + (1 << task_type_init) | (1 << task_type_ghost) | + (1 << task_type_kick) | (1 << task_type_send) | + (1 << task_type_recv)); scheduler_print_tasks(&e->sched, "tasks_after.dat"); - // error("done step"); + error("done step"); TIMER_TOC(timer_runners); diff --git a/src/runner.c b/src/runner.c index 52e106cb59e7585beef7ede2946ae499d45a9f4e..54f3dab561e435a0666f38b28c3f02b784aac13e 100644 --- a/src/runner.c +++ b/src/runner.c @@ -44,6 +44,8 @@ #include "timers.h" #include "timestep.h" +struct task *store = NULL; + /* Include the right variant of the SPH interactions */ #ifdef LEGACY_GADGET2_SPH @@ -1074,9 +1076,6 @@ void *runner_main(void *data) { struct part *parts; int k, nr_parts; - message("here"); - fflush(stdout); - /* Main loop. */ while (1) { @@ -1194,11 +1193,30 @@ 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++) { - for (k = 0; k < t2->nr_unlock_tasks; k++) - atomic_inc(&t2->unlock_tasks[k]->wait); - } + + + + 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); + } + + } + } + + + break; default: error("Unknown task type."); diff --git a/src/scheduler.c b/src/scheduler.c index 6ef83179709437964b902ec531380a3b18068841..341a681ddcd12922b4409241ea48fd967c311f2b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -46,6 +46,8 @@ #include "kernel.h" #include "timers.h" +extern struct task *store; + /** * @brief Add an unlock_task to the given task. * @@ -961,6 +963,8 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { struct task *t, *tasks = s->tasks; // ticks tic; + store = NULL; + /* Store the mask */ s->mask = mask | (1 << task_type_rewait); @@ -978,6 +982,7 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { const int num_rewait_tasks = s->nr_queues > s->size - s->nr_tasks ? s->size - s->nr_tasks : s->nr_queues; + const int waiting_old = s->waiting; // Remember that engine_launch may fiddle with this value. for (int k = 0; k < num_rewait_tasks; k++) { @@ -1004,6 +1009,8 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { /* message("waiting tasks took %.3f ms.", (double)(getticks() - tic) / CPU_TPS * 1000); */ + scheduler_print_tasks(s, "tasks_start.dat"); + /* Loop over the tasks and enqueue whoever is ready. */ // tic = getticks(); for (int k = 0; k < s->nr_tasks; k++) { @@ -1043,6 +1050,12 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { if (t->implicit) { for (int j = 0; j < t->nr_unlock_tasks; j++) { struct task *t2 = t->unlock_tasks[j]; + + if (t2 == store) { + message("Unlocked by task %s-%s address: %p", taskID_names[t->type], + subtaskID_names[t->subtype], t); + } + if (atomic_dec(&t2->wait) == 1) scheduler_enqueue(s, t2); } } @@ -1137,10 +1150,20 @@ struct task *scheduler_done(struct scheduler *s, struct task *t) { /* Release whatever locks this task held. */ if (!t->implicit) task_unlock(t); + if (t == store) + message("\nChecking task %s-%s address: %p", taskID_names[t->type], + subtaskID_names[t->subtype], t); + /* Loop through the dependencies and add them to a queue if they are ready. */ for (int k = 0; k < t->nr_unlock_tasks; k++) { struct task *t2 = t->unlock_tasks[k]; + + if (t2 == store) { + message("Unlocked by task %s-%s address: %p", taskID_names[t->type], + subtaskID_names[t->subtype], t); + } + int res = atomic_dec(&t2->wait); if (res < 1) { error("Negative wait!"); @@ -1176,9 +1199,6 @@ struct task *scheduler_done(struct scheduler *s, struct task *t) { struct task *scheduler_unlock(struct scheduler *s, struct task *t) { - int k, res; - struct task *t2, *next = NULL; - /* Loop through the dependencies and add them to a queue if they are ready. */ for (int k = 0; k < t->nr_unlock_tasks; k++) { @@ -1337,28 +1357,27 @@ void scheduler_init(struct scheduler *s, struct space *space, int nr_queues, s->tasks_next = 0; } - /** * @brief Prints the list of tasks to a file * * @param s The #scheduler * @param fileName Name of the file to write to */ - void scheduler_print_tasks(struct scheduler *s, char *fileName) { +void scheduler_print_tasks(struct scheduler *s, char *fileName) { - const int nr_tasks = s->nr_tasks, *tid = s->tasks_ind; - struct task *t, *tasks = s->tasks; + const int nr_tasks = s->nr_tasks, *tid = s->tasks_ind; + struct task *t, *tasks = s->tasks; - FILE *file = fopen(fileName, "w"); + FILE *file = fopen(fileName, "w"); - fprintf(file, "# Rank Name Subname unlocks waits\n"); + fprintf(file, "# Rank Name Subname unlocks waits\n"); - for (int k = nr_tasks - 1; k >= 0; k--) { - t = &tasks[tid[k]]; - if (!((1 << t->type)) || 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); - } + for (int k = nr_tasks - 1; k >= 0; k--) { + t = &tasks[tid[k]]; + if (!((1 << t->type)) || 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); + } - fclose(file); - } + fclose(file); +}