diff --git a/src/scheduler.c b/src/scheduler.c index 956fcc2c92bb6db9247e6de5384cda31b1c5fe63..90f20d776361ea27d79083500f14f1ff536b894a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1066,20 +1066,13 @@ struct task *scheduler_addtask(struct scheduler *s, enum task_types type, */ void scheduler_set_unlocks(struct scheduler *s) { - /* Extract constant information and make non-volatile pointers */ - const int nr_tasks = s->nr_tasks; - const int nr_unlocks = s->nr_unlocks; - int* unlock_ind = (int*) s->unlock_ind; - struct task **unlocks = (struct task **) s->unlocks; - /* Store the counts for each task. */ - int *counts; - if (posix_memalign((void **) &counts, 64, sizeof(int) * nr_tasks) != 0) + short int *counts; + if ((counts = (short int *)malloc(sizeof(short int) * s->nr_tasks)) == NULL) error("Failed to allocate temporary counts array."); - swift_align_information(int, counts, 64); - bzero(counts, sizeof(int) * nr_tasks); - for (int k = 0; k < nr_unlocks; k++) { - counts[unlock_ind[k]] += 1; + bzero(counts, sizeof(short int) * s->nr_tasks); + for (int k = 0; k < s->nr_unlocks; k++) { + counts[s->unlock_ind[k]] += 1; #ifdef SWIFT_DEBUG_CHECKS /* Check that we are not overflowing */ @@ -1093,10 +1086,10 @@ void scheduler_set_unlocks(struct scheduler *s) { /* Compute the offset for each unlock block. */ int *offsets; - if (posix_memalign((void **) &offsets, 64, sizeof(int) * (nr_tasks + 1)) != 0) + 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 < nr_tasks; k++) { + for (int k = 0; k < s->nr_tasks; k++) { offsets[k + 1] = offsets[k] + counts[k]; #ifdef SWIFT_DEBUG_CHECKS @@ -1106,31 +1099,30 @@ void scheduler_set_unlocks(struct scheduler *s) { } /* Create and fill a temporary array with the sorted unlocks. */ - struct task **new_unlocks; - if (posix_memalign((void **) &new_unlocks, 64, sizeof(struct task *) * s->size_unlocks) != 0) + struct task **unlocks; + if ((unlocks = (struct task **)malloc(sizeof(struct task *) * + s->size_unlocks)) == NULL) error("Failed to allocate temporary unlocks array."); - for (int k = 0; k < nr_unlocks; k++) { - const int ind = unlock_ind[k]; - new_unlocks[offsets[ind]] = unlocks[k]; + for (int k = 0; k < s->nr_unlocks; k++) { + const int ind = s->unlock_ind[k]; + unlocks[offsets[ind]] = s->unlocks[k]; offsets[ind] += 1; } /* Swap the unlocks. */ free(s->unlocks); - s->unlocks = new_unlocks; + s->unlocks = unlocks; /* Re-set the offsets. */ offsets[0] = 0; - for (int k = 1; k < nr_tasks; k++) + for (int k = 1; k < s->nr_tasks; k++) offsets[k] = offsets[k - 1] + counts[k - 1]; /* Set the unlocks in the tasks. */ - swift_align_information(int, counts, 64); - swift_align_information(int, offsets, 64); - for (int k = 0; k < nr_tasks; k++) { + for (int k = 0; k < s->nr_tasks; k++) { struct task *t = &s->tasks[k]; t->nr_unlock_tasks = counts[k]; - t->unlock_tasks = &new_unlocks[offsets[k]]; + t->unlock_tasks = &s->unlocks[offsets[k]]; } #ifdef SWIFT_DEBUG_CHECKS