Commit 62962a2f authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

fix formatting.

parent 1a4de4b7
......@@ -318,7 +318,7 @@ void engine_repartition(struct engine *e) {
/* Nothing to do if only using a single node. Also avoids METIS
* bug that doesn't handle this case well. */
if ( nr_nodes == 1 ) return;
if (nr_nodes == 1) return;
/* Allocate the inds and weights. */
if ((inds = (idx_t *)malloc(sizeof(idx_t) * 26 *nr_cells)) == NULL ||
......@@ -589,7 +589,7 @@ void engine_repartition(struct engine *e) {
/* Check that the nodeIDs are ok. */
for (k = 0; k < nr_cells; k++)
if (nodeIDs[k] < 0 || nodeIDs[k] >= nr_nodes)
error("Got bad nodeID %"PRIDX" for cell %i.", nodeIDs[k], k);
error("Got bad nodeID %" PRIDX " for cell %i.", nodeIDs[k], k);
/* Check that the partition is complete and all nodes have some work. */
int present[nr_nodes];
......@@ -597,7 +597,7 @@ void engine_repartition(struct engine *e) {
for (i = 0; i < nr_nodes; i++) present[i] = 0;
for (i = 0; i < nr_cells; i++) present[nodeIDs[i]]++;
for (i = 0; i < nr_nodes; i++) {
if (! present[i]) {
if (!present[i]) {
failed = 1;
message("Node %d is not present after repartition", i);
}
......@@ -606,11 +606,11 @@ void engine_repartition(struct engine *e) {
/* If partition failed continue with the current one, but make this
* clear. */
if (failed) {
message("WARNING: METIS repartition has failed, continuing with "
"the current partition, load balance will not be optimal");
message(
"WARNING: METIS repartition has failed, continuing with "
"the current partition, load balance will not be optimal");
for (k = 0; k < nr_cells; k++) nodeIDs[k] = cells[k].nodeID;
}
}
/* Broadcast the result of the partition. */
......@@ -2238,7 +2238,7 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
for (i = 0; i < e->nr_threads; i++)
scheduler_addtask(&e->sched, task_type_psort, task_subtype_none, i, 0, NULL,
NULL, 0);
scheduler_ranktasks(&e->sched);
/* Allocate and init the threads. */
......
......@@ -56,17 +56,18 @@
void scheduler_addunlock(struct scheduler *s, struct task *ta,
struct task *tb) {
/* Lock the scheduler since re-allocating the unlocks is not
thread-safe. */
thread-safe. */
if (lock_lock(&s->lock) != 0) error("Unable to lock scheduler.");
/* Does the buffer need to be grown? */
if (s->nr_unlocks == s->size_unlocks) {
struct task **unlocks_new;
int *unlock_ind_new;
s->size_unlocks *= 2;
if ((unlocks_new = (struct task **)malloc(sizeof(struct task *) * s->size_unlocks)) == NULL ||
if ((unlocks_new = (struct task **)malloc(
sizeof(struct task *) *s->size_unlocks)) == NULL ||
(unlock_ind_new = (int *)malloc(sizeof(int) * s->size_unlocks)) == NULL)
error("Failed to re-allocate unlocks.");
memcpy(unlocks_new, s->unlocks, sizeof(struct task *) * s->nr_unlocks);
......@@ -76,12 +77,12 @@ void scheduler_addunlock(struct scheduler *s, struct task *ta,
s->unlocks = unlocks_new;
s->unlock_ind = unlock_ind_new;
}
/* Write the unlock to the scheduler. */
const int ind = atomic_inc(&s->nr_unlocks);
s->unlocks[ind] = tb;
s->unlock_ind[ind] = ta - s->tasks;
/* Release the scheduler. */
if (lock_unlock(&s->lock) != 0) error("Unable to unlock scheduler.");
}
......@@ -695,7 +696,7 @@ struct task *scheduler_addtask(struct scheduler *s, int type, int subtype,
*
* @param s The #scheduler.
*/
void scheduler_set_unlocks(struct scheduler *s) {
/* Store the counts for each task. */
......@@ -703,20 +704,19 @@ void scheduler_set_unlocks(struct scheduler *s) {
if ((counts = (int *)malloc(sizeof(int) * s->nr_tasks)) == NULL)
error("Failed to allocate temporary counts array.");
bzero(counts, sizeof(int) * s->nr_tasks);
for (int k = 0; k < s->nr_unlocks; k++)
counts[s->unlock_ind[k]] += 1;
for (int k = 0; k < s->nr_unlocks; k++) counts[s->unlock_ind[k]] += 1;
/* Compute the offset for each unlock block. */
int *offsets;
if ((offsets = (int *)malloc(sizeof(int) * (s->nr_tasks + 1))) == NULL)
error("Failed to allocate temporary offsets array.");
offsets[0] = 0;
for (int k = 0; k < s->nr_tasks; k++)
offsets[k + 1] = offsets[k] + counts[k];
for (int k = 0; k < s->nr_tasks; k++) offsets[k + 1] = offsets[k] + counts[k];
/* Create and fill a temporary array with the sorted unlocks. */
struct task **unlocks;
if ((unlocks = (struct task **)malloc(sizeof(struct task *) * s->size_unlocks)) == NULL)
if ((unlocks = (struct task **)malloc(sizeof(struct task *) *
s->size_unlocks)) == NULL)
error("Failed to allocate temporary unlocks array.");
for (int k = 0; k < s->nr_unlocks; k++) {
const int ind = s->unlock_ind[k];
......@@ -727,24 +727,22 @@ void scheduler_set_unlocks(struct scheduler *s) {
/* Swap the unlocks. */
free(s->unlocks);
s->unlocks = unlocks;
/* Re-set the offsets. */
offsets[0] = 0;
for (int k = 1; k < s->nr_tasks; k++)
offsets[k] = offsets[k - 1] + counts[k - 1];
for (int k = 0; k < s->nr_tasks; k++)
for (int j = offsets[k]; j < offsets[k + 1]; j++)
s->unlock_ind[j] = k;
for (int j = offsets[k]; j < offsets[k + 1]; j++) s->unlock_ind[j] = k;
/* Set the unlocks in the tasks. */
for (int k = 0; k < s->nr_tasks; k++) {
struct task *t = &s->tasks[k];
t->nr_unlock_tasks = counts[k];
t->unlock_tasks = &s->unlocks[offsets[k]];
for (int j = offsets[k]; j < offsets[k + 1]; j++)
s->unlock_ind[j] = k;
for (int j = offsets[k]; j < offsets[k + 1]; j++) s->unlock_ind[j] = k;
}
/* Clean up. */
free(counts);
free(offsets);
......@@ -989,9 +987,7 @@ void scheduler_start(struct scheduler *s, unsigned int mask) {
// tic = getticks();
for (int k = 0; k < s->nr_tasks; k++) {
t = &tasks[tid[k]];
if (atomic_dec(&t->wait) == 1 &&
((1 << t->type) & s->mask) &&
!t->skip) {
if (atomic_dec(&t->wait) == 1 && ((1 << t->type) & s->mask) && !t->skip) {
scheduler_enqueue(s, t);
pthread_cond_broadcast(&s->sleep_cond);
}
......@@ -1290,10 +1286,12 @@ void scheduler_init(struct scheduler *s, struct space *space, int nr_queues,
if (pthread_cond_init(&s->sleep_cond, NULL) != 0 ||
pthread_mutex_init(&s->sleep_mutex, NULL) != 0)
error("Failed to initialize sleep barrier.");
/* Init the unlocks. */
if ((s->unlocks = (struct task **)malloc(sizeof(struct task *) * scheduler_init_nr_unlocks)) == NULL ||
(s->unlock_ind = (int *)malloc(sizeof(int) * scheduler_init_nr_unlocks)) == NULL)
if ((s->unlocks = (struct task **)malloc(
sizeof(struct task *) *scheduler_init_nr_unlocks)) == NULL ||
(s->unlock_ind =
(int *)malloc(sizeof(int) * scheduler_init_nr_unlocks)) == NULL)
error("Failed to allocate unlocks.");
s->nr_unlocks = 0;
s->size_unlocks = scheduler_init_nr_unlocks;
......
......@@ -71,7 +71,7 @@ struct scheduler {
/* The task indices. */
int *tasks_ind;
/* The task unlocks. */
struct task **unlocks;
int *unlock_ind;
......
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