Skip to content

Commit 46e38b9

Browse files
committed
regx: fixed the order of hosts for ranges with different prefixes
Example: For the list of hosts `a01,b00,a00` a regex is generated: `a[2:1.0],b[2:0]`, where `a`-hosts prefixes moved to the begining, it breaks the hosts ordering. This commit fixes regex for that case to `a[2:1],b[2:0],a[2:0]` Signed-off-by: Boris Karasev <karasev.b@gmail.com>
1 parent 1967e41 commit 46e38b9

File tree

3 files changed

+64
-80
lines changed

3 files changed

+64
-80
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: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,35 +170,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
170170
}
171171
/* is this node name already on our list? */
172172
found = false;
173-
for (item = opal_list_get_first(&nodenms);
174-
!found && item != opal_list_get_end(&nodenms);
175-
item = opal_list_get_next(item)) {
176-
ndreg = (orte_regex_node_t*)item;
177-
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
178-
continue;
179-
}
180-
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
181-
continue;
182-
}
183-
if (0 < strlen(prefix) && NULL != ndreg->prefix
184-
&& 0 != strcmp(prefix, ndreg->prefix)) {
185-
continue;
186-
}
187-
if (NULL == suffix && NULL != ndreg->suffix) {
188-
continue;
189-
}
190-
if (NULL != suffix && NULL == ndreg->suffix) {
191-
continue;
192-
}
193-
if (NULL != suffix && NULL != ndreg->suffix &&
194-
0 != strcmp(suffix, ndreg->suffix)) {
195-
continue;
196-
}
197-
if (numdigits != ndreg->num_digits) {
198-
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;
199189
}
200-
/* found a match - flag it */
201-
found = true;
190+
}
191+
if (found) {
202192
/* get the last range on this nodeid - we do this
203193
* to preserve order
204194
*/
@@ -209,22 +199,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
209199
range->vpid = nodenum;
210200
range->cnt = 1;
211201
opal_list_append(&ndreg->ranges, &range->super);
212-
break;
213-
}
214202
/* see if the node number is out of sequence */
215-
if (nodenum != (range->vpid + range->cnt)) {
203+
} else if (nodenum != (range->vpid + range->cnt)) {
216204
/* start a new range */
217205
range = OBJ_NEW(orte_regex_range_t);
218206
range->vpid = nodenum;
219207
range->cnt = 1;
220208
opal_list_append(&ndreg->ranges, &range->super);
221-
break;
209+
} else {
210+
/* everything matches - just increment the cnt */
211+
range->cnt++;
222212
}
223-
/* everything matches - just increment the cnt */
224-
range->cnt++;
225-
break;
226-
}
227-
if (!found) {
213+
} else {
228214
/* need to add it */
229215
ndreg = OBJ_NEW(orte_regex_node_t);
230216
if (0 < strlen(prefix)) {

orte/test/system/regex.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
int main(int argc, char **argv)
2222
{
2323
int rc;
24-
char *regex, **nodelist;
24+
char *regex = NULL, **nodelist;
2525
char **nodes=NULL;
2626
int i;
2727
opal_pointer_array_t *node_pool;
@@ -71,7 +71,7 @@ int main(int argc, char **argv)
7171

7272
nptr->index = opal_pointer_array_add(node_pool, nptr);
7373
}
74-
opal_argv_free(nodelist);
74+
7575

7676

7777
if (ORTE_SUCCESS != (rc = orte_regx.nidmap_create(node_pool, &regex))) {
@@ -85,14 +85,29 @@ int main(int argc, char **argv)
8585
}
8686
free(regex);
8787
regex = opal_argv_join(nodes, ',');
88-
opal_argv_free(nodes);
8988
if (0 == strcmp(regex, argv[1])) {
9089
fprintf(stderr, "EXACT MATCH\n");
9190
} else {
9291
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+
}
93103
}
94104
free(regex);
105+
regex = NULL;
95106
}
107+
exit:
108+
opal_argv_free(nodelist);
109+
opal_argv_free(nodes);
110+
96111

97112
for (i=0; (nptr = opal_pointer_array_get_item(node_pool, i)) != NULL; i++) {
98113
free(nptr->name);

0 commit comments

Comments
 (0)