|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2018 IBM Corporation. All rights reserved. |
| 3 | + * $COPYRIGHT$ |
| 4 | + * |
| 5 | + * Additional copyrights may follow |
| 6 | + * |
| 7 | + * $HEADER$ |
| 8 | + */ |
| 9 | + |
| 10 | +#include "ompi_config.h" |
| 11 | + |
| 12 | +#include "hook_comm_method.h" |
| 13 | + |
| 14 | +static int ompi_hook_comm_method_component_open(void); |
| 15 | +static int ompi_hook_comm_method_component_close(void); |
| 16 | +static int ompi_hook_comm_method_component_register(void); |
| 17 | + |
| 18 | +/* |
| 19 | + * Public string showing the component version number |
| 20 | + */ |
| 21 | +const char *mca_hook_comm_method_component_version_string = |
| 22 | + "Open MPI 'comm_method' hook MCA component version " OMPI_VERSION; |
| 23 | + |
| 24 | +/* |
| 25 | + * Instantiate the public struct with all of our public information |
| 26 | + * and pointers to our public functions in it |
| 27 | + */ |
| 28 | +const ompi_hook_base_component_1_0_0_t mca_hook_comm_method_component = { |
| 29 | + |
| 30 | + /* First, the mca_component_t struct containing meta information |
| 31 | + * about the component itself */ |
| 32 | + .hookm_version = { |
| 33 | + OMPI_HOOK_BASE_VERSION_1_0_0, |
| 34 | + |
| 35 | + /* Component name and version */ |
| 36 | + .mca_component_name = "comm_method", |
| 37 | + MCA_BASE_MAKE_VERSION(component, OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, |
| 38 | + OMPI_RELEASE_VERSION), |
| 39 | + |
| 40 | + /* Component open and close functions */ |
| 41 | + .mca_open_component = ompi_hook_comm_method_component_open, |
| 42 | + .mca_close_component = ompi_hook_comm_method_component_close, |
| 43 | + .mca_register_component_params = ompi_hook_comm_method_component_register, |
| 44 | + |
| 45 | + // Force this component to always be considered - component must be static |
| 46 | + //.mca_component_flags = MCA_BASE_COMPONENT_FLAG_ALWAYS_CONSIDER, |
| 47 | + }, |
| 48 | + .hookm_data = { |
| 49 | + /* The component is checkpoint ready */ |
| 50 | + MCA_BASE_METADATA_PARAM_CHECKPOINT |
| 51 | + }, |
| 52 | + |
| 53 | + /* Component functions */ |
| 54 | + .hookm_mpi_initialized_top = NULL, |
| 55 | + .hookm_mpi_initialized_bottom = NULL, |
| 56 | + |
| 57 | + .hookm_mpi_finalized_top = NULL, |
| 58 | + .hookm_mpi_finalized_bottom = NULL, |
| 59 | + |
| 60 | + .hookm_mpi_init_top = NULL, |
| 61 | + .hookm_mpi_init_top_post_opal = NULL, |
| 62 | + .hookm_mpi_init_bottom = ompi_hook_comm_method_mpi_init_bottom, |
| 63 | + .hookm_mpi_init_error = NULL, |
| 64 | + |
| 65 | + .hookm_mpi_finalize_top = ompi_hook_comm_method_mpi_finalize_top, |
| 66 | + .hookm_mpi_finalize_bottom = NULL, |
| 67 | +}; |
| 68 | + |
| 69 | +int mca_hook_comm_method_verbose = 0; |
| 70 | +int mca_hook_comm_method_output = -1; |
| 71 | +bool hook_comm_method_enable_mpi_init = false; |
| 72 | +bool hook_comm_method_enable_mpi_finalize = false; |
| 73 | +int hook_comm_method_max = 12; |
| 74 | +int hook_comm_method_brief = 0; |
| 75 | +char *hook_comm_method_fakefile = NULL; |
| 76 | + |
| 77 | +static int ompi_hook_comm_method_component_open(void) |
| 78 | +{ |
| 79 | + // Nothing to do |
| 80 | + return OMPI_SUCCESS; |
| 81 | +} |
| 82 | + |
| 83 | +static int ompi_hook_comm_method_component_close(void) |
| 84 | +{ |
| 85 | + // Nothing to do |
| 86 | + return OMPI_SUCCESS; |
| 87 | +} |
| 88 | + |
| 89 | +static int ompi_hook_comm_method_component_register(void) |
| 90 | +{ |
| 91 | + |
| 92 | + /* |
| 93 | + * Component verbosity level |
| 94 | + */ |
| 95 | + // Inherit the verbosity of the base framework, but also allow this to be overridden |
| 96 | + if( ompi_hook_base_framework.framework_verbose > MCA_BASE_VERBOSE_NONE ) { |
| 97 | + mca_hook_comm_method_verbose = ompi_hook_base_framework.framework_verbose; |
| 98 | + } |
| 99 | + else { |
| 100 | + mca_hook_comm_method_verbose = MCA_BASE_VERBOSE_NONE; |
| 101 | + } |
| 102 | + (void) mca_base_component_var_register(&mca_hook_comm_method_component.hookm_version, "verbose", |
| 103 | + NULL, |
| 104 | + MCA_BASE_VAR_TYPE_INT, NULL, |
| 105 | + 0, 0, |
| 106 | + OPAL_INFO_LVL_9, |
| 107 | + MCA_BASE_VAR_SCOPE_READONLY, |
| 108 | + &mca_hook_comm_method_verbose); |
| 109 | + |
| 110 | + mca_hook_comm_method_output = opal_output_open(NULL); |
| 111 | + opal_output_set_verbosity(mca_hook_comm_method_output, mca_hook_comm_method_verbose); |
| 112 | + |
| 113 | + /* |
| 114 | + * If the component is active for mpi_init / mpi_finalize |
| 115 | + */ |
| 116 | + 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 | + &hook_comm_method_enable_mpi_init); |
| 124 | + |
| 125 | + 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 | + &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 | + hook_comm_method_enable_mpi_init = true; |
| 146 | + } |
| 147 | + else if( 2 == hook_comm_method ) { |
| 148 | + hook_comm_method_enable_mpi_finalize = true; |
| 149 | + } |
| 150 | + |
| 151 | + // comm_method_max |
| 152 | + (void) mca_base_var_register("ompi", NULL, NULL, "comm_method_max", |
| 153 | + "Number of hosts for which to print unabbreviated 2d table of comm methods.", |
| 154 | + MCA_BASE_VAR_TYPE_INT, NULL, |
| 155 | + 0, 0, |
| 156 | + OPAL_INFO_LVL_3, |
| 157 | + MCA_BASE_VAR_SCOPE_READONLY, |
| 158 | + &hook_comm_method_max); |
| 159 | + // comm_method_brief |
| 160 | + (void) mca_base_var_register("ompi", NULL, NULL, "comm_method_brief", |
| 161 | + "Only print the comm method summary, skip the 2d table.", |
| 162 | + MCA_BASE_VAR_TYPE_INT, NULL, |
| 163 | + 0, 0, |
| 164 | + OPAL_INFO_LVL_3, |
| 165 | + MCA_BASE_VAR_SCOPE_READONLY, |
| 166 | + &hook_comm_method_brief); |
| 167 | + |
| 168 | + // comm_method_fakefile is just for debugging, allows complete override of all the |
| 169 | + // comm method in the table |
| 170 | + (void) mca_base_var_register("ompi", NULL, NULL, "comm_method_fakefile", |
| 171 | + "For debugging only: read comm methods from a file", |
| 172 | + MCA_BASE_VAR_TYPE_STRING, NULL, |
| 173 | + 0, 0, |
| 174 | + OPAL_INFO_LVL_3, |
| 175 | + MCA_BASE_VAR_SCOPE_READONLY, |
| 176 | + &hook_comm_method_fakefile); |
| 177 | + |
| 178 | + return OMPI_SUCCESS; |
| 179 | +} |
0 commit comments