From 3da1787c062ff366d16267b888bd5a518d788410 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Wed, 15 Feb 2012 04:16:05 +0000 Subject: [PATCH] Allow there to be no default hostfile without generating an error This commit was SVN r25930. --- orte/runtime/orte_globals.c | 1 + orte/runtime/orte_globals.h | 1 + orte/runtime/orte_mca_params.c | 18 +++++++++++++----- orte/util/hostfile/hostfile.c | 21 +++++++++++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/orte/runtime/orte_globals.c b/orte/runtime/orte_globals.c index fa920f5aca..733f58f93c 100644 --- a/orte/runtime/orte_globals.c +++ b/orte/runtime/orte_globals.c @@ -150,6 +150,7 @@ bool orte_report_launch_progress = false; /* allocation specification */ char *orte_default_hostfile = NULL; +bool orte_default_hostfile_given = false; char *orte_rankfile = NULL; #ifdef __WINDOWS__ char *orte_ccp_headnode; diff --git a/orte/runtime/orte_globals.h b/orte/runtime/orte_globals.h index 93cc06ea38..c2f71ed2f2 100644 --- a/orte/runtime/orte_globals.h +++ b/orte/runtime/orte_globals.h @@ -615,6 +615,7 @@ ORTE_DECLSPEC extern bool orte_report_launch_progress; /* allocation specification */ ORTE_DECLSPEC extern char *orte_default_hostfile; +ORTE_DECLSPEC extern bool orte_default_hostfile_given; ORTE_DECLSPEC extern char *orte_rankfile; #ifdef __WINDOWS__ ORTE_DECLSPEC extern char *orte_ccp_headnode; diff --git a/orte/runtime/orte_mca_params.c b/orte/runtime/orte_mca_params.c index 95af9231e8..a55b594546 100644 --- a/orte/runtime/orte_mca_params.c +++ b/orte/runtime/orte_mca_params.c @@ -251,15 +251,23 @@ int orte_register_params(void) false, false, 1000, &orte_timeout_usec_per_proc); /* default hostfile */ - asprintf(&orte_default_hostfile, "%s/etc/openmpi-default-hostfile", opal_install_dirs.prefix); mca_base_param_reg_string_name("orte", "default_hostfile", "Name of the default hostfile (relative or absolute path, \"none\" to ignore environmental or default MCA param setting)", - false, false, orte_default_hostfile, &orte_default_hostfile); - if (0 == strcmp(orte_default_hostfile, "none")) { - free(orte_default_hostfile); + false, false, NULL, &strval); + if (NULL == strval) { + /* nothing was given, so define the default */ + asprintf(&orte_default_hostfile, "%s/etc/openmpi-default-hostfile", opal_install_dirs.prefix); + /* flag that nothing was given */ + orte_default_hostfile_given = false; + } else if (0 == strcmp(orte_default_hostfile, "none")) { orte_default_hostfile = NULL; + /* flag that it was given */ + orte_default_hostfile_given = true; + } else { + orte_default_hostfile = strval; + /* flag that it was given */ + orte_default_hostfile_given = true; } - #ifdef __WINDOWS__ mca_base_param_reg_string_name("orte", "ccp_headnode", diff --git a/orte/util/hostfile/hostfile.c b/orte/util/hostfile/hostfile.c index 87eb5413da..aec28395b9 100644 --- a/orte/util/hostfile/hostfile.c +++ b/orte/util/hostfile/hostfile.c @@ -419,8 +419,25 @@ static int hostfile_parse(const char *hostfile, opal_list_t* updates, opal_list_ orte_util_hostfile_done = false; orte_util_hostfile_in = fopen(hostfile, "r"); if (NULL == orte_util_hostfile_in) { - orte_show_help("help-hostfile.txt", "no-hostfile", true, hostfile); - rc = ORTE_ERR_NOT_FOUND; + if (NULL == orte_default_hostfile || + 0 != strcmp(orte_default_hostfile, hostfile)) { + /* not the default hostfile, so not finding it + * is an error + */ + orte_show_help("help-hostfile.txt", "no-hostfile", true, hostfile); + rc = ORTE_ERR_SILENT; + goto unlock; + } + /* if this is the default hostfile and it was given, + * then it's an error + */ + if (orte_default_hostfile_given) { + orte_show_help("help-hostfile.txt", "no-hostfile", true, hostfile); + rc = ORTE_ERR_NOT_FOUND; + goto unlock; + } + /* otherwise, not finding it is okay */ + rc = ORTE_SUCCESS; goto unlock; }