⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp_parse_command_line.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 5 页
字号:
		host_list->nproc = -1;		host_list->alt_host[0] = '\0';		strncpy(host_list->host, (*argvp)[2], SMPD_MAX_HOST_LENGTH);		num_args_to_strip = 2;		smpd_add_host_to_default_list((*argvp)[2]);	    }	    else if (strcmp(&(*argvp)[1][1], "ghost") == 0)	    {		if (argc < 3)		{		    printf("Error: no host specified after -ghost option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		if (ghost_list != NULL)		{		    printf("Error: -ghost option can only be specified once.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		/* create a host list of one and set nproc to -1 to be replaced by		   nproc after parsing the block */		ghost_list = (smpd_host_node_t*)malloc(sizeof(smpd_host_node_t));		if (ghost_list == NULL)		{		    printf("failed to allocate memory for a host node.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		ghost_list->next = NULL;		ghost_list->left = NULL;		ghost_list->right = NULL;		ghost_list->connected = SMPD_FALSE;		ghost_list->connect_cmd_tag = -1;		ghost_list->nproc = -1;		ghost_list->alt_host[0] = '\0';		strncpy(ghost_list->host, (*argvp)[2], SMPD_MAX_HOST_LENGTH);		num_args_to_strip = 2;		smpd_add_host_to_default_list((*argvp)[2]);	    }	    else if (strcmp(&(*argvp)[1][1], "hosts") == 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 (host_list != NULL)		{		    printf("Error: -hosts option can only be called once and it cannot be combined with -host.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		if (argc > 2)		{		    if (smpd_isnumber((*argvp)[2]))		    {			/* initially set nproc to be the number of hosts */			nproc = atoi((*argvp)[2]);			if (nproc < 1)			{			    printf("Error: You must specify a number greater than 0 after -hosts.\n");			    smpd_exit_fn(FCNAME);			    return SMPD_FAIL;			}			num_args_to_strip = 2 + nproc;			index = 3;			for (i=0; i<nproc; i++)			{			    if (index >= argc)			    {				printf("Error: missing host name after -hosts option.\n");				smpd_exit_fn(FCNAME);				return SMPD_FAIL;			    }			    host_node_ptr = (smpd_host_node_t*)malloc(sizeof(smpd_host_node_t));			    if (host_node_ptr == NULL)			    {				printf("failed to allocate memory for a host node.\n");				smpd_exit_fn(FCNAME);				return SMPD_FAIL;			    }			    host_node_ptr->next = NULL;			    host_node_ptr->left = NULL;			    host_node_ptr->right = NULL;			    host_node_ptr->connected = SMPD_FALSE;			    host_node_ptr->connect_cmd_tag = -1;			    host_node_ptr->nproc = 1;			    host_node_ptr->alt_host[0] = '\0';			    strncpy(host_node_ptr->host, (*argvp)[index], SMPD_MAX_HOST_LENGTH);			    smpd_add_host_to_default_list((*argvp)[index]);			    index++;			    if (argc > index)			    {				if (smpd_isnumber((*argvp)[index]))				{				    host_node_ptr->nproc = atoi((*argvp)[index]);				    index++;				    num_args_to_strip++;				}			    }			    if (host_list == NULL)			    {				host_list = host_node_ptr;			    }			    else			    {				host_node_iter = host_list;				while (host_node_iter->next)				    host_node_iter = host_node_iter->next;				host_node_iter->next = host_node_ptr;			    }			}			/* adjust nproc to be the actual number of processes */			host_node_iter = host_list;			nproc = 0;			while (host_node_iter)			{			    nproc += host_node_iter->nproc;			    host_node_iter = host_node_iter->next;			}		    }		    else		    {			printf("Error: You must specify the number of hosts after the -hosts option.\n");			smpd_exit_fn(FCNAME);			return SMPD_FAIL;		    }		}		else		{		    printf("Error: not enough arguments specified for -hosts option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}	    }	    else if (strcmp(&(*argvp)[1][1], "nocolor") == 0)	    {		smpd_process.do_multi_color_output = SMPD_FALSE;	    }	    else if (strcmp(&(*argvp)[1][1], "nompi") == 0)	    {		smpd_process.no_mpi = SMPD_TRUE;	    }	    else if (strcmp(&(*argvp)[1][1], "nomapping") == 0)	    {		no_drive_mapping = SMPD_TRUE;	    }	    else if (strcmp(&(*argvp)[1][1], "nopopup_debug") == 0)	    {#ifdef HAVE_WINDOWS_H		SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);#endif	    }	    else if (strcmp(&(*argvp)[1][1], "help") == 0 || (*argvp)[1][1] == '?')	    {		mp_print_options();		exit(0);	    }	    else if (strcmp(&(*argvp)[1][1], "help2") == 0)	    {		mp_print_extra_options();		exit(0);	    }	    else if (strcmp(&(*argvp)[1][1], "exitcodes") == 0)	    {		smpd_process.output_exit_codes = SMPD_TRUE;	    }	    else if (strcmp(&(*argvp)[1][1], "localroot") == 0)	    {		smpd_process.local_root = SMPD_TRUE;	    }	    else if (strcmp(&(*argvp)[1][1], "priority") == 0)	    {		if (argc < 3)		{		    printf("Error: you must specify a priority after the -priority option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		if (smpd_isnumbers_with_colon((*argvp)[2]))		{		    char *str;		    n_priority_class = atoi((*argvp)[2]); /* This assumes atoi will stop at the colon and return a number */		    str = strchr((*argvp)[2], ':');		    if (str)		    {			str++;			n_priority = atoi(str);		    }		    if (n_priority_class < 0 || n_priority_class > 4 || n_priority < 0 || n_priority > 5)		    {			printf("Error: priorities must be between 0-4:0-5\n");			smpd_exit_fn(FCNAME);			return SMPD_FAIL;		    }		}		else		{		    printf("Error: you must specify a priority after the -priority option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		smpd_dbg_printf("priorities = %d:%d\n", n_priority_class, n_priority);		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "iproot") == 0)	    {		smpd_process.use_iproot = SMPD_TRUE;	    }	    else if (strcmp(&(*argvp)[1][1], "noiproot") == 0)	    {		smpd_process.use_iproot = SMPD_FALSE;	    }	    else if (strcmp(&(*argvp)[1][1], "verbose") == 0)	    {		smpd_process.verbose = SMPD_TRUE;		smpd_process.dbg_state |= SMPD_DBG_STATE_ERROUT | SMPD_DBG_STATE_STDOUT | SMPD_DBG_STATE_TRACE;	    }	    else if ( (strcmp(&(*argvp)[1][1], "p") == 0) || (strcmp(&(*argvp)[1][1], "port") == 0))	    {		if (argc > 2)		{		    if (smpd_isnumber((*argvp)[2]))		    {			smpd_process.port = atoi((*argvp)[2]);		    }		    else		    {			printf("Error: you must specify the port smpd is listening on after the %s option.\n", (*argvp)[1]);			smpd_exit_fn(FCNAME);			return SMPD_FAIL;		    }		}		else		{		    printf("Error: you must specify the port smpd is listening on 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], "path") == 0)	    {		if (argc < 3)		{		    printf("Error: no path specifed after -path option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		strncpy(path, (*argvp)[2], SMPD_MAX_PATH_LENGTH);		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "gpath") == 0)	    {		if (argc < 3)		{		    printf("Error: no path specifed after -gpath option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		strncpy(gpath, (*argvp)[2], SMPD_MAX_PATH_LENGTH);		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "noprompt") == 0)	    {		smpd_process.noprompt = SMPD_TRUE;		smpd_process.credentials_prompt = SMPD_FALSE;	    }	    else if (strcmp(&(*argvp)[1][1], "phrase") == 0)	    {		if (argc < 3)		{		    printf("Error: no passphrase specified afterh -phrase option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		strncpy(smpd_process.passphrase, (*argvp)[2], SMPD_PASSPHRASE_MAX_LENGTH);		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "smpdfile") == 0)	    {		if (argc < 3)		{		    printf("Error: no file name specified after -smpdfile option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		strncpy(smpd_process.smpd_filename, (*argvp)[2], SMPD_MAX_FILENAME);		{		    struct stat s;		    if (stat(smpd_process.smpd_filename, &s) == 0)		    {			if (s.st_mode & 00077)			{			    printf("Error: .smpd file cannot be readable by anyone other than the current user.\n");			    smpd_exit_fn(FCNAME);			    return SMPD_FAIL;			}		    }		}		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "timeout") == 0)	    {		if (argc < 3)		{		    printf("Error: no timeout specified after -timeout option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		smpd_process.timeout = atoi((*argvp)[2]);		if (smpd_process.timeout < 1)		{		    printf("Warning: invalid timeout specified, ignoring timeout value of '%s'\n", (*argvp)[2]);		    smpd_process.timeout = -1;		}		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "hide_console") == 0)	    {#ifdef HAVE_WINDOWS_H		FreeConsole();#endif	    }	    else if (strcmp(&(*argvp)[1][1], "quiet_abort") == 0)	    {		smpd_process.verbose_abort_output = SMPD_FALSE;	    }	    else if ((strcmp(&(*argvp)[1][1], "rsh") == 0) || (strcmp(&(*argvp)[1][1], "ssh") == 0))	    {		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 if ((strcmp(&(*argvp)[1][1], "nosmpd") == 0) || (strcmp(&(*argvp)[1][1], "no_smpd") == 0) || (strcmp(&(*argvp)[1][1], "nopm") == 0))	    {		smpd_process.use_pmi_server = SMPD_FALSE;	    }	    else if (strcmp(&(*argvp)[1][1], "plaintext") == 0)	    {		smpd_process.plaintext = SMPD_TRUE;	    }	    else if (strcmp(&(*argvp)[1][1], "channel") == 0)	    {		if (argc < 3)		{		    printf("Error: no name specified after -channel option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		strncpy(channel, (*argvp)[2], SMPD_MAX_NAME_LENGTH);		num_args_to_strip = 2;	    }	    else if (strcmp(&(*argvp)[1][1], "log") == 0)	    {		/* -log is a shortcut to create log files using the mpe wrapper dll */		env_node = (smpd_env_node_t*)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, "MPI_WRAP_DLL_NAME", SMPD_MAX_NAME_LENGTH);		strncpy(env_node->value, "mpe", SMPD_MAX_VALUE_LENGTH);		env_node->next = env_list;		env_list = env_node;	    }#ifdef HAVE_WINDOWS_H	    else if (strcmp(&(*argvp)[1][1], "user") == 0)	    {		if (argc < 3)		{		    printf("Error: no index specified after -user option.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		smpd_process.user_index = atoi((*argvp)[2]);		if (smpd_process.user_index < 0)		    smpd_process.user_index = 0;		num_args_to_strip = 2;		smpd_delete_cached_password();	    }#endif	    else if (strcmp(&(*argvp)[1][1], "l") == 0)	    {		smpd_process.prefix_output = SMPD_TRUE;	    }	    else	    {		printf("Unknown option: %s\n", (*argvp)[1]);	    }	    strip_args(argcp, argvp, num_args_to_strip);	}	/* check to see if a timeout is specified by the environment variable only if	 * a timeout has not been specified on the command line	 */	if (smpd_process.timeout == -1)	{	    char *p = getenv("MPIEXEC_TIMEOUT");	    if (p)	    {		smpd_process.timeout = atoi(p);		if (smpd_process.timeout < 1)		{		    smpd_process.timeout = -1;		}	    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -