17 char const *
name = NULL;
18 for (
size_t i = 0; (i < count) && (
name == NULL); ++i)
28 for (
size_t i = 0; (i < count) && (
type == INT_MAX); ++i)
34 return (
string != NULL) ?
xstrdup(
string) : NULL;
56 YAC_ASSERT(
name != NULL,
"Environment variable name must not be NULL");
57 YAC_ASSERT((default_value == 0) || (default_value == 1),
58 "Default value must be 0(false) or 1(true)");
59 YAC_ASSERT(comm != MPI_COMM_NULL,
"Communicator must not be MPI_COMM_NULL");
61 int value = default_value;
69 char * str_value = getenv(
name);
71 if ((str_value != NULL) && (str_value[0] !=
'\0')) {
78 "\"%s\" is not a valid boolean value for environment variable %s",
90 const char *
name,
int default_value,
int threshold, MPI_Comm comm) {
92 YAC_ASSERT(
name != NULL,
"Environment variable name must not be NULL");
93 YAC_ASSERT(comm != MPI_COMM_NULL,
"Communicator must not be MPI_COMM_NULL");
95 int value = default_value;
103 char * str_value = getenv(
name);
105 if ((str_value != NULL) && (str_value[0] !=
'\0')) {
108 char * end_ptr = NULL;
109 long value_long = strtol(str_value, &end_ptr, 10);
112 (value_long >= INT_MIN) && (value_long <= INT_MAX),
113 "\"%s\" is not a valid integer value for environment variable %s",
116 value = ((int)value_long < threshold) ? default_value : (int)value_long;
126 const char *
name,
const char * default_value, MPI_Comm comm) {
128 YAC_ASSERT(
name != NULL,
"Environment variable name must not be NULL");
129 YAC_ASSERT(comm != MPI_COMM_NULL,
"Communicator must not be MPI_COMM_NULL");
134 size_t str_value_len = SIZE_MAX;
135 char * str_value = NULL;
142 if ((str_value != NULL) && (str_value[0] !=
'\0')) {
143 str_value_len = strlen(str_value);
151 if (str_value_len == SIZE_MAX) {
157 if (rank != 0) str_value =
xmalloc(str_value_len + 1);
161 MPI_Bcast(str_value, str_value_len + 1, MPI_CHAR, 0, comm), comm);
#define YAC_ASSERT(exp, msg)
int yac_name_type_pair_get_type(struct yac_name_type_pair const *pairs, size_t count, char const *name)
#define DEF_NAME_TYPE_PAIR(NAME, TYPE)
char const * yac_name_type_pair_get_name(struct yac_name_type_pair const *pairs, size_t count, int type)
#define DEF_NAME_TYPE_PAIRS(NAME,...)
static const struct yac_name_type_pair bool_table[]
const char * name
String name (e.g., "true")
int yac_getenv_bool(const char *name, int default_value, MPI_Comm comm)
int yac_getenv_int(const char *name, int default_value, int threshold, MPI_Comm comm)
char * yac_string_dup(char const *string)
char * yac_getenv_str(const char *name, const char *default_value, MPI_Comm comm)
#define YAC_ASSERT_F(exp, format,...)
#define yac_mpi_call(call, comm)