8 const PS::F64ort pos_root_domain,
12 xlow = pos_root_domain.low_[cid];
15 xlow = 0.5 * (pos_sample[istart-1][cid] + pos_sample[istart][cid]);
18 xhigh = pos_root_domain.high_[cid];
21 xhigh = 0.5 * (pos_sample[iend][cid] + pos_sample[iend+1][cid]);
28 const PS::S32 n_proc = PS::Comm::getNumberOfProc();
29 assert(n_proc%4 == 0);
31 int n_loc_tmp = system.getNumberOfParticleLocal();
32 int * n_recv_tmp =
new int[n_proc];
33 int * n_recv_disp_tmp =
new int[n_proc+1];
35 for(
int i=0; i<n_loc_tmp; i++){
36 pos_loc_tmp[i].z = system[i].pos.z;
37 if(system[i].pos.x * system[i].pos.y > 0.0){
38 pos_loc_tmp[i].x = fabs(system[i].pos.x);
39 pos_loc_tmp[i].y = fabs(system[i].pos.y);
42 pos_loc_tmp[i].x = fabs(system[i].pos.y);
43 pos_loc_tmp[i].y = fabs(system[i].pos.x);
46 PS::Comm::allGather(&n_loc_tmp, 1, n_recv_tmp);
47 n_recv_disp_tmp[0] = 0;
48 for(
int i=0; i<n_proc; i++){
49 n_recv_disp_tmp[i+1] = n_recv_disp_tmp[i] + n_recv_tmp[i];
51 int n_glb_tmp = n_recv_disp_tmp[n_proc];
53 PS::Comm::allGatherV(pos_loc_tmp, n_loc_tmp, pos_glb_tmp, n_recv_tmp, n_recv_disp_tmp);
54 PS::S32 n_proc_quat = n_proc / 4;
57 while( n_proc_quat % nx_quat != 0) nx_quat++;
58 PS::S32 ny_quat = n_proc_quat / nx_quat;
66 dinfo.setNumberOfDomainMultiDimension(
nx,
ny,
nz);
67 PS::F64ort * pos_domain_tmp =
new PS::F64ort[n_proc];
68 if(PS::Comm::getRank() == 0){
72 PS::F64ort pos_root_domain_tmp = PS::F64ort(
PS::F64vec(0.0, 0.0, -PS::LARGE_FLOAT),
PS::F64vec(PS::LARGE_FLOAT, PS::LARGE_FLOAT, PS::LARGE_FLOAT));
74 std::sort(pos_glb_tmp, pos_glb_tmp+n_glb_tmp, PS::LessOPX());
76 std::sort(pos_glb_tmp, pos_glb_tmp+n_glb_tmp,
81 for(
PS::S32 i = 0; i < n_proc_quat; i++) {
83 if(i > 0) iend[i-1] = istart[i] - 1;
85 iend[n_proc_quat-1] = n_glb_tmp - 1;
86 for(
PS::S32 ix = 0; ix<nx_quat; ix++) {
93 pos_domain_tmp[offset+i].low_[0] = x0;
94 pos_domain_tmp[offset+i].high_[0] = x1;
95 pos_domain_tmp[offset+ny_quat+i].low_[0] = x0;
96 pos_domain_tmp[offset+ny_quat+i].high_[0] = x1;
98 offset = (nx_quat-1-ix)*
ny;
99 pos_domain_tmp[offset+i].low_[0] = -x1;
100 pos_domain_tmp[offset+i].high_[0] = -x0;
101 pos_domain_tmp[offset+ny_quat+i].low_[0] = -x1;
102 pos_domain_tmp[offset+ny_quat+i].high_[0] = -x0;
106 for(
PS::S32 ix = 0; ix<nx_quat; ix++) {
110 std::sort(pos_glb_tmp+istart[ix0], pos_glb_tmp+iend[ix1-1]+1, PS::LessOPY());
112 std::sort(pos_glb_tmp+istart[ix0], pos_glb_tmp+iend[ix1-1]+1,
116 PS::S32 n_tmp_y = iend[ix1-1] - istart[ix0] + 1;
117 for(
PS::S32 iy = 0; iy<ny_quat; iy++) {
121 CalculateBoundaryOfDomain(n_tmp_y, pos_glb_tmp+istart[ix0], 1, istart[iy0]-istart[ix0], iend[iy1-1]-istart[ix0], pos_root_domain_tmp, y0, y1);
123 PS::S32 offset = (nx_quat+ix)*
ny + ny_quat + iy;
124 pos_domain_tmp[offset+i].low_[1] = y0;
125 pos_domain_tmp[offset+i].high_[1] = y1;
126 offset = (nx_quat-ix-1)*
ny + ny_quat + iy;
127 pos_domain_tmp[offset+i].low_[1] = y0;
128 pos_domain_tmp[offset+i].high_[1] = y1;
129 offset = (nx_quat+ix)*
ny + ny_quat-iy-1;
130 pos_domain_tmp[offset+i].low_[1] = -y1;
131 pos_domain_tmp[offset+i].high_[1] = -y0;
132 offset = (nx_quat-ix-1)*
ny + ny_quat-iy-1;
133 pos_domain_tmp[offset+i].low_[1] = -y1;
134 pos_domain_tmp[offset+i].high_[1] = -y0;
141 PS::Comm::broadcast(pos_domain_tmp, n_proc);
142 for(
PS::S32 i=0; i<n_proc; i++){
143 pos_domain_tmp[i].low_.z = -PS::LARGE_FLOAT;
144 pos_domain_tmp[i].high_.z = PS::LARGE_FLOAT;
145 dinfo.setPosDomain(i, pos_domain_tmp[i]);
147 delete [] n_recv_tmp;
148 delete [] n_recv_disp_tmp;
149 delete [] pos_loc_tmp;
150 delete [] pos_glb_tmp;
151 delete [] pos_domain_tmp;