1
1

Since parsing comma-delimited, range-capable options is being used in multiple places, create a new utility that consolidates that code.

Have orte-iof use it.

This commit was SVN r20346.
Этот коммит содержится в:
Ralph Castain 2009-01-25 17:16:25 +00:00
родитель 61adb331d2
Коммит fd5e15ea58
4 изменённых файлов: 133 добавлений и 8 удалений

@ -75,6 +75,7 @@
#include "orte/util/hnp_contact.h"
#include "orte/util/name_fns.h"
#include "orte/util/show_help.h"
#include "orte/util/parse_options.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/iof/iof.h"
#if OPAL_ENABLE_FT == 1
@ -129,10 +130,10 @@ opal_cmd_line_init_t cmd_line_opts[] = {
"Display stddiag from specified process" },
{ NULL, NULL, NULL,
'\0', "rank", "rank",
'\0', "ranks", "ranks",
1,
&my_globals.ranks, OPAL_CMD_LINE_TYPE_STRING,
"Rank whose output is to be displayed" },
"Ranks whose output is to be displayed (Comma separated list, each element can contain range)" },
{ "orte", "tag", "output",
'\0', "tag-output", "tag-output",
@ -161,11 +162,12 @@ static orte_process_name_t target_proc;
int
main(int argc, char *argv[])
{
int ret;
int ret, i;
opal_cmd_line_t cmd_line;
opal_list_item_t* item = NULL;
orte_iof_tag_t stream;
char **ranks=NULL;
/***************
* Initialize
***************/
@ -270,14 +272,22 @@ main(int argc, char *argv[])
stream |= ORTE_IOF_STDOUT;
}
/* we have our target - pull the specified output streams and dump to our stdout */
target_proc.jobid = my_globals.target_hnp->name.jobid + 1;
target_proc.vpid = strtol(my_globals.ranks, NULL, 10);
if (ORTE_SUCCESS != (ret = orte_iof.pull(&target_proc, stream, 1))) {
/* parse the input ranks */
if (ORTE_SUCCESS != (ret = orte_util_parse_rank_options(my_globals.ranks, &ranks))) {
ORTE_ERROR_LOG(ret);
goto cleanup;
}
/* pull the specified output streams and dump to our stdout */
for (i=0; i < opal_argv_count(ranks); i++) {
target_proc.jobid = my_globals.target_hnp->name.jobid + 1;
target_proc.vpid = strtol(ranks[i], NULL, 10);
if (ORTE_SUCCESS != (ret = orte_iof.pull(&target_proc, stream, 1))) {
ORTE_ERROR_LOG(ret);
goto cleanup;
}
}
/* just wait until the abort is fired */
opal_event_dispatch();
@ -289,6 +299,7 @@ main(int argc, char *argv[])
OBJ_RELEASE(item);
}
OBJ_DESTRUCT(&hnp_list);
opal_argv_free(ranks);
orte_finalize();
return ret;

@ -54,6 +54,7 @@ if !ORTE_DISABLE_FULL_SUPPORT
headers += \
util/context_fns.h \
util/parse_options.h \
util/pre_condition_transports.h \
util/hnp_contact.h \
util/hostfile/hostfile.h \
@ -64,6 +65,7 @@ headers += \
libopen_rte_la_SOURCES += \
util/context_fns.c \
util/parse_options.c \
util/pre_condition_transports.c \
util/hnp_contact.c \
util/hostfile/hostfile_lex.l \

77
orte/util/parse_options.c Обычный файл

@ -0,0 +1,77 @@
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2008 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include "opal/util/argv.h"
#include "orte/util/name_fns.h"
#include "orte/util/parse_options.h"
int orte_util_parse_rank_options(char *input, char ***output)
{
char **r1=NULL, **r2=NULL;
int i, vint;
orte_vpid_t start, end, vpid;
/* split on commas */
r1 = opal_argv_split(input, ',');
/* for each resulting element, check for range */
for (i=0; i < opal_argv_count(r1); i++) {
r2 = opal_argv_split(r1[i], '-');
if (1 < opal_argv_count(r2)) {
/* given range - get start and end */
start = strtol(r2[0], NULL, 10);
end = strtol(r2[1], NULL, 10);
} else {
/* check for wildcard - have to do this here because
* the -1 would have been caught in the split
*/
vint = strtol(r1[i], NULL, 10);
if (-1 == vint) {
opal_argv_free(*output);
opal_argv_append_nosize(output, "-1");
goto cleanup;
}
start = strtol(r2[0], NULL, 10);
end = start + 1;
}
for (vpid = start; vpid < end; vpid++) {
opal_argv_append_nosize(output, ORTE_VPID_PRINT(vpid));
}
}
cleanup:
opal_argv_free(r1);
opal_argv_free(r2);
/* All was good */
return ORTE_SUCCESS;
}

35
orte/util/parse_options.h Обычный файл

@ -0,0 +1,35 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*
*/
#ifndef _ORTE_PARSE_OPTIONS_H_
#define _ORTE_PARSE_OPTIONS_H_
#include "orte_config.h"
#include "orte/types.h"
BEGIN_C_DECLS
ORTE_DECLSPEC int orte_util_parse_rank_options(char *input, char ***output);
END_C_DECLS
#endif