From 66ab9da46925f739e61214d22ac8deec6cb2d889 Mon Sep 17 00:00:00 2001 From: Joshua Hursey Date: Tue, 20 Sep 2016 14:13:50 -0400 Subject: [PATCH 1/2] orte/iof: Add orte_map_stddiag_to_stdout option * Similar to `orte_map_stddiag_to_stderr` except it redirects `stddiag` to `stdout` instead of `stderr`. * Add protection so that the user canot supply both: - `orte_map_stddiag_to_stderr` - `orte_map_stddiag_to_stdout` Signed-off-by: Joshua Hursey (cherry picked from commit dcd9801f7c759cea8af5f2c3b056462972f4853c) Signed-off-by: Joshua Hursey --- opal/mca/base/mca_base_open.c | 9 ++++++++- opal/util/output.c | 9 ++++++++- orte/mca/iof/base/iof_base_setup.c | 6 +++++- orte/mca/plm/base/plm_base_launch_support.c | 5 +++++ orte/runtime/orte_globals.c | 2 ++ orte/runtime/orte_globals.h | 2 ++ orte/runtime/orte_mca_params.c | 13 +++++++++++++ 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/opal/mca/base/mca_base_open.c b/opal/mca/base/mca_base_open.c index 7f14ffaf02e..0e7144ac1a6 100644 --- a/opal/mca/base/mca_base_open.c +++ b/opal/mca/base/mca_base_open.c @@ -13,6 +13,7 @@ * Copyright (c) 2011 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -121,7 +122,13 @@ int mca_base_open(void) MCA_BASE_VAR_SYN_FLAG_DEPRECATED); /* What verbosity level do we want for the default 0 stream? */ - mca_base_verbose = "stderr"; + char *str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT"); + if (NULL != str && str[0] == '1') { + mca_base_verbose = "stdout"; + } + else { + mca_base_verbose = "stderr"; + } var_id = mca_base_var_register("opal", "mca", "base", "verbose", "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:, syslogid: (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)", MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, diff --git a/opal/util/output.c b/opal/util/output.c index b17ce05779d..3bc335f3e21 100644 --- a/opal/util/output.c +++ b/opal/util/output.c @@ -15,6 +15,7 @@ * reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -174,7 +175,13 @@ bool opal_output_init(void) verbose.lds_want_stderr = false; verbose.lds_want_stdout = false; } else { - verbose.lds_want_stderr = true; + str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT"); + if (NULL != str && str[0] == '1') { + verbose.lds_want_stdout = true; + } + else { + verbose.lds_want_stderr = true; + } } gethostname(hostname, sizeof(hostname)); asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid()); diff --git a/orte/mca/iof/base/iof_base_setup.c b/orte/mca/iof/base/iof_base_setup.c index d03895ca9d3..b7325441060 100644 --- a/orte/mca/iof/base/iof_base_setup.c +++ b/orte/mca/iof/base/iof_base_setup.c @@ -10,6 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -181,7 +182,7 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env) close(opts->p_stderr[1]); } - if (!orte_map_stddiag_to_stderr) { + if (!orte_map_stddiag_to_stderr && !orte_map_stddiag_to_stdout ) { /* Set an environment variable that the new child process can use to get the fd of the pipe connected to the INTERNAL IOF tag. */ asprintf(&str, "%d", opts->p_internal[1]); @@ -190,6 +191,9 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env) free(str); } } + else if( orte_map_stddiag_to_stdout ) { + opal_setenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT", "1", true, env); + } return ORTE_SUCCESS; } diff --git a/orte/mca/plm/base/plm_base_launch_support.c b/orte/mca/plm/base/plm_base_launch_support.c index c159fe5757a..61032b0d653 100644 --- a/orte/mca/plm/base/plm_base_launch_support.c +++ b/orte/mca/plm/base/plm_base_launch_support.c @@ -1254,6 +1254,11 @@ int orte_plm_base_orted_append_basic_args(int *argc, char ***argv, opal_argv_append(argc, argv, "orte_map_stddiag_to_stderr"); opal_argv_append(argc, argv, "1"); } + else if (orte_map_stddiag_to_stdout) { + opal_argv_append(argc, argv, "-"OPAL_MCA_CMD_LINE_ID); + opal_argv_append(argc, argv, "orte_map_stddiag_to_stdout"); + opal_argv_append(argc, argv, "1"); + } /* the following is not an mca param */ if (NULL != getenv("ORTE_TEST_ORTED_SUICIDE")) { diff --git a/orte/runtime/orte_globals.c b/orte/runtime/orte_globals.c index b571b127dde..e577a8c50b8 100644 --- a/orte/runtime/orte_globals.c +++ b/orte/runtime/orte_globals.c @@ -16,6 +16,7 @@ * Copyright (c) 2013-2015 Intel, Inc. All rights reserved * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -188,6 +189,7 @@ bool orte_staged_execution = false; /* map stddiag output to stderr so it isn't forwarded to mpirun */ bool orte_map_stddiag_to_stderr = false; +bool orte_map_stddiag_to_stdout = false; /* maximum size of virtual machine - used to subdivide allocation */ int orte_max_vm_size = -1; diff --git a/orte/runtime/orte_globals.h b/orte/runtime/orte_globals.h index bfa4cd63afb..5a9da011f3d 100644 --- a/orte/runtime/orte_globals.h +++ b/orte/runtime/orte_globals.h @@ -14,6 +14,7 @@ * Copyright (c) 2011-2013 Los Alamos National Security, LLC. * All rights reserved. * Copyright (c) 2013-2015 Intel, Inc. All rights reserved + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -572,6 +573,7 @@ ORTE_DECLSPEC extern bool orte_staged_execution; /* map stddiag output to stderr so it isn't forwarded to mpirun */ ORTE_DECLSPEC extern bool orte_map_stddiag_to_stderr; +ORTE_DECLSPEC extern bool orte_map_stddiag_to_stdout; /* maximum size of virtual machine - used to subdivide allocation */ ORTE_DECLSPEC extern int orte_max_vm_size; diff --git a/orte/runtime/orte_mca_params.c b/orte/runtime/orte_mca_params.c index 69c0c7ee02d..012df915939 100644 --- a/orte/runtime/orte_mca_params.c +++ b/orte/runtime/orte_mca_params.c @@ -16,6 +16,7 @@ * Copyright (c) 2013-2015 Intel, Inc. All rights reserved * Copyright (c) 2014 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -523,6 +524,18 @@ int orte_register_params(void) OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &orte_map_stddiag_to_stderr); + /* whether or not to map stddiag to stderr */ + orte_map_stddiag_to_stdout = false; + (void) mca_base_var_register ("orte", "orte", NULL, "map_stddiag_to_stdout", + "Map output from opal_output to stdout of the local process [default: no]", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &orte_map_stddiag_to_stdout); + if( orte_map_stddiag_to_stderr && orte_map_stddiag_to_stdout ) { + 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."); + return ORTE_ERROR; + } + /* generate new terminal windows to display output from specified ranks */ orte_xterm = NULL; (void) mca_base_var_register ("orte", "orte", NULL, "xterm", From 637d32e55582161732754ae71c8fcca7cbfbdb17 Mon Sep 17 00:00:00 2001 From: Joshua Hursey Date: Tue, 20 Sep 2016 12:29:46 -0400 Subject: [PATCH 2/2] orte/iof: Add app stderr to stdout redirection at source * Add an MCA parameter to combine stdout and stderr at the source - `iof_base_redirect_app_stderr_to_stdout` * Aids in user debugging when using libraries that mix stderr with stdout Signed-off-by: Joshua Hursey (cherry picked from commit 0e9a06d2c3c4fa0e4fbbbe32f16c1ee944c20a0c) Signed-off-by: Joshua Hursey --- orte/mca/iof/base/base.h | 1 + orte/mca/iof/base/iof_base_frame.c | 10 ++++++++++ orte/mca/iof/base/iof_base_setup.c | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/orte/mca/iof/base/base.h b/orte/mca/iof/base/base.h index 4dd72e6c623..676a57a2592 100644 --- a/orte/mca/iof/base/base.h +++ b/orte/mca/iof/base/base.h @@ -131,6 +131,7 @@ struct orte_iof_base_t { char *input_files; orte_iof_sink_t *iof_write_stdout; orte_iof_sink_t *iof_write_stderr; + bool redirect_app_stderr_to_stdout; }; typedef struct orte_iof_base_t orte_iof_base_t; diff --git a/orte/mca/iof/base/iof_base_frame.c b/orte/mca/iof/base/iof_base_frame.c index f0018b5cf4c..439c7a451d3 100644 --- a/orte/mca/iof/base/iof_base_frame.c +++ b/orte/mca/iof/base/iof_base_frame.c @@ -14,6 +14,7 @@ * Copyright (c) 2015 Intel, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -204,6 +205,15 @@ static int orte_iof_base_register(mca_base_register_flag_t flags) MCA_BASE_VAR_SCOPE_READONLY, &orte_iof_base.input_files); + /* Redirect application stderr to stdout (at source) */ + orte_iof_base.redirect_app_stderr_to_stdout = false; + (void) mca_base_var_register("orte", "iof","base", "redirect_app_stderr_to_stdout", + "Redirect application stderr to stdout at source (default: false)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, + OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, + &orte_iof_base.redirect_app_stderr_to_stdout); + return ORTE_SUCCESS; } diff --git a/orte/mca/iof/base/iof_base_setup.c b/orte/mca/iof/base/iof_base_setup.c index b7325441060..88b4cd87299 100644 --- a/orte/mca/iof/base/iof_base_setup.c +++ b/orte/mca/iof/base/iof_base_setup.c @@ -66,6 +66,7 @@ #include "orte/runtime/orte_globals.h" #include "orte/mca/iof/iof.h" +#include "orte/mca/iof/base/base.h" #include "orte/mca/iof/base/iof_base_setup.h" int @@ -151,11 +152,19 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env) } ret = dup2(opts->p_stdout[1], fileno(stdout)); if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE; + if( orte_iof_base.redirect_app_stderr_to_stdout ) { + ret = dup2(opts->p_stdout[1], fileno(stderr)); + if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE; + } close(opts->p_stdout[1]); } else { if(opts->p_stdout[1] != fileno(stdout)) { ret = dup2(opts->p_stdout[1], fileno(stdout)); if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE; + if( orte_iof_base.redirect_app_stderr_to_stdout ) { + ret = dup2(opts->p_stdout[1], fileno(stderr)); + if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE; + } close(opts->p_stdout[1]); } } @@ -176,9 +185,12 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env) close(fd); } } + if(opts->p_stderr[1] != fileno(stderr)) { - ret = dup2(opts->p_stderr[1], fileno(stderr)); - if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE; + if( !orte_iof_base.redirect_app_stderr_to_stdout ) { + ret = dup2(opts->p_stderr[1], fileno(stderr)); + if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE; + } close(opts->p_stderr[1]); }