diff --git a/opal/mca/base/base.h b/opal/mca/base/base.h index 7d31a0277b2..1fdcbd899d7 100644 --- a/opal/mca/base/base.h +++ b/opal/mca/base/base.h @@ -156,7 +156,7 @@ OPAL_DECLSPEC int mca_base_is_component_required(opal_list_t *components_availab /* mca_base_cmd_line.c */ OPAL_DECLSPEC int mca_base_cmd_line_setup(opal_cmd_line_t *cmd); -OPAL_DECLSPEC int mca_base_cmd_line_process_args(char **argv, +OPAL_DECLSPEC int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***app_env, char ***global_env); OPAL_DECLSPEC void mca_base_cmd_line_wrap_args(char **args); diff --git a/opal/mca/base/mca_base_cmd_line.c b/opal/mca/base/mca_base_cmd_line.c index ded9b22e7c6..2a26018c379 100644 --- a/opal/mca/base/mca_base_cmd_line.c +++ b/opal/mca/base/mca_base_cmd_line.c @@ -94,25 +94,29 @@ int mca_base_cmd_line_setup(opal_cmd_line_t *cmd) /* * Look for and handle any -mca options on the command line */ -int mca_base_cmd_line_process_args(char **argv, +int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***context_env, char ***global_env) { - int i, rc; + int i, num_insts, rc; char **params; char **values; + /* If no relevant parameters were given, just return */ + + if (!opal_cmd_line_is_taken(cmd, OPAL_MCA_CMD_LINE_ID) && + !opal_cmd_line_is_taken(cmd, "g"OPAL_MCA_CMD_LINE_ID)) { + return OPAL_SUCCESS; + } + + /* Handle app context-specific parameters */ + + num_insts = opal_cmd_line_get_ninsts(cmd, OPAL_MCA_CMD_LINE_ID); params = values = NULL; - for (i = 0; NULL != argv[i]; ++i) { - if (0 == strcmp("-"OPAL_MCA_CMD_LINE_ID, argv[i]) || - 0 == strcmp("--"OPAL_MCA_CMD_LINE_ID, argv[i])) { - if (NULL == argv[i+1] || NULL == argv[i+2]) { - return OPAL_ERR_BAD_PARAM; - } - if (OPAL_SUCCESS != (rc = process_arg(argv[i+1], argv[i+2], - ¶ms, &values))) { - return rc; - } - i += 2; + for (i = 0; i < num_insts; ++i) { + if (OPAL_SUCCESS != (rc = process_arg(opal_cmd_line_get_param(cmd, OPAL_MCA_CMD_LINE_ID, i, 0), + opal_cmd_line_get_param(cmd, OPAL_MCA_CMD_LINE_ID, i, 1), + ¶ms, &values))) { + return rc; } } if (NULL != params) { @@ -121,19 +125,15 @@ int mca_base_cmd_line_process_args(char **argv, opal_argv_free(values); } + /* Handle global parameters */ + num_insts = opal_cmd_line_get_ninsts(cmd, "g"OPAL_MCA_CMD_LINE_ID); params = values = NULL; - for (i = 0; NULL != argv[i]; ++i) { - if (0 == strcmp("-g"OPAL_MCA_CMD_LINE_ID, argv[i]) || - 0 == strcmp("--g"OPAL_MCA_CMD_LINE_ID, argv[i])) { - if (NULL == argv[i+1] || NULL == argv[i+2]) { - return OPAL_ERR_BAD_PARAM; - } - if (OPAL_SUCCESS != (rc = process_arg(argv[i+1], argv[i+2], - ¶ms, &values))) { - return rc; - } - i += 2; + for (i = 0; i < num_insts; ++i) { + if (OPAL_SUCCESS != (rc = process_arg(opal_cmd_line_get_param(cmd, "g"OPAL_MCA_CMD_LINE_ID, i, 0), + opal_cmd_line_get_param(cmd, "g"OPAL_MCA_CMD_LINE_ID, i, 1), + ¶ms, &values))) { + return rc; } } if (NULL != params) { @@ -148,6 +148,7 @@ int mca_base_cmd_line_process_args(char **argv, } + /* * Process a single MCA argument. */ diff --git a/opal/runtime/opal_info_support.c b/opal/runtime/opal_info_support.c index 0db87893218..3f4694ce27e 100644 --- a/opal/runtime/opal_info_support.c +++ b/opal/runtime/opal_info_support.c @@ -207,7 +207,7 @@ int opal_info_init(int argc, char **argv, exit(cmd_error ? 1 : 0); } - mca_base_cmd_line_process_args(argv, &app_env, &global_env); + mca_base_cmd_line_process_args(opal_info_cmd_line, &app_env, &global_env); /* set the flags */ diff --git a/orte/mca/rmaps/base/rmaps_base_map_job.c b/orte/mca/rmaps/base/rmaps_base_map_job.c index 9bfc09df2a9..088e0afb29a 100644 --- a/orte/mca/rmaps/base/rmaps_base_map_job.c +++ b/orte/mca/rmaps/base/rmaps_base_map_job.c @@ -49,7 +49,6 @@ void orte_rmaps_base_map_job(int fd, short args, void *cbdata) { orte_job_t *jdata; - orte_job_map_t *map; orte_node_t *node; int rc, i; bool did_map, given; @@ -113,94 +112,21 @@ void orte_rmaps_base_map_job(int fd, short args, void *cbdata) } } - /* NOTE: CHECK FOR JDATA->MAP == NULL. IF IT IS, THEN USE - * THE VALUES THAT WERE READ BY THE LOCAL MCA PARAMS. THE - * PLM PROXY WILL SEND A JOB-OBJECT THAT WILL INCLUDE ANY - * MAPPING DIRECTIVES - OTHERWISE, THAT OBJECT WILL HAVE A - * NULL MAP FIELD - * LONE EXCEPTION - WE COPY DISPLAY MAP ACROSS IF THEY - * DIDN'T SET IT - */ - if (NULL == jdata->map) { - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps: creating new map for job %s", - ORTE_JOBID_PRINT(jdata->jobid)); - /* create a map object where we will store the results */ - map = OBJ_NEW(orte_job_map_t); - if (NULL == map) { - ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); - ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE); - OBJ_RELEASE(caddy); - return; - } - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps: nprocs %s", - ORTE_VPID_PRINT(nprocs)); + + opal_output_verbose(5, orte_rmaps_base_framework.framework_output, + "mca:rmaps: setting mapping policies for job %s", + ORTE_JOBID_PRINT(jdata->jobid)); + + if (!jdata->map->display_map) { + jdata->map->display_map = orte_rmaps_base.display_map; + } + /* set the default mapping policy IFF it wasn't provided */ + if (!ORTE_MAPPING_POLICY_IS_SET(jdata->map->mapping)) { if (ORTE_MAPPING_GIVEN & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps mapping given - using default"); - map->mapping = orte_rmaps_base.mapping; + "mca:rmaps mapping given by MCA param"); + jdata->map->mapping = orte_rmaps_base.mapping; } else { - /* default based on number of procs */ - if (nprocs <= 2) { - if (1 < orte_rmaps_base.cpus_per_rank) { - /* assigning multiple cpus to a rank requires that we map to - * objects that have multiple cpus in them, so default - * to byslot if nothing else was specified by the user. - */ - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps[%d] mapping not given - using byslot", __LINE__); - ORTE_SET_MAPPING_POLICY(map->mapping, ORTE_MAPPING_BYSLOT); - } else if (opal_hwloc_use_hwthreads_as_cpus) { - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps[%d] mapping not given - using byhwthread", __LINE__); - ORTE_SET_MAPPING_POLICY(map->mapping, ORTE_MAPPING_BYHWTHREAD); - } else { - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps[%d] mapping not given - using bycore", __LINE__); - ORTE_SET_MAPPING_POLICY(map->mapping, ORTE_MAPPING_BYCORE); - } - } else { - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps[%d] mapping not given - using bysocket", __LINE__); - ORTE_SET_MAPPING_POLICY(map->mapping, ORTE_MAPPING_BYSOCKET); - } - /* check for oversubscribe directives */ - if (!(ORTE_MAPPING_SUBSCRIBE_GIVEN & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping))) { - ORTE_SET_MAPPING_DIRECTIVE(map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); - } else { - /* pass along the directive */ - if (ORTE_MAPPING_NO_OVERSUBSCRIBE & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { - ORTE_SET_MAPPING_DIRECTIVE(map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); - } else { - ORTE_UNSET_MAPPING_DIRECTIVE(map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); - } - } - /* check for no-use-local directive */ - if (ORTE_MAPPING_NO_USE_LOCAL & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { - ORTE_SET_MAPPING_DIRECTIVE(map->mapping, ORTE_MAPPING_NO_USE_LOCAL); - } - } - /* ranking was already handled, so just use it here */ - map->ranking = orte_rmaps_base.ranking; - - if (NULL != orte_rmaps_base.ppr) { - map->ppr = strdup(orte_rmaps_base.ppr); - } - map->cpus_per_rank = orte_rmaps_base.cpus_per_rank; - map->display_map = orte_rmaps_base.display_map; - /* assign the map object to this job */ - jdata->map = map; - } else { - opal_output_verbose(5, orte_rmaps_base_framework.framework_output, - "mca:rmaps: setting mapping policies for job %s", - ORTE_JOBID_PRINT(jdata->jobid)); - - if (!jdata->map->display_map) { - jdata->map->display_map = orte_rmaps_base.display_map; - } - /* set the default mapping policy IFF it wasn't provided */ - if (!ORTE_MAPPING_POLICY_IS_SET(jdata->map->mapping)) { /* default based on number of procs */ if (nprocs <= 2) { if (1 < orte_rmaps_base.cpus_per_rank) { @@ -226,26 +152,33 @@ void orte_rmaps_base_map_job(int fd, short args, void *cbdata) ORTE_SET_MAPPING_POLICY(jdata->map->mapping, ORTE_MAPPING_BYSOCKET); } } - /* check for oversubscribe directives */ - if (!(ORTE_MAPPING_SUBSCRIBE_GIVEN & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping))) { + } + /* check for oversubscribe directives */ + if (!(ORTE_MAPPING_SUBSCRIBE_GIVEN & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping))) { + ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); + } else { + /* pass along the directive */ + if (ORTE_MAPPING_NO_OVERSUBSCRIBE & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); } else { - /* pass along the directive */ - if (ORTE_MAPPING_NO_OVERSUBSCRIBE & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { - ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); - } else { - ORTE_UNSET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); - } - } - /* check for no-use-local directive */ - if (ORTE_MAPPING_NO_USE_LOCAL & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { - ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_USE_LOCAL); - } - /* ditto for rank and bind policies */ - if (!ORTE_RANKING_POLICY_IS_SET(jdata->map->ranking)) { - jdata->map->ranking = orte_rmaps_base.ranking; + ORTE_UNSET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); } } + /* check for no-use-local directive */ + if (ORTE_MAPPING_NO_USE_LOCAL & ORTE_GET_MAPPING_DIRECTIVE(orte_rmaps_base.mapping)) { + ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_USE_LOCAL); + } + /* ditto for rank policy */ + if (!ORTE_RANKING_POLICY_IS_SET(jdata->map->ranking)) { + jdata->map->ranking = orte_rmaps_base.ranking; + } + + if (NULL == jdata->map->ppr && NULL != orte_rmaps_base.ppr) { + jdata->map->ppr = strdup(orte_rmaps_base.ppr); + } + if (0 == jdata->map->cpus_per_rank) { + jdata->map->cpus_per_rank = orte_rmaps_base.cpus_per_rank; + } /* define the binding policy for this job - if the user specified one * already (e.g., during the call to comm_spawn), then we don't diff --git a/orte/mca/schizo/ompi/schizo_ompi.c b/orte/mca/schizo/ompi/schizo_ompi.c index 786d166bd64..dfc3999908b 100644 --- a/orte/mca/schizo/ompi/schizo_ompi.c +++ b/orte/mca/schizo/ompi/schizo_ompi.c @@ -74,22 +74,22 @@ orte_schizo_base_module_t orte_schizo_ompi_module = { static opal_cmd_line_init_t cmd_line_init[] = { /* Various "obvious" options */ { NULL, 'h', NULL, "help", 0, - &orte_cmd_line.help, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.help, OPAL_CMD_LINE_TYPE_BOOL, "This help message" }, { NULL, 'V', NULL, "version", 0, - &orte_cmd_line.version, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.version, OPAL_CMD_LINE_TYPE_BOOL, "Print version and exit" }, { NULL, 'v', NULL, "verbose", 0, - &orte_cmd_line.verbose, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.verbose, OPAL_CMD_LINE_TYPE_BOOL, "Be verbose" }, { "orte_execute_quiet", 'q', NULL, "quiet", 0, NULL, OPAL_CMD_LINE_TYPE_BOOL, "Suppress helpful messages" }, { NULL, '\0', "report-pid", "report-pid", 1, - &orte_cmd_line.report_pid, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.report_pid, OPAL_CMD_LINE_TYPE_STRING, "Printout pid on stdout [-], stderr [+], or a file [anything else]" }, { NULL, '\0', "report-uri", "report-uri", 1, - &orte_cmd_line.report_uri, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.report_uri, OPAL_CMD_LINE_TYPE_STRING, "Printout URI on stdout [-], stderr [+], or a file [anything else]" }, /* exit status reporting */ @@ -99,7 +99,7 @@ static opal_cmd_line_init_t cmd_line_init[] = { /* uri of the dvm, or at least where to get it */ { NULL, '\0', "hnp", "hnp", 1, - &orte_cmd_line.hnp, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.hnp, OPAL_CMD_LINE_TYPE_STRING, "Specify the URI of the HNP, or the name of the file (specified as file:filename) that contains that info" }, /* hetero apps */ @@ -117,16 +117,16 @@ static opal_cmd_line_init_t cmd_line_init[] = { /* tag output */ { "orte_tag_output", '\0', "tag-output", "tag-output", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.tag_output, OPAL_CMD_LINE_TYPE_BOOL, "Tag all output with [job,rank]" }, { "orte_timestamp_output", '\0', "timestamp-output", "timestamp-output", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.timestamp_output, OPAL_CMD_LINE_TYPE_BOOL, "Timestamp all application process output" }, { "orte_output_filename", '\0', "output-filename", "output-filename", 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.output_filename, OPAL_CMD_LINE_TYPE_STRING, "Redirect output from application processes into filename/job/rank/std[out,err,diag]" }, { NULL, '\0', "merge-stderr-to-stdout", "merge-stderr-to-stdout", 0, - &orte_cmd_line.merge, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.merge, OPAL_CMD_LINE_TYPE_BOOL, "Merge stderr to stdout for each process"}, { "orte_xterm", '\0', "xterm", "xterm", 1, NULL, OPAL_CMD_LINE_TYPE_STRING, @@ -134,12 +134,12 @@ static opal_cmd_line_init_t cmd_line_init[] = { /* select stdin option */ { NULL, '\0', "stdin", "stdin", 1, - &orte_cmd_line.stdin_target, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.stdin_target, OPAL_CMD_LINE_TYPE_STRING, "Specify procs to receive stdin [rank, all, none] (default: 0, indicating rank 0)" }, /* request that argv[0] be indexed */ { NULL, '\0', "index-argv-by-rank", "index-argv-by-rank", 0, - &orte_cmd_line.index_argv, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.index_argv, OPAL_CMD_LINE_TYPE_BOOL, "Uniquely index argv[0] for each process using its rank" }, /* Specify the launch agent to be used */ @@ -149,33 +149,33 @@ static opal_cmd_line_init_t cmd_line_init[] = { /* Preload the binary on the remote machine */ { NULL, 's', NULL, "preload-binary", 0, - &orte_cmd_line.preload_binaries, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.preload_binaries, OPAL_CMD_LINE_TYPE_BOOL, "Preload the binary on the remote machine before starting the remote process." }, /* Preload files on the remote machine */ { NULL, '\0', NULL, "preload-files", 1, - &orte_cmd_line.preload_files, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.preload_files, OPAL_CMD_LINE_TYPE_STRING, "Preload the comma separated list of files to the remote machines current working directory before starting the remote process." }, #if OPAL_ENABLE_FT_CR == 1 /* Tell SStore to preload a snapshot before launch */ { NULL, '\0', NULL, "sstore-load", 1, - &orte_cmd_line.sstore_load, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.sstore_load, OPAL_CMD_LINE_TYPE_STRING, "Internal Use Only! Tell SStore to preload a snapshot before launch." }, #endif /* Use an appfile */ { NULL, '\0', NULL, "app", 1, - &orte_cmd_line.appfile, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.appfile, OPAL_CMD_LINE_TYPE_STRING, "Provide an appfile; ignore all other command line options" }, /* Number of processes; -c, -n, --n, -np, and --np are all synonyms */ { NULL, 'c', "np", "np", 1, - &orte_cmd_line.num_procs, OPAL_CMD_LINE_TYPE_INT, + &orte_cmd_options.num_procs, OPAL_CMD_LINE_TYPE_INT, "Number of processes to run" }, { NULL, '\0', "n", "n", 1, - &orte_cmd_line.num_procs, OPAL_CMD_LINE_TYPE_INT, + &orte_cmd_options.num_procs, OPAL_CMD_LINE_TYPE_INT, "Number of processes to run" }, /* maximum size of VM - typically used to subdivide an allocation */ @@ -233,19 +233,19 @@ static opal_cmd_line_init_t cmd_line_init[] = { NULL, OPAL_CMD_LINE_TYPE_STRING, "List of hosts to invoke processes on" }, { "rmaps_base_no_schedule_local", '\0', "nolocal", "nolocal", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.nolocal, OPAL_CMD_LINE_TYPE_BOOL, "Do not run any MPI applications on the local node" }, { "rmaps_base_no_oversubscribe", '\0', "nooversubscribe", "nooversubscribe", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.no_oversubscribe, OPAL_CMD_LINE_TYPE_BOOL, "Nodes are not to be oversubscribed, even if the system supports such operation"}, { "rmaps_base_oversubscribe", '\0', "oversubscribe", "oversubscribe", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.oversubscribe, OPAL_CMD_LINE_TYPE_BOOL, "Nodes are allowed to be oversubscribed, even on a managed system, and overloading of processing elements"}, { "rmaps_base_cpus_per_rank", '\0', "cpus-per-proc", "cpus-per-proc", 1, - NULL, OPAL_CMD_LINE_TYPE_INT, + &orte_cmd_options.cpus_per_proc, OPAL_CMD_LINE_TYPE_INT, "Number of cpus to use for each process [default=1]" }, { "rmaps_base_cpus_per_rank", '\0', "cpus-per-rank", "cpus-per-rank", 1, - NULL, OPAL_CMD_LINE_TYPE_INT, + &orte_cmd_options.cpus_per_proc, OPAL_CMD_LINE_TYPE_INT, "Synonym for cpus-per-proc" }, /* backward compatiblity */ @@ -284,17 +284,17 @@ static opal_cmd_line_init_t cmd_line_init[] = { /* Mapping options */ { "rmaps_base_mapping_policy", '\0', NULL, "map-by", 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.mapping_policy, OPAL_CMD_LINE_TYPE_STRING, "Mapping Policy [slot | hwthread | core | socket (default) | numa | board | node]" }, /* Ranking options */ { "rmaps_base_ranking_policy", '\0', NULL, "rank-by", 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.ranking_policy, OPAL_CMD_LINE_TYPE_STRING, "Ranking Policy [slot (default) | hwthread | core | socket | numa | board | node]" }, /* Binding options */ { "hwloc_base_binding_policy", '\0', NULL, "bind-to", 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.binding_policy, OPAL_CMD_LINE_TYPE_STRING, "Policy for binding processes. Allowed values: none, hwthread, core, l1cache, l2cache, l3cache, socket, numa, board (\"none\" is the default when oversubscribed, \"core\" is the default when np<=2, and \"socket\" is the default when np>2). Allowed qualifiers: overload-allowed, if-supported" }, /* backward compatiblity */ @@ -306,12 +306,12 @@ static opal_cmd_line_init_t cmd_line_init[] = { "Bind processes to sockets" }, { "hwloc_base_report_bindings", '\0', "report-bindings", "report-bindings", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.report_bindings, OPAL_CMD_LINE_TYPE_BOOL, "Whether to report process bindings to stderr" }, /* slot list option */ { "hwloc_base_slot_list", '\0', "slot-list", "slot-list", 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.slot_list, OPAL_CMD_LINE_TYPE_STRING, "List of processor IDs to bind processes to [default=NULL]"}, /* generalized pattern mapping option */ @@ -332,24 +332,24 @@ static opal_cmd_line_init_t cmd_line_init[] = { /* mpiexec-like arguments */ { NULL, '\0', "wdir", "wdir", 1, - &orte_cmd_line.wdir, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.wdir, OPAL_CMD_LINE_TYPE_STRING, "Set the working directory of the started processes" }, { NULL, '\0', "wd", "wd", 1, - &orte_cmd_line.wdir, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.wdir, OPAL_CMD_LINE_TYPE_STRING, "Synonym for --wdir" }, { NULL, '\0', "set-cwd-to-session-dir", "set-cwd-to-session-dir", 0, - &orte_cmd_line.set_cwd_to_session_dir, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.set_cwd_to_session_dir, OPAL_CMD_LINE_TYPE_BOOL, "Set the working directory of the started processes to their session directory" }, { NULL, '\0', "path", "path", 1, - &orte_cmd_line.path, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.path, OPAL_CMD_LINE_TYPE_STRING, "PATH to be used to look for executables to start processes" }, /* User-level debugger arguments */ { NULL, '\0', "tv", "tv", 0, - &orte_cmd_line.debugger, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.debugger, OPAL_CMD_LINE_TYPE_BOOL, "Deprecated backwards compatibility flag; synonym for \"--debug\"" }, { NULL, '\0', "debug", "debug", 0, - &orte_cmd_line.debugger, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.debugger, OPAL_CMD_LINE_TYPE_BOOL, "Invoke the user-level debugger indicated by the orte_base_user_debugger MCA parameter" }, { "orte_base_user_debugger", '\0', "debugger", "debugger", 1, NULL, OPAL_CMD_LINE_TYPE_STRING, @@ -399,7 +399,7 @@ static opal_cmd_line_init_t cmd_line_init[] = { "Report events to a tool listening at the specified URI" }, { "orte_enable_recovery", '\0', "enable-recovery", "enable-recovery", 0, - NULL, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.enable_recovery, OPAL_CMD_LINE_TYPE_BOOL, "Enable recovery from process failure [Default = disabled]" }, { "orte_max_restarts", '\0', "max-restarts", "max-restarts", 1, @@ -417,7 +417,7 @@ static opal_cmd_line_init_t cmd_line_init[] = { #endif { NULL, '\0', "disable-recovery", "disable-recovery", 0, - &orte_cmd_line.disable_recovery, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.disable_recovery, OPAL_CMD_LINE_TYPE_BOOL, "Disable recovery (resets all recovery options to off)" }, { "state_novm_select", '\0', "novm", "novm", 0, @@ -425,24 +425,24 @@ static opal_cmd_line_init_t cmd_line_init[] = { "Execute without creating an allocation-spanning virtual machine (only start daemons on nodes hosting application procs)" }, { NULL, '\0', "staged", "staged", 0, - &orte_cmd_line.staged_exec, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.staged_exec, OPAL_CMD_LINE_TYPE_BOOL, "Used staged execution if inadequate resources are present (cannot support MPI jobs)" }, { NULL, '\0', "allow-run-as-root", "allow-run-as-root", 0, - &orte_cmd_line.run_as_root, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.run_as_root, OPAL_CMD_LINE_TYPE_BOOL, "Allow execution as root (STRONGLY DISCOURAGED)" }, { NULL, '\0', "personality", "personality", 1, - &orte_cmd_line.personality, OPAL_CMD_LINE_TYPE_STRING, + &orte_cmd_options.personality, OPAL_CMD_LINE_TYPE_STRING, "Comma-separated list of programming model, languages, and containers being used (default=\"ompi\")" }, { NULL, '\0', "dvm", "dvm", 0, - &orte_cmd_line.create_dvm, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.create_dvm, OPAL_CMD_LINE_TYPE_BOOL, "Create a persistent distributed virtual machine (DVM)" }, /* tell the dvm to terminate */ { NULL, '\0', "terminate", "terminate", 0, - &orte_cmd_line.terminate_dvm, OPAL_CMD_LINE_TYPE_BOOL, + &orte_cmd_options.terminate_dvm, OPAL_CMD_LINE_TYPE_BOOL, "Terminate the DVM" }, /* End of list */ diff --git a/orte/orted/orted_main.c b/orte/orted/orted_main.c index 12452aac117..3ced75ff216 100644 --- a/orte/orted/orted_main.c +++ b/orte/orted/orted_main.c @@ -263,7 +263,7 @@ int orte_daemon(int argc, char *argv[]) * Since this process can now handle MCA/GMCA parameters, make sure to * process them. */ - mca_base_cmd_line_process_args(argv, &environ, &environ); + mca_base_cmd_line_process_args(cmd_line, &environ, &environ); /* Ensure that enough of OPAL is setup for us to be able to run */ /* diff --git a/orte/orted/orted_submit.c b/orte/orted/orted_submit.c index 281e3071a5d..4c440ec298c 100644 --- a/orte/orted/orted_submit.c +++ b/orte/orted/orted_submit.c @@ -92,14 +92,13 @@ #include "orte/mca/rml/rml.h" #include "orte/mca/rml/base/rml_contact.h" #include "orte/mca/routed/routed.h" -#include "orte/mca/schizo/schizo.h" +#include "orte/mca/schizo/base/base.h" #include "orte/mca/state/state.h" #include "orte/runtime/runtime.h" #include "orte/runtime/orte_globals.h" #include "orte/runtime/orte_wait.h" #include "orte/runtime/orte_quit.h" -#include "orte/util/cmd_line.h" #include "orte/util/pre_condition_transports.h" #include "orte/util/show_help.h" @@ -108,13 +107,13 @@ /** * Global struct for catching orte command line options. */ -orte_cmd_line_t orte_cmd_line = {0}; +orte_cmd_options_t orte_cmd_options = {0}; +opal_cmd_line_t *orte_cmd_line = NULL; static char **global_mca_env = NULL; static orte_std_cntr_t total_num_apps = 0; static bool want_prefix_by_default = (bool) ORTE_WANT_ORTERUN_PREFIX_BY_DEFAULT; static opal_pointer_array_t tool_jobs; -static opal_cmd_line_t *cmd_line=NULL; static bool mycmdline = false; int orte_debugger_attach_fd = -1; bool orte_debugger_fifo_active=false; @@ -203,38 +202,22 @@ static OBJ_CLASS_INSTANCE(trackr_t, int orte_submit_init(int argc, char *argv[], opal_cmd_line_t *opts) { - int rc; - bool version, help; + int rc, i; char *param; - OBJ_CONSTRUCT(&tool_jobs, opal_pointer_array_t); - opal_pointer_array_init(&tool_jobs, 256, INT_MAX, 128); + /* init the globals */ + memset(&orte_cmd_options, 0, sizeof(orte_cmd_options)); /* find our basename (the name of the executable) so that we can use it in pretty-print error messages */ orte_basename = opal_basename(argv[0]); - /* setup the cmd line only once */ - if (NULL != opts) { - /* just add the component-defined ones to the end */ - if (OPAL_SUCCESS != (rc = orte_schizo.define_cli(opts))) { - return rc; - } - cmd_line = opts; - mycmdline = false; - } else { - /* create our own */ - cmd_line = OBJ_NEW(opal_cmd_line_t); - rc = orte_cmd_line_create(cmd_line, argc, argv, - &environ, &environ, - &version, &help); - if (ORTE_SUCCESS != rc) { - OBJ_RELEASE(cmd_line); - return rc; - } - /* print version if requested. Do this before check for help so - that --version --help works as one might expect. */ - if (version) { + /* see if print version is requested. Do this before + * check for help so that --version --help works as + * one might expect. */ + for (i=0; NULL != argv[i]; i++) { + if (0 == strcmp(argv[i], "--version") || + 0 == strcmp(argv[i], "-V")) { char *str, *project_name = NULL; if (0 == strcmp(orte_basename, "mpirun")) { project_name = "Open MPI"; @@ -253,69 +236,149 @@ int orte_submit_init(int argc, char *argv[], } exit(0); } + } + + /* init only the util portion of OPAL */ + if (OPAL_SUCCESS != (rc = opal_init_util(&argc, &argv))) { + return rc; + } + /* open the SCHIZO framework so we can setup the command line */ + if (ORTE_SUCCESS != (rc = mca_base_framework_open(&orte_schizo_base_framework, 0))) { + ORTE_ERROR_LOG(rc); + return rc; + } + if (ORTE_SUCCESS != (rc = orte_schizo_base_select())) { + ORTE_ERROR_LOG(rc); + return rc; + } + + OBJ_CONSTRUCT(&tool_jobs, opal_pointer_array_t); + opal_pointer_array_init(&tool_jobs, 256, INT_MAX, 128); + + /* setup the cmd line only once */ + if (NULL != opts) { + /* just add the component-defined ones to the end */ + if (OPAL_SUCCESS != (rc = orte_schizo.define_cli(opts))) { + return rc; + } + orte_cmd_line = opts; + mycmdline = false; + } else { + + /* have to create the cmd line next as even --help + * will need it */ + orte_cmd_line = OBJ_NEW(opal_cmd_line_t); + if (OPAL_SUCCESS != (rc = orte_schizo.define_cli(orte_cmd_line))) { + OBJ_RELEASE(orte_cmd_line); + return rc; + } mycmdline = true; } + /* now that options have been defined, finish setup */ + mca_base_cmd_line_setup(orte_cmd_line); + + /* parse the result to get values */ + if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(orte_cmd_line, + true, argc, argv)) ) { + if (OPAL_ERR_SILENT != rc) { + fprintf(stderr, "%s: command line error (%s)\n", argv[0], + opal_strerror(rc)); + } + return rc; + } + + /* check if we are running as root - if we are, then only allow + * us to proceed if the allow-run-as-root flag was given. Otherwise, + * exit with a giant warning flag + */ + if (0 == geteuid() && !orte_cmd_options.run_as_root) { + fprintf(stderr, "--------------------------------------------------------------------------\n"); + if (orte_cmd_options.help) { + fprintf(stderr, "%s cannot provide the help message when run as root.\n", orte_basename); + } else { + /* show_help is not yet available, so print an error manually */ + fprintf(stderr, "%s has detected an attempt to run as root.\n", orte_basename); + } + fprintf(stderr, "Running at root is *strongly* discouraged as any mistake (e.g., in\n"); + fprintf(stderr, "defining TMPDIR) or bug can result in catastrophic damage to the OS\n"); + fprintf(stderr, "file system, leaving your system in an unusable state.\n\n"); + fprintf(stderr, "You can override this protection by adding the --allow-run-as-root\n"); + fprintf(stderr, "option to your cmd line. However, we reiterate our strong advice\n"); + fprintf(stderr, "against doing so - please do so at your own risk.\n"); + fprintf(stderr, "--------------------------------------------------------------------------\n"); + exit(1); + } + + /* process any mca params */ + rc = mca_base_cmd_line_process_args(orte_cmd_line, &environ, &environ); + if (ORTE_SUCCESS != rc) { + return rc; + } + /* Need to initialize OPAL so that install_dirs are filled in */ if (OPAL_SUCCESS != (rc = opal_init(&argc, &argv))) { return rc; } /* Check for help request */ - if (help) { - char *str, *args = NULL; - char *project_name = NULL; - if (0 == strcmp(orte_basename, "mpirun")) { - project_name = "Open MPI"; - } else { - project_name = "OpenRTE"; - } - args = opal_cmd_line_get_usage_msg(cmd_line); - str = opal_show_help_string("help-orterun.txt", "orterun:usage", false, - orte_basename, project_name, OPAL_VERSION, - orte_basename, args, - PACKAGE_BUGREPORT); - if (NULL != str) { - printf("%s", str); - free(str); + for (i=0; NULL != argv[i]; i++) { + if (0 == strcmp(argv[i], "--help") || + 0 == strcmp(argv[i], "-h")) { + char *str, *args = NULL; + char *project_name = NULL; + if (0 == strcmp(orte_basename, "mpirun")) { + project_name = "Open MPI"; + } else { + project_name = "OpenRTE"; + } + args = opal_cmd_line_get_usage_msg(orte_cmd_line); + str = opal_show_help_string("help-orterun.txt", "orterun:usage", false, + orte_basename, project_name, OPAL_VERSION, + orte_basename, args, + PACKAGE_BUGREPORT); + if (NULL != str) { + printf("%s", str); + free(str); + } + free(args); + /* If someone asks for help, that should be all we do */ + exit(0); } - free(args); - /* If someone asks for help, that should be all we do */ - exit(0); } - /* set the flags - if they gave us a -hnp option, then + /* set the flags - if they gave us a -hnp option, then * we are a tool. If not, then we are an HNP */ - if (NULL == orte_cmd_line.hnp) { + if (NULL == orte_cmd_options.hnp) { orte_process_info.proc_type = ORTE_PROC_HNP; } else { orte_process_info.proc_type = ORTE_PROC_TOOL; } if (ORTE_PROC_IS_TOOL) { - if (0 == strncasecmp(orte_cmd_line.hnp, "file", strlen("file"))) { + if (0 == strncasecmp(orte_cmd_options.hnp, "file", strlen("file"))) { char input[1024], *filename; FILE *fp; /* it is a file - get the filename */ - filename = strchr(orte_cmd_line.hnp, ':'); + filename = strchr(orte_cmd_options.hnp, ':'); if (NULL == filename) { /* filename is not correctly formatted */ - orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-bad", true, "uri", orte_cmd_line.hnp); + orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-bad", true, "uri", orte_cmd_options.hnp); exit(1); } ++filename; /* space past the : */ if (0 >= strlen(filename)) { /* they forgot to give us the name! */ - orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-bad", true, "uri", orte_cmd_line.hnp); + orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-bad", true, "uri", orte_cmd_options.hnp); exit(1); } /* open the file and extract the uri */ fp = fopen(filename, "r"); if (NULL == fp) { /* can't find or read file! */ - orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-access", true, orte_cmd_line.hnp); + orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-access", true, orte_cmd_options.hnp); exit(1); } /* initialize the input to NULLs to ensure any input @@ -324,7 +387,7 @@ int orte_submit_init(int argc, char *argv[], if (NULL == fgets(input, 1024, fp)) { /* something malformed about file */ fclose(fp); - orte_show_help("help-orte-top.txt", "orte-top:hnp-file-bad", true, orte_cmd_line.hnp); + orte_show_help("help-orte-top.txt", "orte-top:hnp-file-bad", true, orte_cmd_options.hnp); exit(1); } fclose(fp); @@ -333,7 +396,7 @@ int orte_submit_init(int argc, char *argv[], opal_setenv(OPAL_MCA_PREFIX"orte_hnp_uri", input, true, &environ); } else { /* should just be the uri itself - construct the target hnp info */ - opal_setenv(OPAL_MCA_PREFIX"orte_hnp_uri", orte_cmd_line.hnp, true, &environ); + opal_setenv(OPAL_MCA_PREFIX"orte_hnp_uri", orte_cmd_options.hnp, true, &environ); } /* we are never allowed to operate as a distributed tool, * so insist on the ess/tool component */ @@ -349,41 +412,42 @@ int orte_submit_init(int argc, char *argv[], * in the global struct as the app_file parser would replace it. * So handle this specific cmd line option manually. */ - orte_cmd_line.prefix = NULL; - orte_cmd_line.path_to_mpirun = NULL; - if (opal_cmd_line_is_taken(cmd_line, "prefix") || + orte_cmd_options.prefix = NULL; + orte_cmd_options.path_to_mpirun = NULL; + if (opal_cmd_line_is_taken(orte_cmd_line, "prefix") || '/' == argv[0][0] || want_prefix_by_default) { size_t param_len; if ('/' == argv[0][0]) { char* tmp_basename = NULL; /* If they specified an absolute path, strip off the /bin/" and leave just the prefix */ - orte_cmd_line.path_to_mpirun = opal_dirname(argv[0]); + orte_cmd_options.path_to_mpirun = opal_dirname(argv[0]); /* Quick sanity check to ensure we got something/bin/ and that the installation tree is at least more or less what we expect it to be */ - tmp_basename = opal_basename(orte_cmd_line.path_to_mpirun); + tmp_basename = opal_basename(orte_cmd_options.path_to_mpirun); if (0 == strcmp("bin", tmp_basename)) { - char* tmp = orte_cmd_line.path_to_mpirun; - orte_cmd_line.path_to_mpirun = opal_dirname(tmp); + char* tmp = orte_cmd_options.path_to_mpirun; + orte_cmd_options.path_to_mpirun = opal_dirname(tmp); free(tmp); } else { - free(orte_cmd_line.path_to_mpirun); - orte_cmd_line.path_to_mpirun = NULL; + free(orte_cmd_options.path_to_mpirun); + orte_cmd_options.path_to_mpirun = NULL; } free(tmp_basename); } /* if both are given, check to see if they match */ - if (opal_cmd_line_is_taken(cmd_line, "prefix") && NULL != orte_cmd_line.path_to_mpirun) { + if (opal_cmd_line_is_taken(orte_cmd_line, "prefix") && + NULL != orte_cmd_options.path_to_mpirun) { char *tmp_basename; /* if they don't match, then that merits a warning */ - param = strdup(opal_cmd_line_get_param(cmd_line, "prefix", 0, 0)); + param = strdup(opal_cmd_line_get_param(orte_cmd_line, "prefix", 0, 0)); /* ensure we strip any trailing '/' */ if (0 == strcmp(OPAL_PATH_SEP, &(param[strlen(param)-1]))) { param[strlen(param)-1] = '\0'; } - tmp_basename = strdup(orte_cmd_line.path_to_mpirun); + tmp_basename = strdup(orte_cmd_options.path_to_mpirun); if (0 == strcmp(OPAL_PATH_SEP, &(tmp_basename[strlen(tmp_basename)-1]))) { tmp_basename[strlen(tmp_basename)-1] = '\0'; } @@ -395,15 +459,15 @@ int orte_submit_init(int argc, char *argv[], * people can specify the backend prefix as different * from the local one */ - free(orte_cmd_line.path_to_mpirun); - orte_cmd_line.path_to_mpirun = NULL; + free(orte_cmd_options.path_to_mpirun); + orte_cmd_options.path_to_mpirun = NULL; } free(tmp_basename); - } else if (NULL != orte_cmd_line.path_to_mpirun) { - param = strdup(orte_cmd_line.path_to_mpirun); - } else if (opal_cmd_line_is_taken(cmd_line, "prefix")){ + } else if (NULL != orte_cmd_options.path_to_mpirun) { + param = strdup(orte_cmd_options.path_to_mpirun); + } else if (opal_cmd_line_is_taken(orte_cmd_line, "prefix")){ /* must be --prefix alone */ - param = strdup(opal_cmd_line_get_param(cmd_line, "prefix", 0, 0)); + param = strdup(opal_cmd_line_get_param(orte_cmd_line, "prefix", 0, 0)); } else { /* --enable-orterun-prefix-default was given to orterun */ param = strdup(opal_install_dirs.prefix); @@ -423,7 +487,7 @@ int orte_submit_init(int argc, char *argv[], } } - orte_cmd_line.prefix = param; + orte_cmd_options.prefix = param; } want_prefix_by_default = true; } @@ -432,7 +496,7 @@ int orte_submit_init(int argc, char *argv[], /* Setup MCA params */ orte_register_params(); - if (orte_cmd_line.debug) { + if (orte_cmd_options.debug) { orte_devel_level_output = true; } @@ -512,7 +576,17 @@ void orte_submit_finalize(void) /* destruct the cmd line object */ if (mycmdline) { - OBJ_RELEASE(cmd_line); + OBJ_RELEASE(orte_cmd_line); + } + + /* if it was created, remove the debugger attach fifo */ + if (0 <= orte_debugger_attach_fd) { + if (orte_debugger_fifo_active) { + opal_event_del(orte_debugger_attach); + free(orte_debugger_attach); + } + close(orte_debugger_attach_fd); + unlink(MPIR_attach_fifo); } } @@ -602,12 +676,12 @@ int orte_submit_job(char *argv[], int *index, /* reset the globals every time thru as the argv * will modify them */ - memset(&orte_cmd_line, 0, sizeof(orte_cmd_line)); + memset(&orte_cmd_options, 0, sizeof(orte_cmd_options)); argc = opal_argv_count(argv); /* parse the cmd line - do this every time thru so we can * repopulate the globals */ - if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(cmd_line, true, + if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(orte_cmd_line, true, argc, argv)) ) { if (OPAL_ERR_SILENT != rc) { fprintf(stderr, "%s: command line error (%s)\n", argv[0], @@ -617,7 +691,7 @@ int orte_submit_job(char *argv[], int *index, } /* Check for some "global" command line params */ - parse_globals(argc, argv, cmd_line); + parse_globals(argc, argv, orte_cmd_line); /* create a new job object to hold the info for this one - the * jobid field will be filled in by the PLM when the job is @@ -644,36 +718,36 @@ int orte_submit_job(char *argv[], int *index, /* check for stdout/err directives */ /* if we were asked to tag output, mark it so */ - if (orte_cmd_line.tag_output) { + if (orte_cmd_options.tag_output) { orte_set_attribute(&jdata->attributes, ORTE_JOB_TAG_OUTPUT, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } /* if we were asked to timestamp output, mark it so */ - if (orte_cmd_line.timestamp_output) { + if (orte_cmd_options.timestamp_output) { orte_set_attribute(&jdata->attributes, ORTE_JOB_TIMESTAMP_OUTPUT, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } /* if we were asked to output to files, pass it along */ - if (NULL != orte_cmd_line.output_filename) { - orte_set_attribute(&jdata->attributes, ORTE_JOB_OUTPUT_TO_FILE, ORTE_ATTR_GLOBAL, orte_cmd_line.output_filename, OPAL_STRING); + if (NULL != orte_cmd_options.output_filename) { + orte_set_attribute(&jdata->attributes, ORTE_JOB_OUTPUT_TO_FILE, ORTE_ATTR_GLOBAL, orte_cmd_options.output_filename, OPAL_STRING); } /* if we were asked to merge stderr to stdout, mark it so */ - if (orte_cmd_line.merge) { + if (orte_cmd_options.merge) { orte_set_attribute(&jdata->attributes, ORTE_JOB_MERGE_STDERR_STDOUT, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } /* check what user wants us to do with stdin */ - if (NULL != orte_cmd_line.stdin_target) { - if (0 == strcmp(orte_cmd_line.stdin_target, "all")) { + if (NULL != orte_cmd_options.stdin_target) { + if (0 == strcmp(orte_cmd_options.stdin_target, "all")) { jdata->stdin_target = ORTE_VPID_WILDCARD; - } else if (0 == strcmp(orte_cmd_line.stdin_target, "none")) { + } else if (0 == strcmp(orte_cmd_options.stdin_target, "none")) { jdata->stdin_target = ORTE_VPID_INVALID; } else { - jdata->stdin_target = strtoul(orte_cmd_line.stdin_target, NULL, 10); + jdata->stdin_target = strtoul(orte_cmd_options.stdin_target, NULL, 10); } } /* if we want the argv's indexed, indicate that */ - if (orte_cmd_line.index_argv) { + if (orte_cmd_options.index_argv) { orte_set_attribute(&jdata->attributes, ORTE_JOB_INDEX_ARGV, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } @@ -692,57 +766,64 @@ int orte_submit_job(char *argv[], int *index, /* create the map object to communicate policies */ jdata->map = OBJ_NEW(orte_job_map_t); - if (NULL != orte_cmd_line.mapping_policy) { - if (ORTE_SUCCESS != (rc = orte_rmaps_base_set_mapping_policy(&jdata->map->mapping, NULL, orte_cmd_line.mapping_policy))) { + if (NULL != orte_cmd_options.mapping_policy) { + if (ORTE_SUCCESS != (rc = orte_rmaps_base_set_mapping_policy(&jdata->map->mapping, NULL, orte_cmd_options.mapping_policy))) { ORTE_ERROR_LOG(rc); return rc; } - } else if (orte_cmd_line.pernode) { + } else if (orte_cmd_options.pernode) { ORTE_SET_MAPPING_POLICY(jdata->map->mapping, ORTE_MAPPING_PPR); ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_GIVEN); /* define the ppr */ jdata->map->ppr = strdup("1:node"); - } else if (0 < orte_cmd_line.npernode) { + } else if (0 < orte_cmd_options.npernode) { ORTE_SET_MAPPING_POLICY(jdata->map->mapping, ORTE_MAPPING_PPR); ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_GIVEN); /* define the ppr */ - (void)asprintf(&jdata->map->ppr, "%d:node", orte_cmd_line.npernode); + (void)asprintf(&jdata->map->ppr, "%d:node", orte_cmd_options.npernode); + } + + /* if the user specified cpus/rank, set it */ + if (0 < orte_cmd_options.cpus_per_proc) { + jdata->map->cpus_per_rank = orte_cmd_options.cpus_per_proc; } - if (NULL != orte_cmd_line.ranking_policy) { + /* if the user specified a ranking policy, then set it */ + if (NULL != orte_cmd_options.ranking_policy) { if (ORTE_SUCCESS != (rc = orte_rmaps_base_set_ranking_policy(&jdata->map->ranking, jdata->map->mapping, - orte_cmd_line.ranking_policy))) { + orte_cmd_options.ranking_policy))) { ORTE_ERROR_LOG(rc); return rc; } } - if (NULL != orte_cmd_line.binding_policy) { + /* if the user specified a binding policy, then set it */ + if (NULL != orte_cmd_options.binding_policy) { if (ORTE_SUCCESS != (rc = opal_hwloc_base_set_binding_policy(&jdata->map->binding, - orte_cmd_line.binding_policy))) { + orte_cmd_options.binding_policy))) { ORTE_ERROR_LOG(rc); return rc; } } /* if they asked for nolocal, mark it so */ - if (orte_cmd_line.nolocal) { + if (orte_cmd_options.nolocal) { ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_USE_LOCAL); } - if (orte_cmd_line.no_oversubscribe) { + if (orte_cmd_options.no_oversubscribe) { ORTE_UNSET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); } - if (orte_cmd_line.oversubscribe) { + if (orte_cmd_options.oversubscribe) { ORTE_UNSET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE); } - if (orte_cmd_line.report_bindings) { + if (orte_cmd_options.report_bindings) { orte_set_attribute(&jdata->attributes, ORTE_JOB_REPORT_BINDINGS, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } - if (orte_cmd_line.slot_list) { - orte_set_attribute(&jdata->attributes, ORTE_JOB_SLOT_LIST, ORTE_ATTR_GLOBAL, orte_cmd_line.slot_list, OPAL_STRING); + if (orte_cmd_options.slot_list) { + orte_set_attribute(&jdata->attributes, ORTE_JOB_SLOT_LIST, ORTE_ATTR_GLOBAL, orte_cmd_options.slot_list, OPAL_STRING); } /* if recovery was disabled on the cmd line, do so */ - if (orte_cmd_line.enable_recovery) { + if (orte_cmd_options.enable_recovery) { ORTE_FLAG_SET(jdata, ORTE_JOB_FLAG_RECOVERABLE); } @@ -776,21 +857,21 @@ int orte_submit_job(char *argv[], int *index, daemons = orte_get_job_data_object(ORTE_PROC_MY_NAME->jobid); /* check for request to report uri */ - if (NULL != orte_cmd_line.report_uri) { + if (NULL != orte_cmd_options.report_uri) { FILE *fp; char *rml_uri; rml_uri = orte_rml.get_contact_info(); - if (0 == strcmp(orte_cmd_line.report_uri, "-")) { + if (0 == strcmp(orte_cmd_options.report_uri, "-")) { /* if '-', then output to stdout */ printf("%s\n", (NULL == rml_uri) ? "NULL" : rml_uri); - } else if (0 == strcmp(orte_cmd_line.report_uri, "+")) { + } else if (0 == strcmp(orte_cmd_options.report_uri, "+")) { /* if '+', output to stderr */ fprintf(stderr, "%s\n", (NULL == rml_uri) ? "NULL" : rml_uri); } else { - fp = fopen(orte_cmd_line.report_uri, "w"); + fp = fopen(orte_cmd_options.report_uri, "w"); if (NULL == fp) { orte_show_help("help-orterun.txt", "orterun:write_file", false, - orte_basename, "uri", orte_cmd_line.report_uri); + orte_basename, "uri", orte_cmd_options.report_uri); exit(0); } fprintf(fp, "%s\n", (NULL == rml_uri) ? "NULL" : rml_uri); @@ -911,25 +992,25 @@ int orte_submit_job(char *argv[], int *index, static int init_globals(void) { /* Reset the other fields every time */ - orte_cmd_line.help = false; - orte_cmd_line.version = false; - orte_cmd_line.num_procs = 0; - if (NULL != orte_cmd_line.appfile) { - free(orte_cmd_line.appfile); + orte_cmd_options.help = false; + orte_cmd_options.version = false; + orte_cmd_options.num_procs = 0; + if (NULL != orte_cmd_options.appfile) { + free(orte_cmd_options.appfile); } - orte_cmd_line.appfile = NULL; - if (NULL != orte_cmd_line.wdir) { - free(orte_cmd_line.wdir); + orte_cmd_options.appfile = NULL; + if (NULL != orte_cmd_options.wdir) { + free(orte_cmd_options.wdir); } - orte_cmd_line.set_cwd_to_session_dir = false; - orte_cmd_line.wdir = NULL; - if (NULL != orte_cmd_line.path) { - free(orte_cmd_line.path); + orte_cmd_options.set_cwd_to_session_dir = false; + orte_cmd_options.wdir = NULL; + if (NULL != orte_cmd_options.path) { + free(orte_cmd_options.path); } - orte_cmd_line.path = NULL; + orte_cmd_options.path = NULL; - orte_cmd_line.preload_binaries = false; - orte_cmd_line.preload_files = NULL; + orte_cmd_options.preload_binaries = false; + orte_cmd_options.preload_files = NULL; /* All done */ return ORTE_SUCCESS; @@ -939,19 +1020,19 @@ static int init_globals(void) static int parse_globals(int argc, char* argv[], opal_cmd_line_t *cmd_line) { /* check for request to report pid */ - if (NULL != orte_cmd_line.report_pid) { + if (NULL != orte_cmd_options.report_pid) { FILE *fp; - if (0 == strcmp(orte_cmd_line.report_pid, "-")) { + if (0 == strcmp(orte_cmd_options.report_pid, "-")) { /* if '-', then output to stdout */ printf("%d\n", (int)getpid()); - } else if (0 == strcmp(orte_cmd_line.report_pid, "+")) { + } else if (0 == strcmp(orte_cmd_options.report_pid, "+")) { /* if '+', output to stderr */ fprintf(stderr, "%d\n", (int)getpid()); } else { - fp = fopen(orte_cmd_line.report_pid, "w"); + fp = fopen(orte_cmd_options.report_pid, "w"); if (NULL == fp) { orte_show_help("help-orterun.txt", "orterun:write_file", false, - orte_basename, "pid", orte_cmd_line.report_pid); + orte_basename, "pid", orte_cmd_options.report_pid); exit(0); } fprintf(fp, "%d\n", (int)getpid()); @@ -961,8 +1042,8 @@ static int parse_globals(int argc, char* argv[], opal_cmd_line_t *cmd_line) /* Do we want a user-level debugger? */ - if (orte_cmd_line.debugger) { - run_debugger(orte_basename, cmd_line, argc, argv, orte_cmd_line.num_procs); + if (orte_cmd_options.debugger) { + run_debugger(orte_basename, cmd_line, argc, argv, orte_cmd_options.num_procs); } return ORTE_SUCCESS; @@ -1146,12 +1227,10 @@ static int create_app(int argc, char* argv[], orte_app_context_t **app_ptr, bool *made_app, char ***app_env) { - opal_cmd_line_t app_cmd_line; char cwd[OPAL_PATH_MAX]; int i, j, count, rc; char *param, *value; orte_app_context_t *app = NULL; - bool cmd_line_made = false; bool found = false; char *appname; @@ -1167,7 +1246,7 @@ static int create_app(int argc, char* argv[], * $ mpirun -np 2 -mca foo bar --app launch.appfile * Only pick up '-mca foo bar' on this pass. */ - if (NULL != orte_cmd_line.appfile) { + if (NULL != orte_cmd_options.appfile) { if (ORTE_SUCCESS != (rc = orte_schizo.parse_cli(argc, 0, argv))) { goto cleanup; } @@ -1175,21 +1254,25 @@ static int create_app(int argc, char* argv[], /* Parse application command line options. */ init_globals(); - OBJ_CONSTRUCT(&app_cmd_line, opal_cmd_line_t); - rc = orte_cmd_line_create(&app_cmd_line, argc, argv, - app_env, &global_mca_env, - NULL, NULL); - cmd_line_made = true; + /* parse the cmd line - do this every time thru so we can + * repopulate the globals */ + if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(orte_cmd_line, true, + argc, argv)) ) { + if (OPAL_ERR_SILENT != rc) { + fprintf(stderr, "%s: command line error (%s)\n", argv[0], + opal_strerror(rc)); + } + return rc; + } /* Is there an appfile in here? */ - if (NULL != orte_cmd_line.appfile) { - OBJ_DESTRUCT(&app_cmd_line); - return parse_appfile(jdata, strdup(orte_cmd_line.appfile), app_env); + if (NULL != orte_cmd_options.appfile) { + return parse_appfile(jdata, strdup(orte_cmd_options.appfile), app_env); } /* Setup application context */ app = OBJ_NEW(orte_app_context_t); - opal_cmd_line_get_tail(&app_cmd_line, &count, &app->argv); + opal_cmd_line_get_tail(orte_cmd_line, &count, &app->argv); /* See if we have anything left */ if (0 == count) { @@ -1213,8 +1296,8 @@ static int create_app(int argc, char* argv[], /* Grab all MCA environment variables */ app->env = opal_argv_copy(*app_env); - if (ORTE_SUCCESS != (rc = orte_schizo.parse_env(orte_cmd_line.path, - &app_cmd_line, + if (ORTE_SUCCESS != (rc = orte_schizo.parse_env(orte_cmd_options.path, + orte_cmd_line, environ, &app->env))) { goto cleanup; } @@ -1222,10 +1305,10 @@ static int create_app(int argc, char* argv[], /* Did the user request a specific wdir? */ - if (NULL != orte_cmd_line.wdir) { + if (NULL != orte_cmd_options.wdir) { /* if this is a relative path, convert it to an absolute path */ - if (opal_path_is_absolute(orte_cmd_line.wdir)) { - app->cwd = strdup(orte_cmd_line.wdir); + if (opal_path_is_absolute(orte_cmd_options.wdir)) { + app->cwd = strdup(orte_cmd_options.wdir); } else { /* get the cwd */ if (OPAL_SUCCESS != (rc = opal_getcwd(cwd, sizeof(cwd)))) { @@ -1234,10 +1317,10 @@ static int create_app(int argc, char* argv[], goto cleanup; } /* construct the absolute path */ - app->cwd = opal_os_path(false, cwd, orte_cmd_line.wdir, NULL); + app->cwd = opal_os_path(false, cwd, orte_cmd_options.wdir, NULL); } orte_set_attribute(&app->attributes, ORTE_APP_USER_CWD, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); - } else if (orte_cmd_line.set_cwd_to_session_dir) { + } else if (orte_cmd_options.set_cwd_to_session_dir) { orte_set_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); orte_set_attribute(&app->attributes, ORTE_APP_USER_CWD, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } else { @@ -1258,25 +1341,25 @@ static int create_app(int argc, char* argv[], /* Check to see if the user explicitly wanted to disable automatic --prefix behavior */ - if (opal_cmd_line_is_taken(&app_cmd_line, "noprefix")) { + if (opal_cmd_line_is_taken(orte_cmd_line, "noprefix")) { want_prefix_by_default = false; } /* Did the user specify a prefix, or want prefix by default? */ - if (opal_cmd_line_is_taken(&app_cmd_line, "prefix") || want_prefix_by_default) { + if (opal_cmd_line_is_taken(orte_cmd_line, "prefix") || want_prefix_by_default) { size_t param_len; /* if both the prefix was given and we have a prefix * given above, check to see if they match */ - if (opal_cmd_line_is_taken(&app_cmd_line, "prefix") && - NULL != orte_cmd_line.prefix) { + if (opal_cmd_line_is_taken(orte_cmd_line, "prefix") && + NULL != orte_cmd_options.prefix) { /* if they don't match, then that merits a warning */ - param = strdup(opal_cmd_line_get_param(&app_cmd_line, "prefix", 0, 0)); + param = strdup(opal_cmd_line_get_param(orte_cmd_line, "prefix", 0, 0)); /* ensure we strip any trailing '/' */ if (0 == strcmp(OPAL_PATH_SEP, &(param[strlen(param)-1]))) { param[strlen(param)-1] = '\0'; } - value = strdup(orte_cmd_line.prefix); + value = strdup(orte_cmd_options.prefix); if (0 == strcmp(OPAL_PATH_SEP, &(value[strlen(value)-1]))) { value[strlen(value)-1] = '\0'; } @@ -1287,14 +1370,14 @@ static int create_app(int argc, char* argv[], * know that one is being used */ free(param); - param = strdup(orte_cmd_line.prefix); + param = strdup(orte_cmd_options.prefix); } free(value); - } else if (NULL != orte_cmd_line.prefix) { - param = strdup(orte_cmd_line.prefix); - } else if (opal_cmd_line_is_taken(&app_cmd_line, "prefix")){ + } else if (NULL != orte_cmd_options.prefix) { + param = strdup(orte_cmd_options.prefix); + } else if (opal_cmd_line_is_taken(orte_cmd_line, "prefix")){ /* must be --prefix alone */ - param = strdup(opal_cmd_line_get_param(&app_cmd_line, "prefix", 0, 0)); + param = strdup(opal_cmd_line_get_param(orte_cmd_line, "prefix", 0, 0)); } else { /* --enable-orterun-prefix-default was given to orterun */ param = strdup(opal_install_dirs.prefix); @@ -1323,32 +1406,32 @@ static int create_app(int argc, char* argv[], * hostfile and machine file. * We can only deal with one hostfile per app context, otherwise give an error. */ - if (0 < (j = opal_cmd_line_get_ninsts(&app_cmd_line, "hostfile"))) { + if (0 < (j = opal_cmd_line_get_ninsts(orte_cmd_line, "hostfile"))) { if(1 < j) { orte_show_help("help-orterun.txt", "orterun:multiple-hostfiles", true, orte_basename, NULL); return ORTE_ERR_FATAL; } else { - value = opal_cmd_line_get_param(&app_cmd_line, "hostfile", 0, 0); + value = opal_cmd_line_get_param(orte_cmd_line, "hostfile", 0, 0); orte_set_attribute(&app->attributes, ORTE_APP_HOSTFILE, ORTE_ATTR_GLOBAL, value, OPAL_STRING); } } - if (0 < (j = opal_cmd_line_get_ninsts(&app_cmd_line, "machinefile"))) { + if (0 < (j = opal_cmd_line_get_ninsts(orte_cmd_line, "machinefile"))) { if(1 < j || orte_get_attribute(&app->attributes, ORTE_APP_HOSTFILE, NULL, OPAL_STRING)) { orte_show_help("help-orterun.txt", "orterun:multiple-hostfiles", true, orte_basename, NULL); return ORTE_ERR_FATAL; } else { - value = opal_cmd_line_get_param(&app_cmd_line, "machinefile", 0, 0); + value = opal_cmd_line_get_param(orte_cmd_line, "machinefile", 0, 0); orte_set_attribute(&app->attributes, ORTE_APP_HOSTFILE, ORTE_ATTR_GLOBAL, value, OPAL_STRING); } } /* Did the user specify any hosts? */ - if (0 < (j = opal_cmd_line_get_ninsts(&app_cmd_line, "host"))) { + if (0 < (j = opal_cmd_line_get_ninsts(orte_cmd_line, "host"))) { char **targ=NULL, *tval; for (i = 0; i < j; ++i) { - value = opal_cmd_line_get_param(&app_cmd_line, "host", i, 0); + value = opal_cmd_line_get_param(orte_cmd_line, "host", i, 0); opal_argv_append_nosize(&targ, value); } tval = opal_argv_join(targ, ','); @@ -1361,18 +1444,18 @@ static int create_app(int argc, char* argv[], } /* check for bozo error */ - if (0 > orte_cmd_line.num_procs) { + if (0 > orte_cmd_options.num_procs) { orte_show_help("help-orterun.txt", "orterun:negative-nprocs", true, orte_basename, app->argv[0], - orte_cmd_line.num_procs, NULL); + orte_cmd_options.num_procs, NULL); return ORTE_ERR_FATAL; } - app->num_procs = (orte_std_cntr_t)orte_cmd_line.num_procs; + app->num_procs = (orte_std_cntr_t)orte_cmd_options.num_procs; total_num_apps++; /* Capture any preload flags */ - if (orte_cmd_line.preload_binaries) { + if (orte_cmd_options.preload_binaries) { orte_set_attribute(&app->attributes, ORTE_APP_PRELOAD_BIN, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } /* if we were told to cwd to the session dir and the app was given in @@ -1383,15 +1466,15 @@ static int create_app(int argc, char* argv[], */ if (!opal_path_is_absolute(app->argv[0]) && NULL == strstr(app->argv[0], "java")) { - if (orte_cmd_line.preload_binaries) { + if (orte_cmd_options.preload_binaries) { orte_set_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } else if (orte_get_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, NULL, OPAL_BOOL)) { orte_set_attribute(&app->attributes, ORTE_APP_PRELOAD_BIN, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL); } } - if (NULL != orte_cmd_line.preload_files) { + if (NULL != orte_cmd_options.preload_files) { orte_set_attribute(&app->attributes, ORTE_APP_PRELOAD_FILES, ORTE_ATTR_GLOBAL, - orte_cmd_line.preload_files, OPAL_STRING); + orte_cmd_options.preload_files, OPAL_STRING); } /* Do not try to find argv[0] here -- the starter is responsible @@ -1565,9 +1648,6 @@ static int create_app(int argc, char* argv[], if (NULL != app) { OBJ_RELEASE(app); } - if (cmd_line_made) { - OBJ_DESTRUCT(&app_cmd_line); - } return rc; } @@ -1600,9 +1680,9 @@ static int parse_appfile(orte_job_t *jdata, char *filename, char ***env) * Make sure to clear out this variable so we don't do anything odd in * app_create() */ - if (NULL != orte_cmd_line.appfile) { - free(orte_cmd_line.appfile); - orte_cmd_line.appfile = NULL; + if (NULL != orte_cmd_options.appfile) { + free(orte_cmd_options.appfile); + orte_cmd_options.appfile = NULL; } /* Try to open the file */ diff --git a/orte/orted/orted_submit.h b/orte/orted/orted_submit.h index ed6a8313d43..1daf1b0ecb0 100644 --- a/orte/orted/orted_submit.h +++ b/orte/orted/orted_submit.h @@ -12,6 +12,8 @@ #include "orte_config.h" +#include "opal/util/cmd_line.h" + #include "orte/mca/plm/plm.h" #include "orte/runtime/orte_globals.h" @@ -37,9 +39,9 @@ extern opal_event_t *orte_debugger_attach; extern char MPIR_attach_fifo[]; /** - * Global struct for catching orte command line options. + * Global struct for caching orte command line options. */ -struct orte_cmd_line_t { +struct orte_cmd_options_t { bool help; bool version; bool verbose; @@ -91,8 +93,9 @@ struct orte_cmd_line_t { char *hnp; bool staged_exec; }; -typedef struct orte_cmd_line_t orte_cmd_line_t; -ORTE_DECLSPEC extern orte_cmd_line_t orte_cmd_line; +typedef struct orte_cmd_options_t orte_cmd_options_t; +ORTE_DECLSPEC extern orte_cmd_options_t orte_cmd_options; +ORTE_DECLSPEC extern opal_cmd_line_t *orte_cmd_line; END_C_DECLS diff --git a/orte/tools/orte-dvm/orte-dvm.c b/orte/tools/orte-dvm/orte-dvm.c index 2a05a685c86..479aed125b4 100644 --- a/orte/tools/orte-dvm/orte-dvm.c +++ b/orte/tools/orte-dvm/orte-dvm.c @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) * opal_init_util() since mca_base_cmd_line_process_args() does *not* * depend upon opal_init_util() functionality. */ - if (OPAL_SUCCESS != mca_base_cmd_line_process_args(argv, &environ, &environ)) { + if (OPAL_SUCCESS != mca_base_cmd_line_process_args(&cmd_line, &environ, &environ)) { exit(1); } diff --git a/orte/tools/orte-info/orte-info.c b/orte/tools/orte-info/orte-info.c index 8ff27811eee..5b2230fbb52 100644 --- a/orte/tools/orte-info/orte-info.c +++ b/orte/tools/orte-info/orte-info.c @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) exit(cmd_error ? 1 : 0); } - mca_base_cmd_line_process_args(argv, &app_env, &global_env); + mca_base_cmd_line_process_args(orte_info_cmd_line, &app_env, &global_env); /* putenv() all the stuff that we got back from env (in case the * user specified some --mca params on the command line). This diff --git a/orte/tools/orte-server/orte-server.c b/orte/tools/orte-server/orte-server.c index 89ac610970f..46ef0b90465 100644 --- a/orte/tools/orte-server/orte-server.c +++ b/orte/tools/orte-server/orte-server.c @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) * Since this process can now handle MCA/GMCA parameters, make sure to * process them. */ - mca_base_cmd_line_process_args(argv, &environ, &environ); + mca_base_cmd_line_process_args(cmd_line, &environ, &environ); /* if debug is set, then set orte_debug_flag so that the data server * code will output diff --git a/orte/tools/orterun/orterun.c b/orte/tools/orterun/orterun.c index 8d5333f8b4e..a79ece7ad92 100644 --- a/orte/tools/orterun/orterun.c +++ b/orte/tools/orterun/orterun.c @@ -85,7 +85,6 @@ #include "orte/mca/odls/odls.h" #include "orte/mca/rml/rml.h" #include "orte/mca/state/state.h" -#include "orte/util/cmd_line.h" #include "orte/util/proc_info.h" #include "orte/util/show_help.h" @@ -100,6 +99,14 @@ #include "orte/orted/orted_submit.h" #include "orterun.h" +/* local type */ + typedef struct { + int status; + volatile bool active; + orte_job_t *jdata; + } orte_submit_status_t; + + /* local data */ static opal_list_t job_stack; @@ -144,8 +151,28 @@ static void run_next_job(int fd, short args, void *cbdata) OBJ_RELEASE(caddy); } +static void launched(int index, orte_job_t *jdata, int ret, void *cbdata) +{ + orte_submit_status_t *launchst = (orte_submit_status_t*)cbdata; + launchst->status = ret; + ORTE_UPDATE_EXIT_STATUS(ret); + OBJ_RETAIN(jdata); + launchst->jdata = jdata; + launchst->active = false; +} +static void completed(int index, orte_job_t *jdata, int ret, void *cbdata) +{ + orte_submit_status_t *completest = (orte_submit_status_t*)cbdata; + completest->status = ret; + ORTE_UPDATE_EXIT_STATUS(ret); + OBJ_RETAIN(jdata); + completest->jdata = jdata; + completest->active = false; +} + int orterun(int argc, char *argv[]) { + orte_submit_status_t launchst, completest; if (ORTE_SUCCESS != orte_submit_init(argc, argv, NULL)) { exit(1); @@ -155,9 +182,9 @@ int orterun(int argc, char *argv[]) * us to proceed if the allow-run-as-root flag was given. Otherwise, * exit with a giant warning flag */ - if (0 == geteuid() && !orte_cmd_line.run_as_root) { + if (0 == geteuid() && !orte_cmd_options.run_as_root) { fprintf(stderr, "--------------------------------------------------------------------------\n"); - if (orte_cmd_line.help) { + if (orte_cmd_options.help) { fprintf(stderr, "%s cannot provide the help message when run as root.\n", orte_basename); } else { /* show_help is not yet available, so print an error manually */ @@ -181,14 +208,43 @@ int orterun(int argc, char *argv[]) orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_DAEMON, ORTE_RML_PERSISTENT, orte_daemon_recv, NULL); - /* spawn the job and its daemons */ - if (ORTE_SUCCESS != orte_submit_job(argv, NULL, - NULL, NULL, - NULL, NULL)) { - ORTE_UPDATE_EXIT_STATUS(1); - goto DONE; + /* if the user just wants us to terminate a DVM, then do so */ + if (orte_cmd_options.terminate_dvm) { + if (ORTE_ERR_OP_IN_PROGRESS != orte_submit_halt()) { + ORTE_UPDATE_EXIT_STATUS(1); + goto DONE; + } + while (1) { + opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE); + } + } else { + /* spawn the job and its daemons */ + memset(&launchst, 0, sizeof(launchst)); + memset(&completest, 0, sizeof(completest)); + launchst.active = true; + completest.active = true; + if (ORTE_SUCCESS != orte_submit_job(argv, NULL, + launched, &launchst, + completed, &completest)) { + ORTE_UPDATE_EXIT_STATUS(1); + goto DONE; + } } + // wait for response and unpack the status, jobid + while (orte_event_base_active && launchst.active) { + opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE); + } + if (orte_debug_flag) { + opal_output(0, "Job %s has launched", ORTE_JOBID_PRINT(launchst.jdata->jobid)); + } + if (!orte_event_base_active || ORTE_SUCCESS != launchst.status) { + goto DONE; + } + + while (orte_event_base_active && completest.active) { + opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE); + } #if 0 if (orte_staged_execution) { @@ -225,31 +281,15 @@ int orterun(int argc, char *argv[]) } #endif - /* loop the event lib until an exit event is detected */ - while (orte_event_base_active) { - opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE); + if (ORTE_PROC_IS_HNP) { + /* ensure all local procs are dead */ + orte_odls.kill_local_procs(NULL); } - /* ensure all local procs are dead */ - orte_odls.kill_local_procs(NULL); - DONE: - /* if it was created, remove the debugger attach fifo */ - if (0 <= orte_debugger_attach_fd) { - if (orte_debugger_fifo_active) { - opal_event_del(orte_debugger_attach); - free(orte_debugger_attach); - } - close(orte_debugger_attach_fd); - unlink(MPIR_attach_fifo); - } - /* cleanup and leave */ - orte_finalize(); + orte_submit_finalize(); - if (NULL != orte_launch_environ) { - opal_argv_free(orte_launch_environ); - } if (orte_debug_flag) { fprintf(stderr, "exiting with status %d\n", orte_exit_status); } diff --git a/orte/util/Makefile.am b/orte/util/Makefile.am index 6873f08328c..d60905b332b 100644 --- a/orte/util/Makefile.am +++ b/orte/util/Makefile.am @@ -57,8 +57,7 @@ headers += \ util/nidmap.h \ util/regex.h \ util/attr.h \ - util/listener.h \ - util/cmd_line.h + util/listener.h lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES += \ util/error_strings.c \ @@ -77,8 +76,7 @@ lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES += \ util/nidmap.c \ util/regex.c \ util/attr.c \ - util/listener.c \ - util/cmd_line.c + util/listener.c # Remove the generated man pages distclean-local: diff --git a/orte/util/cmd_line.c b/orte/util/cmd_line.c deleted file mode 100644 index cf5d755140c..00000000000 --- a/orte/util/cmd_line.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2016 Intel, Inc. All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ -#include "orte_config.h" -#include "orte/types.h" -#include "orte/constants.h" - -#include -#include - -#include "opal/mca/base/base.h" -#include "opal/util/cmd_line.h" -#include "opal/util/printf.h" -#include "opal/runtime/opal.h" - -#include "orte/mca/errmgr/errmgr.h" -#include "orte/mca/schizo/base/base.h" - -#include "orte/util/cmd_line.h" - -int orte_cmd_line_create(opal_cmd_line_t *cmd_line, - int argc, char **argv, - char ***context_env, char ***global_env, - bool *version, bool *help) -{ - int i, rc; - - if (NULL != version) { - *version = false; - } - if (NULL != help) { - *help = false; - } - - if (NULL != version) { - /* see if they asked for us to print version */ - for (i=0; NULL != argv[i]; i++) { - if (0 == strcmp(argv[i], "--version") || - 0 == strcmp(argv[i], "-V")) { - *version = true; - return ORTE_SUCCESS; - } - } - } - - /* process any mca params */ - if (OPAL_SUCCESS != (rc = mca_base_cmd_line_process_args(argv, context_env, global_env))) { - ORTE_ERROR_LOG(rc); - return rc; - } - - - opal_cmd_line_create(cmd_line, NULL); - - /* init the MCA system - will just refcount if already initialized */ - opal_init_util(NULL, NULL); - - /* open the SCHIZO framework so we can define the cmd line options */ - if (ORTE_SUCCESS != (rc = mca_base_framework_open(&orte_schizo_base_framework, 0))) { - ORTE_ERROR_LOG(rc); - return rc; - } - if (ORTE_SUCCESS != (rc = orte_schizo_base_select())) { - ORTE_ERROR_LOG(rc); - return rc; - } - /* define the cli options */ - if (ORTE_SUCCESS != (rc = orte_schizo.define_cli(cmd_line))) { - ORTE_ERROR_LOG(rc); - return rc; - } - /* close the framework for bookkeeping purposes */ - mca_base_framework_close(&orte_schizo_base_framework); - - /* decrement the opal refcount */ - opal_finalize_util(); - - /* now that options have been defined, finish setup */ - mca_base_cmd_line_setup(cmd_line); - - - /* Check for help request - must do this after we setup - * the cmd line so the help messages can display */ - if (NULL != help) { - for (i=0; NULL != argv[i]; i++) { - if (0 == strcmp(argv[i], "--help") || - 0 == strcmp(argv[i], "-h")) { - *help = true; - return ORTE_SUCCESS; - } - } - } - - /* parse the result to get values */ - if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(cmd_line, true, - argc, argv)) ) { - if (OPAL_ERR_SILENT != rc) { - fprintf(stderr, "%s: command line error (%s)\n", argv[0], - opal_strerror(rc)); - } - return rc; - } - - return ORTE_SUCCESS; -} diff --git a/orte/util/cmd_line.h b/orte/util/cmd_line.h deleted file mode 100644 index 231fa1d96c9..00000000000 --- a/orte/util/cmd_line.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2016 Intel, Inc. All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -/** @file: - * - * Populates global structure with system-specific information. - * - * Notes: add limits.h, compute size of integer and other types via sizeof(type)*CHAR_BIT - * - */ - -#ifndef _ORTE_CMD_LINE_H_ -#define _ORTE_CMD_LINE_H_ - -#include "orte_config.h" - -#ifdef HAVE_STDINT_h -#include -#endif - -#include "orte/types.h" - -#include "opal/util/cmd_line.h" - -BEGIN_C_DECLS - -ORTE_DECLSPEC int orte_cmd_line_create(opal_cmd_line_t *cmd_line, - int argc, char **argv, - char ***context_env, char ***global_env, - bool *version, bool *help); - -END_C_DECLS -#endif