|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2018 Intel, Inc. All rights reserved. |
| 3 | + * Copyright (c) 2019 IBM Corporation. All rights reserved. |
| 4 | + * Copyright (c) 2018 Research Organization for Information Science |
| 5 | + * and Technology (RIST). All rights reserved. |
| 6 | + * $COPYRIGHT$ |
| 7 | + * |
| 8 | + * Additional copyrights may follow |
| 9 | + * |
| 10 | + * $HEADER$ |
| 11 | + * |
| 12 | + */ |
| 13 | + |
| 14 | +#include "orte_config.h" |
| 15 | +#include "orte/types.h" |
| 16 | +#include "opal/types.h" |
| 17 | + |
| 18 | +#ifdef HAVE_UNISTD_H |
| 19 | +#include <unistd.h> |
| 20 | +#endif |
| 21 | +#include <ctype.h> |
| 22 | + |
| 23 | +#include "opal/util/argv.h" |
| 24 | +#include "opal/util/basename.h" |
| 25 | +#include "opal/util/opal_environ.h" |
| 26 | + |
| 27 | +#include "orte/runtime/orte_globals.h" |
| 28 | +#include "orte/util/name_fns.h" |
| 29 | +#include "orte/util/show_help.h" |
| 30 | +#include "orte/mca/errmgr/errmgr.h" |
| 31 | +#include "orte/mca/rmaps/base/base.h" |
| 32 | +#include "orte/mca/routed/routed.h" |
| 33 | +#include "orte/mca/regx/base/base.h" |
| 34 | + |
| 35 | +#include "regx_none.h" |
| 36 | + |
| 37 | +static int nidmap_create(opal_pointer_array_t *pool, char **regex); |
| 38 | + |
| 39 | +orte_regx_base_module_t orte_regx_none_module = { |
| 40 | + .nidmap_create = nidmap_create, |
| 41 | + .nidmap_parse = orte_regx_base_nidmap_parse, |
| 42 | + .extract_node_names = orte_regx_base_extract_node_names, |
| 43 | + .encode_nodemap = orte_regx_base_encode_nodemap, |
| 44 | + .decode_daemon_nodemap = orte_regx_base_decode_daemon_nodemap, |
| 45 | + .generate_ppn = orte_regx_base_generate_ppn, |
| 46 | + .parse_ppn = orte_regx_base_parse_ppn |
| 47 | +}; |
| 48 | + |
| 49 | +static int nidmap_create(opal_pointer_array_t *pool, char **regex) |
| 50 | +{ |
| 51 | + char *node; |
| 52 | + int n; |
| 53 | + char *nodenames; |
| 54 | + orte_regex_range_t *rng; |
| 55 | + opal_list_t dvpids; |
| 56 | + opal_list_item_t *item; |
| 57 | + char **regexargs = NULL, **vpidargs = NULL, *tmp, *tmp2; |
| 58 | + orte_node_t *nptr; |
| 59 | + orte_vpid_t vpid; |
| 60 | + |
| 61 | + if (mca_regx_none_component.compress_vpids) { |
| 62 | + OBJ_CONSTRUCT(&dvpids, opal_list_t); |
| 63 | + } |
| 64 | + |
| 65 | + rng = NULL; |
| 66 | + for (n=0; n < pool->size; n++) { |
| 67 | + if (NULL == (nptr = (orte_node_t*)opal_pointer_array_get_item(pool, n))) { |
| 68 | + continue; |
| 69 | + } |
| 70 | + /* if no daemon has been assigned, then this node is not being used */ |
| 71 | + if (NULL == nptr->daemon) { |
| 72 | + vpid = -1; // indicates no daemon assigned |
| 73 | + } else { |
| 74 | + vpid = nptr->daemon->name.vpid; |
| 75 | + } |
| 76 | + |
| 77 | + if (mca_regx_none_component.compress_vpids) { |
| 78 | + /* deal with the daemon vpid - see if it is next in the |
| 79 | + * current range */ |
| 80 | + if (NULL == rng) { |
| 81 | + /* just starting */ |
| 82 | + rng = OBJ_NEW(orte_regex_range_t); |
| 83 | + rng->vpid = vpid; |
| 84 | + rng->cnt = 1; |
| 85 | + opal_list_append(&dvpids, &rng->super); |
| 86 | + } else if (UINT32_MAX == vpid) { |
| 87 | + if (-1 == rng->vpid) { |
| 88 | + rng->cnt++; |
| 89 | + } else { |
| 90 | + /* need to start another range */ |
| 91 | + rng = OBJ_NEW(orte_regex_range_t); |
| 92 | + rng->vpid = vpid; |
| 93 | + rng->cnt = 1; |
| 94 | + opal_list_append(&dvpids, &rng->super); |
| 95 | + } |
| 96 | + } else if (-1 == rng->vpid) { |
| 97 | + /* need to start another range */ |
| 98 | + rng = OBJ_NEW(orte_regex_range_t); |
| 99 | + rng->vpid = vpid; |
| 100 | + rng->cnt = 1; |
| 101 | + opal_list_append(&dvpids, &rng->super); |
| 102 | + } else { |
| 103 | + /* is this the next in line */ |
| 104 | + if (vpid == (orte_vpid_t)(rng->vpid + rng->cnt)) { |
| 105 | + rng->cnt++; |
| 106 | + } else { |
| 107 | + /* need to start another range */ |
| 108 | + rng = OBJ_NEW(orte_regex_range_t); |
| 109 | + rng->vpid = vpid; |
| 110 | + rng->cnt = 1; |
| 111 | + opal_list_append(&dvpids, &rng->super); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + else { |
| 116 | + asprintf(&tmp, "%u", vpid); |
| 117 | + opal_argv_append_nosize(&vpidargs, tmp); |
| 118 | + free(tmp); |
| 119 | + } |
| 120 | + |
| 121 | + node = nptr->name; |
| 122 | + opal_output_verbose(5, orte_regx_base_framework.framework_output, |
| 123 | + "%s PROCESS NODE <%s>", |
| 124 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), |
| 125 | + node); |
| 126 | + |
| 127 | + /* Don't compress the name - just add it to the list */ |
| 128 | + if (NULL != node) { |
| 129 | + /* solitary node */ |
| 130 | + asprintf(&tmp, "%s", node); |
| 131 | + opal_argv_append_nosize(®exargs, tmp); |
| 132 | + free(tmp); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + /* assemble final result */ |
| 137 | + nodenames = opal_argv_join(regexargs, ','); |
| 138 | + /* cleanup */ |
| 139 | + opal_argv_free(regexargs); |
| 140 | + |
| 141 | + if (mca_regx_none_component.compress_vpids) { |
| 142 | + /* do the same for the vpids */ |
| 143 | + tmp = NULL; |
| 144 | + while (NULL != (item = opal_list_remove_first(&dvpids))) { |
| 145 | + rng = (orte_regex_range_t*)item; |
| 146 | + if (1 < rng->cnt) { |
| 147 | + if (NULL == tmp) { |
| 148 | + asprintf(&tmp, "%u(%u)", rng->vpid, rng->cnt); |
| 149 | + } else { |
| 150 | + asprintf(&tmp2, "%s,%u(%u)", tmp, rng->vpid, rng->cnt); |
| 151 | + free(tmp); |
| 152 | + tmp = tmp2; |
| 153 | + } |
| 154 | + } else { |
| 155 | + if (NULL == tmp) { |
| 156 | + asprintf(&tmp, "%u", rng->vpid); |
| 157 | + } else { |
| 158 | + asprintf(&tmp2, "%s,%u", tmp, rng->vpid); |
| 159 | + free(tmp); |
| 160 | + tmp = tmp2; |
| 161 | + } |
| 162 | + } |
| 163 | + OBJ_RELEASE(rng); |
| 164 | + } |
| 165 | + OPAL_LIST_DESTRUCT(&dvpids); |
| 166 | + } |
| 167 | + else { |
| 168 | + tmp = opal_argv_join(vpidargs, ','); |
| 169 | + /* cleanup */ |
| 170 | + opal_argv_free(vpidargs); |
| 171 | + } |
| 172 | + |
| 173 | + /* now concatenate the results into one string */ |
| 174 | + asprintf(&tmp2, "%s@%s", nodenames, tmp); |
| 175 | + free(nodenames); |
| 176 | + free(tmp); |
| 177 | + *regex = tmp2; |
| 178 | + opal_output_verbose(5, orte_regx_base_framework.framework_output, |
| 179 | + "%s Final regex: <%s>", |
| 180 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), |
| 181 | + *regex); |
| 182 | + return ORTE_SUCCESS; |
| 183 | +} |
0 commit comments