Skip to content

Commit 89038b0

Browse files
committed
fix bug in read_input
1 parent c725001 commit 89038b0

File tree

2 files changed

+71
-68
lines changed

2 files changed

+71
-68
lines changed

source/module_io/read_input.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,22 @@ void ReadInput::read_parameters(Parameter& param, const std::string& filename_in
113113
// 1. only rank 0 read the input file
114114
if (this->rank == 0)
115115
{
116-
// 1. read the input file
117116
// We can also easily add other input file formats here
118117
this->read_txt_input(param, filename_in);
118+
}
119119

120-
// 2. check the value of the parameters
120+
// 2. check the number of atom types from STRU file
121+
// set the global directories
122+
this->set_global_dir(param.inp, param.sys);
123+
if (this->check_ntype_flag && this->rank == 0)
124+
{
125+
check_ntype(param.globalv.global_in_stru, param.input.ntype);
126+
}
127+
128+
// 3. check the value of the parameters
129+
// It must be after the check_ntype, because some parameters need to checked according to ntype
130+
if (this->rank == 0)
131+
{
121132
for (auto& input_item: this->input_lists)
122133
{
123134
Input_Item* checkvalue_item = &(input_item.second);
@@ -128,14 +139,6 @@ void ReadInput::read_parameters(Parameter& param, const std::string& filename_in
128139
}
129140
}
130141

131-
// 3. check the number of atom types from STRU file
132-
// set the global directories
133-
this->set_global_dir(param.inp, param.sys);
134-
if (this->check_ntype_flag && this->rank == 0)
135-
{
136-
check_ntype(param.globalv.global_in_stru, param.input.ntype);
137-
}
138-
139142
// 4. broadcast input parameters
140143
// It must be after the check_ntype, because some parameters need to be filled due to ntype
141144
for (auto& bcastfunc: this->bcastfuncs)
@@ -146,7 +149,7 @@ void ReadInput::read_parameters(Parameter& param, const std::string& filename_in
146149
// 5. set the globalv parameters, some parameters in different processes are different. e.g. rank
147150
this->set_globalv(param.inp, param.sys);
148151

149-
// 6. check kpar, it must be after bcastfunc and kpar and bndpar are synchronized
152+
// 6. check kpar, it must be after bcastfunc, and kpar and bndpar are synchronized
150153
if (param.inp.device == "gpu" && param.inp.basis_type == "pw")
151154
{
152155
param.input.kpar = base_device::information::get_device_kpar(param.inp.kpar, param.inp.bndpar);

source/module_io/read_set_globalv.cpp

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,63 @@
55
#include "read_input_tool.h"
66
namespace ModuleIO
77
{
8+
/// @note Here para.inp has been synchronized of all ranks.
9+
/// All para.inp have the same value.
10+
void ReadInput::set_globalv(const Input_para& inp, System_para& sys)
11+
{
12+
/// caculate the gamma_only_pw and gamma_only_local
13+
if (inp.gamma_only)
14+
{
15+
sys.gamma_only_local = true;
16+
}
17+
if (sys.gamma_only_local)
18+
{
19+
if (inp.esolver_type == "tddft")
20+
{
21+
GlobalV::ofs_running << " WARNING : gamma_only is not applicable for tddft" << std::endl;
22+
sys.gamma_only_local = false;
23+
}
24+
}
25+
/// set deepks_setorb
26+
if (inp.deepks_scf || inp.deepks_out_labels)
27+
{
28+
sys.deepks_setorb = true;
29+
}
30+
/// set the noncolin and lspinorb from nspin
31+
switch (inp.nspin)
32+
{
33+
case 4:
34+
if (inp.noncolin)
35+
{
36+
sys.domag = true;
37+
sys.domag_z = false;
38+
}
39+
else
40+
{
41+
sys.domag = false;
42+
sys.domag_z = true;
43+
}
44+
sys.npol = 2;
45+
break;
46+
case 2:
47+
case 1:
48+
sys.domag = false;
49+
sys.domag_z = false;
50+
sys.npol = 1;
51+
default:
52+
break;
53+
}
54+
sys.nqx = static_cast<int>((sqrt(inp.ecutwfc) / sys.dq + 4.0) * inp.cell_factor);
55+
sys.nqxq = static_cast<int>((sqrt(inp.ecutrho) / sys.dq + 4.0) * inp.cell_factor);
56+
/// set ncx,ncy,ncz
57+
sys.ncx = inp.nx;
58+
sys.ncy = inp.ny;
59+
sys.ncz = inp.nz;
60+
#ifdef __MPI
61+
Parallel_Common::bcast_bool(sys.double_grid);
62+
#endif
63+
}
64+
865
/// @note Here para.inp has been synchronized of all ranks.
966
/// Only para.inp in rank 0 is right.
1067
/// So we need to broadcast the results to all ranks.
@@ -69,61 +126,4 @@ void ReadInput::set_global_dir(const Input_para& inp, System_para& sys)
69126
Parallel_Common::bcast_string(sys.global_in_stru);
70127
#endif
71128
}
72-
73-
/// @note Here para.inp has been synchronized of all ranks.
74-
/// All para.inp have the same value.
75-
void ReadInput::set_globalv(const Input_para& inp, System_para& sys)
76-
{
77-
/// caculate the gamma_only_pw and gamma_only_local
78-
if (inp.gamma_only)
79-
{
80-
sys.gamma_only_local = true;
81-
}
82-
if (sys.gamma_only_local)
83-
{
84-
if (inp.esolver_type == "tddft")
85-
{
86-
GlobalV::ofs_running << " WARNING : gamma_only is not applicable for tddft" << std::endl;
87-
sys.gamma_only_local = false;
88-
}
89-
}
90-
/// set deepks_setorb
91-
if (inp.deepks_scf || inp.deepks_out_labels)
92-
{
93-
sys.deepks_setorb = true;
94-
}
95-
/// set the noncolin and lspinorb from nspin
96-
switch (inp.nspin)
97-
{
98-
case 4:
99-
if (inp.noncolin)
100-
{
101-
sys.domag = true;
102-
sys.domag_z = false;
103-
}
104-
else
105-
{
106-
sys.domag = false;
107-
sys.domag_z = true;
108-
}
109-
sys.npol = 2;
110-
break;
111-
case 2:
112-
case 1:
113-
sys.domag = false;
114-
sys.domag_z = false;
115-
sys.npol = 1;
116-
default:
117-
break;
118-
}
119-
sys.nqx = static_cast<int>((sqrt(inp.ecutwfc) / sys.dq + 4.0) * inp.cell_factor);
120-
sys.nqxq = static_cast<int>((sqrt(inp.ecutrho) / sys.dq + 4.0) * inp.cell_factor);
121-
/// set ncx,ncy,ncz
122-
sys.ncx = inp.nx;
123-
sys.ncy = inp.ny;
124-
sys.ncz = inp.nz;
125-
#ifdef __MPI
126-
Parallel_Common::bcast_bool(sys.double_grid);
127-
#endif
128-
}
129129
} // namespace ModuleIO

0 commit comments

Comments
 (0)