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

📄 errutil.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 4 页
字号:
	    if (use_user_error_code)	    {		ErrorRing[ring_idx].use_user_error_code = 1;		ErrorRing[ring_idx].user_error_code     = user_error_code;	    }	    else if (lastcode != MPI_SUCCESS)	    {		int last_ring_idx;		int last_ring_id;		int last_generic_idx;		if (convertErrcodeToIndexes( lastcode, &last_ring_idx, 					     &last_ring_id,					     &last_generic_idx ) != 0) {		    MPIU_Error_printf( 		  "Invalid error code (%d) (error ring index %d invalid)\n", 		  lastcode, last_ring_idx );		}		else {		    if (last_generic_idx >= 0 && 			ErrorRing[last_ring_idx].id == last_ring_id) {			if (ErrorRing[last_ring_idx].use_user_error_code) {			    ErrorRing[ring_idx].use_user_error_code = 1;			    ErrorRing[ring_idx].user_error_code = 				ErrorRing[last_ring_idx].user_error_code;			}		    }		}	    }	    if (fcname != NULL)	    {		MPIU_Snprintf(ErrorRing[ring_idx].location, MAX_LOCATION_LEN, "%s(%d)", fcname, line);		ErrorRing[ring_idx].location[MAX_LOCATION_LEN] = '\0';	    }	    else	    {		ErrorRing[ring_idx].location[0] = '\0';	    }	}	error_ring_mutex_unlock();	err_code |= ring_idx << ERROR_SPECIFIC_INDEX_SHIFT;	err_code |= ring_seq << ERROR_SPECIFIC_SEQ_SHIFT;    }#   endif    if (fatal || MPIR_Err_is_fatal(lastcode))    {	err_code |= ERROR_FATAL_MASK;    }        return err_code;}/* Append an error code, error2, to the end of a list of messages in the error   ring whose head endcoded in error1_code.  An error code pointing at the   combination is returned.  If the list of messages does not terminate cleanly   (i.e. ring wrap has occurred), then the append is not performed. and error1   is returned (although it may include the class of error2 if the class of   error1 was MPI_ERR_OTHER). */int MPIR_Err_combine_codes(int error1, int error2){    int error1_code = error1;    int error2_code = error2;    int error2_class;        if (error2_code == MPI_SUCCESS) return error1_code;    if (error2_code & ERROR_DYN_MASK) return error2_code;    if (error1_code == MPI_SUCCESS) return error2_code;	        error2_class = MPIR_ERR_GET_CLASS(error2_code);    if (MPIR_ERR_GET_CLASS(error2_class) < MPI_SUCCESS ||	MPIR_ERR_GET_CLASS(error2_class) > MPICH_ERR_LAST_CLASS)    {	error2_class = MPI_ERR_OTHER;    }#   if MPICH_ERROR_MSG_LEVEL >= MPICH_ERROR_MSG_ALL    {	int error_code;	error_code = error1_code;		error_ring_mutex_lock();	{	    for (;;)	    {		int error_class;		int ring_idx;		int ring_id;		int generic_idx;				if (convertErrcodeToIndexes(error_code, &ring_idx, &ring_id,		    &generic_idx) != 0 || generic_idx < 0 ||		    ErrorRing[ring_idx].id != ring_id)		{		    break;		}		error_code = ErrorRing[ring_idx].prev_error;		if (error_code == MPI_SUCCESS)		{		    ErrorRing[ring_idx].prev_error = error2;		    break;		}				error_class = MPIR_ERR_GET_CLASS(error_code);				if (error_class == MPI_ERR_OTHER)		{		    ErrorRing[ring_idx].prev_error &= ~(ERROR_CLASS_MASK);		    ErrorRing[ring_idx].prev_error |= error2_class;		}	    }	}	error_ring_mutex_unlock();    }#   endif    if (MPIR_ERR_GET_CLASS(error1_code) == MPI_ERR_OTHER)    {	error1_code = (error1_code & ~(ERROR_CLASS_MASK)) | error2_class;    }    return error1_code;}/* ------------------------------------------------------------------------- *//* Manage the error reporting stack                                          *//* ------------------------------------------------------------------------- *//* FIXME: This flag wasn't documented in the release specs, and in any   event shouldn't be controlled through source-code changes (i.e.,   make it either a configure option or a runtime option) *//* turn this flag on until we debug and release mpich2 */static int MPIR_Err_print_stack_flag = TRUE;static int MPIR_Err_chop_error_stack = FALSE;static int MPIR_Err_chop_width = 80;static void MPIR_Err_stack_init( void ){    int n, rc, mpi_errno = MPI_SUCCESS;        error_ring_mutex_create(&mpi_errno);    MPIR_Err_chop_error_stack = FALSE;        rc = MPIU_GetEnvBool( "MPICH_PRINT_ERROR_STACK", 			  &MPIR_Err_print_stack_flag );        rc = MPIU_GetEnvInt( "MPICH_CHOP_ERROR_STACK", &n );    if (rc == 1) {#ifdef HAVE_WINDOWS_H	/* If windows, set the default width to the window size */	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);	if (hConsole != INVALID_HANDLE_VALUE)	{	    CONSOLE_SCREEN_BUFFER_INFO info;	    if (GetConsoleScreenBufferInfo(hConsole, &info))	    {		MPIR_Err_chop_width = info.dwMaximumWindowSize.X;	    }	}#endif	if (n > 0) {	    MPIR_Err_chop_error_stack = TRUE;	    MPIR_Err_chop_width = n;	}	else if (n == 0) {	    /* Use the default width */	    MPIR_Err_chop_error_stack = TRUE;	}    }}/**//* Given an error code, print the stack of messages corresponding to this   error code. */void MPIR_Err_print_stack(FILE * fp, int errcode){    error_ring_mutex_lock();    {	while (errcode != MPI_SUCCESS) {	    int ring_idx;	    int ring_id;	    int generic_idx;	    	    if (convertErrcodeToIndexes( errcode, &ring_idx, &ring_id,					 &generic_idx ) != 0) {		MPIU_Error_printf( 		    "Invalid error code (%d) (error ring index %d invalid)\n", 		    errcode, ring_idx );		break;	    }	    	    if (generic_idx < 0)	    {		break;	    }	    	    if (ErrorRing[ring_idx].id == ring_id)	    {		fprintf(fp, "%s: %s\n", ErrorRing[ring_idx].location, 			ErrorRing[ring_idx].msg);		errcode = ErrorRing[ring_idx].prev_error;	    }	    else	    {		break;	    }	}    }    error_ring_mutex_unlock();	    /* FIXME: This is wrong.  The only way that you can get here without       errcode beign MPI_SUCCESS is if there is an error in the        processing of the error codes.  Dropping through into the next       level of code (particularly when that code doesn't check for        valid error codes!) is erroneous */    if (errcode == MPI_SUCCESS)    {	goto fn_exit;    }    {	int generic_idx;		    	generic_idx = ((errcode & ERROR_GENERIC_MASK) >> ERROR_GENERIC_SHIFT) - 1;		if (generic_idx >= 0)	{	    fprintf(fp, "(unknown)(): %s\n", generic_err_msgs[generic_idx].long_name);	    goto fn_exit;	}    }        {	int error_class;	error_class = ERROR_GET_CLASS(errcode);		if (error_class <= MPICH_ERR_LAST_CLASS)	{	    fprintf(fp, "(unknown)(): %s\n", get_class_msg(ERROR_GET_CLASS(errcode)));	}	else	{	    /* FIXME: Not internationalized */	    fprintf(fp, "Error code contains an invalid class (%d)\n", error_class);	}    }      fn_exit:    return;}/* FIXME: Shouldn't str be const char * ? */static void MPIR_Err_print_stack_string(int errcode, char *str, int maxlen ){    char *str_orig = str;    int len;    error_ring_mutex_lock();    {	/* Find the longest fcname in the stack */	int max_location_len = 0;	int tmp_errcode = errcode;	while (tmp_errcode != MPI_SUCCESS) {	    int ring_idx;	    int ring_id;	    int generic_idx;	    	    if (convertErrcodeToIndexes( tmp_errcode, &ring_idx, &ring_id,					 &generic_idx ) != 0) {		MPIU_Error_printf( 		    "Invalid error code (%d) (error ring index %d invalid)\n", 		    errcode, ring_idx );		break;	    }	    if (generic_idx < 0) {		break;	    }	    	    if (ErrorRing[ring_idx].id == ring_id) {		len = (int)strlen(ErrorRing[ring_idx].location);		max_location_len = MPIR_MAX(max_location_len, len);		tmp_errcode = ErrorRing[ring_idx].prev_error;	    }	    else	    {		break;	    }	}	max_location_len += 2; /* add space for the ": " */	/* print the error stack */	while (errcode != MPI_SUCCESS) {	    int ring_idx;	    int ring_id;	    int generic_idx;	    int i;	    char *cur_pos;	    	    if (convertErrcodeToIndexes( errcode, &ring_idx, &ring_id,					 &generic_idx ) != 0) {		MPIU_Error_printf( 		    "Invalid error code (%d) (error ring index %d invalid)\n", 		    errcode, ring_idx );	    }	    	    if (generic_idx < 0)	    {		break;	    }	    	    if (ErrorRing[ring_idx].id == ring_id) {		int nchrs;		MPIU_Snprintf(str, maxlen, "%s", ErrorRing[ring_idx].location);		len     = (int)strlen(str);		maxlen -= len;		str    += len;		nchrs   = max_location_len - 		    (int)strlen(ErrorRing[ring_idx].location) - 2;		while (nchrs > 0 && maxlen > 0) {		    *str++ = '.';		    nchrs--;		    maxlen--;		}		if (maxlen > 0) {		    *str++ = ':';		    maxlen--;		}		if (maxlen > 0) {		    *str++ = ' ';		    maxlen--;		}				if (MPIR_Err_chop_error_stack)		{		    cur_pos = ErrorRing[ring_idx].msg;		    len = (int)strlen(cur_pos);		    if (len == 0 && maxlen > 0) {			*str++ = '\n';			maxlen--;		    }		    while (len)		    {			if (len >= MPIR_Err_chop_width - max_location_len)			{			    if (len > maxlen)				break;			    /* FIXME: Don't use Snprint to append a string ! */			    MPIU_Snprintf(str, MPIR_Err_chop_width - 1 - max_location_len, "%s", cur_pos);			    str[MPIR_Err_chop_width - 1 - max_location_len] = '\n';			    cur_pos += MPIR_Err_chop_width - 1 - max_location_len;			    str += MPIR_Err_chop_width - max_location_len;			    maxlen -= MPIR_Err_chop_width - max_location_len;			    if (maxlen < max_location_len)				break;			    for (i=0; i<max_location_len; i++)			    {				MPIU_Snprintf(str, maxlen, " ");				maxlen--;				str++;			    }			    len = (int)strlen(cur_pos);			}			else			{			    MPIU_Snprintf(str, maxlen, "%s\n", cur_pos);			    len = (int)strlen(str);			    maxlen -= len;			    str += len;			    len = 0;			}		    }		}		else		{		    MPIU_Snprintf(str, maxlen, "%s\n", ErrorRing[ring_idx].msg);		    len = (int)strlen(str);		    maxlen -= len;		    str += len;		}		errcode = ErrorRing[ring_idx].prev_error;	    }	    else	    {		break;	    }	}    }    error_ring_mutex_unlock();    if (errcode == MPI_SUCCESS)    {	goto fn_exit;    }    /* FIXME: The following code is broken as described above (if the errcode       is not valid, then this code is just going to cause more problems) */    {	int generic_idx;		generic_idx = ((errcode & ERROR_GENERIC_MASK) >> ERROR_GENERIC_SHIFT) - 1;		if (generic_idx >= 0)	{	    const char *p;	    /* FIXME: (Here and elsewhere)  Make sure any string is	       non-null before you use it */	    p = generic_err_msgs[generic_idx].long_name;	    if (!p) { p = "<NULL>"; }	    MPIU_Snprintf(str, maxlen, "(unknown)(): %s\n", p );	    len = (int)strlen(str);	    maxlen -= len;	    str += len;	    goto fn_exit;	}    }        {	int error_class;	error_class = ERROR_GET_CLASS(errcode);		if (error_class <= MPICH_ERR_LAST_CLASS)	{	    MPIU_Snprintf(str, maxlen, "(unknown)(): %s\n", 			  get_class_msg(ERROR_GET_CLASS(errcode)));	    len = (int)strlen(str);	    maxlen -= len;	    str += len;	}	else	{	    /* FIXME: Not internationalized */	    MPIU_Snprintf(str, maxlen, 			  "Error code contains an invalid class (%d)\n",			  error_class);	    len = (int)strlen(str);	    maxlen -= len;	    str += len;	}    }     fn_exit:    if (str_orig != str)    {	str--;	*str = '\0';    }    return;}static int ErrGetInstanceString( int errorcode, char *msg, int num_remaining, 				 MPIR_Err_get_class_string_func_t fn ){    int len;    if (MPIR_Err_print_stack_flag) {	MPIU_Strncpy(msg, ", error stack:\n", num_remaining);	msg[num_remaining - 1] = '\0';	len = (int)strlen(msg);	msg += len;	num_remaining -= len;	/* note: this took the "fn" arg, but that appears to be unused	 and is undocumented.  */	MPIR_Err_print_stack_string(errorcode, msg, num_remaining);	msg[num_remaining - 1] = '\0';    }    else {	error_ring_mutex_lock();	{	    while (errorcode != MPI_SUCCESS) {		int ring_idx;		int ring_id;		int generic_idx;				if (convertErrcodeToIndexes( errorcode, &ring_idx, 					     &ring_id,					     &generic_idx ) != 0) {		    MPIU_Error_printf( 	      "Invalid error code (%d) (error ring index %d invalid)\n", 	      errorcode, ring_idx );		    break;		}				if (generic_idx < 0) {		    break;		}				if (ErrorRing[ring_idx].id == ring_id) {		    /* just keep clobbering old values until the 		       end of the stack is reached */		    MPIU_Snprintf(msg, num_remaining, ", %s", 				  ErrorRing[ring_idx].msg);		    msg[num_remaining - 1] = '\0';		    errorcode = ErrorRing[ring_idx].prev_error;		}		else {		    break;		}	    }	}	error_ring_mutex_unlock();    }    /* FIXME: How do we determine that we failed to unwind the stack? */    if (errorcode != MPI_SUCCESS) return 1;    return 0;}#endif

⌨️ 快捷键说明

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