Skip to content

Commit fcbc7ea

Browse files
authored
Merge pull request #6306 from karasevb/regx_host_ordering_fix
regex: fixed host ordering for different prefixes
2 parents 8bbd201 + 46e38b9 commit fcbc7ea

File tree

3 files changed

+107
-86
lines changed

3 files changed

+107
-86
lines changed

orte/mca/regx/fwd/regx_fwd.c

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -154,61 +154,44 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
154154
}
155155
/* is this node name already on our list? */
156156
found = false;
157-
for (item = opal_list_get_first(&nodenms);
158-
!found && item != opal_list_get_end(&nodenms);
159-
item = opal_list_get_next(item)) {
160-
ndreg = (orte_regex_node_t*)item;
161-
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
162-
continue;
163-
}
164-
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
165-
continue;
166-
}
167-
if (0 < strlen(prefix) && NULL != ndreg->prefix
168-
&& 0 != strcmp(prefix, ndreg->prefix)) {
169-
continue;
170-
}
171-
if (NULL == suffix && NULL != ndreg->suffix) {
172-
continue;
173-
}
174-
if (NULL != suffix && NULL == ndreg->suffix) {
175-
continue;
176-
}
177-
if (NULL != suffix && NULL != ndreg->suffix &&
178-
0 != strcmp(suffix, ndreg->suffix)) {
179-
continue;
180-
}
181-
if (numdigits != ndreg->num_digits) {
182-
continue;
157+
if (0 != opal_list_get_size(&nodenms)) {
158+
ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);
159+
160+
if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
161+
(0 == strlen(prefix) && NULL != ndreg->prefix) ||
162+
(0 < strlen(prefix) && NULL != ndreg->prefix &&
163+
0 != strcmp(prefix, ndreg->prefix)) ||
164+
(NULL == suffix && NULL != ndreg->suffix) ||
165+
(NULL != suffix && NULL == ndreg->suffix) ||
166+
(NULL != suffix && NULL != ndreg->suffix &&
167+
0 != strcmp(suffix, ndreg->suffix)) ||
168+
(numdigits != ndreg->num_digits)) {
169+
found = false;
170+
} else {
171+
/* found a match - flag it */
172+
found = true;
183173
}
184-
/* found a match - flag it */
185-
found = true;
186-
/* get the last range on this nodeid - we do this
187-
* to preserve order
188-
*/
174+
}
175+
if (found) {
189176
range = (orte_regex_range_t*)opal_list_get_last(&ndreg->ranges);
190177
if (NULL == range) {
191178
/* first range for this nodeid */
192179
range = OBJ_NEW(orte_regex_range_t);
193180
range->vpid = nodenum;
194181
range->cnt = 1;
195182
opal_list_append(&ndreg->ranges, &range->super);
196-
break;
197-
}
198183
/* see if the node number is out of sequence */
199-
if (nodenum != (range->vpid + range->cnt)) {
184+
} else if (nodenum != (range->vpid + range->cnt)) {
200185
/* start a new range */
201186
range = OBJ_NEW(orte_regex_range_t);
202187
range->vpid = nodenum;
203188
range->cnt = 1;
204189
opal_list_append(&ndreg->ranges, &range->super);
205-
break;
190+
} else {
191+
/* everything matches - just increment the cnt */
192+
range->cnt++;
206193
}
207-
/* everything matches - just increment the cnt */
208-
range->cnt++;
209-
break;
210-
}
211-
if (!found) {
194+
} else {
212195
/* need to add it */
213196
ndreg = OBJ_NEW(orte_regex_node_t);
214197
if (0 < strlen(prefix)) {

orte/mca/regx/reverse/regx_reverse.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
142142
for( j = 0; j <= i; ++j) {
143143
prefix[j] = node[j];
144144
}
145-
startnum = j;
145+
if (numdigits) {
146+
startnum = j;
147+
}
146148
break;
147149
}
148150
}
@@ -168,35 +170,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
168170
}
169171
/* is this node name already on our list? */
170172
found = false;
171-
for (item = opal_list_get_first(&nodenms);
172-
!found && item != opal_list_get_end(&nodenms);
173-
item = opal_list_get_next(item)) {
174-
ndreg = (orte_regex_node_t*)item;
175-
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
176-
continue;
177-
}
178-
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
179-
continue;
180-
}
181-
if (0 < strlen(prefix) && NULL != ndreg->prefix
182-
&& 0 != strcmp(prefix, ndreg->prefix)) {
183-
continue;
184-
}
185-
if (NULL == suffix && NULL != ndreg->suffix) {
186-
continue;
187-
}
188-
if (NULL != suffix && NULL == ndreg->suffix) {
189-
continue;
190-
}
191-
if (NULL != suffix && NULL != ndreg->suffix &&
192-
0 != strcmp(suffix, ndreg->suffix)) {
193-
continue;
194-
}
195-
if (numdigits != ndreg->num_digits) {
196-
continue;
173+
if (0 != opal_list_get_size(&nodenms)) {
174+
ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);
175+
176+
if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
177+
(0 == strlen(prefix) && NULL != ndreg->prefix) ||
178+
(0 < strlen(prefix) && NULL != ndreg->prefix &&
179+
0 != strcmp(prefix, ndreg->prefix)) ||
180+
(NULL == suffix && NULL != ndreg->suffix) ||
181+
(NULL != suffix && NULL == ndreg->suffix) ||
182+
(NULL != suffix && NULL != ndreg->suffix &&
183+
0 != strcmp(suffix, ndreg->suffix)) ||
184+
(numdigits != ndreg->num_digits)) {
185+
found = false;
186+
} else {
187+
/* found a match - flag it */
188+
found = true;
197189
}
198-
/* found a match - flag it */
199-
found = true;
190+
}
191+
if (found) {
200192
/* get the last range on this nodeid - we do this
201193
* to preserve order
202194
*/
@@ -207,22 +199,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
207199
range->vpid = nodenum;
208200
range->cnt = 1;
209201
opal_list_append(&ndreg->ranges, &range->super);
210-
break;
211-
}
212202
/* see if the node number is out of sequence */
213-
if (nodenum != (range->vpid + range->cnt)) {
203+
} else if (nodenum != (range->vpid + range->cnt)) {
214204
/* start a new range */
215205
range = OBJ_NEW(orte_regex_range_t);
216206
range->vpid = nodenum;
217207
range->cnt = 1;
218208
opal_list_append(&ndreg->ranges, &range->super);
219-
break;
209+
} else {
210+
/* everything matches - just increment the cnt */
211+
range->cnt++;
220212
}
221-
/* everything matches - just increment the cnt */
222-
range->cnt++;
223-
break;
224-
}
225-
if (!found) {
213+
} else {
226214
/* need to add it */
227215
ndreg = OBJ_NEW(orte_regex_node_t);
228216
if (0 < strlen(prefix)) {

orte/test/system/regex.c

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
#include "opal/util/argv.h"
1414

1515
#include "orte/util/proc_info.h"
16-
#include "orte/util/regex.h"
1716
#include "orte/mca/errmgr/errmgr.h"
1817
#include "orte/runtime/runtime.h"
18+
#include "orte/mca/regx/regx.h"
19+
#include "orte/mca/regx/base/base.h"
1920

2021
int main(int argc, char **argv)
2122
{
2223
int rc;
23-
char *regex, *save;
24+
char *regex = NULL, **nodelist;
2425
char **nodes=NULL;
2526
int i;
27+
opal_pointer_array_t *node_pool;
28+
orte_node_t *nptr;
2629

2730
if (argc < 1 || NULL == argv[1]) {
2831
fprintf(stderr, "usage: regex <comma-separated list of nodes>\n");
@@ -31,10 +34,19 @@ int main(int argc, char **argv)
3134

3235
orte_init(&argc, &argv, ORTE_PROC_NON_MPI);
3336

37+
if (ORTE_SUCCESS != (rc = mca_base_framework_open(&orte_regx_base_framework, 0))) {
38+
ORTE_ERROR_LOG(rc);
39+
return rc;
40+
}
41+
if (ORTE_SUCCESS != (rc = orte_regx_base_select())) {
42+
ORTE_ERROR_LOG(rc);
43+
return rc;
44+
}
45+
3446
if (NULL != strchr(argv[1], '[')) {
3547
/* given a regex to analyze */
3648
fprintf(stderr, "ANALYZING REGEX: %s\n", argv[1]);
37-
if (ORTE_SUCCESS != (rc = orte_regex_extract_node_names(argv[1], &nodes))) {
49+
if (ORTE_SUCCESS != (rc = orte_regx.extract_node_names(argv[1], &nodes))) {
3850
ORTE_ERROR_LOG(rc);
3951
}
4052
for (i=0; NULL != nodes[i]; i++) {
@@ -45,23 +57,61 @@ int main(int argc, char **argv)
4557
return 0;
4658
}
4759

48-
save = strdup(argv[1]);
49-
if (ORTE_SUCCESS != (rc = orte_regex_create(save, &regex))) {
60+
node_pool = OBJ_NEW(opal_pointer_array_t);
61+
nodelist = opal_argv_split(argv[1], ',');
62+
for (i=0; NULL != nodelist[i]; i++) {
63+
orte_proc_t *daemon = NULL;
64+
65+
nptr = OBJ_NEW(orte_node_t);
66+
nptr->name = strdup(nodelist[i]);
67+
daemon = OBJ_NEW(orte_proc_t);
68+
daemon->name.jobid = 123;
69+
daemon->name.vpid = i;
70+
nptr->daemon = daemon;
71+
72+
nptr->index = opal_pointer_array_add(node_pool, nptr);
73+
}
74+
75+
76+
77+
if (ORTE_SUCCESS != (rc = orte_regx.nidmap_create(node_pool, &regex))) {
5078
ORTE_ERROR_LOG(rc);
5179
} else {
80+
char *vpids = strchr(regex, '@');
81+
vpids[0] = '\0';
5282
fprintf(stderr, "REGEX: %s\n", regex);
53-
if (ORTE_SUCCESS != (rc = orte_regex_extract_node_names(regex, &nodes))) {
83+
if (ORTE_SUCCESS != (rc = orte_regx.extract_node_names(regex, &nodes))) {
5484
ORTE_ERROR_LOG(rc);
5585
}
5686
free(regex);
5787
regex = opal_argv_join(nodes, ',');
58-
opal_argv_free(nodes);
5988
if (0 == strcmp(regex, argv[1])) {
6089
fprintf(stderr, "EXACT MATCH\n");
6190
} else {
6291
fprintf(stderr, "ERROR: %s\n", regex);
92+
if (opal_argv_count(nodes) != opal_argv_count(nodelist)) {
93+
fprintf(stderr, "ERROR: number of nodes %d, expected %d\n",
94+
opal_argv_count(nodes), opal_argv_count(nodelist));
95+
goto exit;
96+
}
97+
for (i=0; NULL != nodelist[i]; i++) {
98+
if (0 == strcmp(nodelist[i], nodes[i])) {
99+
fprintf(stderr, "%s OK\n", nodelist[i]);
100+
}
101+
fprintf(stderr, "%s ERROR, expect %s\n", nodes[i], nodelist[i]);
102+
}
63103
}
64104
free(regex);
105+
regex = NULL;
106+
}
107+
exit:
108+
opal_argv_free(nodelist);
109+
opal_argv_free(nodes);
110+
111+
112+
for (i=0; (nptr = opal_pointer_array_get_item(node_pool, i)) != NULL; i++) {
113+
free(nptr->name);
114+
OBJ_RELEASE(nptr->daemon);
65115
}
66-
free(save);
116+
OBJ_RELEASE(node_pool);
67117
}

0 commit comments

Comments
 (0)