Commit ac685af2 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Also register the updates in proxy type if the cell pair was already found before.

parent 88cc703a
......@@ -4421,6 +4421,11 @@ void engine_reconstruct_multipoles(struct engine *e) {
clocks_getunit());
}
int count_in_hydro;
int count_out_hydro;
int count_in_grav;
int count_out_grav;
/**
* @brief Create and fill the proxies.
*
......@@ -4438,7 +4443,7 @@ void engine_makeproxies(struct engine *e) {
const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]};
const struct gravity_props *props = e->gravity_properties;
const double theta_crit2 = props->theta_crit2;
ticks tic = getticks();
const ticks tic = getticks();
const int with_hydro = (e->policy & engine_policy_hydro);
const int with_gravity = (e->policy & engine_policy_self_gravity);
double CoM_i[3] = {0., 0., 0.};
......@@ -4488,7 +4493,21 @@ void engine_makeproxies(struct engine *e) {
if (cells[cid].nodeID != nodeID && cells[cjd].nodeID != nodeID)
continue;
char proxy_type = proxy_cell_type_none;
int proxy_type = 0;
/* In the hydro case, only care about neighbours */
if (with_hydro) {
/* This is super-ugly but checks for direct neighbours */
/* with periodic BC */
if (((abs(i - ii) <= 1 || abs(i - ii - cdim[0]) <= 1 ||
abs(i - ii + cdim[0]) <= 1) &&
(abs(j - jj) <= 1 || abs(j - jj - cdim[1]) <= 1 ||
abs(j - jj + cdim[1]) <= 1) &&
(abs(k - kk) <= 1 || abs(k - kk - cdim[2]) <= 1 ||
abs(k - kk + cdim[2]) <= 1)))
proxy_type |= (int)proxy_cell_type_hydro;
}
/* In the gravity case, check distances using the MAC. */
if (with_gravity) {
......@@ -4514,21 +4533,7 @@ void engine_makeproxies(struct engine *e) {
/* Are we too close for M2L? */
if (!gravity_M2L_accept(r_max_i, r_max_j, theta_crit2, r2))
proxy_type |= proxy_cell_type_gravity;
}
/* In the hydro case, only care about neighbours */
if (with_hydro) {
/* This is super-ugly but checks for direct neighbours */
/* with periodic BC */
if (((abs(i - ii) <= 1 || abs(i - ii - cdim[0]) <= 1 ||
abs(i - ii + cdim[0]) <= 1) &&
(abs(j - jj) <= 1 || abs(j - jj - cdim[1]) <= 1 ||
abs(j - jj + cdim[1]) <= 1) &&
(abs(k - kk) <= 1 || abs(k - kk - cdim[2]) <= 1 ||
abs(k - kk + cdim[2]) <= 1)))
proxy_type |= proxy_cell_type_hydro;
proxy_type |= (int)proxy_cell_type_gravity;
}
/* Abort if not in range at all */
......@@ -4594,6 +4599,28 @@ void engine_makeproxies(struct engine *e) {
}
}
count_in_hydro = 0;
count_out_hydro = 0;
count_in_grav = 0;
count_out_grav = 0;
for (int pid = 0; pid < e->nr_proxies; pid++) {
/* Get a handle on the proxy. */
struct proxy *p = &e->proxies[pid];
for (int k = 0; k < p->nr_cells_in; k++) {
if (p->cells_in_type[k] & proxy_cell_type_hydro) ++count_in_hydro;
if (p->cells_in_type[k] & proxy_cell_type_gravity) ++count_in_grav;
}
for (int k = 0; k < p->nr_cells_out; k++) {
if (p->cells_out_type[k] & proxy_cell_type_hydro) ++count_out_hydro;
if (p->cells_out_type[k] & proxy_cell_type_gravity) ++count_out_grav;
}
}
message("in hydro: %d out hydro: %d", count_in_hydro, count_out_hydro);
message("in grav: %d out grav: %d", count_in_grav, count_out_grav);
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
......
......@@ -40,6 +40,11 @@
/* Local headers. */
#include "error.h"
extern int count_in_hydro;
extern int count_out_hydro;
extern int count_in_grav;
extern int count_out_grav;
/**
* @brief Exchange cells with a remote node.
*
......@@ -126,17 +131,22 @@ void proxy_cells_exch2(struct proxy *p) {
* @param c The #cell.
* @param type Why is this cell in the proxy (hdro, gravity, ...) ?
*/
void proxy_addcell_in(struct proxy *p, struct cell *c, char type) {
void proxy_addcell_in(struct proxy *p, struct cell *c, int type) {
if (type == proxy_cell_type_none) error("Invalid type for proxy");
/* Check if the cell is already registered with the proxy. */
for (int k = 0; k < p->nr_cells_in; k++)
if (p->cells_in[k] == c) return;
if (p->cells_in[k] == c) {
/* Update the type */
p->cells_in_type[k] = type;
return;
}
/* Do we need to grow the number of in cells? */
if (p->nr_cells_in == p->size_cells_in) {
message("Increasing proxy size");
p->size_cells_in *= proxy_buffgrow;
struct cell **temp_cell;
......@@ -146,10 +156,10 @@ void proxy_addcell_in(struct proxy *p, struct cell *c, char type) {
free(p->cells_in);
p->cells_in = temp_cell;
char *temp_type;
if ((temp_type = malloc(sizeof(char) * p->size_cells_in)) == NULL)
int *temp_type;
if ((temp_type = malloc(sizeof(int) * p->size_cells_in)) == NULL)
error("Failed to allocate incoming cell type list.");
memcpy(temp_type, p->cells_in_type, sizeof(char) * p->nr_cells_in);
memcpy(temp_type, p->cells_in_type, sizeof(int) * p->nr_cells_in);
free(p->cells_in_type);
p->cells_in_type = temp_type;
}
......@@ -167,11 +177,18 @@ void proxy_addcell_in(struct proxy *p, struct cell *c, char type) {
* @param c The #cell.
* @param type Why is this cell in the proxy (hdro, gravity, ...) ?
*/
void proxy_addcell_out(struct proxy *p, struct cell *c, char type) {
void proxy_addcell_out(struct proxy *p, struct cell *c, int type) {
if (type == proxy_cell_type_none) error("Invalid type for proxy");
/* Check if the cell is already registered with the proxy. */
for (int k = 0; k < p->nr_cells_out; k++)
if (p->cells_out[k] == c) return;
if (p->cells_out[k] == c) {
/* Update the type */
p->cells_out_type[k] |= type;
return;
}
/* Do we need to grow the number of out cells? */
if (p->nr_cells_out == p->size_cells_out) {
......@@ -184,10 +201,10 @@ void proxy_addcell_out(struct proxy *p, struct cell *c, char type) {
free(p->cells_out);
p->cells_out = temp_cell;
char *temp_type;
if ((temp_type = malloc(sizeof(char) * p->size_cells_out)) == NULL)
int *temp_type;
if ((temp_type = malloc(sizeof(int) * p->size_cells_out)) == NULL)
error("Failed to allocate outgoing cell type list.");
memcpy(temp_type, p->cells_out_type, sizeof(char) * p->nr_cells_out);
memcpy(temp_type, p->cells_out_type, sizeof(int) * p->nr_cells_out);
free(p->cells_out_type);
p->cells_out_type = temp_type;
}
......@@ -456,7 +473,7 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
if ((p->cells_in =
(struct cell **)malloc(sizeof(void *) * p->size_cells_in)) == NULL)
error("Failed to allocate cells_in buffer.");
if ((p->cells_in_type = (char *)malloc(sizeof(char) * p->size_cells_in)) ==
if ((p->cells_in_type = (int *)malloc(sizeof(int) * p->size_cells_in)) ==
NULL)
error("Failed to allocate cells_in_type buffer.");
}
......@@ -466,8 +483,8 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
if ((p->cells_out = (struct cell **)malloc(sizeof(void *) *
p->size_cells_out)) == NULL)
error("Failed to allocate cells_out buffer.");
if ((p->cells_out_type =
(char *)malloc(sizeof(char) * p->size_cells_out)) == NULL)
if ((p->cells_out_type = (int *)malloc(sizeof(int) * p->size_cells_out)) ==
NULL)
error("Failed to allocate cells_out_type buffer.");
}
p->nr_cells_out = 0;
......
......@@ -42,7 +42,7 @@
enum proxy_cell_type {
proxy_cell_type_none = 0,
proxy_cell_type_hydro = (1 << 0),
proxy_cell_type_gravity = (1 << 1)
proxy_cell_type_gravity = (1 << 1),
};
/* Data structure for the proxy. */
......@@ -53,13 +53,13 @@ struct proxy {
/* Incoming cells. */
struct cell **cells_in;
char *cells_in_type;
int *cells_in_type;
struct pcell *pcells_in;
int nr_cells_in, size_cells_in, size_pcells_in;
/* Outgoing cells. */
struct cell **cells_out;
char *cells_out_type;
int *cells_out_type;
struct pcell *pcells_out;
int nr_cells_out, size_cells_out, size_pcells_out;
......@@ -98,8 +98,8 @@ void proxy_gparts_load(struct proxy *p, const struct gpart *gparts, int N);
void proxy_sparts_load(struct proxy *p, const struct spart *sparts, int N);
void proxy_parts_exch1(struct proxy *p);
void proxy_parts_exch2(struct proxy *p);
void proxy_addcell_in(struct proxy *p, struct cell *c, char type);
void proxy_addcell_out(struct proxy *p, struct cell *c, char type);
void proxy_addcell_in(struct proxy *p, struct cell *c, int type);
void proxy_addcell_out(struct proxy *p, struct cell *c, int type);
void proxy_cells_exch1(struct proxy *p);
void proxy_cells_exch2(struct proxy *p);
......
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