Skip to content

Commit 8c89e3c

Browse files
authored
Merge pull request #8313 from jjhursey/prot-enum
Update hook component to use enum MCA parameter
2 parents 8115bd2 + ed0697f commit 8c89e3c

File tree

1 file changed

+52
-37
lines changed

1 file changed

+52
-37
lines changed

ompi/mca/hook/comm_method/hook_comm_method_component.c

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,29 @@ const ompi_hook_base_component_1_0_0_t mca_hook_comm_method_component = {
6666
.hookm_mpi_finalize_bottom = NULL,
6767
};
6868

69+
enum mca_hook_comm_method_mode_flags_t {
70+
/* Display on MPI_INIT */
71+
OMPI_HOOK_COMM_METHOD_INIT = 0x01,
72+
/* Display on MPI_FINALIZE */
73+
OMPI_HOOK_COMM_METHOD_FINALIZE = 0x02,
74+
};
75+
6976
int mca_hook_comm_method_verbose = 0;
7077
int mca_hook_comm_method_output = -1;
7178
bool mca_hook_comm_method_enable_mpi_init = false;
7279
bool mca_hook_comm_method_enable_mpi_finalize = false;
80+
uint32_t mca_hook_comm_method_enabled_flags = 0x00;
7381
int mca_hook_comm_method_max = 12;
7482
int mca_hook_comm_method_brief = 0;
7583
char *mca_hook_comm_method_fakefile = NULL;
7684

85+
static mca_base_var_enum_value_flag_t mca_hook_comm_method_modes[] = {
86+
{.flag = OMPI_HOOK_COMM_METHOD_INIT, .string = "mpi_init"},
87+
{.flag = OMPI_HOOK_COMM_METHOD_FINALIZE, .string = "mpi_finalize"},
88+
{0, NULL, 0}
89+
};
90+
91+
7792
static int ompi_hook_comm_method_component_open(void)
7893
{
7994
// Nothing to do
@@ -88,6 +103,8 @@ static int ompi_hook_comm_method_component_close(void)
88103

89104
static int ompi_hook_comm_method_component_register(void)
90105
{
106+
int ret;
107+
mca_base_var_enum_flag_t *mca_hook_comm_method_flags = NULL;
91108

92109
/*
93110
* Component verbosity level
@@ -111,63 +128,61 @@ static int ompi_hook_comm_method_component_register(void)
111128
opal_output_set_verbosity(mca_hook_comm_method_output, mca_hook_comm_method_verbose);
112129

113130
/*
114-
* If the component is active for mpi_init / mpi_finalize
131+
* If the component is active for mpi_init / mpi_finalize via the MCA
132+
* option: ompi_display_comm
133+
* We created both a component level version of this parameter: hook_comm_method_display
134+
* along with a OMPI project level version (ompi_display_comm) for ease of
135+
* use to enable this feature. The user can fine tune the behavior of this
136+
* feature using the additional component level MCA options.
115137
*/
116138
mca_hook_comm_method_enable_mpi_init = false;
117-
(void) mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "enable_mpi_init",
118-
"Enable comm_method behavior on mpi_init",
119-
MCA_BASE_VAR_TYPE_BOOL, NULL,
120-
0, 0,
121-
OPAL_INFO_LVL_3,
122-
MCA_BASE_VAR_SCOPE_READONLY,
123-
&mca_hook_comm_method_enable_mpi_init);
124-
125139
mca_hook_comm_method_enable_mpi_finalize = false;
126-
(void) mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "enable_mpi_finalize",
127-
"Enable comm_method behavior on mpi_finalize",
128-
MCA_BASE_VAR_TYPE_BOOL, NULL,
129-
0, 0,
130-
OPAL_INFO_LVL_3,
131-
MCA_BASE_VAR_SCOPE_READONLY,
132-
&mca_hook_comm_method_enable_mpi_finalize);
133-
134-
// User can set the comm_method mca variable too
135-
int hook_comm_method = -1;
136-
(void) mca_base_var_register("ompi", NULL, NULL, "comm_method",
137-
"Enable comm_method behavior (1) mpi_init or (2) mpi_finalize",
138-
MCA_BASE_VAR_TYPE_INT, NULL,
139-
0, 0,
140-
OPAL_INFO_LVL_3,
141-
MCA_BASE_VAR_SCOPE_READONLY,
142-
&hook_comm_method);
143-
144-
if( 1 == hook_comm_method ) {
145-
mca_hook_comm_method_enable_mpi_init = true;
140+
mca_base_var_enum_create_flag("ompi_comm_method", mca_hook_comm_method_modes, &mca_hook_comm_method_flags);
141+
142+
ret = mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "display",
143+
"Enable the communication protocol report: when MPI_INIT is invoked (using the 'mpi_init' value) and/or when MPI_FINALIZE is invoked (using the 'mpi_finalize' value).",
144+
MCA_BASE_VAR_TYPE_UNSIGNED_INT,
145+
&mca_hook_comm_method_flags->super,
146+
0, 0,
147+
OPAL_INFO_LVL_3,
148+
MCA_BASE_VAR_SCOPE_READONLY,
149+
&mca_hook_comm_method_enabled_flags);
150+
151+
(void) mca_base_var_register_synonym(ret, "ompi", "ompi", NULL, "display_comm", MCA_BASE_VAR_SYN_FLAG_INTERNAL);
152+
153+
OBJ_RELEASE(mca_hook_comm_method_flags);
154+
if(OPAL_ERR_VALUE_OUT_OF_BOUNDS == ret) {
155+
opal_output(0, "hook:comm_method: Warning invalid comm_method specified.");
146156
}
147-
else if( 2 == hook_comm_method ) {
148-
mca_hook_comm_method_enable_mpi_finalize = true;
157+
else {
158+
if( mca_hook_comm_method_enabled_flags & OMPI_HOOK_COMM_METHOD_INIT ) {
159+
mca_hook_comm_method_enable_mpi_init = true;
160+
}
161+
if( mca_hook_comm_method_enabled_flags & OMPI_HOOK_COMM_METHOD_FINALIZE ) {
162+
mca_hook_comm_method_enable_mpi_finalize = true;
163+
}
149164
}
150165

151-
// comm_method_max
152-
(void) mca_base_var_register("ompi", NULL, NULL, "comm_method_max",
166+
// hook_comm_method_max
167+
(void) mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "max",
153168
"Number of hosts for which to print unabbreviated 2d table of comm methods.",
154169
MCA_BASE_VAR_TYPE_INT, NULL,
155170
0, 0,
156171
OPAL_INFO_LVL_3,
157172
MCA_BASE_VAR_SCOPE_READONLY,
158173
&mca_hook_comm_method_max);
159-
// comm_method_brief
160-
(void) mca_base_var_register("ompi", NULL, NULL, "comm_method_brief",
174+
// hook_comm_method_brief
175+
(void) mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "brief",
161176
"Only print the comm method summary, skip the 2d table.",
162177
MCA_BASE_VAR_TYPE_INT, NULL,
163178
0, 0,
164179
OPAL_INFO_LVL_3,
165180
MCA_BASE_VAR_SCOPE_READONLY,
166181
&mca_hook_comm_method_brief);
167182

168-
// comm_method_fakefile is just for debugging, allows complete override of all the
183+
// hook_comm_method_fakefile is just for debugging, allows complete override of all the
169184
// comm method in the table
170-
(void) mca_base_var_register("ompi", NULL, NULL, "comm_method_fakefile",
185+
(void) mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "fakefile",
171186
"For debugging only: read comm methods from a file",
172187
MCA_BASE_VAR_TYPE_STRING, NULL,
173188
0, 0,

0 commit comments

Comments
 (0)