From 9ffb024e4623d48f119da25aa4ae29890968842e Mon Sep 17 00:00:00 2001 From: Joshua Hursey Date: Tue, 5 Jan 2021 13:29:52 -0500 Subject: [PATCH] hook/comm_method: Use enum flags to select protocols Signed-off-by: Joshua Hursey --- .../comm_method/hook_comm_method_component.c | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/ompi/mca/hook/comm_method/hook_comm_method_component.c b/ompi/mca/hook/comm_method/hook_comm_method_component.c index ec27016b683..e3653261b50 100644 --- a/ompi/mca/hook/comm_method/hook_comm_method_component.c +++ b/ompi/mca/hook/comm_method/hook_comm_method_component.c @@ -74,13 +74,21 @@ int mca_hook_comm_method_max = 12; int mca_hook_comm_method_brief = 0; char *mca_hook_comm_method_fakefile = NULL; -mca_base_var_enum_value_t mca_hook_comm_method_modes[] = { - {1, "init"}, - {1, "mpi_init"}, - {2, "finalize"}, - {2, "mpi_finalize"}, - {3, "all"}, - {0, NULL} +enum mca_hook_comm_method_mode_flags_t { + /* Default: Display nothing */ + OMPI_HOOK_COMM_METHOD_NONE = 0x01, + /* Display on MPI_INIT */ + OMPI_HOOK_COMM_METHOD_INIT = 0x02, + /* Display on MPI_FINALIZE */ + OMPI_HOOK_COMM_METHOD_FINALIZE = 0x04, +}; + +static mca_base_var_enum_value_flag_t mca_hook_comm_method_modes[] = { + {.flag = OMPI_HOOK_COMM_METHOD_NONE, .string = "none", + .conflicting_flag = OMPI_HOOK_COMM_METHOD_INIT | OMPI_HOOK_COMM_METHOD_FINALIZE}, + {.flag = OMPI_HOOK_COMM_METHOD_INIT, .string = "mpi_init"}, + {.flag = OMPI_HOOK_COMM_METHOD_FINALIZE, .string = "mpi_finalize"}, + {0, NULL, 0} }; @@ -99,8 +107,8 @@ static int ompi_hook_comm_method_component_close(void) static int ompi_hook_comm_method_component_register(void) { int ret; - int mca_hook_comm_method_enabled = -1; - mca_base_var_enum_t *new_enum = NULL; + mca_base_var_enum_flag_t *mca_hook_comm_method_flags = NULL; + uint32_t mca_hook_comm_method_enabled_flags = OMPI_HOOK_COMM_METHOD_NONE; /* * Component verbosity level @@ -145,27 +153,27 @@ static int ompi_hook_comm_method_component_register(void) &mca_hook_comm_method_enable_mpi_finalize); // User can set the comm_method mca variable too - mca_base_var_enum_create("ompi_comm_method", mca_hook_comm_method_modes, &new_enum); + mca_base_var_enum_create_flag("ompi_comm_method", mca_hook_comm_method_modes, &mca_hook_comm_method_flags); + ret = mca_base_var_register("ompi", NULL, NULL, "comm_method", - "Enable the communication protocol report: when MPI_INIT is invoked (using the '1', 'init', or 'mpi_init' values), when MPI_FINALIZE is inboked (using the '2', 'finalize', or 'mpi_finalize' values), or when both are invoked (using the '3', or 'all' values)", - MCA_BASE_VAR_TYPE_INT, new_enum, + "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).", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, + &mca_hook_comm_method_flags->super, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY, - &mca_hook_comm_method_enabled); - OBJ_RELEASE(new_enum); + &mca_hook_comm_method_enabled_flags); + OBJ_RELEASE(mca_hook_comm_method_flags); if(OPAL_ERR_VALUE_OUT_OF_BOUNDS == ret) { - opal_output(0, "hook:comm_method: Warning invalid prot mode specified: %d", mca_hook_comm_method_enabled); - } - else if( 1 == mca_hook_comm_method_enabled ) { - mca_hook_comm_method_enable_mpi_init = true; + opal_output(0, "hook:comm_method: Warning invalid comm_method specified."); } - else if( 2 == mca_hook_comm_method_enabled ) { - mca_hook_comm_method_enable_mpi_finalize = true; - } - else if( 3 == mca_hook_comm_method_enabled ) { - mca_hook_comm_method_enable_mpi_init = true; - mca_hook_comm_method_enable_mpi_finalize = true; + else { + if( mca_hook_comm_method_enabled_flags & OMPI_HOOK_COMM_METHOD_INIT ) { + mca_hook_comm_method_enable_mpi_init = true; + } + if( mca_hook_comm_method_enabled_flags & OMPI_HOOK_COMM_METHOD_FINALIZE ) { + mca_hook_comm_method_enable_mpi_finalize = true; + } } // comm_method_max