8#include "plumbing/com_mpi.h"
55 std::ifstream inputfile;
56 bool is_initialized =
false;
60 std::string linebuffer;
70 input(
const std::string &fname) {
92 bool open(
const std::string &fname,
bool use_cmdline =
true,
bool exit_on_error =
true);
124 returntype(
const std::string &str,
input *a) : label(str), parent(a) {}
129 template <
typename T, std::enable_if_t<(hila::is_complex_or_arithmetic<T>::value &&
130 !std::is_same<T,
char>::value) ||
131 std::is_same<T, std::
string>::value,
135 if (!parent->
get_value(val, label,
true))
140 template <
typename T,
int n>
143 if (!parent->
get_value(val, label,
true))
150 if (!parent->
get_value(val, label,
true))
155 template <typename T, std::enable_if_t<hila::is_complex_or_arithmetic<T>::value ||
156 std::is_same<T, std::string>::value,
158 operator std::vector<T>() {
160 if (!parent->
get_value(val, label,
true))
273 inline returntype get() {
274 return returntype(
"",
this);
301 template <
typename T>
302 bool get_value(T &val,
const std::string &label,
bool bcast =
true) {
304 bool no_error = handle_key(label);
308 if (!(get_token(tok) && is_value(tok, val))) {
311 hila::out <<
"Error: expecting a value of type '" << type_id<T>() <<
"' after '"
320 if constexpr (std::is_same<T, std::string>::value) {
332 template <
typename T>
335 bool no_error = handle_key(label);
342 (match_token(
"(") && get_token(tok) && is_value(tok, re) && match_token(
",") &&
343 get_token(tok) && is_value(tok, im) && match_token(
")"));
344 if (!no_error && speaking) {
345 hila::out <<
"Error: expecting complex value '(re,im)' after '" << label <<
"'\n";
357 template <
int n,
typename T>
360 bool no_error =
true;
363 no_error =
get_value(val[0], label,
false);
364 for (
int i = 1; i < n && no_error; i++) {
365 no_error =
get_value(val[i],
",",
false);
368 if (!no_error && speaking) {
369 hila::out <<
"Error: expecting " << n <<
" comma-separated " << type_id<T>()
370 <<
"s after '" << label <<
"'\n";
381 template <
int n = NDIM>
390 template <
typename T>
391 bool get_value(std::vector<T> &val,
const std::string &label,
bool bcast =
true) {
393 bool no_error =
true;
399 while (no_error && match_token(
",")) {
404 if (!no_error && speaking) {
405 hila::out <<
"Error: expecting a comma-separated list of " << type_id<T>()
406 <<
"s after '" << label <<
"'\n";
466 int get_item(
const std::string &label,
const std::vector<std::string> &items,
471 template <
typename T>
472 inline const char *type_id() {
476 bool peek_token(std::string &tok);
477 bool get_token(std::string &tok);
478 bool match_token(
const std::string &tok);
480 bool scan_string(std::string &val);
482 template <typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
483 bool is_value(
const std::string &s, T &val) {
484 std::istringstream ss(s);
486 if (ss.fail() || ss.bad())
492 bool is_value(
const std::string &s, std::string &val);
494 bool contains_word_list(
const std::string &list,
int &end_of_key);
496 std::string remove_quotes(
const std::string &val);
498 void print_linebuf(
int eok);
501 bool handle_key(
const std::string &c);
503 bool remove_whitespace();
509inline const char *input::type_id<int>() {
513inline const char *input::type_id<long>() {
517inline const char *input::type_id<long long>() {
521inline const char *input::type_id<unsigned int>() {
522 return "unsigned int";
525inline const char *input::type_id<unsigned long>() {
526 return "unsigned long";
529inline const char *input::type_id<unsigned long long>() {
530 return "unsigned long long";
534inline const char *input::type_id<float>() {
538inline const char *input::type_id<double>() {
542inline const char *input::type_id<std::string>() {
546inline const char *input::type_id<Complex<float>>() {
547 return "complex value";
550inline const char *input::type_id<Complex<double>>() {
551 return "complex value";
Matrix class which defines matrix operations.
CoordinateVector_t< int > CoordinateVector
CoordinateVector alias for CoordinateVector_t.
This file defines all includes for HILA.
Implement hila::swap for gauge fields.
int myrank()
rank of this node
std::ostream out
this is our default output file stream
T broadcast(T &var, int rank=0)
Broadcast the value of var to all MPI ranks from rank (default=0).
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...
void broadcast2(T &t, U &u, int rank=0)
and broadcast with two values