Commit 5604c42c authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

change space_getcell to space_getcells, can pick up more than one cell at a time.

parent 67a7a2da
...@@ -110,7 +110,8 @@ int cell_unpack(struct pcell *pc, struct cell *c, struct space *s) { ...@@ -110,7 +110,8 @@ int cell_unpack(struct pcell *pc, struct cell *c, struct space *s) {
/* Fill the progeny recursively, depth-first. */ /* Fill the progeny recursively, depth-first. */
for (int k = 0; k < 8; k++) for (int k = 0; k < 8; k++)
if (pc->progeny[k] >= 0) { if (pc->progeny[k] >= 0) {
struct cell *temp = space_getcell(s); struct cell *temp;
space_getcells(s, 1, &temp);
temp->count = 0; temp->count = 0;
temp->gcount = 0; temp->gcount = 0;
temp->loc[0] = c->loc[0]; temp->loc[0] = c->loc[0];
......
...@@ -1477,7 +1477,6 @@ void space_split_recursive(struct space *s, struct cell *c, int *buff) { ...@@ -1477,7 +1477,6 @@ void space_split_recursive(struct space *s, struct cell *c, int *buff) {
int maxdepth = 0; int maxdepth = 0;
float h_max = 0.0f; float h_max = 0.0f;
int ti_end_min = max_nr_timesteps, ti_end_max = 0; int ti_end_min = max_nr_timesteps, ti_end_max = 0;
struct cell *temp;
struct part *parts = c->parts; struct part *parts = c->parts;
struct gpart *gparts = c->gparts; struct gpart *gparts = c->gparts;
struct xpart *xparts = c->xparts; struct xpart *xparts = c->xparts;
...@@ -1506,29 +1505,29 @@ void space_split_recursive(struct space *s, struct cell *c, int *buff) { ...@@ -1506,29 +1505,29 @@ void space_split_recursive(struct space *s, struct cell *c, int *buff) {
c->split = 1; c->split = 1;
/* Create the cell's progeny. */ /* Create the cell's progeny. */
space_getcells(s, 8, c->progeny);
for (int k = 0; k < 8; k++) { for (int k = 0; k < 8; k++) {
temp = space_getcell(s); struct cell *cp = c->progeny[k];
temp->count = 0; cp->count = 0;
temp->gcount = 0; cp->gcount = 0;
temp->ti_old = c->ti_old; cp->ti_old = c->ti_old;
temp->loc[0] = c->loc[0]; cp->loc[0] = c->loc[0];
temp->loc[1] = c->loc[1]; cp->loc[1] = c->loc[1];
temp->loc[2] = c->loc[2]; cp->loc[2] = c->loc[2];
temp->width[0] = c->width[0] / 2; cp->width[0] = c->width[0] / 2;
temp->width[1] = c->width[1] / 2; cp->width[1] = c->width[1] / 2;
temp->width[2] = c->width[2] / 2; cp->width[2] = c->width[2] / 2;
temp->dmin = c->dmin / 2; cp->dmin = c->dmin / 2;
if (k & 4) temp->loc[0] += temp->width[0]; if (k & 4) cp->loc[0] += cp->width[0];
if (k & 2) temp->loc[1] += temp->width[1]; if (k & 2) cp->loc[1] += cp->width[1];
if (k & 1) temp->loc[2] += temp->width[2]; if (k & 1) cp->loc[2] += cp->width[2];
temp->depth = c->depth + 1; cp->depth = c->depth + 1;
temp->split = 0; cp->split = 0;
temp->h_max = 0.0; cp->h_max = 0.0;
temp->dx_max = 0.f; cp->dx_max = 0.f;
temp->nodeID = c->nodeID; cp->nodeID = c->nodeID;
temp->parent = c; cp->parent = c;
temp->super = NULL; cp->super = NULL;
c->progeny[k] = temp;
} }
/* Split the cell data. */ /* Split the cell data. */
...@@ -1705,12 +1704,18 @@ void space_recycle_list(struct space *s, struct cell *list_begin, ...@@ -1705,12 +1704,18 @@ void space_recycle_list(struct space *s, struct cell *list_begin,
* If we have no cells, allocate a new chunk of memory and pick one from there. * If we have no cells, allocate a new chunk of memory and pick one from there.
* *
* @param s The #space. * @param s The #space.
* @param nr_cells Number of #cell to pick up.
* @param cells Array of @c nr_cells #cell pointers in which to store the
* new cells.
*/ */
struct cell *space_getcell(struct space *s) { void space_getcells(struct space *s, int nr_cells, struct cell **cells) {
/* Lock the space. */ /* Lock the space. */
lock_lock(&s->lock); lock_lock(&s->lock);
/* For each requested cell... */
for (int j = 0; j < nr_cells; j++) {
/* Is the buffer empty? */ /* Is the buffer empty? */
if (s->cells_sub == NULL) { if (s->cells_sub == NULL) {
if (posix_memalign((void *)&s->cells_sub, cell_align, if (posix_memalign((void *)&s->cells_sub, cell_align,
...@@ -1724,20 +1729,21 @@ struct cell *space_getcell(struct space *s) { ...@@ -1724,20 +1729,21 @@ struct cell *space_getcell(struct space *s) {
} }
/* Pick off the next cell. */ /* Pick off the next cell. */
struct cell *c = s->cells_sub; cells[j] = s->cells_sub;
s->cells_sub = c->next; s->cells_sub = cells[j]->next;
s->tot_cells += 1; s->tot_cells += 1;
}
/* Unlock the space. */ /* Unlock the space. */
lock_unlock_blind(&s->lock); lock_unlock_blind(&s->lock);
/* Init some things in the cell we just got. */ /* Init some things in the cell we just got. */
bzero(c, sizeof(struct cell)); for (int j = 0; j < nr_cells; j++) {
c->nodeID = -1; bzero(cells[j], sizeof(struct cell));
if (lock_init(&c->lock) != 0 || lock_init(&c->glock) != 0) cells[j]->nodeID = -1;
if (lock_init(&cells[j]->lock) != 0 || lock_init(&cells[j]->glock) != 0)
error("Failed to initialize cell spinlocks."); error("Failed to initialize cell spinlocks.");
}
return c;
} }
/** /**
......
...@@ -147,7 +147,7 @@ void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max, ...@@ -147,7 +147,7 @@ void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max,
int verbose); int verbose);
void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max, void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
int verbose); int verbose);
struct cell *space_getcell(struct space *s); void space_getcells(struct space *s, int nr_cells, struct cell **cells);
int space_getsid(struct space *s, struct cell **ci, struct cell **cj, int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
double *shift); double *shift);
void space_init(struct space *s, const struct swift_params *params, void space_init(struct space *s, const struct swift_params *params,
......
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