Skip to content

Commit 1983846

Browse files
committed
MPI not working yet. Need to think about logic
1 parent 661a3d8 commit 1983846

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/communication_mpi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ void reb_communication_mpi_distribute_particles(struct reb_simulation* const r){
154154
}
155155
}
156156

157+
// Distribute all particle to all other nodes, but do not add to local simulation.
158+
// Used for energy calculation (not ideal, should be improved).
157159
void reb_communication_mpi_distribute_particles_all_to_all(struct reb_simulation* const r){
158160
// Distribute the number of particles to be transferred.
159161
MPI_Allgather(&r->N, 1, MPI_INT, r->N_particles_recv, 1, MPI_INT, MPI_COMM_WORLD);

src/gravity.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,25 @@ void reb_calculate_and_apply_jerk(struct reb_simulation* r, const double v){
14291429
*/
14301430
static void reb_calculate_acceleration_for_particle_from_cell(const struct reb_simulation* const r, const int pt, const struct reb_treecell *node, const struct reb_vec6d gb);
14311431

1432+
// For debugging
1433+
void reb_tree_print(const struct reb_treecell *node, int indent){
1434+
for (int o=0; o<8; o++) {
1435+
if (node->oct[o] != NULL) {
1436+
for (int i=0;i<indent;i++){
1437+
printf(" ");
1438+
}
1439+
printf("%d",o);
1440+
reb_tree_print(node->oct[o], indent++);
1441+
}
1442+
}
1443+
if (node->pt >=0){
1444+
for (int i=0;i<indent;i++){
1445+
printf(" ");
1446+
}
1447+
printf("pt=%d\n",node->pt);
1448+
}
1449+
}
1450+
14321451
static void reb_calculate_acceleration_for_particle(const struct reb_simulation* const r, const int pt, const struct reb_vec6d gb) {
14331452
for(size_t i=0;i<r->N_root;i++){
14341453
struct reb_treecell* node = r->tree_root[i];

src/tree.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ void reb_tree_add_particle_to_tree(struct reb_simulation* const r, int pt){
7272
}
7373
int rootbox = reb_get_rootbox_for_particle(r, p);
7474
#ifdef MPI
75-
// Do not add particles that do not belong to this tree (avoid removing active particles)
76-
int N_root_per_node = r->N_root/r->mpi_num;
77-
int proc_id = rootbox/N_root_per_node;
78-
if (proc_id!=r->mpi_id) return;
75+
if (reb_communication_mpi_rootbox_is_local(r, rootbox)==0) return;
7976
#endif // MPI
8077
r->tree_root[rootbox] = reb_tree_add_particle_to_cell(r, r->tree_root[rootbox],pt,NULL,0);
8178
}

0 commit comments

Comments
 (0)