/* * Look for and handle any -mca options on the command line */ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***context_env, char ***global_env) { int i, num_insts; char **params; char **values; /* If no relevant parameters were given, just return */ if (!opal_cmd_line_is_taken(cmd, "mca") && !opal_cmd_line_is_taken(cmd, "gmca")) { return OPAL_SUCCESS; } /* Handle app context-specific parameters */ num_insts = opal_cmd_line_get_ninsts(cmd, "mca"); params = values = NULL; for (i = 0; i < num_insts; ++i) { process_arg(opal_cmd_line_get_param(cmd, "mca", i, 0), opal_cmd_line_get_param(cmd, "mca", i, 1), ¶ms, &values); } if (NULL != params) { add_to_env(params, values, context_env); opal_argv_free(params); opal_argv_free(values); } /* Handle global parameters */ num_insts = opal_cmd_line_get_ninsts(cmd, "gmca"); params = values = NULL; for (i = 0; i < num_insts; ++i) { process_arg(opal_cmd_line_get_param(cmd, "gmca", i, 0), opal_cmd_line_get_param(cmd, "gmca", i, 1), ¶ms, &values); } if (NULL != params) { add_to_env(params, values, global_env); opal_argv_free(params); opal_argv_free(values); } /* All done */ return OPAL_SUCCESS; }
int main(int argc, char *argv[]) { int ret = 0; bool want_help = false; bool cmd_error = false; bool acted = false; bool want_all = false; char **app_env = NULL, **global_env = NULL; int i, len; char *str; /* Initialize the argv parsing handle */ if (OMPI_SUCCESS != opal_init_util(&argc, &argv)) { orte_show_help("help-ompi_info.txt", "lib-call-fail", true, "opal_init_util", __FILE__, __LINE__, NULL); exit(ret); } ompi_info_cmd_line = OBJ_NEW(opal_cmd_line_t); if (NULL == ompi_info_cmd_line) { ret = errno; orte_show_help("help-ompi_info.txt", "lib-call-fail", true, "opal_cmd_line_create", __FILE__, __LINE__, NULL); opal_finalize_util(); exit(ret); } opal_cmd_line_make_opt3(ompi_info_cmd_line, 'v', NULL, "version", 2, "Show version of Open MPI or a component. The first parameter can be the keywords \"ompi\" or \"all\", a framework name (indicating all components in a framework), or a framework:component string (indicating a specific component). The second parameter can be one of: full, major, minor, release, greek, svn."); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "param", 2, "Show MCA parameters. The first parameter is the framework (or the keyword \"all\"); the second parameter is the specific component name (or the keyword \"all\")."); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "internal", 0, "Show internal MCA parameters (not meant to be modified by users)"); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "path", 1, "Show paths that Open MPI was configured with. Accepts the following parameters: prefix, bindir, libdir, incdir, mandir, pkglibdir, sysconfdir"); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "arch", 0, "Show architecture Open MPI was compiled on"); opal_cmd_line_make_opt3(ompi_info_cmd_line, 'c', NULL, "config", 0, "Show configuration options"); opal_cmd_line_make_opt3(ompi_info_cmd_line, 'h', NULL, "help", 0, "Show this help message"); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "ompi_info_pretty", 0, "When used in conjunction with other parameters, the output is displayed in 'ompi_info_prettyprint' format (default)"); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "parsable", 0, "When used in conjunction with other parameters, the output is displayed in a machine-parsable format"); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "parseable", 0, "Synonym for --parsable"); opal_cmd_line_make_opt3(ompi_info_cmd_line, '\0', NULL, "hostname", 0, "Show the hostname that Open MPI was configured " "and built on"); opal_cmd_line_make_opt3(ompi_info_cmd_line, 'a', NULL, "all", 0, "Show all configuration options and MCA parameters"); /* Call some useless functions in order to guarantee to link in some * global variables. Only check the return value so that the * compiler doesn't optimize out the useless function. */ if (OMPI_SUCCESS != ompi_comm_link_function()) { /* Stop .. or I'll say stop again! */ ++ret; } else { --ret; } /* set our threading level */ opal_set_using_threads(false); /* Get MCA parameters, if any */ if( OMPI_SUCCESS != mca_base_open() ) { orte_show_help("help-ompi_info.txt", "lib-call-fail", true, "mca_base_open", __FILE__, __LINE__ ); OBJ_RELEASE(ompi_info_cmd_line); opal_finalize_util(); exit(1); } mca_base_cmd_line_setup(ompi_info_cmd_line); /* Do the parsing */ if (OMPI_SUCCESS != opal_cmd_line_parse(ompi_info_cmd_line, false, argc, argv)) { cmd_error = true; } if (!cmd_error && (opal_cmd_line_is_taken(ompi_info_cmd_line, "help") || opal_cmd_line_is_taken(ompi_info_cmd_line, "h"))) { want_help = true; } if (cmd_error || want_help) { char *usage = opal_cmd_line_get_usage_msg(ompi_info_cmd_line); orte_show_help("help-ompi_info.txt", "usage", true, usage); free(usage); mca_base_close(); OBJ_RELEASE(ompi_info_cmd_line); opal_finalize_util(); exit(cmd_error ? 1 : 0); } mca_base_cmd_line_process_args(ompi_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 * creates a memory leak, but that's unfortunately how putenv() * works. :-( */ len = opal_argv_count(app_env); for (i = 0; i < len; ++i) { putenv(app_env[i]); } len = opal_argv_count(global_env); for (i = 0; i < len; ++i) { putenv(global_env[i]); } /* setup the mca_types array */ OBJ_CONSTRUCT(&mca_types, opal_pointer_array_t); opal_pointer_array_init(&mca_types, 256, INT_MAX, 128); opal_pointer_array_add(&mca_types, "mca"); opal_pointer_array_add(&mca_types, "mpi"); opal_pointer_array_add(&mca_types, "orte"); opal_pointer_array_add(&mca_types, "opal"); opal_pointer_array_add(&mca_types, "filter"); opal_pointer_array_add(&mca_types, "backtrace"); opal_pointer_array_add(&mca_types, "memchecker"); opal_pointer_array_add(&mca_types, "memory"); opal_pointer_array_add(&mca_types, "paffinity"); opal_pointer_array_add(&mca_types, "carto"); opal_pointer_array_add(&mca_types, "shmem"); opal_pointer_array_add(&mca_types, "maffinity"); opal_pointer_array_add(&mca_types, "timer"); opal_pointer_array_add(&mca_types, "installdirs"); opal_pointer_array_add(&mca_types, "sysinfo"); opal_pointer_array_add(&mca_types, "hwloc"); #if OPAL_ENABLE_FT_CR == 1 opal_pointer_array_add(&mca_types, "crs"); #endif opal_pointer_array_add(&mca_types, "dpm"); opal_pointer_array_add(&mca_types, "pubsub"); opal_pointer_array_add(&mca_types, "allocator"); opal_pointer_array_add(&mca_types, "coll"); opal_pointer_array_add(&mca_types, "io"); opal_pointer_array_add(&mca_types, "mpool"); opal_pointer_array_add(&mca_types, "pml"); opal_pointer_array_add(&mca_types, "bml"); opal_pointer_array_add(&mca_types, "rcache"); opal_pointer_array_add(&mca_types, "btl"); opal_pointer_array_add(&mca_types, "mtl"); opal_pointer_array_add(&mca_types, "topo"); opal_pointer_array_add(&mca_types, "osc"); opal_pointer_array_add(&mca_types, "op"); opal_pointer_array_add(&mca_types, "common"); #if OPAL_ENABLE_FT_CR == 1 opal_pointer_array_add(&mca_types, "crcp"); #endif #if !ORTE_DISABLE_FULL_SUPPORT opal_pointer_array_add(&mca_types, "iof"); opal_pointer_array_add(&mca_types, "oob"); opal_pointer_array_add(&mca_types, "odls"); opal_pointer_array_add(&mca_types, "ras"); opal_pointer_array_add(&mca_types, "rmaps"); opal_pointer_array_add(&mca_types, "rml"); opal_pointer_array_add(&mca_types, "routed"); opal_pointer_array_add(&mca_types, "plm"); #if OPAL_ENABLE_FT_CR == 1 opal_pointer_array_add(&mca_types, "snapc"); #endif opal_pointer_array_add(&mca_types, "filem"); #endif /* these are always included */ opal_pointer_array_add(&mca_types, "errmgr"); opal_pointer_array_add(&mca_types, "ess"); opal_pointer_array_add(&mca_types, "grpcomm"); opal_pointer_array_add(&mca_types, "notifier"); /* Execute the desired action(s) */ if (opal_cmd_line_is_taken(ompi_info_cmd_line, "ompi_info_pretty")) { ompi_info_pretty = true; } else if (opal_cmd_line_is_taken(ompi_info_cmd_line, "parsable") || opal_cmd_line_is_taken(ompi_info_cmd_line, "parseable")) { ompi_info_pretty = false; } want_all = opal_cmd_line_is_taken(ompi_info_cmd_line, "all"); if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "version")) { ompi_info_do_version(want_all, ompi_info_cmd_line); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "path")) { ompi_info_do_path(want_all, ompi_info_cmd_line); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "arch")) { ompi_info_do_arch(); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "hostname")) { ompi_info_do_hostname(); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "config")) { ompi_info_do_config(true); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "param")) { ompi_info_do_params(want_all, opal_cmd_line_is_taken(ompi_info_cmd_line, "internal")); acted = true; } /* If no command line args are specified, show default set */ if (!acted) { ompi_info_show_ompi_version(ompi_info_ver_full); ompi_info_show_path(ompi_info_path_prefix, opal_install_dirs.prefix); ompi_info_do_arch(); ompi_info_do_hostname(); ompi_info_do_config(false); ompi_info_open_components(); for (i = 0; i < mca_types.size; ++i) { if (NULL == (str = (char*)opal_pointer_array_get_item(&mca_types, i))) { continue; } if (0 != strcmp("mpi", str)) { ompi_info_show_component_version(str, ompi_info_component_all, ompi_info_ver_full, ompi_info_type_all); } } } /* All done */ if (NULL != app_env) { opal_argv_free(app_env); } if (NULL != global_env) { opal_argv_free(global_env); } ompi_info_close_components(); OBJ_RELEASE(ompi_info_cmd_line); OBJ_DESTRUCT(&mca_types); mca_base_close(); opal_finalize_util(); return 0; }
static int parse_env(char **personality, char *path, opal_cmd_line_t *cmd_line, char **srcenv, char ***dstenv) { int i, j; char *param; char *value; char *env_set_flag; char **vars; bool takeus = false; /* see if we are included */ for (i=0; NULL != personality[i]; i++) { if (0 == strcmp(personality[i], "ompi")) { takeus = true; break; } } if (!takeus) { return ORTE_ERR_TAKE_NEXT_OPTION; } for (i = 0; NULL != srcenv[i]; ++i) { if (0 == strncmp("OMPI_", srcenv[i], 5)) { /* check for duplicate in app->env - this * would have been placed there by the * cmd line processor. By convention, we * always let the cmd line override the * environment */ param = strdup(srcenv[i]); value = strchr(param, '='); *value = '\0'; value++; opal_setenv(param, value, false, dstenv); free(param); } } /* set necessary env variables for external usage from tune conf file*/ int set_from_file = 0; vars = NULL; if (OPAL_SUCCESS == mca_base_var_process_env_list_from_file(&vars) && NULL != vars) { for (i=0; NULL != vars[i]; i++) { value = strchr(vars[i], '='); /* terminate the name of the param */ *value = '\0'; /* step over the equals */ value++; /* overwrite any prior entry */ opal_setenv(vars[i], value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(vars[i], value, true, &orte_forwarded_envars); } set_from_file = 1; opal_argv_free(vars); } /* Did the user request to export any environment variables on the cmd line? */ env_set_flag = getenv("OMPI_MCA_mca_base_env_list"); if (opal_cmd_line_is_taken(cmd_line, "x")) { if (NULL != env_set_flag) { orte_show_help("help-orterun.txt", "orterun:conflict-env-set", false); return ORTE_ERR_FATAL; } j = opal_cmd_line_get_ninsts(cmd_line, "x"); for (i = 0; i < j; ++i) { param = opal_cmd_line_get_param(cmd_line, "x", i, 0); if (NULL != (value = strchr(param, '='))) { /* terminate the name of the param */ *value = '\0'; /* step over the equals */ value++; /* overwrite any prior entry */ opal_setenv(param, value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(param, value, true, &orte_forwarded_envars); } else { value = getenv(param); if (NULL != value) { /* overwrite any prior entry */ opal_setenv(param, value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(param, value, true, &orte_forwarded_envars); } else { opal_output(0, "Warning: could not find environment variable \"%s\"\n", param); } } } } else if (NULL != env_set_flag) { /* if mca_base_env_list was set, check if some of env vars were set via -x from a conf file. * If this is the case, error out. */ if (!set_from_file) { /* set necessary env variables for external usage */ vars = NULL; if (OPAL_SUCCESS == mca_base_var_process_env_list(&vars) && NULL != vars) { for (i=0; NULL != vars[i]; i++) { value = strchr(vars[i], '='); /* terminate the name of the param */ *value = '\0'; /* step over the equals */ value++; /* overwrite any prior entry */ opal_setenv(vars[i], value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(vars[i], value, true, &orte_forwarded_envars); } opal_argv_free(vars); } } else { orte_show_help("help-orterun.txt", "orterun:conflict-env-set", false); return ORTE_ERR_FATAL; } } /* If the user specified --path, store it in the user's app environment via the OMPI_exec_path variable. */ if (NULL != path) { asprintf(&value, "OMPI_exec_path=%s", path); opal_argv_append_nosize(dstenv, value); /* save it for any comm_spawn'd apps */ opal_argv_append_nosize(&orte_forwarded_envars, value); free(value); } return ORTE_SUCCESS; }
int main(int argc, char *argv[]) { int ret = 0; bool acted = false; bool want_all = false; char **app_env = NULL, **global_env = NULL; int i; opal_cmd_line_t *ompi_info_cmd_line; opal_pointer_array_t mca_types; opal_pointer_array_t component_map; opal_info_component_map_t *map; /* protect against problems if someone passes us thru a pipe * and then abnormally terminates the pipe early */ signal(SIGPIPE, SIG_IGN); /* Initialize the argv parsing handle */ if (OPAL_SUCCESS != opal_init_util(&argc, &argv)) { opal_show_help("help-opal_info.txt", "lib-call-fail", true, "opal_init_util", __FILE__, __LINE__, NULL); exit(ret); } ompi_info_cmd_line = OBJ_NEW(opal_cmd_line_t); if (NULL == ompi_info_cmd_line) { ret = errno; opal_show_help("help-opal_info.txt", "lib-call-fail", true, "opal_cmd_line_create", __FILE__, __LINE__, NULL); exit(ret); } /* initialize the command line, parse it, and return the directives * telling us what the user wants output */ if (OPAL_SUCCESS != (ret = opal_info_init(argc, argv, ompi_info_cmd_line))) { exit(ret); } if (opal_cmd_line_is_taken(ompi_info_cmd_line, "version")) { fprintf(stdout, "Open MPI v%s\n\n%s\n", OPAL_VERSION, PACKAGE_BUGREPORT); exit(0); } /* setup the mca_types array */ OBJ_CONSTRUCT(&mca_types, opal_pointer_array_t); opal_pointer_array_init(&mca_types, 256, INT_MAX, 128); /* add in the opal frameworks */ opal_info_register_types(&mca_types); #if OMPI_RTE_ORTE /* add in the orte frameworks */ orte_info_register_types(&mca_types); #endif ompi_info_register_types(&mca_types); /* init the component map */ OBJ_CONSTRUCT(&component_map, opal_pointer_array_t); opal_pointer_array_init(&component_map, 256, INT_MAX, 128); /* Register OMPI's params */ if (OMPI_SUCCESS != (ret = ompi_info_register_framework_params(&component_map))) { if (OMPI_ERR_BAD_PARAM == ret) { /* output what we got */ opal_info_do_params(true, opal_cmd_line_is_taken(ompi_info_cmd_line, "internal"), &mca_types, &component_map, NULL); } exit(1); } /* Execute the desired action(s) */ want_all = opal_cmd_line_is_taken(ompi_info_cmd_line, "all"); if (want_all) { opal_info_out("Package", "package", OPAL_PACKAGE_STRING); ompi_info_show_ompi_version(opal_info_ver_full); } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "path")) { opal_info_do_path(want_all, ompi_info_cmd_line); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "arch")) { opal_info_do_arch(); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "hostname")) { opal_info_do_hostname(); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "config")) { ompi_info_do_config(true); acted = true; } if (want_all || opal_cmd_line_is_taken(ompi_info_cmd_line, "param") || opal_cmd_line_is_taken(ompi_info_cmd_line, "params")) { opal_info_do_params(want_all, opal_cmd_line_is_taken(ompi_info_cmd_line, "internal"), &mca_types, &component_map, ompi_info_cmd_line); acted = true; } if (opal_cmd_line_is_taken(ompi_info_cmd_line, "type")) { opal_info_do_type(ompi_info_cmd_line); acted = true; } /* If no command line args are specified, show default set */ if (!acted) { opal_info_out("Package", "package", OPAL_PACKAGE_STRING); ompi_info_show_ompi_version(opal_info_ver_full); opal_info_show_path(opal_info_path_prefix, opal_install_dirs.prefix); opal_info_do_arch(); opal_info_do_hostname(); ompi_info_do_config(false); opal_info_show_component_version(&mca_types, &component_map, opal_info_type_all, opal_info_component_all, opal_info_ver_full, opal_info_ver_all); } /* All done */ if (NULL != app_env) { opal_argv_free(app_env); } if (NULL != global_env) { opal_argv_free(global_env); } ompi_info_close_components(); OBJ_RELEASE(ompi_info_cmd_line); OBJ_DESTRUCT(&mca_types); for (i=0; i < component_map.size; i++) { if (NULL != (map = (opal_info_component_map_t*)opal_pointer_array_get_item(&component_map, i))) { OBJ_RELEASE(map); } } OBJ_DESTRUCT(&component_map); opal_info_finalize(); /* Put our own call to opal_finalize_util() here because we called it up above (and it refcounts) */ opal_finalize_util(); return 0; }
int main(int argc, char *argv[]) { int rc, i, j; opal_cmd_line_t cmd_line; char *param, *value; orte_job_t *jdata=NULL; orte_app_context_t *app; char *uri, *ptr; /* Setup and parse the command line */ memset(&myglobals, 0, sizeof(myglobals)); /* find our basename (the name of the executable) so that we can use it in pretty-print error messages */ myglobals.basename = opal_basename(argv[0]); opal_cmd_line_create(&cmd_line, cmd_line_init); mca_base_cmd_line_setup(&cmd_line); 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; } /* print version if requested. Do this before check for help so that --version --help works as one might expect. */ if (myglobals.version) { char *str; str = opal_info_make_version_str("all", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, OPAL_GREEK_VERSION, OPAL_REPO_REV); if (NULL != str) { fprintf(stdout, "%s %s\n\nReport bugs to %s\n", myglobals.basename, str, PACKAGE_BUGREPORT); free(str); } exit(0); } /* 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() && !myglobals.run_as_root) { fprintf(stderr, "--------------------------------------------------------------------------\n"); if (myglobals.help) { fprintf(stderr, "%s cannot provide the help message when run as root\n", myglobals.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", myglobals.basename); } fprintf(stderr, " This is *strongly* discouraged as any mistake (e.g., in defining TMPDIR) or bug can\n"); fprintf(stderr, "result in catastrophic damage to the OS file system, leaving\n"); fprintf(stderr, "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); } /* * Since this process can now handle MCA/GMCA parameters, make sure to * process them. * NOTE: It is "safe" to call mca_base_cmd_line_process_args() before * 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(&cmd_line, &environ, &environ)) { exit(1); } /* Need to initialize OPAL so that install_dirs are filled in */ if (OPAL_SUCCESS != opal_init(&argc, &argv)) { exit(1); } /* Check for help request */ if (myglobals.help) { char *str, *args = NULL; char *project_name = NULL; if (0 == strcmp(myglobals.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, myglobals.basename, project_name, OPAL_VERSION, myglobals.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); } /* flag that I am the HNP */ orte_process_info.proc_type = ORTE_PROC_HNP; /* Setup MCA params */ orte_register_params(); /* specify the DVM state machine */ opal_setenv("OMPI_MCA_state", "dvm", true, &environ); /* Intialize our Open RTE environment */ if (ORTE_SUCCESS != (rc = orte_init(&argc, &argv, ORTE_PROC_HNP))) { /* cannot call ORTE_ERROR_LOG as it could be the errmgr * never got loaded! */ return rc; } /* finalize OPAL. As it was opened again from orte_init->opal_init * we continue to have a reference count on it. So we have to finalize it twice... */ opal_finalize(); /* check for request to report uri */ uri = orte_rml.get_contact_info(); if (NULL != myglobals.report_uri) { FILE *fp; if (0 == strcmp(myglobals.report_uri, "-")) { /* if '-', then output to stdout */ printf("VMURI: %s\n", uri); } else if (0 == strcmp(myglobals.report_uri, "+")) { /* if '+', output to stderr */ fprintf(stderr, "VMURI: %s\n", uri); } else if (0 == strncasecmp(myglobals.report_uri, "file:", strlen("file:"))) { ptr = strchr(myglobals.report_uri, ':'); ++ptr; fp = fopen(ptr, "w"); if (NULL == fp) { orte_show_help("help-orterun.txt", "orterun:write_file", false, myglobals.basename, "pid", ptr); exit(0); } fprintf(fp, "%s\n", uri); fclose(fp); } else { fp = fopen(myglobals.report_uri, "w"); if (NULL == fp) { orte_show_help("help-orterun.txt", "orterun:write_file", false, myglobals.basename, "pid", myglobals.report_uri); exit(0); } fprintf(fp, "%s\n", uri); fclose(fp); } free(uri); } else { printf("VMURI: %s\n", uri); } /* get the daemon job object - was created by ess/hnp component */ if (NULL == (jdata = orte_get_job_data_object(ORTE_PROC_MY_NAME->jobid))) { orte_show_help("help-orterun.txt", "bad-job-object", true, myglobals.basename); exit(0); } /* also should have created a daemon "app" */ if (NULL == (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, 0))) { orte_show_help("help-orterun.txt", "bad-app-object", true, myglobals.basename); exit(0); } /* Did the user specify a prefix, or want prefix by default? */ if (opal_cmd_line_is_taken(&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(&cmd_line, "prefix") && NULL != myglobals.prefix) { /* if they don't match, then that merits a warning */ param = strdup(opal_cmd_line_get_param(&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(myglobals.prefix); if (0 == strcmp(OPAL_PATH_SEP, &(value[strlen(value)-1]))) { value[strlen(value)-1] = '\0'; } if (0 != strcmp(param, value)) { orte_show_help("help-orterun.txt", "orterun:app-prefix-conflict", true, myglobals.basename, value, param); /* let the global-level prefix take precedence since we * know that one is being used */ free(param); param = strdup(myglobals.prefix); } free(value); } else if (NULL != myglobals.prefix) { param = myglobals.prefix; } else if (opal_cmd_line_is_taken(&cmd_line, "prefix")){ /* must be --prefix alone */ param = strdup(opal_cmd_line_get_param(&cmd_line, "prefix", 0, 0)); } else { /* --enable-orterun-prefix-default was given to orterun */ param = strdup(opal_install_dirs.prefix); } if (NULL != param) { /* "Parse" the param, aka remove superfluous path_sep. */ param_len = strlen(param); while (0 == strcmp (OPAL_PATH_SEP, &(param[param_len-1]))) { param[param_len-1] = '\0'; param_len--; if (0 == param_len) { orte_show_help("help-orterun.txt", "orterun:empty-prefix", true, myglobals.basename, myglobals.basename); return ORTE_ERR_FATAL; } } orte_set_attribute(&app->attributes, ORTE_APP_PREFIX_DIR, ORTE_ATTR_GLOBAL, param, OPAL_STRING); free(param); } } /* Did the user specify a hostfile. Need to check for both * 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(&cmd_line, "hostfile"))) { if(1 < j) { orte_show_help("help-orterun.txt", "orterun:multiple-hostfiles", true, myglobals.basename, NULL); return ORTE_ERR_FATAL; } else { value = opal_cmd_line_get_param(&cmd_line, "hostfile", 0, 0); orte_set_attribute(&app->attributes, ORTE_APP_HOSTFILE, ORTE_ATTR_LOCAL, value, OPAL_STRING); } } if (0 < (j = opal_cmd_line_get_ninsts(&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, myglobals.basename, NULL); return ORTE_ERR_FATAL; } else { value = opal_cmd_line_get_param(&cmd_line, "machinefile", 0, 0); orte_set_attribute(&app->attributes, ORTE_APP_HOSTFILE, ORTE_ATTR_LOCAL, value, OPAL_STRING); } } /* Did the user specify any hosts? */ if (0 < (j = opal_cmd_line_get_ninsts(&cmd_line, "host"))) { char **targ=NULL, *tval; for (i = 0; i < j; ++i) { value = opal_cmd_line_get_param(&cmd_line, "host", i, 0); opal_argv_append_nosize(&targ, value); } tval = opal_argv_join(targ, ','); orte_set_attribute(&app->attributes, ORTE_APP_DASH_HOST, ORTE_ATTR_LOCAL, tval, OPAL_STRING); opal_argv_free(targ); free(tval); } OBJ_DESTRUCT(&cmd_line); /* setup to listen for commands sent specifically to me, even though I would probably * be the one sending them! Unfortunately, since I am a participating daemon, * there are times I need to send a command to "all daemons", and that means *I* have * to receive it too */ orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_DAEMON, ORTE_RML_PERSISTENT, orte_daemon_recv, NULL); /* override the notify_completed state so we can send a message * back to anyone who submits a job to us telling them the job * completed */ if (ORTE_SUCCESS != (rc = orte_state.set_job_state_callback(ORTE_JOB_STATE_NOTIFY_COMPLETED, notify_requestor))) { ORTE_ERROR_LOG(rc); ORTE_UPDATE_EXIT_STATUS(rc); exit(orte_exit_status); } /* spawn the DVM - we skip the initial steps as this * isn't a user-level application */ ORTE_ACTIVATE_JOB_STATE(jdata, ORTE_JOB_STATE_ALLOCATE); /* loop the event lib until an exit event is detected */ while (orte_event_base_active) { opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE); } /* cleanup and leave */ orte_finalize(); if (orte_debug_flag) { fprintf(stderr, "exiting with status %d\n", orte_exit_status); } exit(orte_exit_status); }
int main(int argc, char *argv[]) { int ret = 0; bool want_help = false; bool cmd_error = false; bool acted = false; bool want_all = false; char **app_env = NULL, **global_env = NULL; int i, len; char *str; /* protect against problems if someone passes us thru a pipe * and then abnormally terminates the pipe early */ signal(SIGPIPE, SIG_IGN); /* Initialize the argv parsing handle */ if (ORTE_SUCCESS != opal_init_util(&argc, &argv)) { orte_show_help("help-orte-info.txt", "lib-call-fail", true, "opal_init_util", __FILE__, __LINE__, NULL); exit(ret); } orte_info_cmd_line = OBJ_NEW(opal_cmd_line_t); if (NULL == orte_info_cmd_line) { ret = errno; orte_show_help("help-orte-info.txt", "lib-call-fail", true, "opal_cmd_line_create", __FILE__, __LINE__, NULL); opal_finalize_util(); exit(ret); } opal_cmd_line_make_opt3(orte_info_cmd_line, 'v', NULL, "version", 2, "Show version of ORTE or a component. The first parameter can be the keywords \"orte\" or \"all\", a framework name (indicating all components in a framework), or a framework:component string (indicating a specific component). The second parameter can be one of: full, major, minor, release, greek, svn."); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "param", 2, "Show MCA parameters. The first parameter is the framework (or the keyword \"all\"); the second parameter is the specific component name (or the keyword \"all\")."); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "internal", 0, "Show internal MCA parameters (not meant to be modified by users)"); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "path", 1, "Show paths that Open MPI was configured with. Accepts the following parameters: prefix, bindir, libdir, incdir, mandir, pkglibdir, sysconfdir"); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "arch", 0, "Show architecture Open MPI was corteled on"); opal_cmd_line_make_opt3(orte_info_cmd_line, 'c', NULL, "config", 0, "Show configuration options"); opal_cmd_line_make_opt3(orte_info_cmd_line, 'h', NULL, "help", 0, "Show this help message"); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "orte_info_pretty", 0, "When used in conjunction with other parameters, the output is displayed in 'orte_info_prettyprint' format (default)"); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "parsable", 0, "When used in conjunction with other parameters, the output is displayed in a machine-parsable format"); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "parseable", 0, "Synonym for --parsable"); opal_cmd_line_make_opt3(orte_info_cmd_line, '\0', NULL, "hostname", 0, "Show the hostname that Open MPI was configured " "and built on"); opal_cmd_line_make_opt3(orte_info_cmd_line, 'a', NULL, "all", 0, "Show all configuration options and MCA parameters"); /* Call some useless functions in order to guarantee to link in some * global variables. Only check the return value so that the * corteler doesn't optimize out the useless function. */ if (ORTE_SUCCESS != orte_locks_init()) { /* Stop .. or I'll say stop again! */ ++ret; } else { --ret; } /* set our threading level */ opal_set_using_threads(false); /* Get MCA parameters, if any */ if( ORTE_SUCCESS != mca_base_open() ) { orte_show_help("help-orte-info.txt", "lib-call-fail", true, "mca_base_open", __FILE__, __LINE__ ); OBJ_RELEASE(orte_info_cmd_line); opal_finalize_util(); exit(1); } mca_base_cmd_line_setup(orte_info_cmd_line); /* Do the parsing */ ret = opal_cmd_line_parse(orte_info_cmd_line, false, argc, argv); if (OPAL_SUCCESS != ret) { if (OPAL_ERR_SILENT != ret) { fprintf(stderr, "%s: command line error (%s)\n", argv[0], opal_strerror(ret)); } cmd_error = true; } if (!cmd_error && (opal_cmd_line_is_taken(orte_info_cmd_line, "help") || opal_cmd_line_is_taken(orte_info_cmd_line, "h"))) { char *str, *usage; want_help = true; usage = opal_cmd_line_get_usage_msg(orte_info_cmd_line); str = opal_show_help_string("help-orte-info.txt", "usage", true, usage); if (NULL != str) { printf("%s", str); free(str); } free(usage); } if (cmd_error || want_help) { mca_base_close(); OBJ_RELEASE(orte_info_cmd_line); opal_finalize_util(); exit(cmd_error ? 1 : 0); } 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 * creates a memory leak, but that's unfortunately how putenv() * works. :-( */ len = opal_argv_count(app_env); for (i = 0; i < len; ++i) { putenv(app_env[i]); } len = opal_argv_count(global_env); for (i = 0; i < len; ++i) { putenv(global_env[i]); } /* setup the mca_types array */ OBJ_CONSTRUCT(&mca_types, opal_pointer_array_t); opal_pointer_array_init(&mca_types, 256, INT_MAX, 128); opal_info_register_types(&mca_types); orte_info_register_types(&mca_types); /* Execute the desired action(s) */ if (opal_cmd_line_is_taken(orte_info_cmd_line, "orte_info_pretty")) { orte_info_pretty = true; } else if (opal_cmd_line_is_taken(orte_info_cmd_line, "parsable") || opal_cmd_line_is_taken(orte_info_cmd_line, "parseable")) { orte_info_pretty = false; } want_all = opal_cmd_line_is_taken(orte_info_cmd_line, "all"); if (want_all || opal_cmd_line_is_taken(orte_info_cmd_line, "version")) { orte_info_do_version(want_all, orte_info_cmd_line); acted = true; } if (want_all || opal_cmd_line_is_taken(orte_info_cmd_line, "path")) { orte_info_do_path(want_all, orte_info_cmd_line); acted = true; } if (want_all || opal_cmd_line_is_taken(orte_info_cmd_line, "arch")) { orte_info_do_arch(); acted = true; } if (want_all || opal_cmd_line_is_taken(orte_info_cmd_line, "hostname")) { orte_info_do_hostname(); acted = true; } if (want_all || opal_cmd_line_is_taken(orte_info_cmd_line, "config")) { orte_info_do_config(true); acted = true; } if (want_all || opal_cmd_line_is_taken(orte_info_cmd_line, "param")) { orte_info_do_params(want_all, opal_cmd_line_is_taken(orte_info_cmd_line, "internal")); acted = true; } /* If no command line args are specified, show default set */ if (!acted) { orte_info_show_orte_version(orte_info_ver_full); orte_info_show_path(orte_info_path_prefix, opal_install_dirs.prefix); orte_info_do_arch(); orte_info_do_hostname(); orte_info_do_config(false); orte_info_components_open(); for (i = 0; i < mca_types.size; ++i) { if (NULL == (str = (char*)opal_pointer_array_get_item(&mca_types, i))) { continue; } orte_info_show_component_version(str, orte_info_component_all, orte_info_ver_full, orte_info_type_all); } } /* All done */ if (NULL != app_env) { opal_argv_free(app_env); } if (NULL != global_env) { opal_argv_free(global_env); } orte_info_components_close (); OBJ_RELEASE(orte_info_cmd_line); OBJ_DESTRUCT(&mca_types); mca_base_close(); opal_finalize_util(); return 0; }