12#include "gadgetconfig.h"
20#include "../data/allvars.h"
21#include "../data/dtypes.h"
22#include "../data/mymalloc.h"
23#include "../domain/domain.h"
24#include "../fof/foftree.h"
25#include "../gravtree/gravtree.h"
27#include "../logs/logs.h"
28#include "../logs/timer.h"
29#include "../main/simulation.h"
30#include "../sort/peano.h"
31#include "../system/system.h"
32#include "../time_integration/driftfac.h"
33#include "../time_integration/timestep.h"
35template <
typename partset>
38 double numnodes = NumNodes, tot_numnodes;
39 MPI_Reduce(&numnodes, &tot_numnodes, 1, MPI_DOUBLE, MPI_SUM, 0, D->Communicator);
41 D->mpi_printf(
"FOFTREE: Ngb-tree construction done. took %g sec <numnodes>=%g NTopnodes=%d NTopleaves=%d\n", Buildtime,
42 tot_numnodes / D->NTask, D->NTopnodes, D->NTopleaves);
45template <
typename partset>
51template <
typename partset>
59 leafnode_data *glob_leaf_node_data, *loc_leaf_node_data;
61 glob_leaf_node_data = (leafnode_data *)
Mem.mymalloc(
"glob_leaf_node_data", D->NTopleaves *
sizeof(leafnode_data));
64 int *recvcounts = (
int *)
Mem.mymalloc(
"recvcounts",
sizeof(
int) * D->NTask);
65 int *recvoffset = (
int *)
Mem.mymalloc(
"recvoffset",
sizeof(
int) * D->NTask);
66 int *bytecounts = (
int *)
Mem.mymalloc(
"bytecounts",
sizeof(
int) * D->NTask);
67 int *byteoffset = (
int *)
Mem.mymalloc(
"byteoffset",
sizeof(
int) * D->NTask);
69 for(
int task = 0; task < D->NTask; task++)
72 for(
int n = 0; n < D->NTopleaves; n++)
73 recvcounts[D->TaskOfLeaf[n]]++;
75 for(
int task = 0; task < D->NTask; task++)
76 bytecounts[task] = recvcounts[task] *
sizeof(leafnode_data);
81 for(
int task = 1; task < D->NTask; task++)
83 recvoffset[task] = recvoffset[task - 1] + recvcounts[task - 1];
84 byteoffset[task] = byteoffset[task - 1] + bytecounts[task - 1];
87 loc_leaf_node_data = (leafnode_data *)
Mem.mymalloc(
"loc_leaf_node_data", recvcounts[D->ThisTask] *
sizeof(leafnode_data));
91 for(
int n = 0; n < D->NTopleaves; n++)
93 if(D->TaskOfLeaf[n] == D->ThisTask)
95 int no = NodeIndex[n];
98 leafnode_data *locp = &loc_leaf_node_data[idx];
100 for(
int k = 0; k < 3; k++)
110 myMPI_Allgatherv(loc_leaf_node_data, bytecounts[D->ThisTask], MPI_BYTE, glob_leaf_node_data, bytecounts, byteoffset, MPI_BYTE,
113 for(
int task = 0; task < D->NTask; task++)
114 recvcounts[task] = 0;
116 for(
int n = 0; n < D->NTopleaves; n++)
118 int task = D->TaskOfLeaf[n];
119 if(task != D->ThisTask)
121 int no = NodeIndex[n];
124 int idx = recvoffset[task] + recvcounts[task]++;
125 leafnode_data *globp = &glob_leaf_node_data[idx];
127 for(
int k = 0; k < 3; k++)
135 Mem.myfree(loc_leaf_node_data);
136 Mem.myfree(byteoffset);
137 Mem.myfree(bytecounts);
138 Mem.myfree(recvoffset);
139 Mem.myfree(recvcounts);
140 Mem.myfree(glob_leaf_node_data);
148template <
typename partset>
154 if(!(no >= MaxPart && no < MaxPart + MaxNodes))
164 if(p < MaxPart || p >= FirstNonTopLevelNode)
168 for(
int k = 0; k < 3; k++)
180 if(p >= MaxPart && p < MaxPart + MaxNodes)
182 int nextsib = get_nodep(p)->sibling;
184 update_node_recursive(p, nextsib, mode);
189 for(
int k = 0; k < 3; k++)
191 if(range_min[k] > Tp->P[p].IntPos[k])
192 range_min[k] = Tp->P[p].IntPos[k];
194 if(range_max[k] < Tp->P[p].IntPos[k])
195 range_max[k] = Tp->P[p].IntPos[k];
200 else if(p < MaxPart + MaxNodes)
204 for(
int k = 0; k < 3; k++)
215 else if(p < MaxPart + MaxNodes + D->NTopleaves)
220 p = Nextnode[p - MaxNodes];
227 p = Nextnode[p - MaxNodes];
232 for(
int k = 0; k < 3; k++)
240#include "../data/simparticles.h"
243#if defined(LIGHTCONE) && (defined(LIGHTCONE_PARTICLES_GROUPS) || defined(LIGHTCONE_IMAGE_COMP_HSML_VELDISP))
245#include "../data/lcparticles.h"
void exchange_topleafdata(void) override
void fill_in_export_points(fofpoint_data *exp_point, int i, int no) override
void update_node_recursive(int no, int sib, int mode) override
void report_log_message(void) override
int myMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcount, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
MyIntPosType range_max[3]
MyIntPosType range_min[3]
#define TREE_MODE_TOPLEVEL