|
9 | 9 |
|
10 | 10 | #include <module_base/formatter.h> |
11 | 11 | #include <module_parameter/parameter.h> |
| 12 | +#include <module_base/parallel_common.h> |
| 13 | +#include <module_base/parallel_reduce.h> |
12 | 14 |
|
13 | 15 | namespace KVectorUtils |
14 | 16 | { |
15 | | -void k_vec_d2c(K_Vectors& kv, const ModuleBase::Matrix3& reciprocal_vec) |
| 17 | +void kvec_d2c(K_Vectors& kv, const ModuleBase::Matrix3& reciprocal_vec) |
16 | 18 | { |
17 | 19 | // throw std::runtime_error("k_vec_d2c: This function is not implemented in the new codebase. Please use the new implementation."); |
18 | 20 | if (kv.kvec_d.size() != kv.kvec_c.size()) |
@@ -56,7 +58,7 @@ void k_vec_d2c(K_Vectors& kv, const ModuleBase::Matrix3& reciprocal_vec) |
56 | 58 | } |
57 | 59 | } |
58 | 60 | } |
59 | | -void k_vec_c2d(K_Vectors& kv, const ModuleBase::Matrix3& latvec) |
| 61 | +void kvec_c2d(K_Vectors& kv, const ModuleBase::Matrix3& latvec) |
60 | 62 | { |
61 | 63 | if (kv.kvec_d.size() != kv.kvec_c.size()) |
62 | 64 | { |
@@ -108,14 +110,14 @@ void set_both_kvec(K_Vectors& kv, const ModuleBase::Matrix3& G, const ModuleBase |
108 | 110 | // set cartesian k vectors. |
109 | 111 | if (!kv.kc_done && kv.kd_done) |
110 | 112 | { |
111 | | - KVectorUtils::k_vec_d2c(kv, G); |
| 113 | + KVectorUtils::kvec_d2c(kv, G); |
112 | 114 | kv.kc_done = true; |
113 | 115 | } |
114 | 116 |
|
115 | 117 | // set direct k vectors |
116 | 118 | else if (kv.kc_done && !kv.kd_done) |
117 | 119 | { |
118 | | - KVectorUtils::k_vec_c2d(kv, R); |
| 120 | + KVectorUtils::kvec_c2d(kv, R); |
119 | 121 | kv.kd_done = true; |
120 | 122 | } |
121 | 123 | std::string table; |
@@ -150,7 +152,7 @@ void set_after_vc(K_Vectors& kv, const int& nspin_in, const ModuleBase::Matrix3& |
150 | 152 | ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nspin", kv.get_nspin()); |
151 | 153 |
|
152 | 154 | // set cartesian k vectors. |
153 | | - KVectorUtils::k_vec_d2c(kv, reciprocal_vec); |
| 155 | + KVectorUtils::kvec_d2c(kv, reciprocal_vec); |
154 | 156 |
|
155 | 157 | std::string table; |
156 | 158 | table += "K-POINTS DIRECT COORDINATES\n"; |
@@ -213,4 +215,127 @@ void print_klists(const K_Vectors& kv, std::ofstream& ofs) |
213 | 215 | GlobalV::ofs_running << "\n" << table << std::endl; |
214 | 216 | return; |
215 | 217 | } |
| 218 | + |
| 219 | +#ifdef __MPI |
| 220 | +void kvec_mpi_k(K_Vectors& kv) |
| 221 | +{ |
| 222 | + ModuleBase::TITLE("KVectorUtils", "kvec_mpi_k"); |
| 223 | + |
| 224 | + Parallel_Common::bcast_bool(kv.kc_done); |
| 225 | + |
| 226 | + Parallel_Common::bcast_bool(kv.kd_done); |
| 227 | + |
| 228 | + Parallel_Common::bcast_int(kv.nspin); |
| 229 | + |
| 230 | + Parallel_Common::bcast_int(kv.nkstot); |
| 231 | + |
| 232 | + Parallel_Common::bcast_int(kv.nkstot_full); |
| 233 | + |
| 234 | + Parallel_Common::bcast_int(kv.nmp, 3); |
| 235 | + |
| 236 | + kv.kl_segids.resize(kv.nkstot); |
| 237 | + Parallel_Common::bcast_int(kv.kl_segids.data(), kv.nkstot); |
| 238 | + |
| 239 | + Parallel_Common::bcast_double(kv.koffset, 3); |
| 240 | + |
| 241 | + kv.nks = kv.para_k.nks_pool[GlobalV::MY_POOL]; |
| 242 | + |
| 243 | + GlobalV::ofs_running << std::endl; |
| 244 | + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "k-point number in this process", kv.nks); |
| 245 | + int nks_minimum = kv.nks; |
| 246 | + |
| 247 | + Parallel_Reduce::gather_min_int_all(GlobalV::NPROC, nks_minimum); |
| 248 | + |
| 249 | + if (nks_minimum == 0) |
| 250 | + { |
| 251 | + ModuleBase::WARNING_QUIT("K_Vectors::mpi_k()", " nks == 0, some processor have no k point!"); |
| 252 | + } |
| 253 | + else |
| 254 | + { |
| 255 | + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "minimum distributed K point number", nks_minimum); |
| 256 | + } |
| 257 | + |
| 258 | + std::vector<int> isk_aux(kv.nkstot); |
| 259 | + std::vector<double> wk_aux(kv.nkstot); |
| 260 | + std::vector<double> kvec_c_aux(kv.nkstot * 3); |
| 261 | + std::vector<double> kvec_d_aux(kv.nkstot * 3); |
| 262 | + |
| 263 | + // collect and process in rank 0 |
| 264 | + if (GlobalV::MY_RANK == 0) |
| 265 | + { |
| 266 | + for (int ik = 0; ik < kv.nkstot; ik++) |
| 267 | + { |
| 268 | + isk_aux[ik] = kv.isk[ik]; |
| 269 | + wk_aux[ik] = kv.wk[ik]; |
| 270 | + kvec_c_aux[3 * ik] = kv.kvec_c[ik].x; |
| 271 | + kvec_c_aux[3 * ik + 1] = kv.kvec_c[ik].y; |
| 272 | + kvec_c_aux[3 * ik + 2] = kv.kvec_c[ik].z; |
| 273 | + kvec_d_aux[3 * ik] = kv.kvec_d[ik].x; |
| 274 | + kvec_d_aux[3 * ik + 1] = kv.kvec_d[ik].y; |
| 275 | + kvec_d_aux[3 * ik + 2] = kv.kvec_d[ik].z; |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + // broadcast k point data to all processors |
| 280 | + Parallel_Common::bcast_int(isk_aux.data(), kv.nkstot); |
| 281 | + |
| 282 | + Parallel_Common::bcast_double(wk_aux.data(), kv.nkstot); |
| 283 | + Parallel_Common::bcast_double(kvec_c_aux.data(), kv.nkstot * 3); |
| 284 | + Parallel_Common::bcast_double(kvec_d_aux.data(), kv.nkstot * 3); |
| 285 | + |
| 286 | + // process k point data in each processor |
| 287 | + kv.renew(kv.nks * kv.nspin); |
| 288 | + |
| 289 | + // distribute |
| 290 | + int k_index = 0; |
| 291 | + |
| 292 | + for (int i = 0; i < kv.nks; i++) |
| 293 | + { |
| 294 | + // 3 is because each k point has three value:kx, ky, kz |
| 295 | + k_index = i + kv.para_k.startk_pool[GlobalV::MY_POOL]; |
| 296 | + kv.kvec_c[i].x = kvec_c_aux[k_index * 3]; |
| 297 | + kv.kvec_c[i].y = kvec_c_aux[k_index * 3 + 1]; |
| 298 | + kv.kvec_c[i].z = kvec_c_aux[k_index * 3 + 2]; |
| 299 | + kv.kvec_d[i].x = kvec_d_aux[k_index * 3]; |
| 300 | + kv.kvec_d[i].y = kvec_d_aux[k_index * 3 + 1]; |
| 301 | + kv.kvec_d[i].z = kvec_d_aux[k_index * 3 + 2]; |
| 302 | + kv.wk[i] = wk_aux[k_index]; |
| 303 | + kv.isk[i] = isk_aux[k_index]; |
| 304 | + } |
| 305 | + |
| 306 | +#ifdef __EXX |
| 307 | + if (ModuleSymmetry::Symmetry::symm_flag == 1) |
| 308 | + {//bcast kstars |
| 309 | + kv.kstars.resize(kv.nkstot); |
| 310 | + for (int ikibz = 0;ikibz < kv.nkstot;++ikibz) |
| 311 | + { |
| 312 | + int starsize = kv.kstars[ikibz].size(); |
| 313 | + Parallel_Common::bcast_int(starsize); |
| 314 | + GlobalV::ofs_running << "starsize: " << starsize << std::endl; |
| 315 | + auto ks = kv.kstars[ikibz].begin(); |
| 316 | + for (int ik = 0;ik < starsize;++ik) |
| 317 | + { |
| 318 | + int isym = 0; |
| 319 | + ModuleBase::Vector3<double> ks_vec(0, 0, 0); |
| 320 | + if (GlobalV::MY_RANK == 0) |
| 321 | + { |
| 322 | + isym = ks->first; |
| 323 | + ks_vec = ks->second; |
| 324 | + ++ks; |
| 325 | + } |
| 326 | + Parallel_Common::bcast_int(isym); |
| 327 | + Parallel_Common::bcast_double(ks_vec.x); |
| 328 | + Parallel_Common::bcast_double(ks_vec.y); |
| 329 | + Parallel_Common::bcast_double(ks_vec.z); |
| 330 | + GlobalV::ofs_running << "isym: " << isym << " ks_vec: " << ks_vec.x << " " << ks_vec.y << " " << ks_vec.z << std::endl; |
| 331 | + if (GlobalV::MY_RANK != 0) |
| 332 | + { |
| 333 | + kv.kstars[ikibz].insert(std::make_pair(isym, ks_vec)); |
| 334 | + } |
| 335 | + } |
| 336 | + } |
| 337 | + } |
| 338 | +#endif |
| 339 | +} // END SUBROUTINE |
| 340 | +#endif |
216 | 341 | } // namespace KVectorUtils |
0 commit comments