Skip to content

Commit 22c88f5

Browse files
author
Ralph Castain
committed
Fix launch_id matching of -hosts
Need to check the entire value instead of just the last N digits. Otherwise, "-host 15" will match nid0015, nid0115, and any other launch id ending in 15 It appears strtol can return either a NULL or a zero-length string, so check for both cases Signed-off-by: Ralph Castain <[email protected]>
1 parent 5c64c0b commit 22c88f5

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

orte/mca/ras/base/ras_base_allocate.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2011-2012 Los Alamos National Security, LLC. All rights
1313
* reserved.
14-
* Copyright (c) 2014-2016 Intel, Inc. All rights reserved.
14+
* Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
1515
* $COPYRIGHT$
1616
*
1717
* Additional copyrights may follow
@@ -266,6 +266,7 @@ void orte_ras_base_allocate(int fd, short args, void *cbdata)
266266
return;
267267
}
268268
}
269+
269270
if (NULL != orte_rankfile) {
270271
OPAL_OUTPUT_VERBOSE((5, orte_ras_base_framework.framework_output,
271272
"%s ras:base:allocate parsing rankfile %s",
@@ -386,7 +387,7 @@ void orte_ras_base_allocate(int fd, short args, void *cbdata)
386387
"%s ras:base:allocate nothing found in rankfile - inserting current node",
387388
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
388389

389-
addlocal:
390+
addlocal:
390391
/* if nothing was found by any of the above methods, then we have no
391392
* earthly idea what to do - so just add the local host
392393
*/
@@ -420,13 +421,13 @@ void orte_ras_base_allocate(int fd, short args, void *cbdata)
420421
}
421422
OBJ_DESTRUCT(&nodes);
422423

423-
DISPLAY:
424+
DISPLAY:
424425
/* shall we display the results? */
425426
if (4 < opal_output_get_verbosity(orte_ras_base_framework.framework_output)) {
426427
orte_ras_base_display_alloc();
427428
}
428429

429-
next_state:
430+
next_state:
430431
/* are we to report this event? */
431432
if (orte_report_events) {
432433
if (ORTE_SUCCESS != (rc = orte_util_comm_report_event(ORTE_COMM_EVENT_ALLOCATE))) {

orte/util/dash_host/dash_host.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "orte_config.h"
2525

2626
#include <string.h>
27+
#include <ctype.h>
2728

2829
#include "orte/constants.h"
2930
#include "orte/types.h"
@@ -515,25 +516,31 @@ int orte_util_filter_dash_host_nodes(opal_list_t *nodes,
515516
/* we are looking for a specific node on the list. The
516517
* parser will have substituted our local name for any
517518
* alias, so we only have to do a strcmp here. */
518-
lmn = strtol(mapped_nodes[i], &cptr, 10);
519-
if (orte_managed_allocation && NULL != cptr) {
520-
/* if we are only given a number, then we only test the
521-
* number of matching characters starting from the rear
522-
* of the mapped_nodes entry. This allows support for
523-
* launch_id-based environments. For example, a hostname
524-
* of "nid0015" can be referenced by "--host 15" */
525-
lmn = strlen(mapped_nodes[i]);
526-
} else {
527-
lmn = 0;
528-
}
519+
cptr = NULL;
520+
lmn = strtoul(mapped_nodes[i], &cptr, 10);
529521
item = opal_list_get_first(nodes);
530522
while (item != opal_list_get_end(nodes)) {
531523
next = opal_list_get_next(item); /* save this position */
532524
node = (orte_node_t*)item;
533525
/* search -host list to see if this one is found */
534-
if (0 < lmn) {
535-
lst = strlen(node->name);
536-
test = strncmp(node->name + lst - lmn, mapped_nodes[i], lmn);
526+
if (orte_managed_allocation &&
527+
(NULL == cptr || 0 == strlen(cptr))) {
528+
/* if we are only given a number, then we test the
529+
* value against the number in the node name. This allows support for
530+
* launch_id-based environments. For example, a hostname
531+
* of "nid0015" can be referenced by "--host 15" */
532+
for (j=strlen(node->name)-1; 0 < j; j--) {
533+
if (!isdigit(node->name[j])) {
534+
j++;
535+
break;
536+
}
537+
}
538+
if (j >= (int)(strlen(node->name) - 1)) {
539+
test = 0;
540+
} else {
541+
lst = strtoul(&node->name[j], NULL, 10);
542+
test = (lmn == lst) ? 0 : 1;
543+
}
537544
} else {
538545
test = strcmp(node->name, mapped_nodes[i]);
539546
}

0 commit comments

Comments
 (0)