diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 7d98c76490e3cc3f87fd2e54902273f2b7f3fa63..db439671ff5fee56c086444ddaa8268571c80a15 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -950,8 +950,8 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj) { sortdt_i = sort_i; countdt_i = count_i; } else if (ci->ti_end_min <= ti_current) { - if ((sortdt_i = (struct entry *)alloca(sizeof(struct entry) * count_i)) == - NULL) + if (posix_memalign((void *)&sortdt_i, VEC_SIZE * sizeof(float), + sizeof(struct entry) * count_i) != 0) error("Failed to allocate dt sortlists."); for (int k = 0; k < count_i; k++) if (parts_i[sort_i[k].i].ti_end <= ti_current) { @@ -963,8 +963,8 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj) { sortdt_j = sort_j; countdt_j = count_j; } else if (cj->ti_end_min <= ti_current) { - if ((sortdt_j = (struct entry *)alloca(sizeof(struct entry) * count_j)) == - NULL) + if (posix_memalign((void *)&sortdt_j, VEC_SIZE * sizeof(float), + sizeof(struct entry) * count_j) != 0) error("Failed to allocate dt sortlists."); for (int k = 0; k < count_j; k++) if (parts_j[sort_j[k].i].ti_end <= ti_current) { @@ -1270,6 +1270,11 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj) { IACT(r2q2[k], &dxq2[3 * k], hiq2[k], hjq2[k], piq2[k], pjq2[k]); #endif + if (ci->ti_end_max > ti_current && ci->ti_end_min <= ti_current) + free(sortdt_i); + if (cj->ti_end_max > ti_current && cj->ti_end_min <= ti_current) + free(sortdt_j); + TIMER_TOC(TIMER_DOPAIR); } @@ -1309,7 +1314,8 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Set up indt. */ int *indt = NULL; int countdt = 0, firstdt = 0; - if ((indt = (int *)alloca(sizeof(int) * count)) == NULL) + if (posix_memalign((void *)&indt, VEC_SIZE * sizeof(int), + count * sizeof(int)) != 0) error("Failed to allocate indt."); for (int k = 0; k < count; k++) if (parts[k].ti_end <= ti_current) { @@ -1499,6 +1505,8 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT(r2q2[k], &dxq2[3 * k], hiq2[k], hjq2[k], piq2[k], pjq2[k]); #endif + free(indt); + TIMER_TOC(TIMER_DOSELF); } @@ -1538,7 +1546,8 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Set up indt. */ int *indt = NULL; int countdt = 0, firstdt = 0; - if ((indt = (int *)alloca(sizeof(int) * count)) == NULL) + if (posix_memalign((void *)&indt, VEC_SIZE * sizeof(int), + count * sizeof(int)) != 0) error("Failed to allocate indt."); for (int k = 0; k < count; k++) if (parts[k].ti_end <= ti_current) { @@ -1701,6 +1710,8 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT(r2q2[k], &dxq2[3 * k], hiq2[k], hjq2[k], piq2[k], pjq2[k]); #endif + free(indt); + TIMER_TOC(TIMER_DOSELF); } diff --git a/src/space.c b/src/space.c index d913ec9b1e49caddc30df93bad10a29c796d662f..ea652f7f9b918e7f4f1ebe0a81e6604765691eb1 100644 --- a/src/space.c +++ b/src/space.c @@ -1566,4 +1566,7 @@ void space_clean(struct space *s) { for (int i = 0; i < s->nr_cells; ++i) cell_clean(&s->cells[i]); free(s->cells); + free(s->parts); + free(s->xparts); + free(s->gparts); }