Skip to content

Commit 6ba5a4b

Browse files
committed
update 055_PW_OW example, add the case of kpar
1 parent 36e7473 commit 6ba5a4b

File tree

10 files changed

+70
-64
lines changed

10 files changed

+70
-64
lines changed

source/module_cell/klist.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ void K_Vectors::cal_ik_global()
1717
{
1818
const int my_pool = this->para_k.my_pool;
1919
this->ik2iktot.resize(this->nks);
20+
2021
#ifdef __MPI
22+
23+
const int startk = this->para_k.startk_pool[my_pool];
24+
2125
if(this->nspin == 2)
2226
{
23-
for (int ik = 0; ik < this->nks / 2; ++ik)
27+
// wos: without spin
28+
const int nks_wos = this->nks/2;
29+
for (int ik = 0; ik < nks_wos; ++ik)
2430
{
25-
this->ik2iktot[ik] = this->para_k.startk_pool[my_pool] + ik;
26-
this->ik2iktot[ik + this->nks / 2] = this->nkstot / 2 + this->para_k.startk_pool[my_pool] + ik;
31+
this->ik2iktot[ik] = startk + ik;
32+
this->ik2iktot[ik+nks_wos] = this->nkstot/2 + startk + ik;
2733
}
2834
}
2935
else
3036
{
3137
for (int ik = 0; ik < this->nks; ++ik)
3238
{
33-
this->ik2iktot[ik] = this->para_k.startk_pool[my_pool] + ik;
39+
this->ik2iktot[ik] = startk + ik;
3440
}
3541
}
3642
#else
@@ -184,13 +190,6 @@ void K_Vectors::renew(const int& kpoint_number)
184190
wk.resize(kpoint_number);
185191
isk.resize(kpoint_number);
186192
ngk.resize(kpoint_number);
187-
188-
/*ModuleBase::Memory::record("KV::kvec_c",sizeof(double) * kpoint_number*3);
189-
ModuleBase::Memory::record("KV::kvec_d",sizeof(double) * kpoint_number*3);
190-
ModuleBase::Memory::record("KV::wk",sizeof(double) * kpoint_number*3);
191-
ModuleBase::Memory::record("KV::isk",sizeof(int) * kpoint_number*3);
192-
ModuleBase::Memory::record("KV::ngk",sizeof(int) * kpoint_number*3);*/
193-
194193
return;
195194
}
196195

@@ -287,12 +286,11 @@ bool K_Vectors::read_kpoints(const UnitCell& ucell,
287286
// input k-points are in 2pi/a units
288287
ModuleBase::GlobalFunc::READ_VALUE(ifk, nkstot);
289288

290-
this->k_nkstot = nkstot; // LiuXh add 20180619
289+
this->k_nkstot = nkstot;
291290

292-
// std::cout << " nkstot = " << nkstot << std::endl;
293291
ModuleBase::GlobalFunc::READ_VALUE(ifk, kword);
294292

295-
this->k_kword = kword; // LiuXh add 20180619
293+
this->k_kword = kword;
296294

297295
// mohan update 2021-02-22
298296
const int max_kpoints = 100000;
@@ -304,7 +302,7 @@ bool K_Vectors::read_kpoints(const UnitCell& ucell,
304302

305303
// 2.2 Select different methods and generate K-point grid
306304
int k_type = 0;
307-
if (nkstot == 0) // nkstot==0, use monkhorst_pack. add by dwan
305+
if (nkstot == 0) // nkstot==0, use monkhorst_pack.
308306
{
309307
if (kword == "Gamma") // MP(Gamma)
310308
{
@@ -402,7 +400,7 @@ bool K_Vectors::read_kpoints(const UnitCell& ucell,
402400

403401
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nkstot", nkstot);
404402
return true;
405-
} // END SUBROUTINE
403+
}
406404

407405
void K_Vectors::interpolate_k_between(std::ifstream& ifk, std::vector<ModuleBase::Vector3<double>>& kvec)
408406
{
@@ -533,10 +531,11 @@ void K_Vectors::update_use_ibz(const int& nkstot_ibz,
533531
const std::vector<ModuleBase::Vector3<double>>& kvec_d_ibz,
534532
const std::vector<double>& wk_ibz)
535533
{
536-
if (GlobalV::MY_RANK != 0) {
537-
return;
538-
}
539-
ModuleBase::TITLE("K_Vectors", "update_use_ibz");
534+
if (GlobalV::MY_RANK != 0)
535+
{
536+
return;
537+
}
538+
ModuleBase::TITLE("K_Vectors", "update_use_ibz");
540539
assert(nkstot_ibz > 0);
541540
assert(nkstot_ibz <= kvec_d_ibz.size());
542541
// update nkstot

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,15 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
711711
//------------------------------------------------------------------
712712
// 4) output wavefunctions in pw basis
713713
//------------------------------------------------------------------
714+
// comment out by mohan, 2025-05-17, this has been called in iter_finish()
715+
/*
714716
if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2)
715717
{
716718
ModuleIO::write_wfc_pw(PARAM.inp.out_wfc_pw,
717719
PARAM.globalv.global_out_dir,
718720
this->psi[0], this->kv, this->pw_wfc);
719721
}
722+
*/
720723

721724
//------------------------------------------------------------------
722725
// 5) calculate band-decomposed (partial) charge density in pw basis

source/module_esolver/pw_others.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "module_io/nscf_band.h"
77
#include "module_io/output_log.h"
88
#include "module_io/write_istate_info.h"
9-
#include "module_io/write_wfc_pw.h"
109

1110
#include <iostream>
1211

source/module_io/filename.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ std::string filename_output(
99
const std::string &directory,
1010
const std::string &property,
1111
const std::string &basis,
12-
const int ik,
12+
const int ik_local, // the ik index within each pool
1313
const std::vector<int> &ik2iktot,
1414
const int nspin,
1515
const int nkstot,
@@ -34,14 +34,15 @@ std::string filename_output(
3434
ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown basis");
3535
}
3636

37-
assert(ik>=0);
38-
assert(ik2iktot.size() == nkstot);
37+
assert(ik_local>=0);
38+
// mohan update 2025.05.07, if KPAR>1, "<" works
39+
assert(ik2iktot.size() <= nkstot);
3940
assert(nspin>0);
4041

4142
// spin index
4243
int is0 = -1;
4344
// ik0 is the k-point index, starting from 1
44-
int ik0 = ik2iktot[ik];
45+
int ik0 = ik2iktot[ik_local];
4546

4647
if(nspin == 1)
4748
{

source/module_io/filename.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ModuleIO
1111
* @param directory: directory of the file
1212
* @param property: wave function (wf), charge density (chg) or matrix (mat)
1313
* @param basis: nao or pw
14-
* @param ik: index of the k-point, and starting from 0.
14+
* @param ik_local: index of the k-points within each pool, and starting from 0.
1515
* @param ik2iktot: map from ik to iktot
1616
* @param nspin: number of spin channels, 1,2 or 4
1717
* @param nkstot: number of total k-points
@@ -25,7 +25,7 @@ std::string filename_output(
2525
const std::string &directory,
2626
const std::string &property,
2727
const std::string &basis,
28-
const int ik,
28+
const int ik_local,
2929
const std::vector<int> &ik2iktot,
3030
const int nspin,
3131
const int nkstot,

source/module_io/write_wfc_pw.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void ModuleIO::write_wfc_pw(
2222
const int nkstot = kv.get_nkstot();
2323
const int nks = kv.get_nks();
2424

25-
2625
assert(nkstot>0);
2726
assert(nks>0);
2827

@@ -33,31 +32,40 @@ void ModuleIO::write_wfc_pw(
3332
bool gamma_only = false; // need to modify later, mohan 2025-05-17
3433
int istep = -1; // need to modify later, mohan 2025-05-17
3534

36-
for (int ik = 0; ik < nkstot; ++ik)
37-
{
38-
std::string fn = filename_output(global_out_dir,"wf","pw",
39-
ik,kv.ik2iktot,PARAM.inp.nspin,nkstot,
40-
out_wfc_pw,out_app_flag,gamma_only,istep);
35+
for (int ip = 0; ip < GlobalV::KPAR; ip++)
36+
{
37+
if (GlobalV::MY_POOL != ip) continue;
38+
if (GlobalV::RANK_IN_POOL != 0) continue;
4139

42-
std::cout << " Write G-space wave functions into \""
43-
<< fn
44-
<< std::endl;
40+
for (int ik_local = 0; ik_local < kv.get_nks(); ik_local++)
41+
{
42+
std::string fn = filename_output(global_out_dir,"wf","pw",
43+
ik_local,kv.ik2iktot,PARAM.inp.nspin,nkstot,
44+
out_wfc_pw,out_app_flag,gamma_only,istep);
4545

46-
wfilename[ik] = fn;
47-
if (GlobalV::MY_RANK == 0)
48-
{
49-
if (out_wfc_pw == 1)
50-
{
51-
std::ofstream ofs(fn.c_str()); // clear all wavefunc files.
52-
ofs.close();
53-
}
54-
else if (out_wfc_pw == 2)
55-
{
56-
Binstream wfs(fn, "w");
57-
wfs.close();
58-
}
59-
}
60-
}
46+
std::string fn_out = fn;
47+
48+
GlobalV::ofs_running << " Write G-space wave functions into file "
49+
<< fn_out << std::endl;
50+
51+
const int ik_global = kv.ik2iktot[ik_local];
52+
53+
wfilename[ik_global] = fn;
54+
if (GlobalV::MY_RANK == 0)
55+
{
56+
if (out_wfc_pw == 1)
57+
{
58+
std::ofstream ofs(fn.c_str()); // clear all wavefunc files.
59+
ofs.close();
60+
}
61+
else if (out_wfc_pw == 2)
62+
{
63+
Binstream wfs(fn, "w");
64+
wfs.close();
65+
}
66+
}
67+
}
68+
}
6169

6270
#ifdef __MPI
6371
MPI_Barrier(MPI_COMM_WORLD);

tests/01_PW/055_PW_OW/INPUT

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ INPUT_PARAMETERS
33
suffix autotest
44
calculation scf
55
nspin 2
6+
kpar 2
67

78
nbands 6
89
symmetry 1
9-
pseudo_dir ../../PP_ORB
10+
pseudo_dir ../../PP_ORB
1011

1112
#Parameters (2.Iteration)
1213
ecutwfc 20
@@ -17,3 +18,4 @@ scf_nmax 100
1718
basis_type pw
1819
out_wfc_pw 1
1920
pw_seed 1
21+
#out_alllog 1

tests/01_PW/055_PW_OW/KPT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
K_POINTS
22
0
33
Gamma
4-
1 2 1 0 0 0
4+
2 1 3 0 0 0

tests/01_PW/055_PW_OW/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
output of electronic wave function with 2 k-points and spin-polarized
1+
output of electronic wave function with multiple k-points and spin-polarized, enable kpar

tests/01_PW/055_PW_OW/result.ref

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
etotref -204.5154646827027
2-
etotperatomref -102.2577323414
3-
Max_wfc_1 0.9073
4-
Max_wfc_2 0.4681
5-
Max_wfc_3 0.3774
6-
Max_wfc_4 0.3421
7-
Max_wfc_5 0.4143
8-
Max_wfc_6 0.3726
1+
etotref -210.4888527399332
2+
etotperatomref -105.2444263700
93
pointgroupref T_d
104
spacegroupref O_h
11-
nksibzref 2
12-
totaltimeref 0.57
5+
nksibzref 4
6+
totaltimeref 0.65

0 commit comments

Comments
 (0)