Skip to content

Commit 2e64bf4

Browse files
authored
Merge pull request #2810 from jjhursey/fix/ibm/stdiag-to-stdout
Extend options for stddiag routing
2 parents 770c41f + 0e9a06d commit 2e64bf4

File tree

9 files changed

+69
-5
lines changed

9 files changed

+69
-5
lines changed

opal/mca/base/mca_base_open.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2011 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
1515
* reserved.
16+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -121,7 +122,13 @@ int mca_base_open(void)
121122
MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
122123

123124
/* What verbosity level do we want for the default 0 stream? */
124-
mca_base_verbose = "stderr";
125+
char *str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT");
126+
if (NULL != str && str[0] == '1') {
127+
mca_base_verbose = "stdout";
128+
}
129+
else {
130+
mca_base_verbose = "stderr";
131+
}
125132
var_id = mca_base_var_register("opal", "mca", "base", "verbose",
126133
"Specifies where the default error output stream goes (this is separate from distinct help messages). Accepts a comma-delimited list of: stderr, stdout, syslog, syslogpri:<notice|info|debug>, syslogid:<str> (where str is the prefix string for all syslog notices), file[:filename] (if filename is not specified, a default filename is used), fileappend (if not specified, the file is opened for truncation), level[:N] (if specified, integer verbose level; otherwise, 0 is implied)",
127134
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,

opal/util/output.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* reserved.
1616
* Copyright (c) 2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
18+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1819
* $COPYRIGHT$
1920
*
2021
* Additional copyrights may follow
@@ -174,7 +175,13 @@ bool opal_output_init(void)
174175
verbose.lds_want_stderr = false;
175176
verbose.lds_want_stdout = false;
176177
} else {
177-
verbose.lds_want_stderr = true;
178+
str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT");
179+
if (NULL != str && str[0] == '1') {
180+
verbose.lds_want_stdout = true;
181+
}
182+
else {
183+
verbose.lds_want_stderr = true;
184+
}
178185
}
179186
gethostname(hostname, sizeof(hostname));
180187
asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid());

orte/mca/iof/base/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2012-2013 Los Alamos National Security, LLC.
1414
* All rights reserved.
1515
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
16+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -136,6 +137,7 @@ struct orte_iof_base_t {
136137
char *input_files;
137138
orte_iof_sink_t *iof_write_stdout;
138139
orte_iof_sink_t *iof_write_stderr;
140+
bool redirect_app_stderr_to_stdout;
139141
};
140142
typedef struct orte_iof_base_t orte_iof_base_t;
141143

orte/mca/iof/base/iof_base_frame.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
1515
* Copyright (c) 2015-2017 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1718
* $COPYRIGHT$
1819
*
1920
* Additional copyrights may follow
@@ -79,6 +80,15 @@ static int orte_iof_base_register(mca_base_register_flag_t flags)
7980
MCA_BASE_VAR_SCOPE_READONLY,
8081
&orte_iof_base.input_files);
8182

83+
/* Redirect application stderr to stdout (at source) */
84+
orte_iof_base.redirect_app_stderr_to_stdout = false;
85+
(void) mca_base_var_register("orte", "iof","base", "redirect_app_stderr_to_stdout",
86+
"Redirect application stderr to stdout at source (default: false)",
87+
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
88+
OPAL_INFO_LVL_9,
89+
MCA_BASE_VAR_SCOPE_READONLY,
90+
&orte_iof_base.redirect_app_stderr_to_stdout);
91+
8292
return ORTE_SUCCESS;
8393
}
8494

orte/mca/iof/base/iof_base_setup.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
14+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1415
* $COPYRIGHT$
1516
*
1617
* Additional copyrights may follow
@@ -67,6 +68,7 @@
6768
#include "orte/runtime/orte_globals.h"
6869

6970
#include "orte/mca/iof/iof.h"
71+
#include "orte/mca/iof/base/base.h"
7072
#include "orte/mca/iof/base/iof_base_setup.h"
7173

7274
int
@@ -152,11 +154,19 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
152154
}
153155
ret = dup2(opts->p_stdout[1], fileno(stdout));
154156
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
157+
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
158+
ret = dup2(opts->p_stdout[1], fileno(stderr));
159+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
160+
}
155161
close(opts->p_stdout[1]);
156162
} else {
157163
if(opts->p_stdout[1] != fileno(stdout)) {
158164
ret = dup2(opts->p_stdout[1], fileno(stdout));
159165
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
166+
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
167+
ret = dup2(opts->p_stdout[1], fileno(stderr));
168+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
169+
}
160170
close(opts->p_stdout[1]);
161171
}
162172
}
@@ -177,13 +187,16 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
177187
close(fd);
178188
}
179189
}
190+
180191
if(opts->p_stderr[1] != fileno(stderr)) {
181-
ret = dup2(opts->p_stderr[1], fileno(stderr));
182-
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
192+
if( !orte_iof_base.redirect_app_stderr_to_stdout ) {
193+
ret = dup2(opts->p_stderr[1], fileno(stderr));
194+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
195+
}
183196
close(opts->p_stderr[1]);
184197
}
185198

186-
if (!orte_map_stddiag_to_stderr) {
199+
if (!orte_map_stddiag_to_stderr && !orte_map_stddiag_to_stdout ) {
187200
/* Set an environment variable that the new child process can use
188201
to get the fd of the pipe connected to the INTERNAL IOF tag. */
189202
asprintf(&str, "%d", opts->p_internal[1]);
@@ -192,6 +205,9 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
192205
free(str);
193206
}
194207
}
208+
else if( orte_map_stddiag_to_stdout ) {
209+
opal_setenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT", "1", true, env);
210+
}
195211

196212
return ORTE_SUCCESS;
197213
}

orte/mca/plm/base/plm_base_launch_support.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,11 @@ int orte_plm_base_orted_append_basic_args(int *argc, char ***argv,
13781378
opal_argv_append(argc, argv, "orte_map_stddiag_to_stderr");
13791379
opal_argv_append(argc, argv, "1");
13801380
}
1381+
else if (orte_map_stddiag_to_stdout) {
1382+
opal_argv_append(argc, argv, "-"OPAL_MCA_CMD_LINE_ID);
1383+
opal_argv_append(argc, argv, "orte_map_stddiag_to_stdout");
1384+
opal_argv_append(argc, argv, "1");
1385+
}
13811386

13821387
/* the following is not an mca param */
13831388
if (NULL != getenv("ORTE_TEST_ORTED_SUICIDE")) {

orte/runtime/orte_globals.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
1717
* Copyright (c) 2014-2015 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
19+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1920
* $COPYRIGHT$
2021
*
2122
* Additional copyrights may follow
@@ -184,6 +185,7 @@ char **orte_forwarded_envars = NULL;
184185

185186
/* map stddiag output to stderr so it isn't forwarded to mpirun */
186187
bool orte_map_stddiag_to_stderr = false;
188+
bool orte_map_stddiag_to_stdout = false;
187189

188190
/* maximum size of virtual machine - used to subdivide allocation */
189191
int orte_max_vm_size = -1;

orte/runtime/orte_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Copyright (c) 2011-2013 Los Alamos National Security, LLC.
1515
* All rights reserved.
1616
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
17+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1718
* $COPYRIGHT$
1819
*
1920
* Additional copyrights may follow
@@ -564,6 +565,7 @@ ORTE_DECLSPEC extern char **orte_forwarded_envars;
564565

565566
/* map stddiag output to stderr so it isn't forwarded to mpirun */
566567
ORTE_DECLSPEC extern bool orte_map_stddiag_to_stderr;
568+
ORTE_DECLSPEC extern bool orte_map_stddiag_to_stdout;
567569

568570
/* maximum size of virtual machine - used to subdivide allocation */
569571
ORTE_DECLSPEC extern int orte_max_vm_size;

orte/runtime/orte_mca_params.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
1717
* Copyright (c) 2014 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
19+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1920
* $COPYRIGHT$
2021
*
2122
* Additional copyrights may follow
@@ -545,6 +546,18 @@ int orte_register_params(void)
545546
OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY,
546547
&orte_map_stddiag_to_stderr);
547548

549+
/* whether or not to map stddiag to stderr */
550+
orte_map_stddiag_to_stdout = false;
551+
(void) mca_base_var_register ("orte", "orte", NULL, "map_stddiag_to_stdout",
552+
"Map output from opal_output to stdout of the local process [default: no]",
553+
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
554+
OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY,
555+
&orte_map_stddiag_to_stdout);
556+
if( orte_map_stddiag_to_stderr && orte_map_stddiag_to_stdout ) {
557+
opal_output(0, "The options \"orte_map_stddiag_to_stderr\" and \"orte_map_stddiag_to_stdout\" are mutually exclusive. They cannot both be set to true.");
558+
return ORTE_ERROR;
559+
}
560+
548561
/* generate new terminal windows to display output from specified ranks */
549562
orte_xterm = NULL;
550563
(void) mca_base_var_register ("orte", "orte", NULL, "xterm",

0 commit comments

Comments
 (0)