📄 orterun.c
字号:
#if 0 /* JMS commented out because we don't handle this in any mapper */ /* Save -arch args */ else if (0 == strcmp("-arch", argv[i])) { char str[2] = { '0' + ORTE_APP_CONTEXT_MAP_ARCH, '\0' }; opal_argv_append(&new_argc, &new_argv, "-rawmap"); opal_argv_append(&new_argc, &new_argv, str); save_arg = false; }#endif /* Save -host args */ else if (0 == strcmp("--host",argv[i]) || 0 == strcmp("-host", argv[i]) || 0 == strcmp("-H", argv[i])) { char str[2] = { '0' + ORTE_APP_CONTEXT_MAP_HOSTNAME, '\0' }; opal_argv_append(&new_argc, &new_argv, "-rawmap"); opal_argv_append(&new_argc, &new_argv, str); save_arg = false; } /* If this token was C/N map data, save it */ if (map_data) { char str[2] = { '0' + ORTE_APP_CONTEXT_MAP_CN, '\0' }; opal_argv_append(&new_argc, &new_argv, "-rawmap"); opal_argv_append(&new_argc, &new_argv, str); } if (save_arg) { opal_argv_append(&new_argc, &new_argv, argv[i]); } } /* Parse application command line options. Add the -rawmap option separately so that the user doesn't see it in the --help message. */ init_globals(); opal_cmd_line_create(&cmd_line, cmd_line_init); mca_base_cmd_line_setup(&cmd_line); cmd_line_made = true; opal_cmd_line_make_opt3(&cmd_line, '\0', NULL, "rawmap", 2, "Hidden / internal parameter -- users should not use this!"); rc = opal_cmd_line_parse(&cmd_line, true, new_argc, new_argv); opal_argv_free(new_argv); new_argv = NULL; if (ORTE_SUCCESS != rc) { goto cleanup; } mca_base_cmd_line_process_args(&cmd_line, app_env, &global_mca_env); /* Is there an appfile in here? */ if (NULL != orterun_globals.appfile) { OBJ_DESTRUCT(&cmd_line); return parse_appfile(strdup(orterun_globals.appfile), app_env); } /* Setup application context */ app = OBJ_NEW(orte_app_context_t); opal_cmd_line_get_tail(&cmd_line, &count, &app->argv); /* See if we have anything left */ if (0 == count) { opal_show_help("help-orterun.txt", "orterun:executable-not-specified", true, orterun_basename, orterun_basename); rc = ORTE_ERR_NOT_FOUND; goto cleanup; } /* Grab all OMPI_* environment variables */ app->env = opal_argv_copy(*app_env); for (i = 0; NULL != environ[i]; ++i) { if (0 == strncmp("OMPI_", environ[i], 5)) { opal_argv_append_nosize(&app->env, environ[i]); } } /* Did the user request to export any environment variables? */ if (opal_cmd_line_is_taken(&cmd_line, "x")) { 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 != strchr(param, '=')) { opal_argv_append_nosize(&app->env, param); } else { value = getenv(param); if (NULL != value) { if (NULL != strchr(value, '=')) { opal_argv_append_nosize(&app->env, value); } else { asprintf(&value2, "%s=%s", param, value); opal_argv_append_nosize(&app->env, value2); free(value2); } } else { opal_output(0, "Warning: could not find environment variable \"%s\"\n", param); } } } } /* Did the user request a specific path? */ if (NULL != orterun_globals.path) { asprintf(&value, "PATH=%s", orterun_globals.path); opal_argv_append_nosize(&app->env, value); free(value); } /* Did the user request a specific wdir? */ if (NULL != orterun_globals.wdir) { app->cwd = strdup(orterun_globals.wdir); app->user_specified_cwd = true; } else { getcwd(cwd, sizeof(cwd)); app->cwd = strdup(cwd); app->user_specified_cwd = false; } /* Check to see if the user explicitly wanted to disable automatic --prefix behavior */ if (opal_cmd_line_is_taken(&cmd_line, "noprefix")) { want_prefix_by_default = false; } /* Did the user specify a specific prefix for this app_context_t or provide an absolute path name to argv[0]? */ if (opal_cmd_line_is_taken(&cmd_line, "prefix") || '/' == argv[0][0] || want_prefix_by_default) { size_t param_len; /* The --prefix option takes precedence over /path/to/orterun */ if (opal_cmd_line_is_taken(&cmd_line, "prefix")) { param = opal_cmd_line_get_param(&cmd_line, "prefix", 0, 0); } /* /path/to/orterun */ else if ('/' == argv[0][0]) { char* tmp_basename = NULL; /* If they specified an absolute path, strip off the /bin/<exec_name>" and leave just the prefix */ param = opal_dirname(argv[0]); /* Quick sanity check to ensure we got something/bin/<exec_name> and that the installation tree is at least more or less what we expect it to be */ tmp_basename = opal_basename(param); if (0 == strcmp("bin", tmp_basename)) { char* tmp = param; param = opal_dirname(tmp); free(tmp); } else { free(param); param = NULL; } free(tmp_basename); } /* --enable-orterun-prefix-default was given to orterun */ else { 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) { opal_show_help("help-orterun.txt", "orterun:empty-prefix", true, orterun_basename, orterun_basename); return ORTE_ERR_FATAL; } } app->prefix_dir = strdup(param); } } /* Did the user request any mappings? They were all converted to --rawmap items, above. */ if (opal_cmd_line_is_taken(&cmd_line, "rawmap")) { j = opal_cmd_line_get_ninsts(&cmd_line, "rawmap"); app->map_data = (orte_app_context_map_t**)malloc(sizeof(orte_app_context_map_t*) * j); if (NULL == app->map_data) { rc = ORTE_ERR_OUT_OF_RESOURCE; goto cleanup; } app->num_map = j; for (i = 0; i < j; ++i) { app->map_data[i] = NULL; } for (i = 0; i < j; ++i) { value = opal_cmd_line_get_param(&cmd_line, "rawmap", i, 0); value2 = opal_cmd_line_get_param(&cmd_line, "rawmap", i, 1); app->map_data[i] = OBJ_NEW(orte_app_context_map_t); if (NULL == app->map_data[i]) { rc = ORTE_ERR_OUT_OF_RESOURCE; goto cleanup; } app->map_data[i]->map_type = value[0] - '0'; app->map_data[i]->map_data = strdup(value2); /* map_data = true; * JJH - This activates the C/N mapping stuff, * or at least allows us to pass the 'num_procs' check below. * since it is not implemented yet, leave commented. */ } } /* Get the numprocs */ app->num_procs = (orte_std_cntr_t)orterun_globals.num_procs; /* If the user didn't specify the number of processes to run, then we default to launching an app process using every slot. We can't do anything about that here - we leave it to the RMAPS framework's components to note this and deal with it later. HOWEVER, we ONLY support this mode of operation if the number of app_contexts is equal to ONE. If the user provides multiple applications, we simply must have more information - in this case, generate an error. */ if (app->num_procs == 0) { have_zero_np = true; /** flag that we have a zero_np situation */ } if (0 < total_num_apps && have_zero_np) { /** we have more than one app and a zero_np - that's no good. * note that we have to do this as a two step logic check since * the user may fail to specify num_procs for the first app, but * then give us another application. */ opal_show_help("help-orterun.txt", "orterun:multi-apps-and-zero-np", true, orterun_basename, NULL); return ORTE_ERR_FATAL; } total_num_apps++; /* Do not try to find argv[0] here -- the starter is responsible for that because it may not be relevant to try to find it on the node where orterun is executing. So just strdup() argv[0] into app. */ app->app = strdup(app->argv[0]); if (NULL == app->app) { opal_show_help("help-orterun.txt", "orterun:call-failed", true, orterun_basename, "library", "strdup returned NULL", errno); rc = ORTE_ERR_NOT_FOUND; goto cleanup; } *app_ptr = app; app = NULL; *made_app = true; /* All done */ cleanup: if (NULL != app) { OBJ_RELEASE(app); } if (NULL != new_argv) { opal_argv_free(new_argv); } if (cmd_line_made) { OBJ_DESTRUCT(&cmd_line); } return rc;}static int parse_appfile(char *filename, char ***env){ size_t i, len; FILE *fp; char line[BUFSIZ]; int rc, argc, app_num; char **argv; orte_app_context_t *app; bool blank, made_app; char bogus[] = "bogus "; char **tmp_env; /* Try to open the file */ fp = fopen(filename, "r"); if (NULL == fp) { opal_show_help("help-orterun.txt", "orterun:appfile-not-found", true, filename); return ORTE_ERR_NOT_FOUND; } /* Read in line by line */ line[sizeof(line) - 1] = '\0'; app_num = 0; do { /* We need a bogus argv[0] (because when argv comes in from the command line, argv[0] is "orterun", so the parsing logic ignores it). So create one here rather than making an argv and then pre-pending a new argv[0] (which would be rather inefficient). */ line[0] = '\0'; strcat(line, bogus); if (NULL == fgets(line + sizeof(bogus) - 1, sizeof(line) - sizeof(bogus) - 1, fp)) { break; } /* Remove a trailing newline */ len = strlen(line); if (len > 0 && '\n' == line[len - 1]) { line[len - 1] = '\0'; if (len > 0) { --len; } } /* Remove comments */ for (i = 0; i < len; ++i) { if ('#' == line[i]) { line[i] = '\0'; break; } else if (i + 1 < len && '/' == line[i] && '/' == line[i + 1]) { line[i] = '\0'; break; } } /* Is this a blank line? */ len = strlen(line); for (blank = true, i = sizeof(bogus); i < len; ++i) { if (!isspace(line[i])) { blank = false; break; } } if (blank) { continue; } /* We got a line with *something* on it. So process it */ argv = opal_argv_split(line, ' '); argc = opal_argv_count(argv); if (argc > 0) { /* Create a temporary env to use in the recursive call -- that is: don't disturb the original env so that we can have a consistent global env. This allows for the case: orterun --mca foo bar --appfile file where the "file" contains multiple apps. In this case, each app in "file" will get *only* foo=bar as the base environment from which its specific environment is constructed. */ if (NULL != *env) { tmp_env = opal_argv_copy(*env); if (NULL == tmp_env) { return ORTE_ERR_OUT_OF_RESOURCE; } } else { tmp_env = NULL; } rc = create_app(argc, argv, &app, &made_app, &tmp_env); if (ORTE_SUCCESS != rc) { /* Assume that the error message has already been printed; no need to cleanup -- we can just exit */ exit(1); } if (NULL != tmp_env) { opal_argv_free(tmp_env); } if (made_app) { orte_std_cntr_t dummy; app->idx = app_num; ++app_num; orte_pointer_array_add(&dummy, apps_pa, app); } } } while (!feof(fp)); fclose(fp); /* All done */ free(filename); return ORTE_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -