Commit 9a8b7e4a authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Correclty move the pointer at the top-level when moving from proxy to proxy....

Correclty move the pointer at the top-level when moving from proxy to proxy. Simplify the linking recursion.
parent 0a61ab22
......@@ -101,7 +101,33 @@ int cell_getsize(struct cell *c) {
*
* @return The number of particles linked.
*/
int cell_link_parts(struct cell *c, struct part *parts, int link) {
int cell_link_parts(struct cell *c, struct part *parts) {
c->hydro.parts = parts;
/* Fill the progeny recursively, depth-first. */
if (c->split) {
int offset = 0;
for (int k = 0; k < 8; k++) {
if (c->progeny[k] != NULL)
offset += cell_link_parts(c->progeny[k], &parts[offset]);
}
}
/* Return the total number of linked particles. */
return c->hydro.count;
}
/**
* @brief Link the cells recursively to the given #part array.
*
* @param c The #cell.
* @param parts The #part array.
*
* @return The number of particles linked.
*/
int cell_link_foreign_parts(struct cell *c, struct part *parts) {
#ifdef SWIFT_DEBUG_CHECKS
if (c->nodeID == engine_rank)
......@@ -110,37 +136,28 @@ int cell_link_parts(struct cell *c, struct part *parts, int link) {
/* Do we have a hydro task at this level? */
if (c->hydro.density != NULL) {
link = 1;
}
/* Ok, link the particles at this level */
if (link) {
c->hydro.parts = parts;
/* Recursively attach the parts */
const int counts = cell_link_parts(c, parts);
#ifdef SWIFT_DEBUG_CHECKS
if (counts != c->hydro.count)
error("Something is wrong with the foreign counts");
#endif
return counts;
}
/* Fill the progeny recursively, depth-first. */
/* Go deeper to find the level where the tasks are */
if (c->split) {
int count = 0;
for (int k = 0; k < 8; k++) {
if (c->progeny[k] != NULL) {
count += cell_link_parts(c->progeny[k], &parts[count], link);
count += cell_link_foreign_parts(c->progeny[k], parts);
}
}
#ifdef SWIFT_DEBUG_CHECKS
if (link && (count != c->hydro.count))
error("Something is wrong with the foreign part counts.");
#endif
return count;
}
/* Return the total number of linked particles. */
if (link)
return c->hydro.count;
else
} else {
return 0;
}
}
/**
......
......@@ -688,7 +688,8 @@ int cell_unpack_end_step(struct cell *c, struct pcell_step *pcell);
int cell_pack_multipoles(struct cell *c, struct gravity_tensors *m);
int cell_unpack_multipoles(struct cell *c, struct gravity_tensors *m);
int cell_getsize(struct cell *c);
int cell_link_parts(struct cell *c, struct part *parts, int link);
int cell_link_parts(struct cell *c, struct part *parts);
int cell_link_foreign_parts(struct cell *c, struct part *parts);
int cell_link_gparts(struct cell *c, struct gpart *gparts);
int cell_link_sparts(struct cell *c, struct spart *sparts);
int cell_count_parts_for_tasks(const struct cell *c);
......
......@@ -1793,20 +1793,24 @@ void engine_allocate_foreign_particles(struct engine *e) {
}
struct part *parts = s->parts_foreign;
size_t count_parts = 0;
size_t total_count_parts = 0;
for (int k = 0; k < nr_proxies; k++) {
for (int j = 0; j < e->proxies[k].nr_cells_in; j++) {
if (e->proxies[k].cells_in_type[j] & proxy_cell_type_hydro) {
count_parts +=
cell_link_parts(e->proxies[k].cells_in[j], parts, /*link=*/0);
parts += count_parts;
const size_t count_parts = cell_link_foreign_parts(e->proxies[k].cells_in[j], parts);
parts = &parts[count_parts];
total_count_parts += count_parts;
}
}
}
message("count_parts: %zd %zd", count_parts_in, count_parts);
/* Update the counters */
s->nr_parts_foreign = parts - s->parts_foreign;
message("count_parts: %zd %zd", count_parts_in, total_count_parts);
return;
......
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