Skip to content

Commit 8562b87

Browse files
authored
Merge pull request #2967 from hjelmn/auto_bool
mca/base: add new base enumerator (auto_bool)
2 parents 5683e78 + 9e692ce commit 8562b87

File tree

3 files changed

+103
-4
lines changed

3 files changed

+103
-4
lines changed

opal/mca/base/mca_base_var_enum.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,96 @@ mca_base_var_enum_t mca_base_var_enum_bool = {
120120
.dump = mca_base_var_enum_bool_dump
121121
};
122122

123+
static int mca_base_var_enum_auto_bool_get_count (mca_base_var_enum_t *enumerator, int *count)
124+
{
125+
*count = 3;
126+
return OPAL_SUCCESS;
127+
}
128+
129+
static int mca_base_var_enum_auto_bool_get_value (mca_base_var_enum_t *self, int index,
130+
int *value, const char **string_value)
131+
{
132+
const int values[3] = {0, 1, -1};
133+
const char *strings[3] = {"false", "true", "auto"};
134+
135+
if (2 < index) {
136+
return OPAL_ERR_VALUE_OUT_OF_BOUNDS;
137+
}
138+
139+
*value = values[index];
140+
*string_value = strings[index];
141+
142+
return OPAL_SUCCESS;
143+
}
144+
145+
static int mca_base_var_enum_auto_bool_vfs (mca_base_var_enum_t *self, const char *string_value,
146+
int *value)
147+
{
148+
char *tmp;
149+
int v;
150+
151+
/* skip whitespace */
152+
string_value += strspn (string_value, " \t\n\v\f\r");
153+
154+
v = strtol (string_value, &tmp, 10);
155+
if (*tmp != '\0') {
156+
if (0 == strcasecmp (string_value, "true") || 0 == strcasecmp (string_value, "t") ||
157+
0 == strcasecmp (string_value, "enabled") || 0 == strcasecmp (string_value, "yes")) {
158+
v = 1;
159+
} else if (0 == strcasecmp (string_value, "false") || 0 == strcasecmp (string_value, "f") ||
160+
0 == strcasecmp (string_value, "disabled") || 0 == strcasecmp (string_value, "no")) {
161+
v = 0;
162+
} else if (0 == strcasecmp (string_value, "auto")) {
163+
v = -1;
164+
} else {
165+
return OPAL_ERR_VALUE_OUT_OF_BOUNDS;
166+
}
167+
}
168+
169+
if (v > 1) {
170+
*value = 1;
171+
} else if (v < -1) {
172+
*value = -1;
173+
} else {
174+
*value = v;
175+
}
176+
177+
return OPAL_SUCCESS;
178+
}
179+
180+
static int mca_base_var_enum_auto_bool_sfv (mca_base_var_enum_t *self, const int value,
181+
char **string_value)
182+
{
183+
if (string_value) {
184+
if (value < 0) {
185+
*string_value = strdup ("auto");
186+
} else if (value > 0) {
187+
*string_value = strdup ("true");
188+
} else {
189+
*string_value = strdup ("false");
190+
}
191+
}
192+
193+
return OPAL_SUCCESS;
194+
}
195+
196+
static int mca_base_var_enum_auto_bool_dump (mca_base_var_enum_t *self, char **out)
197+
{
198+
*out = strdup ("-1: auto, 0: f|false|disabled|no, 1: t|true|enabled|yes");
199+
return *out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE;
200+
}
201+
202+
mca_base_var_enum_t mca_base_var_enum_auto_bool = {
203+
.super = OPAL_OBJ_STATIC_INIT(opal_object_t),
204+
.enum_is_static = true,
205+
.enum_name = "auto_boolean",
206+
.get_count = mca_base_var_enum_auto_bool_get_count,
207+
.get_value = mca_base_var_enum_auto_bool_get_value,
208+
.value_from_string = mca_base_var_enum_auto_bool_vfs,
209+
.string_from_value = mca_base_var_enum_auto_bool_sfv,
210+
.dump = mca_base_var_enum_auto_bool_dump
211+
};
212+
123213
/* verbosity enumerator */
124214
static mca_base_var_enum_value_t verbose_values[] = {
125215
{MCA_BASE_VERBOSE_NONE, "none"},

opal/mca/base/mca_base_var_enum.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ OPAL_DECLSPEC int mca_base_var_enum_register(const char *project_name, const cha
242242
*/
243243
extern mca_base_var_enum_t mca_base_var_enum_bool;
244244

245+
/**
246+
* Extended boolean enumerator
247+
*
248+
* This enumerator maps:
249+
* positive integer, true, yes, enabled, t -> 1
250+
* 0, false, no, disabled, f -> 0
251+
* auto -> -1
252+
*/
253+
extern mca_base_var_enum_t mca_base_var_enum_auto_bool;
254+
245255
/**
246256
* Verbosity level enumerator
247257
*/

opal/runtime/opal_params.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ int opal_register_params(void)
248248
/* Leave pinned parameter */
249249
opal_leave_pinned = -1;
250250
ret = mca_base_var_register("ompi", "mpi", NULL, "leave_pinned",
251-
"Whether to use the \"leave pinned\" protocol or not. Enabling this setting can help bandwidth performance when repeatedly sending and receiving large messages with the same buffers over RDMA-based networks (0 = do not use \"leave pinned\" protocol, 1 = use \"leave pinned\" protocol, -1 = allow network to choose at runtime).",
252-
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
253-
OPAL_INFO_LVL_9,
254-
MCA_BASE_VAR_SCOPE_READONLY,
251+
"Whether to use the \"leave pinned\" protocol or not. Enabling this setting can help bandwidth performance when repeatedly sending and receiving large messages with the same buffers over RDMA-based networks (false = do not use \"leave pinned\" protocol, true = use \"leave pinned\" protocol, auto = allow network to choose at runtime).",
252+
MCA_BASE_VAR_TYPE_INT, &mca_base_var_enum_auto_bool, 0, 0,
253+
OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY,
255254
&opal_leave_pinned);
256255
mca_base_var_register_synonym(ret, "opal", "opal", NULL, "leave_pinned",
257256
MCA_BASE_VAR_SYN_FLAG_DEPRECATED);

0 commit comments

Comments
 (0)