📄 mp_parse_command_line.c
字号:
printf("Error: no filename specifed after -configfile option.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(configfilename, (*argvp)[2], SMPD_MAX_FILENAME); use_configfile = SMPD_TRUE; fin_config = fopen(configfilename, "r"); if (fin_config == NULL) { printf("Error: unable to open config file '%s'\n", configfilename); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (!smpd_get_argcv_from_file(fin_config, argcp, argvp)) { fclose(fin_config); printf("Error: unable to parse config file '%s'\n", configfilename); smpd_exit_fn(FCNAME); return SMPD_FAIL; } } if (strcmp(&(*argvp)[1][1], "file") == 0) { if (argc < 3) { printf("Error: no filename specifed after -file option.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } mp_parse_mpich1_configfile((*argvp)[2], configfilename, SMPD_MAX_FILENAME); delete_configfile = SMPD_TRUE; use_configfile = SMPD_TRUE; fin_config = fopen(configfilename, "r"); if (fin_config == NULL) { printf("Error: unable to open config file '%s'\n", configfilename); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (!smpd_get_argcv_from_file(fin_config, argcp, argvp)) { fclose(fin_config); printf("Error: unable to parse config file '%s'\n", configfilename); smpd_exit_fn(FCNAME); return SMPD_FAIL; } } } /* parse the current block */ /* parse the mpiexec options */ while ((*argvp)[1] && (*argvp)[1][0] == '-') { if ((*argvp)[1][1] == '-') { /* double -- option provided, trim it to a single - */ index = 2; while ((*argvp)[1][index] != '\0') { (*argvp)[1][index-1] = (*argvp)[1][index]; index++; } (*argvp)[1][index-1] = '\0'; } num_args_to_strip = 1; if ((strcmp(&(*argvp)[1][1], "np") == 0) || (strcmp(&(*argvp)[1][1], "n") == 0)) { if (nproc != 0) { printf("Error: only one option is allowed to determine the number of processes.\n"); printf(" -hosts, -n, -np and -localonly x are mutually exclusive\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (argc < 3) { printf("Error: no number specified after %s option.\n", (*argvp)[1]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } nproc = atoi((*argvp)[2]); if (nproc < 1) { printf("Error: must specify a number greater than 0 after the %s option\n", (*argvp)[1]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } num_args_to_strip = 2; } else if (strcmp(&(*argvp)[1][1], "localonly") == 0) { /* check to see if there is a number after the localonly option */ if (argc > 2) { if (smpd_isnumber((*argvp)[2])) { if (nproc != 0) { printf("Error: only one option is allowed to determine the number of processes.\n"); printf(" -hosts, -n, -np and -localonly x are mutually exclusive\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } nproc = atoi((*argvp)[2]); if (nproc < 1) { printf("Error: If you specify a number after -localonly option,\n it must be greater than 0.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } num_args_to_strip = 2; } }#if 0 /* the run_local flag + the rsh_mpiexec flag causes the rsh code to launch the processes locally */ smpd_process.mpiexec_run_local = SMPD_TRUE; smpd_process.rsh_mpiexec = SMPD_TRUE; if (smpd_process.mpiexec_inorder_launch == SMPD_FALSE) { smpd_launch_node_t *temp_node, *ordered_list = NULL; /* sort any existing reverse order nodes to be in order */ while (smpd_process.launch_list) { temp_node = smpd_process.launch_list->next; smpd_process.launch_list->next = ordered_list; ordered_list = smpd_process.launch_list; smpd_process.launch_list = temp_node; } smpd_process.launch_list = ordered_list; } smpd_process.mpiexec_inorder_launch = SMPD_TRUE;#else /* Use localroot to implement localonly */ smpd_process.local_root = SMPD_TRUE; /* create a host list of one and set nproc to -1 to be replaced by nproc after parsing the block */ host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t)); if (host_list == NULL) { printf("failed to allocate memory for a host node.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } host_list->next = NULL; host_list->left = NULL; host_list->right = NULL; host_list->connected = SMPD_FALSE; host_list->connect_cmd_tag = -1; host_list->connect_cmd_tag = -1; host_list->nproc = -1; host_list->alt_host[0] = '\0'; smpd_get_hostname(host_list->host, SMPD_MAX_HOST_LENGTH);#endif } else if (strcmp(&(*argvp)[1][1], "machinefile") == 0) { if (smpd_process.s_host_list != NULL) { printf("Error: -machinefile can only be specified once per section.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (argc < 3) { printf("Error: no filename specified after -machinefile option.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(machine_file_name, (*argvp)[2], SMPD_MAX_FILENAME); use_machine_file = SMPD_TRUE; smpd_parse_machine_file(machine_file_name); num_args_to_strip = 2; } else if (strcmp(&(*argvp)[1][1], "map") == 0) { if (argc < 3) { printf("Error: no drive specified after -map option.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (smpd_parse_map_string((*argvp)[2], &drive_map_list) != SMPD_SUCCESS) { printf("Error: unable to parse the drive mapping option - '%s'\n", (*argvp)[2]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } num_args_to_strip = 2; } else if (strcmp(&(*argvp)[1][1], "mapall") == 0){#ifdef HAVE_WINDOWS_H if(smpd_mapall(&drive_map_list) != SMPD_SUCCESS){ printf("Error: unable to map all network drives"); smpd_exit_fn(FCNAME); return SMPD_FAIL; }#endif num_args_to_strip = 1; } else if (strcmp(&(*argvp)[1][1], "gmap") == 0) { if (argc < 3) { printf("Error: no drive specified after -gmap option.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (smpd_parse_map_string((*argvp)[2], &gdrive_map_list) != SMPD_SUCCESS) { printf("Error: unable to parse the drive mapping option - '%s'\n", (*argvp)[2]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } num_args_to_strip = 2; } else if ( (strcmp(&(*argvp)[1][1], "dir") == 0) || (strcmp(&(*argvp)[1][1], "wdir") == 0) ) { if (argc < 3) { printf("Error: no directory after %s option\n", (*argvp)[1]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(wdir, (*argvp)[2], SMPD_MAX_DIR_LENGTH); num_args_to_strip = 2; } else if ( (strcmp(&(*argvp)[1][1], "gdir") == 0) || (strcmp(&(*argvp)[1][1], "gwdir") == 0) ) { if (argc < 3) { printf("Error: no directory after %s option\n", (*argvp)[1]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(gwdir, (*argvp)[2], SMPD_MAX_DIR_LENGTH); num_args_to_strip = 2; } else if (strcmp(&(*argvp)[1][1], "env") == 0) { if (argc < 4) { printf("Error: no environment variable after -env option\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } env_node = (smpd_env_node_t*)MPIU_Malloc(sizeof(smpd_env_node_t)); if (env_node == NULL) { printf("Error: malloc failed to allocate structure to hold an environment variable.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(env_node->name, (*argvp)[2], SMPD_MAX_NAME_LENGTH); strncpy(env_node->value, (*argvp)[3], SMPD_MAX_VALUE_LENGTH); env_node->next = env_list; env_list = env_node; if (strcmp(env_node->name, "MPI_DLL_NAME") == 0) { MPIU_Strncpy(smpd_process.env_dll, env_node->value, SMPD_MAX_FILENAME); } if (strcmp(env_node->name, "MPI_WRAP_DLL_NAME") == 0) { MPIU_Strncpy(smpd_process.env_wrap_dll, env_node->value, SMPD_MAX_FILENAME); }#ifdef HAVE_WINDOWS_H if ((strcmp(env_node->name, "MPICH_CHOP_ERROR_STACK") == 0) && ((env_node->value[0] == '\0') || (env_node->value[0] == '-'))) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if (hConsole != INVALID_HANDLE_VALUE) { CONSOLE_SCREEN_BUFFER_INFO info; if (GetConsoleScreenBufferInfo(hConsole, &info)) { /* The user chose default so set the value to the width of the current output console window */ snprintf(env_node->value, SMPD_MAX_VALUE_LENGTH, "%d", info.dwMaximumWindowSize.X); /*printf("width = %d\n", info.dwMaximumWindowSize.X);*/ } } }#endif num_args_to_strip = 3; } else if (strcmp(&(*argvp)[1][1], "envlist") == 0){ char *str, *token, *value; if (argc < 4){ printf("Error: no environment variable after -envlist option\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } str = MPIU_Strdup((*argvp)[2]);
if (str == NULL){
printf("Error: unable to allocate memory for copying envlist - '%s'\n", (*argvp)[2]);
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
token = strtok(str, ",");
while (token){
value = getenv(token);
if (value != NULL){
env_node = (smpd_env_node_t*)MPIU_Malloc(sizeof(smpd_env_node_t));
if (env_node == NULL){
printf("Error: malloc failed to allocate structure to hold an environment variable.\n");
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
strncpy(env_node->name, token, SMPD_MAX_NAME_LENGTH);
strncpy(env_node->value, value, SMPD_MAX_VALUE_LENGTH);
env_node->next = env_list;
env_list = env_node;
}
else{
printf("Error: Cannot obtain value of env variable : %s\n", token);
}
token = strtok(NULL, ",");
}
MPIU_Free(str);
num_args_to_strip = 2; } else if (strcmp(&(*argvp)[1][1], "envnone") == 0){ printf("-envnone option is not implemented\n"); num_args_to_strip = 1; } else if (strcmp(&(*argvp)[1][1], "genv") == 0) { if (argc < 4) { printf("Error: no environment variable after -genv option\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } env_node = (smpd_env_node_t*)MPIU_Malloc(sizeof(smpd_env_node_t)); if (env_node == NULL) { printf("Error: malloc failed to allocate structure to hold an environment variable.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(env_node->name, (*argvp)[2], SMPD_MAX_NAME_LENGTH); strncpy(env_node->value, (*argvp)[3], SMPD_MAX_VALUE_LENGTH); env_node->next = genv_list; genv_list = env_node;#ifdef HAVE_WINDOWS_H if ((strcmp(env_node->name, "MPICH_CHOP_ERROR_STACK") == 0) && ((env_node->value[0] == '\0') || (env_node->value[0] == '-'))) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if (hConsole != INVALID_HANDLE_VALUE) { CONSOLE_SCREEN_BUFFER_INFO info; if (GetConsoleScreenBufferInfo(hConsole, &info)) { /* The user chose default so set the value to the width of the current output console window */ snprintf(env_node->value, SMPD_MAX_VALUE_LENGTH, "%d", info.dwMaximumWindowSize.X); /*printf("width = %d\n", info.dwMaximumWindowSize.X);*/ } } }#endif num_args_to_strip = 3; } else if (strcmp(&(*argvp)[1][1], "genvall") == 0) { printf("-genvall option not implemented\n"); num_args_to_strip = 1; } else if (strcmp(&(*argvp)[1][1], "genvnone") == 0) { printf("-genvnone option not implemented\n"); num_args_to_strip = 1; } else if (strcmp(&(*argvp)[1][1], "genvlist") == 0) { char *str, *token, *value; if (argc < 4) { printf("Error: no environment variables after -genvlist option\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } str = MPIU_Strdup((*argvp)[2]); if (str == NULL) { printf("Error: unable to allocate memory for a string - '%s'\n", (*argvp)[2]); smpd_exit_fn(FCNAME); return SMPD_FAIL; } token = strtok(str, ","); while (token) { value = getenv(token); if (value != NULL) { env_node = (smpd_env_node_t*)MPIU_Malloc(sizeof(smpd_env_node_t)); if (env_node == NULL) { printf("Error: malloc failed to allocate structure to hold an environment variable.\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } strncpy(env_node->name, token, SMPD_MAX_NAME_LENGTH); strncpy(env_node->value, value, SMPD_MAX_VALUE_LENGTH); env_node->next = genv_list; genv_list = env_node; } token = strtok(NULL, ","); } MPIU_Free(str); num_args_to_strip = 2; } else if ( (strcmp(&(*argvp)[1][1], "logon") == 0) || (strcmp(&(*argvp)[1][1], "login") == 0) ) { smpd_process.logon = SMPD_TRUE; } else if ( (strcmp(&(*argvp)[1][1], "impersonate") == 0) || (strcmp(&(*argvp)[1][1], "impersonation") == 0) ) { smpd_process.use_sspi = SMPD_TRUE; smpd_process.use_delegation = SMPD_FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -