1#ifndef HILA_PARAM_INPUT_H
2#define HILA_PARAM_INPUT_H
9#include "plumbing/com_mpi.h"
56 std::ifstream inputfile;
57 bool is_initialized =
false;
62 std::string linebuffer;
67 std::vector<std::string> cmdline_p;
74 input(
const std::string &fname) {
96 bool open(
const std::string &fname,
bool use_cmdline =
true,
bool exit_on_error =
true);
128 returntype(
const std::string &str,
input *a) : label(str), parent(a) {}
133 template <
typename T, std::enable_if_t<(hila::is_complex_or_arithmetic<T>::value &&
134 !std::is_same<T,
char>::value) ||
135 std::is_same<T, std::
string>::value,
139 if (!parent->
get_value(val, label,
true))
144 template <
typename T,
int n>
147 if (!parent->
get_value(val, label,
true))
154 if (!parent->
get_value(val, label,
true))
159 template <typename T, std::enable_if_t<hila::is_complex_or_arithmetic<T>::value ||
160 std::is_same<T, std::string>::value,
162 operator std::vector<T>() {
164 if (!parent->
get_value(val, label,
true))
277 inline returntype get() {
278 return returntype(
"",
this);
305 template <
typename T>
306 bool get_value(T &val,
const std::string &label,
bool bcast =
true) {
308 bool no_error = handle_key(label);
312 if (!(get_token(tok) && is_value(tok, val))) {
315 hila::out <<
"Error: expecting a value of type '" << type_id<T>() <<
"' after '"
324 if constexpr (std::is_same<T, std::string>::value) {
336 template <
typename T>
339 bool no_error = handle_key(label);
346 (match_token(
"(") && get_token(tok) && is_value(tok, re) && match_token(
",") &&
347 get_token(tok) && is_value(tok, im) && match_token(
")"));
348 if (!no_error && speaking) {
349 hila::out <<
"Error: expecting complex value '(re,im)' after '" << label <<
"'\n";
361 template <
int n,
typename T>
364 bool no_error =
true;
367 no_error =
get_value(val[0], label,
false);
368 for (
int i = 1; i < n && no_error; i++) {
369 no_error =
get_value(val[i],
",",
false);
372 if (!no_error && speaking) {
373 hila::out <<
"Error: expecting " << n <<
" comma-separated " << type_id<T>()
374 <<
"s after '" << label <<
"'\n";
385 template <
int n = NDIM>
394 template <
typename T>
395 bool get_value(std::vector<T> &val,
const std::string &label,
bool bcast =
true) {
397 bool no_error =
true;
403 while (no_error && match_token(
",")) {
408 if (!no_error && speaking) {
409 hila::out <<
"Error: expecting a comma-separated list of " << type_id<T>()
410 <<
"s after '" << label <<
"'\n";
470 int get_item(
const std::string &label,
const std::vector<std::string> &items,
475 template <
typename T>
476 inline const char *type_id() {
480 bool peek_token(std::string &tok);
481 bool get_token(std::string &tok);
482 bool match_token(
const std::string &tok);
484 void scan_cmdline(
const std::string &key,
int &end_of_key);
486 bool scan_string(std::string &val);
488 template <typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
489 bool is_value(
const std::string &s, T &val) {
490 std::istringstream ss(s);
492 if (ss.fail() || ss.bad())
498 bool is_value(
const std::string &s, std::string &val);
500 bool contains_word_list(
const std::string &list,
int &end_of_key);
502 std::string remove_quotes(
const std::string &val);
504 void print_linebuf(
int eok);
507 bool handle_key(
const std::string &c);
509 bool remove_whitespace();
515inline const char *input::type_id<int>() {
519inline const char *input::type_id<long>() {
523inline const char *input::type_id<long long>() {
527inline const char *input::type_id<unsigned int>() {
528 return "unsigned int";
531inline const char *input::type_id<unsigned long>() {
532 return "unsigned long";
535inline const char *input::type_id<unsigned long long>() {
536 return "unsigned long long";
540inline const char *input::type_id<float>() {
544inline const char *input::type_id<double>() {
548inline const char *input::type_id<std::string>() {
552inline const char *input::type_id<Complex<float>>() {
553 return "complex value";
556inline const char *input::type_id<Complex<double>>() {
557 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