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

📄 mp_parse_command_line.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 5 页
字号:
	    else	    {		/* If a timeout is specified in the smpd settings but not in an env variable and not on the command line then use it. */		if (smpd_setting_timeout != SMPD_INVALID_SETTING)		{		    smpd_process.timeout = smpd_setting_timeout;		}	    }	}	/* Check to see if the environment wants all processes to run locally.	 * This is useful for test scripts.	 */	env_str = getenv("MPIEXEC_LOCALONLY");	if (env_str == NULL && smpd_setting_localonly == SMPD_TRUE)	{	    smpd_setting_tmp_buffer[0] = '1';	    smpd_setting_tmp_buffer[1] = '\0';	    env_str = smpd_setting_tmp_buffer;	}	if (env_str != NULL)	{	    if (smpd_is_affirmative(env_str) || strcmp(env_str, "1") == 0)	    {#if 1		/* This block creates a host list of one host to implement -localonly */		if (host_list == NULL)		{		    /* 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*)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->nproc = -1;		    host_list->alt_host[0] = '\0';		    smpd_get_hostname(host_list->host, SMPD_MAX_HOST_LENGTH);		}		else		{		    smpd_dbg_printf("host_list not null, not using localonly\n");		}#else		/* This block uses the rsh code to implement -localonly */		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;#endif	    }	    else	    {		smpd_dbg_printf("MPIEXEC_LOCALONLY env is not affirmative: '%s'\n", env_str);	    }	}	/* remaining args are the executable and it's args */	if (argc < 2)	{	    printf("Error: no executable specified\n");	    smpd_exit_fn(FCNAME);	    return SMPD_FAIL;	}	exe_iter = exe;	exe_len_remaining = SMPD_MAX_EXE_LENGTH;	if (!((*argvp)[1][0] == '\\' && (*argvp)[1][1] == '\\') && (*argvp)[1][0] != '/' &&	    !(strlen((*argvp)[1]) > 3 && (*argvp)[1][1] == ':' && (*argvp)[1][2] == '\\') )	{	    /* an absolute path was not specified so find the executable an save the path */	    if (smpd_get_full_path_name((*argvp)[1], SMPD_MAX_EXE_LENGTH, exe_path, &namepart))	    {		if (path[0] != '\0')		{		    if (strlen(path) < SMPD_MAX_PATH_LENGTH)		    {			strcat(path, ";");			strncat(path, exe_path, SMPD_MAX_PATH_LENGTH - strlen(path));			path[SMPD_MAX_PATH_LENGTH-1] = '\0';		    }		}		else		{		    strncpy(path, exe_path, SMPD_MAX_PATH_LENGTH);		}		result = MPIU_Str_add_string(&exe_iter, &exe_len_remaining, namepart);		if (result != MPIU_STR_SUCCESS)		{		    printf("Error: insufficient buffer space for the command line.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}	    }	    else	    {		result = MPIU_Str_add_string(&exe_iter, &exe_len_remaining, (*argvp)[1]);		if (result != MPIU_STR_SUCCESS)		{		    printf("Error: insufficient buffer space for the command line.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}	    }	}	else	{	    /* an absolute path was specified */#ifdef HAVE_WINDOWS_H	    char *pTemp = (char*)malloc(SMPD_MAX_EXE_LENGTH);	    if (pTemp == NULL)	    {		smpd_exit_fn(FCNAME);		return SMPD_FAIL;	    }	    strncpy(pTemp, (*argvp)[1], SMPD_MAX_EXE_LENGTH);	    pTemp[SMPD_MAX_EXE_LENGTH-1] = '\0';	    ExeToUnc(pTemp, SMPD_MAX_EXE_LENGTH);	    result = MPIU_Str_add_string(&exe_iter, &exe_len_remaining, pTemp);	    free(pTemp);	    if (result != MPIU_STR_SUCCESS)	    {		printf("Error: insufficient buffer space for the command line.\n");		smpd_exit_fn(FCNAME);		return SMPD_FAIL;	    }#else	    result = MPIU_Str_add_string(&exe_iter, &exe_len_remaining, (*argvp)[1]);	    if (result != MPIU_STR_SUCCESS)	    {		printf("Error: insufficient buffer space for the command line.\n");		smpd_exit_fn(FCNAME);		return SMPD_FAIL;	    }#endif	}	for (i=2; i<argc; i++)	{	    result = MPIU_Str_add_string(&exe_iter, &exe_len_remaining, (*argvp)[i]);	}	/* remove the trailing space */	exe[strlen(exe)-1] = '\0';	smpd_dbg_printf("handling executable:\n%s\n", exe);	if (nproc == 0)	{	    smpd_err_printf("missing num_proc flag: -n, -np, -hosts, or -localonly.\n");	    smpd_exit_fn(FCNAME);	    return SMPD_FAIL;	}	if (ghost_list != NULL && host_list == NULL && use_machine_file != SMPD_TRUE)	{	    host_list = (smpd_host_node_t*)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->nproc = -1;	    host_list->alt_host[0] = '\0';	    strncpy(host_list->host, ghost_list->host, SMPD_MAX_HOST_LENGTH);	}	if (host_list != NULL && host_list->nproc == -1)	{	    /* -host specified, replace nproc field */	    host_list->nproc = nproc;	}	/* add environment variables */	env_data[0] = '\0';	env_str = env_data;	maxlen = SMPD_MAX_ENV_LENGTH;	/* add and destroy the local environment variable list */	while (env_list)	{	    MPIU_Str_add_string_arg(&env_str, &maxlen, env_list->name, env_list->value);	    /*	    env_str += snprintf(env_str,		SMPD_MAX_ENV_LENGTH - (env_str - env_data),		"%s=%s", env_list->name, env_list->value);	    if (env_list->next)	    {		env_str += snprintf(env_str, SMPD_MAX_ENV_LENGTH - (env_str - env_data), ";");	    }	    */	    env_node = env_list;	    env_list = env_list->next;	    free(env_node);	}	/* add the global environment variable list */	env_node = genv_list;	while (env_node)	{	    MPIU_Str_add_string_arg(&env_str, &maxlen, env_node->name, env_node->value);	    env_node = env_node->next;	}	if (env_str > env_data)	{	    /* trim the trailing white space */	    env_str--;	    *env_str = '\0';	}	/* merge global drive mappings with the local drive mappings */	gmap_node = gdrive_map_list;	while (gmap_node)	{	    map_node = drive_map_list;	    while (map_node)	    {		if (map_node->drive == gmap_node->drive)		{		    /* local option trumps the global option */		    break;		}		if (map_node->next == NULL)		{		    /* add a copy of the global node to the end of the list */		    map_node->next = (smpd_map_drive_node_t*)malloc(sizeof(smpd_map_drive_node_t));		    if (map_node->next == NULL)		    {			printf("Error: malloc failed to allocate map structure.\n");			smpd_exit_fn(FCNAME);			return SMPD_FAIL;		    }		    map_node = map_node->next;		    map_node->ref_count = 0;		    map_node->drive = gmap_node->drive;		    strncpy(map_node->share, gmap_node->share, SMPD_MAX_EXE_LENGTH);		    map_node->next = NULL;		    break;		}		map_node = map_node->next;	    }	    if (drive_map_list == NULL)	    {		map_node = (smpd_map_drive_node_t*)malloc(sizeof(smpd_map_drive_node_t));		if (map_node == NULL)		{		    printf("Error: malloc failed to allocate map structure.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}		map_node->ref_count = 0;		map_node->drive = gmap_node->drive;		strncpy(map_node->share, gmap_node->share, SMPD_MAX_EXE_LENGTH);		map_node->next = NULL;		drive_map_list = map_node;	    }	    gmap_node = gmap_node->next;	}	for (i=0; i<nproc; i++)	{	    /* create a launch_node */	    launch_node = (smpd_launch_node_t*)malloc(sizeof(smpd_launch_node_t));	    if (launch_node == NULL)	    {		smpd_err_printf("unable to allocate a launch node structure.\n");		smpd_exit_fn(FCNAME);		return SMPD_FAIL;	    }	    launch_node->clique[0] = '\0';	    smpd_get_next_host(&host_list, launch_node);	    launch_node->iproc = cur_rank++;	    launch_node->appnum = appnum;	    launch_node->priority_class = n_priority_class;	    launch_node->priority_thread = n_priority;	    launch_node->env = launch_node->env_data;	    strcpy(launch_node->env_data, env_data);	    if (launch_node->alt_hostname[0] != '\0')	    {		if (smpd_append_env_option(launch_node->env_data, SMPD_MAX_ENV_LENGTH, "MPICH_INTERFACE_HOSTNAME", launch_node->alt_hostname) != SMPD_SUCCESS)		{		    smpd_err_printf("unable to add the MPICH_INTERFACE_HOSTNAME environment variable to the launch command.\n");		    smpd_exit_fn(FCNAME);		    return SMPD_FAIL;		}	    }	    if (wdir[0] != '\0')	    {		strcpy(launch_node->dir, wdir);	    }	    else	    {		if (gwdir[0] != '\0')		{		    strcpy(launch_node->dir, gwdir);		}		else		{		    launch_node->dir[0] = '\0';		    getcwd(launch_node->dir, SMPD_MAX_DIR_LENGTH);		}	    }	    if (path[0] != '\0')	    {		strcpy(launch_node->path, path);		/* should the gpath be appended to the local path? */	    }	    else	    {		if (gpath[0] != '\0')		{		    strcpy(launch_node->path, gpath);		}		else		{		    launch_node->path[0] = '\0';		}	    }	    launch_node->map_list = drive_map_list;	    if (drive_map_list)	    {		/* ref count the list so when freeing the launch_node it can be known when to free the list */		drive_map_list->ref_count++;	    }	    strcpy(launch_node->exe, exe);	    launch_node->args[0] = '\0';	    if (smpd_process.mpiexec_inorder_launch == SMPD_TRUE)	    {		/* insert the node in order */		launch_node->next = NULL;		if (smpd_process.launch_list == NULL)		{		    smpd_process.launch_list = launch_node;		    launch_node->prev = NULL;		}		else		{		    launch_node_iter = smpd_process.launch_list;		    while (launch_node_iter->next)			launch_node_iter = launch_node_iter->next;		    launch_node_iter->next = launch_node;		    launch_node->prev = launch_node_iter;		}	    }	    else	    {		/* insert the node in reverse order */		launch_node->next = smpd_process.launch_list;		if (smpd_process.launch_list)		    smpd_process.launch_list->prev = launch_node;		smpd_process.launch_list = launch_node;		launch_node->prev = NULL;	    }	}	/* advance the application number for each : separated command line block or line in a configuration file */	appnum++;	if (smpd_process.s_host_list)	{	    /* free the current host list */	    while (smpd_process.s_host_list)	    {		host_node_iter = smpd_process.s_host_list;		smpd_process.s_host_list = smpd_process.s_host_list->next;		free(host_node_iter);	    }	}	if (use_configfile)	{	    if (smpd_get_argcv_from_file(fin_config, argcp, argvp))	    {		/* FIXME: How do we tell the difference between an error parsing the file and parsing the last entry? */		goto configfile_loop;	    }	    fclose(fin_config);	    if (delete_configfile)	    {		unlink(configfilename);	    }	}	/* move to the next block */	*argvp = next_argv - 1;	if (*next_argv)	    **argvp = exe_ptr;    } while (*next_argv);    /* add nproc to all the launch nodes */    launch_node_iter = smpd_process.launch_list;    while (launch_node_iter)    {	launch_node_iter->nproc = cur_rank;	launch_node_iter = launch_node_iter->next;    }    /* create the cliques */    smpd_create_cliques(smpd_process.launch_list);    if (smpd_process.launch_list != N

⌨️ 快捷键说明

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