📄 mp_parse_command_line.c
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */#include <stdio.h>#include "mpiexec.h"#include "smpd.h"#include <stdlib.h>#ifdef HAVE_STRING_H#include <string.h>#endif#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H#include <sys/stat.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#if defined(HAVE_DIRECT_H) || defined(HAVE_WINDOWS_H)#include <direct.h>#endif#ifdef HAVE_WINDOWS_H#include <crtdbg.h>#endif#ifdef HAVE_CTYPE_H#include <ctype.h>#endifvoid mp_print_options(void){ printf("\n"); printf("Usage:\n"); printf("mpiexec -n <maxprocs> [options] executable [args ...]\n"); printf("mpiexec [options] executable [args ...] : [options] exe [args] : ...\n"); printf("mpiexec -configfile <configfile>\n"); printf("\n"); printf("options:\n"); printf("\n"); printf("standard:\n"); printf("-n <maxprocs>\n"); printf("-wdir <working directory>\n"); printf("-configfile <filename> -\n"); printf(" each line contains a complete set of mpiexec options\n"); printf(" including the executable and arguments\n"); printf("-host <hostname>\n"); /* printf("-soft <Fortran90 triple> - acceptable number of processes up to maxprocs\n"); printf(" a or a:b or a:b:c where\n"); printf(" 1) a = a\n"); printf(" 2) a:b = a, a+1, a+2, ..., b\n"); printf(" 3) a:b:c = a, a+c, a+2c, a+3c, ..., a+kc\n"); printf(" where a+kc <= b if c>0\n"); printf(" a+kc >= b if c<0\n"); */ printf("-path <search path for executable, ; separated>\n"); /*printf("-arch <architecture> - sun, linux, rs6000, ...\n");*/ printf("\n"); printf("extensions:\n"); printf("-env <variable value>\n"); printf("-hosts <n host1 host2 ... hostn>\n"); printf("-hosts <n host1 m1 host2 m2 ... hostn mn>\n"); printf("-machinefile <filename> - one host per line, #commented\n"); printf("-localonly <numprocs>\n"); printf("-exitcodes - print the exit codes of processes as they exit\n"); /* printf("-genvall - pass all env vars in current environment\n"); printf("-genvnone - pass no env vars\n"); */ printf("-genvlist <list of env var names a,b,c,...> - pass current values of these vars\n"); printf("-g<local arg name> - global version of local options\n"); printf(" genv, gwdir, ghost, gpath, gmap\n"); printf("-file <filename> - old mpich1 job configuration file\n"); printf("\n"); printf("examples:\n"); printf("mpiexec -n 4 cpi\n"); printf("mpiexec -n 1 -host foo master : -n 8 worker\n"); printf("\n"); printf("For a list of all mpiexec options, execute 'mpiexec -help2'\n");}void mp_print_extra_options(void){ printf("\n"); printf("All options to mpiexec:\n"); printf("\n"); printf("-n x\n"); printf("-np x\n"); printf(" launch x processes\n"); printf("-localonly x\n"); printf("-n x -localonly\n"); printf(" launch x processes on the local machine\n"); printf("-machinefile filename\n"); printf(" use a file to list the names of machines to launch on\n"); printf("-host hostname\n"); printf("-hosts n host1 host2 ... hostn\n"); printf("-hosts n host1 m1 host2 m2 ... hostn mn\n"); printf(" launch on the specified hosts\n"); printf(" In the second version the number of processes = m1 + m2 + ... + mn\n"); printf("-map drive:\\\\host\\share\n"); printf(" map a drive on all the nodes\n"); printf(" this mapping will be removed when the processes exit\n"); printf("-mapall\n"); printf(" map all of the current network drives\n"); printf(" this mapping will be removed when the processes exit\n"); printf(" (Available currently only on windows)\n"); printf("-dir drive:\\my\\working\\directory\n"); printf("-wdir /my/working/directory\n"); printf(" launch processes in the specified directory\n"); printf("-env var val\n"); printf(" set environment variable before launching the processes\n"); printf("-logon\n"); printf(" prompt for user account and password\n"); printf("-pwdfile filename\n"); printf(" read the account and password from the file specified\n"); printf(" put the account on the first line and the password on the second\n"); /* printf("-nocolor\n"); printf(" don't use process specific output coloring\n"); */ printf("-nompi\n"); printf(" launch processes without the mpi startup mechanism\n"); /* printf("-nomapping\n"); printf(" don't try to map the current directory on the remote nodes\n"); */ printf("-nopopup_debug\n"); printf(" disable the system popup dialog if the process crashes\n"); /* printf("-dbg\n"); printf(" catch unhandled exceptions\n"); */ printf("-exitcodes\n"); printf(" print the process exit codes when each process exits.\n"); printf("-noprompt\n"); printf(" prevent mpiexec from prompting for user credentials.\n"); printf("-priority class[:level]\n"); printf(" set the process startup priority class and optionally level.\n"); printf(" class = 0,1,2,3,4 = idle, below, normal, above, high\n"); printf(" level = 0,1,2,3,4,5 = idle, lowest, below, normal, above, highest\n"); printf(" the default is -priority 1:3\n"); printf("-localroot\n"); printf(" launch the root process directly from mpiexec if the host is local.\n"); printf(" (This allows the root process to create windows and be debugged.)\n"); printf("-port port\n"); printf("-p port\n"); printf(" specify the port that smpd is listening on.\n"); printf("-phrase passphrase\n"); printf(" specify the passphrase to authenticate connections to smpd with.\n"); printf("-smpdfile filename\n"); printf(" specify the file where the smpd options are stored including the passphrase.\n"); /* printf("-soft Fortran90_triple\n"); printf(" acceptable number of processes to launch up to maxprocs\n"); */ printf("-path search_path\n"); printf(" search path for executable, ; separated\n"); /* printf("-arch architecture\n"); printf(" sun, linux, rs6000, ...\n"); */ printf("-register [-user n]\n"); printf(" encrypt a user name and password to the Windows registry.\n"); printf(" optionally specify a user slot index\n"); printf("-remove [-user n]\n"); printf(" delete the encrypted credentials from the Windows registry.\n"); printf(" If no user index is specified then all entries are removed.\n"); printf("-validate [-user n] [-host hostname]\n"); printf(" validate the encrypted credentials for the current or specified host.\n"); printf(" A specific user index can be specified otherwise index 0 is the default.\n"); printf("-user n\n"); printf(" use the registered user credentials from slot n to launch the job.\n"); printf("-timeout seconds\n"); printf(" timeout for the job.\n"); printf("-plaintext\n"); printf(" don't encrypt the data on the wire.\n"); printf("-delegate\n"); printf(" use passwordless delegation to launch processes\n"); printf("-impersonate\n"); printf(" use passwordless authentication to launch processes\n"); printf("-add_job <job_name> <domain\\user>\n"); printf("-add_job <job_name> <domain\\user> -host <hostname>\n"); printf(" add a job key for the specified domain user on the local or specified host\n"); printf(" requires administrator privileges\n"); printf("-remove_job <name>\n"); printf("-remove_job <name> -host <hostname>\n"); printf(" remove a job key from the local or specified host\n"); printf(" requires administrator privileges\n"); printf("-associate_job <name>\n"); printf("-associate_job <name> -host <hostname>\n"); printf(" associate the current user's token with the specified job on the local or specified host\n"); printf("-job <name>\n"); printf(" launch the processes in the context of the specified job\n"); printf("-whomai\n"); printf(" print the current user name\n"); printf("-l\n"); printf(" prefix output with the process number. (This option is a lowercase L not the number one)\n");}#ifdef HAVE_WINDOWS_H/* check to see if a path is on a network mapped drive and would need to be mapped on a remote system */SMPD_BOOL NeedToMap(char *pszFullPath, char *pDrive, char *pszShare){ DWORD dwResult; DWORD dwLength; char pBuffer[4096]; REMOTE_NAME_INFO *info = (REMOTE_NAME_INFO*)pBuffer; char pszTemp[SMPD_MAX_EXE_LENGTH]; if (*pszFullPath == '"') { strncpy(pszTemp, &pszFullPath[1], SMPD_MAX_EXE_LENGTH); pszTemp[SMPD_MAX_EXE_LENGTH-1] = '\0'; if (pszTemp[strlen(pszTemp)-1] == '"') pszTemp[strlen(pszTemp)-1] = '\0'; pszFullPath = pszTemp; } dwLength = 4096; info->lpConnectionName = NULL; info->lpRemainingPath = NULL; info->lpUniversalName = NULL; dwResult = WNetGetUniversalName(pszFullPath, REMOTE_NAME_INFO_LEVEL, info, &dwLength); if (dwResult == NO_ERROR) { *pDrive = *pszFullPath; strcpy(pszShare, info->lpConnectionName); return SMPD_TRUE; } /*printf("WNetGetUniversalName: '%s'\n error %d\n", pszExe, dwResult);*/ return SMPD_FALSE;}/* convert an executable name to a universal naming convention version so that it can be used on a remote system */void ExeToUnc(char *pszExe, int length){ DWORD dwResult; DWORD dwLength; char pBuffer[4096]; REMOTE_NAME_INFO *info = (REMOTE_NAME_INFO*)pBuffer; char pszTemp[SMPD_MAX_EXE_LENGTH]; SMPD_BOOL bQuoted = SMPD_FALSE; char *pszOriginal; pszOriginal = pszExe; if (*pszExe == '"') { bQuoted = SMPD_TRUE; strncpy(pszTemp, &pszExe[1], SMPD_MAX_EXE_LENGTH); pszTemp[SMPD_MAX_EXE_LENGTH-1] = '\0'; if (pszTemp[strlen(pszTemp)-1] == '"') pszTemp[strlen(pszTemp)-1] = '\0'; pszExe = pszTemp; } dwLength = 4096; info->lpConnectionName = NULL; info->lpRemainingPath = NULL; info->lpUniversalName = NULL; dwResult = WNetGetUniversalName(pszExe, REMOTE_NAME_INFO_LEVEL, info, &dwLength); if (dwResult == NO_ERROR) { if (bQuoted) snprintf(pszOriginal, length, "\"%s\"", info->lpUniversalName); else { strncpy(pszOriginal, info->lpUniversalName, length); pszOriginal[length-1] = '\0'; } }}#endifstatic int strip_args(int *argcp, char **argvp[], int n){ int i; if (n+1 > (*argcp)) { printf("Error: cannot strip %d args, only %d left.\n", n, (*argcp)-1); return SMPD_FAIL; } for (i=n+1; i<=(*argcp); i++) { (*argvp)[i-n] = (*argvp)[i]; } (*argcp) -= n; return SMPD_SUCCESS;}static SMPD_BOOL smpd_isnumber(char *str){ size_t i, n = strlen(str); for (i=0; i<n; i++) { if (!isdigit(str[i])) return SMPD_FALSE; } return SMPD_TRUE;}#ifdef HAVE_WINDOWS_Hstatic int mpiexec_assert_hook( int reportType, char *message, int *returnValue ){ SMPD_UNREFERENCED_ARG(reportType); fprintf(stderr, "%s", message); if (returnValue != NULL) exit(*returnValue); exit(-1);}#endif#undef FCNAME#define FCNAME "mp_parse_command_args"int mp_parse_command_args(int *argcp, char **argvp[]){ int cur_rank; int argc, next_argc; char **next_argv; char *exe_ptr; int num_args_to_strip; int nproc; char machine_file_name[SMPD_MAX_FILENAME]; int use_machine_file = SMPD_FALSE; smpd_map_drive_node_t *map_node, *drive_map_list; smpd_map_drive_node_t *gmap_node, *gdrive_map_list; smpd_env_node_t *env_node, *env_list; smpd_env_node_t *genv_list; char *env_str, env_data[SMPD_MAX_ENV_LENGTH]; char wdir[SMPD_MAX_DIR_LENGTH]; char gwdir[SMPD_MAX_DIR_LENGTH]; int use_debug_flag; char pwd_file_name[SMPD_MAX_FILENAME]; int use_pwd_file; smpd_host_node_t *host_node_ptr, *host_list, *host_node_iter; smpd_host_node_t *ghost_list; int no_drive_mapping; int n_priority_class, n_priority; int index, i; char configfilename[SMPD_MAX_FILENAME]; int use_configfile, delete_configfile; char exe[SMPD_MAX_EXE_LENGTH], *exe_iter; char exe_path[SMPD_MAX_EXE_LENGTH], *namepart; smpd_launch_node_t *launch_node, *launch_node_iter; int exe_len_remaining; char path[SMPD_MAX_PATH_LENGTH]; char gpath[SMPD_MAX_PATH_LENGTH]; char temp_password[SMPD_MAX_PASSWORD_LENGTH]; FILE *fin_config = NULL; int result; int maxlen; int appnum = 0; char channel[SMPD_MAX_NAME_LENGTH] = ""; /* smpd configured settings */ char smpd_setting_tmp_buffer[20]; char smpd_setting_channel[20] = ""; char smpd_setting_internode_channel[20] = ""; SMPD_BOOL smpd_setting_timeout = SMPD_INVALID_SETTING; SMPD_BOOL smpd_setting_priority_class = SMPD_INVALID_SETTING; SMPD_BOOL smpd_setting_priority = SMPD_INVALID_SETTING; char smpd_setting_path[SMPD_MAX_PATH_LENGTH] = ""; SMPD_BOOL smpd_setting_localonly = SMPD_INVALID_SETTING;#ifdef HAVE_WINDOWS_H int user_index; char user_index_str[20];#endif smpd_enter_fn(FCNAME);#ifdef HAVE_WINDOWS_H /* prevent mpiexec from bringing up an error message window if it crashes */ _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); _CrtSetReportHook(mpiexec_assert_hook); /* check for windows specific arguments */ if (*argcp > 1) { if (strcmp((*argvp)[1], "-register") == 0) { user_index = 0; smpd_get_opt_int(argcp, argvp, "-user", &user_index); if (user_index < 0) { user_index = 0; } for (;;) { smpd_get_account_and_password(smpd_process.UserAccount, smpd_process.UserPassword); fprintf(stderr, "confirm password: ");fflush(stderr); smpd_get_password(temp_password); if (strcmp(smpd_process.UserPassword, temp_password) == 0) break; printf("passwords don't match, please try again.\n"); } if (smpd_save_password_to_registry(user_index, smpd_process.UserAccount, smpd_process.UserPassword, SMPD_TRUE)) { printf("Password encrypted into the Registry.\n"); smpd_delete_cached_password(); } else { printf("Error: Unable to save encrypted password.\n"); } fflush(stdout); smpd_exit(0); } if ( (strcmp((*argvp)[1], "-remove") == 0) || (strcmp((*argvp)[1], "-unregister") == 0) ) { user_index = 0; if (smpd_get_opt_string(argcp, argvp, "-user", user_index_str, 20))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -