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

📄 smpd_handle_spawn.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 3 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* *  (C) 2001 by Argonne National Laboratory. *      See COPYRIGHT in top-level directory. */#include "smpd.h"#ifdef HAVE_CTYPE_H#include <ctype.h>#endif#undef FCNAME#define FCNAME "smpd_isnumbers_with_colon"SMPD_BOOL smpd_isnumbers_with_colon(const char *str){    size_t i, n;    SMPD_BOOL colon_found;    smpd_enter_fn(FCNAME);    n = strlen(str);    colon_found = SMPD_FALSE;    for (i=0; i<n; i++)    {	if (!isdigit(str[i]))	{	    if (str[i] == ':')	    {		if (colon_found == SMPD_TRUE)		{		    smpd_exit_fn(FCNAME);		    return SMPD_FALSE;		}		colon_found = SMPD_TRUE;	    }	    else	    {		smpd_exit_fn(FCNAME);		return SMPD_FALSE;	    }	}    }    smpd_exit_fn(FCNAME);    return SMPD_TRUE;}#undef FCNAME#define FCNAME "smpd_handle_spawn_command"int smpd_handle_spawn_command(smpd_context_t *context){    int result;    smpd_command_t *cmd, *temp_cmd;    char ctx_key[100];    int ncmds, *maxprocs, *nkeyvals, i, j;    smpd_launch_node_t node;    char key[100], val[1024];    char *iter1, *iter2;    char maxprocs_str[1024], nkeyvals_str[1024], keyvals_str[1024];    smpd_launch_node_t *launch_list, *launch_iter/*, *launch_temp*/;    PMI_keyval_t *info;    char key_temp[SMPD_MAX_NAME_LENGTH], val_temp[SMPD_MAX_VALUE_LENGTH];    int cur_iproc;    smpd_host_node_t *host_iter, *host_list;    int nproc;    char *cur_env_loc;    int env_maxlen;    SMPD_BOOL env_channel_specified = SMPD_FALSE;    SMPD_BOOL env_dll_specified = SMPD_FALSE;    SMPD_BOOL env_wrap_dll_specified = SMPD_FALSE;    smpd_map_drive_node_t *drive_map_list = NULL;    smpd_enter_fn(FCNAME);    if (smpd_process.spawning == SMPD_TRUE)    {	result = smpd_delayed_spawn_enqueue(context);	smpd_exit_fn(FCNAME);	return result;    }    cmd = &context->read_cmd;    smpd_process.exit_on_done = SMPD_TRUE;    /* populate the host list */    smpd_get_default_hosts();        /* prepare the result command */    result = smpd_create_command("result", smpd_process.id, cmd->src, SMPD_FALSE, &temp_cmd);    if (result != SMPD_SUCCESS)    {	smpd_err_printf("unable to create a result command for a spawn command.\n");	smpd_exit_fn(FCNAME);	return SMPD_FAIL;    }    /* add the command tag for result matching */    result = smpd_add_command_int_arg(temp_cmd, "cmd_tag", cmd->tag);    if (result != SMPD_SUCCESS)    {	smpd_err_printf("unable to add the tag to the result command for a spawn command.\n");	smpd_exit_fn(FCNAME);	return SMPD_FAIL;    }    result = smpd_add_command_arg(temp_cmd, "cmd_orig", cmd->cmd_str);    if (result != SMPD_SUCCESS)    {	smpd_err_printf("unable to add cmd_orig to the result command for a %s command\n", cmd->cmd_str);	smpd_exit_fn(FCNAME);	return SMPD_FAIL;    }    /* copy the ctx_key for pmi control channel lookup */    if (MPIU_Str_get_string_arg(cmd->cmd, "ctx_key", ctx_key, 100) != MPIU_STR_SUCCESS)    {	smpd_err_printf("no ctx_key in the spawn command: '%s'\n", cmd->cmd);	smpd_exit_fn(FCNAME);	return SMPD_FAIL;    }    result = smpd_add_command_arg(temp_cmd, "ctx_key", ctx_key);    if (result != SMPD_SUCCESS)    {	smpd_err_printf("unable to add the ctx_key to the result command for spawn command '%s'.\n", cmd->cmd);	smpd_exit_fn(FCNAME);	return SMPD_FAIL;    }    smpd_process.spawning = SMPD_TRUE;    /* parse the spawn command */    if (MPIU_Str_get_int_arg(cmd->cmd, "ncmds", &ncmds) != MPIU_STR_SUCCESS)    {	smpd_err_printf("unable to get the ncmds parameter from the spawn command '%s'.\n", cmd->cmd);	goto spawn_failed;    }    /*printf("ncmds = %d\n", ncmds);fflush(stdout);*/    if (MPIU_Str_get_string_arg(cmd->cmd, "maxprocs", maxprocs_str, 1024) != MPIU_STR_SUCCESS)    {	smpd_err_printf("unable to get the maxrpocs parameter from the spawn command '%s'.\n", cmd->cmd);	goto spawn_failed;    }    if (MPIU_Str_get_string_arg(cmd->cmd, "nkeyvals", nkeyvals_str, 1024) != MPIU_STR_SUCCESS)    {	smpd_err_printf("unable to get the nkeyvals parameter from the spawn command '%s'.\n", cmd->cmd);	goto spawn_failed;    }    maxprocs = (int*)MPIU_Malloc(ncmds * sizeof(int));    if (maxprocs == NULL)    {	smpd_err_printf("unable to allocate the maxprocs array.\n");	goto spawn_failed;    }    nkeyvals = (int*)MPIU_Malloc(ncmds * sizeof(int));    if (nkeyvals == NULL)    {	smpd_err_printf("unable to allocate the nkeyvals array.\n");	goto spawn_failed;    }    iter1 = maxprocs_str;    iter2 = nkeyvals_str;    for (i=0; i<ncmds; i++)    {	result = MPIU_Str_get_string(&iter1, key, 100);	if (result != MPIU_STR_SUCCESS)	{	    smpd_err_printf("unable to get the %dth string from the maxprocs parameter to the spawn command '%s'.\n", i, cmd->cmd);	    goto spawn_failed;	}	maxprocs[i] = atoi(key);	/*printf("maxprocs[%d] = %d\n", i, maxprocs[i]);fflush(stdout);*/	result = MPIU_Str_get_string(&iter2, key, 100);	if (result != MPIU_STR_SUCCESS)	{	    smpd_err_printf("unable to get the %dth string from the nkeyvals parameter to the spawn command '%s'.\n", i, cmd->cmd);	    goto spawn_failed;	}	nkeyvals[i] = atoi(key);	/*printf("nkeyvals[%d] = %d\n", i, nkeyvals[i]);fflush(stdout);*/    }    info = NULL;    launch_list = NULL;    launch_iter = NULL;    cur_iproc = 0;    for (i=0; i<ncmds; i++)    {	/* reset the node fields */	node.appnum = -1;	node.args[0] = '\0';	node.clique[0] = '\0';	node.dir[0] = '\0';	node.env = node.env_data;	node.env_data[0] = '\0';	node.exe[0] = '\0';	node.host_id = -1;	node.hostname[0] = '\0';	node.iproc = -1;	node.map_list = NULL;	node.next = NULL;	node.nproc = -1;	node.path[0] = '\0';	node.prev = NULL;	node.priority_class = -1;	node.priority_thread = -1;	cur_env_loc = node.env_data;	env_maxlen = SMPD_MAX_ENV_LENGTH;	drive_map_list = NULL;	if (info != NULL)	{	    /* free the last round of infos */	    for (j=0; j<nkeyvals[i-1]; j++)	    {		MPIU_Free(info[j].key);		MPIU_Free(info[j].val);	    }	    MPIU_Free(info);	}	/* allocate some new infos */	if (nkeyvals[i] > 0)	{	    info = (PMI_keyval_t*)MPIU_Malloc(nkeyvals[i] * sizeof(PMI_keyval_t));	    if (info == NULL)	    {		smpd_err_printf("unable to allocate memory for the info keyvals (cmd %d, num_infos %d).\n", i, nkeyvals[i]);		goto spawn_failed;	    }	}	else	{	    info = NULL;	}	/* parse the keyvals into infos */	sprintf(key, "keyvals%d", i);	if (MPIU_Str_get_string_arg(cmd->cmd, key, keyvals_str, 1024) == MPIU_STR_SUCCESS)	{	    /*printf("%s = '%s'\n", key, keyvals_str);fflush(stdout);*/	    for (j=0; j<nkeyvals[i]; j++)	    {		sprintf(key, "%d", j);		if (MPIU_Str_get_string_arg(keyvals_str, key, val, 1024) != MPIU_STR_SUCCESS)		{		    smpd_err_printf("unable to get the %sth key from the keyval string '%s'.\n", key, keyvals_str);		    goto spawn_failed;		}		/*printf("key %d = %s\n", j, val);fflush(stdout);*/		key_temp[0] = '\0';		val_temp[0] = '\0';		iter1 = val;		result = MPIU_Str_get_string(&iter1, key_temp, SMPD_MAX_NAME_LENGTH);		if (result != MPIU_STR_SUCCESS)		{		    smpd_err_printf("unable to parse the key from the %dth keyval pair in the %dth keyvals string.\n", j, i);		    goto spawn_failed;		}		result = MPIU_Str_get_string(&iter1, val_temp, SMPD_MAX_VALUE_LENGTH); /* eat the '=' character */		if (result != MPIU_STR_SUCCESS)		{		    smpd_err_printf("unable to parse the key from the %dth keyval pair in the %dth keyvals string.\n", j, i);		    goto spawn_failed;		}		result = MPIU_Str_get_string(&iter1, val_temp, SMPD_MAX_VALUE_LENGTH);		if (result != MPIU_STR_SUCCESS)		{		    smpd_err_printf("unable to parse the key from the %dth keyval pair in the %dth keyvals string.\n", j, i);		    goto spawn_failed;		}		info[j].key = MPIU_Strdup(key_temp);		info[j].val = MPIU_Strdup(val_temp);	    }	}	/* get the current command */	sprintf(key, "cmd%d", i);	if (MPIU_Str_get_string_arg(cmd->cmd, key, node.exe, SMPD_MAX_EXE_LENGTH) != MPIU_STR_SUCCESS)	{	    smpd_err_printf("unable to get the %s parameter from the spawn command '%s'.\n", key, cmd->cmd);	    goto spawn_failed;	}#ifdef HAVE_WINDOWS_H	if (strlen(node.exe) > 2)	{	    /* the Windows version handles the common unix case where executables are specified like this: ./foo */	    /* Instead of failing, simply fix the / character */	    if (node.exe[0] == '.' && node.exe[1] == '/')		node.exe[1] = '\\';	    /* If there are / characters but no \ characters should we change them all to \ ? */	    /* my/sub/dir/app                : yes change them      - check works */	    /* my\sub\dir\app /1 /2 /bugaloo : no don't change them - check works */	    /* app /arg:foo                  : no don't change them - check does not work */	}#endif	/*printf("%s = %s\n", key, node.exe);fflush(stdout);*/	sprintf(key, "argv%d", i);	if (MPIU_Str_get_string_arg(cmd->cmd, key, node.args, SMPD_MAX_EXE_LENGTH) != MPIU_STR_SUCCESS)	{	    node.args[0] = '\0';	    /*	    smpd_err_printf("unable to get the %s parameter from the spawn command '%s'.\n", key, cmd->cmd);	    goto spawn_failed;	    smpd_exit_fn(FCNAME);	    return SMPD_FAIL;	    */	}	/*printf("%s = %s\n", key, node.args);fflush(stdout);*/	/* interpret the infos for this command */	for (j=0; j<nkeyvals[i]; j++)	{	    /* path */	    if (strcmp(info[j].key, "path") == 0)	    {		if (node.path[0] != '\0')		{		    /* multiple path keys */		    /* replace old, append, error out? */		}		strcpy(node.path, info[j].val);		smpd_dbg_printf("path = %s\n", info[j].val);	    }	    /* host */	    if (strcmp(info[j].key, "host") == 0)	    {		if (node.hostname[0] != '\0')		{		    /* multiple host keys */		    /* replace old, error out? */		}		smpd_dbg_printf("host key sent with spawn command: <%s>\n", info[j].val);		if (smpd_get_host_id(info[j].val, &node.host_id) == SMPD_SUCCESS)		{		    strcpy(node.hostname, info[j].val);		}		else		{		    /* smpd_get_host_id should not modify host_id if there is a failure but just to be safe ... */		    node.host_id = -1;		}	    }	    /* hosts */	    if (strcmp(info[j].key, "hosts") == 0)	    {		smpd_dbg_printf("hosts key sent with spawn command: <%s>\n", info[j].val);		if (smpd_parse_hosts_string(info[j].val))		{		    /*use_machine_file = SMPD_TRUE;*/		}	    }	    /* env */	    if (strcmp(info[j].key, "env") == 0)	    {		char *token;		char *env_str = MPIU_Strdup(info[j].val);		/* This simplistic parsing code assumes that environment variables do not have spaces in them		 * and that the variable name does not have the equals character in it.		 */

⌨️ 快捷键说明

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