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

📄 smpd_ipmi.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    /*printf("iPMI_KVS_Put success.\n");fflush(stdout);*/    return PMI_SUCCESS;}int iPMI_KVS_Commit(const char kvsname[]){    if (pmi_process.init_finalized == PMI_FINALIZED)	return PMI_ERR_INIT;    if (kvsname == NULL)	return PMI_ERR_INVALID_ARG;    if (pmi_process.local_kvs)    {	return PMI_SUCCESS;    }    /* Make the puts return when the commands are written but not acknowledged.       Then have this function wait until all outstanding puts are acknowledged.       */    return PMI_SUCCESS;}int iPMI_KVS_Get(const char kvsname[], const char key[], char value[], int length){    int result;    char str[1024];    if (pmi_process.init_finalized == PMI_FINALIZED)	return PMI_ERR_INIT;    if (kvsname == NULL)	return PMI_ERR_INVALID_ARG;    if (key == NULL)	return PMI_ERR_INVALID_KEY;    if (value == NULL)	return PMI_ERR_INVALID_VAL;    if (pmi_process.local_kvs)    {	result = smpd_dbs_get(kvsname, key, value);	return (result == SMPD_SUCCESS) ? PMI_SUCCESS : PMI_FAIL;    }    result = pmi_create_post_command("dbget", kvsname, key, NULL);    if (result != PMI_SUCCESS)    {	pmi_err_printf("PMI_KVS_Get failed: unable to get '%s:%s'\n", kvsname, key);	return PMI_FAIL;    }    /* parse the result of the command */    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "result", str, 1024) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Get failed: no result string in the result command.\n");	return PMI_FAIL;    }    if (strcmp(str, DBS_SUCCESS_STR))    {	/* FIXME: If we are going to use pmi for the publish/lookup interface then gets should be allowed to fail without printing errors */	pmi_err_printf("PMI_KVS_Get failed: '%s'\n", str);	return PMI_FAIL;    }    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "value", value, length) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Get failed: no value in the result command for the get: '%s'\n", pmi_process.context->read_cmd.cmd);	return PMI_FAIL;    }    /*    printf("iPMI_KVS_Get success.\n");fflush(stdout);    printf("get <%s><%s><%s>\n", kvsname, key, value);    fflush(stdout);    */    return PMI_SUCCESS;}int iPMI_KVS_Iter_first(const char kvsname[], char key[], int key_len, char value[], int val_len){    int result;    char str[1024];    if (pmi_process.init_finalized == PMI_FINALIZED)	return PMI_ERR_INIT;    if (kvsname == NULL)	return PMI_ERR_INVALID_ARG;    if (key == NULL)	return PMI_ERR_INVALID_KEY;    if (key_len < PMI_MAX_KEY_LEN)	return PMI_ERR_INVALID_KEY_LENGTH;    if (value == NULL)	return PMI_ERR_INVALID_VAL;    if (val_len < PMI_MAX_VALUE_LEN)	return PMI_ERR_INVALID_VAL_LENGTH;    if (pmi_process.local_kvs)    {	result = smpd_dbs_first(kvsname, key, value);	return (result == SMPD_SUCCESS) ? PMI_SUCCESS : PMI_FAIL;    }    result = pmi_create_post_command("dbfirst", kvsname, NULL, NULL);    if (result != PMI_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_first failed: unable to get the first key/value pair from '%s'\n", kvsname);	return PMI_FAIL;    }    /* parse the result of the command */    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "result", str, 1024) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_first failed: no result string in the result command.\n");	return PMI_FAIL;    }    if (strcmp(str, DBS_SUCCESS_STR))    {	pmi_err_printf("PMI_KVS_Iter_first failed: %s\n", str);	return PMI_FAIL;    }    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "key", str, PMI_MAX_KEY_LEN) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_first failed: no key in the result command for the pmi iter_first: '%s'\n", pmi_process.context->read_cmd.cmd);	return PMI_FAIL;    }    if (strcmp(str, DBS_END_STR) == 0)    {	*key = '\0';	*value = '\0';	return PMI_SUCCESS;    }    strcpy(key, str);    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "value", value, PMI_MAX_VALUE_LEN) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_first failed: no value in the result command for the pmi iter_first: '%s'\n", pmi_process.context->read_cmd.cmd);	return PMI_FAIL;    }    return PMI_SUCCESS;}int iPMI_KVS_Iter_next(const char kvsname[], char key[], int key_len, char value[], int val_len){    int result;    char str[1024];    if (pmi_process.init_finalized == PMI_FINALIZED)	return PMI_ERR_INIT;    if (kvsname == NULL)	return PMI_ERR_INVALID_ARG;    if (key == NULL)	return PMI_ERR_INVALID_KEY;    if (key_len < PMI_MAX_KEY_LEN)	return PMI_ERR_INVALID_KEY_LENGTH;    if (value == NULL)	return PMI_ERR_INVALID_VAL;    if (val_len < PMI_MAX_VALUE_LEN)	return PMI_ERR_INVALID_VAL_LENGTH;    if (pmi_process.local_kvs)    {	result = smpd_dbs_next(kvsname, key, value);	return (result == SMPD_SUCCESS) ? PMI_SUCCESS : PMI_FAIL;    }    result = pmi_create_post_command("dbnext", kvsname, NULL, NULL);    if (result != PMI_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_next failed: unable to get the next key/value pair from '%s'\n", kvsname);	return PMI_FAIL;    }    /* parse the result of the command */    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "result", str, 1024) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_next failed: no result string in the result command.\n");	return PMI_FAIL;    }    if (strcmp(str, DBS_SUCCESS_STR))    {	pmi_err_printf("PMI_KVS_Iter_next failed: %s\n", str);	return PMI_FAIL;    }    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "key", str, PMI_MAX_KEY_LEN) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_next failed: no key in the result command for the pmi iter_next: '%s'\n", pmi_process.context->read_cmd.cmd);	return PMI_FAIL;    }    if (strcmp(str, DBS_END_STR) == 0)    {	*key = '\0';	*value = '\0';	return PMI_SUCCESS;    }    strcpy(key, str);    if (MPIU_Str_get_string_arg(pmi_process.context->read_cmd.cmd, "value", value, PMI_MAX_VALUE_LEN) != MPIU_STR_SUCCESS)    {	pmi_err_printf("PMI_KVS_Iter_next failed: no value in the result command for the pmi iter_next: '%s'\n", pmi_process.context->read_cmd.cmd);	return PMI_FAIL;    }    return PMI_SUCCESS;}int iPMI_Spawn_multiple(int count,                       const char * cmds[],                       const char ** argvs[],                       const int maxprocs[],                       const int cinfo_keyval_sizes[],                       const PMI_keyval_t * info_keyval_vectors[],                       int preput_keyval_size,                       const PMI_keyval_t preput_keyval_vector[],                       int errors[]){    int result;    smpd_command_t *cmd_ptr;    int dest = 0;    char buffer[SMPD_MAX_CMD_LENGTH];    char keyval_buf[SMPD_MAX_CMD_LENGTH];    char key[100];    char *iter, *iter2;    int i, j, maxlen, maxlen2;    int path_specified = 0, wdir_specified = 0;    char path[SMPD_MAX_PATH_LENGTH] = "";    int *info_keyval_sizes;    int total_num_processes;    int appnum = 0;    if (pmi_process.init_finalized == PMI_FINALIZED)	return PMI_ERR_INIT;    if(pmi_process.init_finalized == PMI_SINGLETON_INIT_BUT_NO_PM){        if(PMIi_InitSingleton() != PMI_SUCCESS){            return PMI_ERR_INIT;        }    }    if (count < 1 || cmds == NULL || maxprocs == NULL || preput_keyval_size < 0)	return PMI_ERR_INVALID_ARG;    if (pmi_process.local_kvs)    {	return PMI_FAIL;    }    /*printf("creating spawn command.\n");fflush(stdout);*/    result = smpd_create_command("spawn", pmi_process.smpd_id, dest, SMPD_TRUE, &cmd_ptr);    if (result != SMPD_SUCCESS)    {	pmi_err_printf("unable to create a spawn command.\n");	return PMI_FAIL;    }    result = smpd_add_command_int_arg(cmd_ptr, "ctx_key", pmi_process.smpd_key);    if (result != SMPD_SUCCESS)    {	pmi_err_printf("unable to add the key to the spawn command.\n");	return PMI_FAIL;    }    /* add the number of commands */    result = smpd_add_command_int_arg(cmd_ptr, "ncmds", count);    if (result != SMPD_SUCCESS)    {	pmi_err_printf("unable to add the ncmds field to the spawn command.\n");	return PMI_FAIL;    }    /* add the commands and their argv arrays */    for (i=0; i<count; i++)    {	sprintf(key, "cmd%d", i);#ifdef HAVE_WINDOWS_H	if (strlen(cmds[i]) > 2)	{	    if (cmds[i][0] == '.' && cmds[i][1] == '/')	    {		result = smpd_add_command_arg(cmd_ptr, key, (char*)&cmds[i][2]);	    }	    else	    {		result = smpd_add_command_arg(cmd_ptr, key, (char*)cmds[i]);	    }	}	else	{	    result = smpd_add_command_arg(cmd_ptr, key, (char*)cmds[i]);	}#else	result = smpd_add_command_arg(cmd_ptr, key, (char*)cmds[i]);#endif	if (result != SMPD_SUCCESS)	{	    pmi_err_printf("unable to add %s(%s) to the spawn command.\n", key, cmds[i]);	    return PMI_FAIL;	}	if (argvs)	{	    buffer[0] = '\0';	    iter = buffer;	    maxlen = SMPD_MAX_CMD_LENGTH;	    if (argvs[i] != NULL)	    {		for (j=0; argvs[i][j] != NULL; j++)		{		    result = MPIU_Str_add_string(&iter, &maxlen, argvs[i][j]);		}		if (iter > buffer)		{		    iter--;		    *iter = '\0'; /* erase the trailing space */		}	    }	    sprintf(key, "argv%d", i);	    result = smpd_add_command_arg(cmd_ptr, key, buffer);	    if (result != SMPD_SUCCESS)	    {		pmi_err_printf("unable to add %s(%s) to the spawn command.\n", key, buffer);		return PMI_FAIL;	    }	}    }    /* add the maxprocs array and count the total number of processes */    total_num_processes = 0;    buffer[0] = '\0';    for (i=0; i<count; i++)    {	total_num_processes += maxprocs[i];	if (i < count-1)	    sprintf(key, "%d ", maxprocs[i]);	else	    sprintf(key, "%d", maxprocs[i]);	strcat(buffer, key);    }    result = smpd_add_command_arg(cmd_ptr, "maxprocs", buffer);    if (result != SMPD_SUCCESS)    {	pmi_err_printf("unable to add maxprocs(%s) to the spawn command.\n", buffer);	return PMI_FAIL;    }#ifdef HAVE_WINDOWS_H    {	HMODULE hModule;	char exe_path[SMPD_MAX_PATH_LENGTH];	char *iter;	int length;	GetCurrentDirectory(SMPD_MAX_PATH_LENGTH, path);	hModule = GetModuleHandle(NULL);	if (GetModuleFileName(hModule, exe_path, SMPD_MAX_PATH_LENGTH)) 	{	    iter = strrchr(exe_path, '\\');	    if (iter != NULL)	    {		if (iter == (exe_path + 2) && *(iter-1) == ':')		{		    /* leave the \ if the path is at the root, like c:\foo.exe */		    iter++;		}		*iter = '\0'; /* erase the file name leaving only the path */	    }	    length = (int)strlen(path);	    iter = &path[length];	    MPIU_Snprintf(iter, SMPD_MAX_PATH_LENGTH-length, ";%s", exe_path);	}    }#else    getcwd(path, SMPD_MAX_PATH_LENGTH);#endif    /* create a copy of the sizes so we can change the values locally */    info_keyval_sizes = (int*)MPIU_Malloc(count * sizeof(int));    if (info_keyval_sizes == NULL)    {	pmi_err_printf("unable to allocate an array of kevval sizes.\n");	return PMI_FAIL;    }    for (i=0; i<count; i++)    {	info_keyval_sizes[i] = cinfo_keyval_sizes[i];    }    /* add the keyvals */    if (info_keyval_sizes && info_keyval_vectors)    {	for (i=0; i<count; i++)	{	    path_specified = 0;	    wdir_specified = 0;	    buffer[0] = '\0';	    iter = buffer;	    maxlen = SMPD_MAX_CMD_LENGTH;	    for (j=0; j<info_keyval_sizes[i]; j++)	    {		keyval_buf[0] = '\0';		iter2 = keyval_buf;		maxlen2 = SMPD_MAX_CMD_LENGTH;		if (strcmp(info_keyval_vectors[i][j].key, "path") == 0)		{		    size_t val2len;		    char *val2;		    val2len = sizeof(char) * strlen(info_keyval_vectors[i][j].val) + 1 + strlen(path) + 1;		    val2 = (char*)MPIU_Malloc(val2len);		    if (val2 == NULL)		    {			pmi_err_printf("unable to allocate memory for the path key.\n");			return PMI_FAIL;		    }		    /*printf("creating path %d: <%s>;<%s>\n", val2len, info_keyval_vectors[i][j].val, path);fflush(stdout);*/		    MPIU_Snprintf(val2, val2len, "%s;%s", info_keyval_vectors[i][j].val, path);		    result = MPIU_Str_add_string_arg(&iter2, &maxlen2, info_keyval_vectors[i][j].key, val2);		    if (result != MPIU_STR_SUCCESS)		    {			pmi_err_printf("unable to add %s=%s to the spawn command.\n", info_keyval_vectors[i][j].key, val2);			MPIU_Free(val2);			return PMI_FAIL;		    }		    MPIU_Free(val2);		    path_specified = 1;		}		else		{		    if(strcmp(info_keyval_vectors[i][j].key, "wdir") == 0)		    {		        wdir_specified = 1;		    }		    result = MPIU_Str_add_string_arg(&iter2, &maxlen2, info_keyval_vectors[i][j].key, info_keyval_vectors[i][j].val);		    if (result != MPIU_STR_SUCCESS)		    {			pmi_err_printf("unable to add %s=%s to the spawn command.\n", info_keyval_vectors[i][j].key, info_keyval_vectors[i][j].val);			return PMI_FAIL;		    }		}		if (iter2 > keyval_buf)		{		    iter2--;		    *iter2 = '\0'; /* remove the trailing space */		}		sprintf(key, "%d", j);		result = MPIU_Str_add_string_arg(&iter, &maxlen, key, keyval_buf);		if (result != MPIU_STR_SUCCESS)		{		    pmi_err_printf("unable to add %s=%s to the spawn command.\n", key, keyval_buf);		    return PMI_FAIL;		}	    }	    /* add the current directory as the default path if a path has not been specified */	    if (!path_specified)	    {		keyval_buf[0] = '\0';		iter2 = keyval_buf;		maxlen2 = SMPD_MAX_CMD_LENGTH;		result = MPIU_Str_add_string_arg(&iter2, &maxlen2, "path", path);		iter2--;		*iter2 = '\0';		sprintf(key, "%d", j++);		result = MPIU_Str_add_string_arg(&iter, &maxlen, key, keyval_buf);		if (result != MPIU_STR_SUCCESS)		{		    pmi_err_printf("unable to add %s=%s to the spawn command.\n", 

⌨️ 快捷键说明

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