@@ -450,14 +450,19 @@ int prte_util_add_dash_host_nodes(pmix_list_t *nodes, char *hosts, bool allocati
450450 */
451451static int parse_dash_host (char * * * mapped_nodes , char * hosts )
452452{
453- int32_t j , k ;
453+ int32_t j , k , start ;
454454 int rc = PRTE_SUCCESS ;
455455 char * * mini_map = NULL , * cptr ;
456- int nodeidx ;
456+ int nodeidx , nnodes , p ;
457457 prte_node_t * node ;
458458 char * * host_argv = NULL ;
459459
460460 host_argv = PMIX_ARGV_SPLIT_COMPAT (hosts , ',' );
461+ if (prte_hnp_is_allocated ) {
462+ start = 0 ;
463+ } else {
464+ start = 1 ;
465+ }
461466
462467 /* Accumulate all of the host name mappings */
463468 for (j = 0 ; j < PMIX_ARGV_COUNT_COMPAT (host_argv ); ++ j ) {
@@ -472,8 +477,35 @@ static int parse_dash_host(char ***mapped_nodes, char *hosts)
472477 */
473478 if (NULL != (cptr = strchr (mini_map [k ], ':' ))) {
474479 /* the colon indicates a specific # are requested */
475- * cptr = '*' ;
476- PMIX_ARGV_APPEND_NOSIZE_COMPAT (mapped_nodes , cptr );
480+ ++ cptr ;
481+ if (NULL == cptr ) {
482+ // missing number of nodes being requested
483+ pmix_show_help ("help-dash-host.txt" ,
484+ "dash-host:invalid-relative-node-syntax" , true,
485+ mini_map [k ]);
486+ rc = PRTE_ERR_SILENT ;
487+ goto cleanup ;
488+ }
489+ nnodes = strtol (cptr , NULL , 10 );
490+ for (j = start , p = 0 ; j < (int32_t )prte_node_pool -> size && p < nnodes ; j ++ ) {
491+ node = (prte_node_t * ) pmix_pointer_array_get_item (prte_node_pool , j );
492+ if (NULL == node ) {
493+ continue ;
494+ }
495+ // if the node is empty, capture it
496+ if (0 == node -> num_procs ) {
497+ PMIX_ARGV_APPEND_NOSIZE_COMPAT (mapped_nodes , node -> name );
498+ ++ p ;
499+ }
500+ }
501+ if (p < nnodes ) {
502+ // not enough empty nodes
503+ pmix_show_help ("help-dash-host.txt" ,
504+ "dash-host:not-enough-empty" , true,
505+ nnodes - p );
506+ rc = PRTE_ERR_SILENT ;
507+ goto cleanup ;
508+ }
477509 } else {
478510 /* add a marker to the list */
479511 PMIX_ARGV_APPEND_NOSIZE_COMPAT (mapped_nodes , "*" );
0 commit comments