11#define strvalue item.str_values[0]
12#define intvalue std::stoi(item.str_values[0])
13#define doublevalue std::stod(item.str_values[0])
14#define boolvalue assume_as_boolean(item.str_values[0])
17#define add_double_bcast(PARAMETER) \
19 bcastfuncs.push_back([](Parameter& para) { Parallel_Common::bcast_double(para.PARAMETER); }); \
21#define add_int_bcast(PARAMETER) \
23 bcastfuncs.push_back([](Parameter& para) { Parallel_Common::bcast_int(para.PARAMETER); }); \
25#define add_bool_bcast(PARAMETER) \
27 bcastfuncs.push_back([](Parameter& para) { Parallel_Common::bcast_bool(para.PARAMETER); }); \
29#define add_string_bcast(PARAMETER) \
31 bcastfuncs.push_back([](Parameter& para) { Parallel_Common::bcast_string(para.PARAMETER); }); \
33#define add_doublevec_bcast(PARAMETER, N, FILL) \
35 bcastfuncs.push_back([](Parameter& para) { \
37 Parallel_Common::bcast_int(_vec_size); \
38 if (para.PARAMETER.size() != _vec_size) \
39 para.PARAMETER.resize(_vec_size, FILL); \
40 Parallel_Common::bcast_double(para.PARAMETER.data(), _vec_size); \
43#define add_intvec_bcast(PARAMETER, N, FILL) \
45 bcastfuncs.push_back([](Parameter& para) { \
47 Parallel_Common::bcast_int(_vec_size); \
48 if (para.PARAMETER.size() != _vec_size) \
49 para.PARAMETER.resize(_vec_size, FILL); \
50 Parallel_Common::bcast_int(para.PARAMETER.data(), _vec_size); \
53#define add_stringvec_bcast(PARAMETER, N, FILL) \
55 bcastfuncs.push_back([](Parameter& para) { \
57 Parallel_Common::bcast_int(_vec_size); \
58 if (para.PARAMETER.size() != _vec_size) \
59 para.PARAMETER.resize(_vec_size, FILL); \
60 Parallel_Common::bcast_string(para.PARAMETER.data(), _vec_size); \
65#define add_double_bcast(PARAMETER)
66#define add_int_bcast(PARAMETER)
67#define add_bool_bcast(PARAMETER)
68#define add_string_bcast(PARAMETER)
69#define add_doublevec_bcast(PARAMETER, N, FILL) \
71 bcastfuncs.push_back([](Parameter& para) { \
72 if (para.PARAMETER.size() != N) \
73 para.PARAMETER.resize(N, FILL); \
77#define add_intvec_bcast(PARAMETER, N, FILL) add_doublevec_bcast(PARAMETER, N, FILL)
78#define add_stringvec_bcast(PARAMETER, N, FILL) add_doublevec_bcast(PARAMETER, N, FILL)
82#define sync_string(PARAMETER) \
84 item.domain.bind(AvailabilityValueKind::String, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
85 item.get_final_value = [](Input_Item& item, const Parameter& para) { item.final_value << para.PARAMETER; }; \
86 add_string_bcast(PARAMETER); \
88#define sync_int(PARAMETER) \
90 item.domain.bind(AvailabilityValueKind::Integer, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
91 item.get_final_value = [](Input_Item& item, const Parameter& para) { item.final_value << para.PARAMETER; }; \
92 add_int_bcast(PARAMETER); \
94#define sync_double(PARAMETER) \
96 item.domain.bind(AvailabilityValueKind::Real, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
97 item.get_final_value = [](Input_Item& item, const Parameter& para) { item.final_value << para.PARAMETER; }; \
98 add_double_bcast(PARAMETER); \
100#define sync_bool(PARAMETER) \
102 item.domain.bind(AvailabilityValueKind::Boolean, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
103 item.get_final_value = [](Input_Item& item, const Parameter& para) { item.final_value << para.PARAMETER; }; \
104 add_bool_bcast(PARAMETER); \
106#define sync_doublevec(PARAMETER, N, FILL) \
108 item.domain.bind(AvailabilityValueKind::RealVector, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
109 item.get_final_value = [](Input_Item& item, const Parameter& para) { \
110 for (int i = 0; i < N; i++) \
112 item.final_value << para.PARAMETER[i] << " "; \
115 add_doublevec_bcast(PARAMETER, N, FILL); \
117#define sync_intvec(PARAMETER, N, FILL) \
119 item.domain.bind(AvailabilityValueKind::IntegerVector, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
120 item.get_final_value = [](Input_Item& item, const Parameter& para) { \
121 for (int i = 0; i < N; i++) \
123 item.final_value << para.PARAMETER[i] << " "; \
126 add_intvec_bcast(PARAMETER, N, FILL); \
128#define sync_stringvec(PARAMETER, N, FILL) \
130 item.domain.bind(AvailabilityValueKind::StringVector, [](const Parameter& para) { return InputValue(para.PARAMETER); }); \
131 item.get_final_value = [](Input_Item& item, const Parameter& para) { \
132 for (int i = 0; i < N; i++) \
134 item.final_value << para.PARAMETER[i] << " "; \
137 add_stringvec_bcast(PARAMETER, N, FILL); \
140#define read_sync_string(PARAMETER) \
142 item.domain.scalar(); \
143 item.read_value = [](const Input_Item& item, Parameter& para) { para.PARAMETER = strvalue; }; \
144 sync_string(PARAMETER); \
146#define read_sync_int(PARAMETER) \
148 item.domain.scalar(); \
149 item.read_value = [](const Input_Item& item, Parameter& para) { para.PARAMETER = intvalue; }; \
150 sync_int(PARAMETER); \
152#define read_sync_double(PARAMETER) \
154 item.domain.scalar(); \
155 item.read_value = [](const Input_Item& item, Parameter& para) { para.PARAMETER = doublevalue; }; \
156 sync_double(PARAMETER); \
158#define read_sync_bool(PARAMETER) \
160 item.domain.scalar(); \
161 item.read_value = [](const Input_Item& item, Parameter& para) { para.PARAMETER = boolvalue; }; \
162 sync_bool(PARAMETER); \
178 if (expressions.empty())
182 else if (expressions[0].empty())
187 for (
const std::string& expr: expressions)
189 size_t first_star_pos = expr.find(
'*');
190 size_t second_star_pos = expr.rfind(
'*');
194 if (first_star_pos == std::string::npos)
196 std::istringstream value_stream(expr);
198 if (!(value_stream >> T_value) || !value_stream.eof())
200 throw std::runtime_error(
"Invalid expression value: " + expr);
202 result.push_back(T_value);
206 else if (first_star_pos == second_star_pos)
208 std::string int_part = expr.substr(0, first_star_pos);
209 std::string T_part = expr.substr(first_star_pos + 1);
211 std::istringstream count_stream(int_part);
213 if (!(count_stream >> num) || !count_stream.eof() || num < 0)
215 throw std::runtime_error(
"Invalid expression count: " + int_part);
217 std::istringstream value_stream(T_part);
219 if (!(value_stream >> T_value) || !value_stream.eof())
221 throw std::runtime_error(
"Invalid expression value: " + T_part);
223 for (
int i = 0; i < num; ++i)
225 result.push_back(T_value);
232 throw std::runtime_error(
"Invalid expression: " + expr +
" - More than one '*' found.");
240 if (vec.size() != size)
242 vec.resize(size, default_value);
260 std::string lower = esolver_type;
261 std::transform(lower.begin(), lower.end(), lower.begin(),
262 [](
unsigned char c) { return std::tolower(c); });
263 return !(lower ==
"dp" || lower ==
"nep");
277 return (basis_type ==
"lcao") ? kpar_lcao : kpar;
291 const std::string& basis_type,
295 const std::string& esolver_type)
306 if (kpar_eff <= 0 || bndpar <= 0)
310 return nproc == kpar_eff * bndpar;
#define T
Definition exp.cpp:237
Internal helpers shared by the R-space sparse text writers. Declared here (instead of duplicated in e...
Definition csr_reader.cpp:8
bool dsp_kpar_layout_valid(const int nproc, const std::string &basis_type, const int kpar, const int kpar_lcao, const int bndpar, const std::string &esolver_type)
Check whether a k-point/band parallel layout satisfies the DSP vendor library constraint.
Definition read_input_tool.h:290
bool dsp_layout_check_needed(const std::string &esolver_type)
Whether the DSP kpar/bndpar layout constraint applies.
Definition read_input_tool.h:258
int dsp_effective_kpar(const std::string &basis_type, const int kpar, const int kpar_lcao)
The k-point pool count actually consumed by the current basis.
Definition read_input_tool.h:273