📄 errutil.c
字号:
if (error_class == MPI_ERR_OTHER) { if (MPIR_ERR_GET_CLASS(lastcode) > MPI_SUCCESS && MPIR_ERR_GET_CLASS(lastcode) <= MPICH_ERR_LAST_CLASS) { /* If the last class is more specific (and is valid), then pass it through */ error_class = MPIR_ERR_GET_CLASS(lastcode); } else { error_class = MPI_ERR_OTHER; } } /* Handle special case of MPI_ERR_IN_STATUS. According to the standard, the code must be equal to the class. See section 3.7.5. Information on the particular error is in the MPI_ERROR field of the status. */ if (error_class == MPI_ERR_IN_STATUS) { return MPI_ERR_IN_STATUS; } err_code = error_class; /* Handle the generic message. This selects a subclass, based on a text string */# if MPICH_ERROR_MSG_LEVEL > MPICH_ERROR_MSG_CLASS { generic_idx = FindGenericMsgIndex(generic_msg); if (generic_idx >= 0) { if (strcmp( generic_err_msgs[generic_idx].short_name, "**user" ) == 0) { use_user_error_code = 1; } err_code |= (generic_idx + 1) << ERROR_GENERIC_SHIFT; } else { /* TODO: lookup index for class error message */ err_code &= ~ERROR_GENERIC_MASK; # ifdef MPICH_DBG_OUTPUT { if (generic_msg[0] == '*' && generic_msg[1] == '*') { /* FIXME : Internal error. Generate some debugging information; Fix for the general release */ fprintf( stderr, "Could not find %s in list of messages\n", generic_msg ); } }# endif } }# endif /* Handle the instance-specific part of the error message */# if MPICH_ERROR_MSG_LEVEL >= MPICH_ERROR_MSG_ALL { int specific_idx; const char * specific_fmt = 0; int ring_idx, ring_seq=0; char * ring_msg; int i; error_ring_mutex_lock(); { ring_idx = error_ring_loc++; if (error_ring_loc >= MAX_ERROR_RING) error_ring_loc %= MAX_ERROR_RING; ring_msg = ErrorRing[ring_idx].msg; if (specific_msg != NULL) { specific_idx = FindSpecificMsgIndex(specific_msg); if (specific_idx >= 0) { specific_fmt = specific_err_msgs[specific_idx].long_name; } else { specific_fmt = specific_msg; } vsnprintf_mpi( ring_msg, MPI_MAX_ERROR_STRING, specific_fmt, Argp );#if 0 specific_fmt = simplify_fmt_string(specific_fmt);# ifdef HAVE_VSNPRINTF { vsnprintf( ring_msg, MPI_MAX_ERROR_STRING, specific_fmt, Argp ); }# elif defined(HAVE_VSPRINTF) { vsprintf( ring_msg, specific_fmt, Argp ); }# else { /* For now, just punt */ if (generic_idx >= 0) { MPIU_Strncpy( ring_msg, generic_err_msgs[generic_idx].long_name, MPI_MAX_ERROR_STRING ); } else { MPIU_Strncpy( ring_msg, generic_msg, MPI_MAX_ERROR_STRING ); } }# endif MPIU_Free(specific_fmt);#endif } else if (generic_idx >= 0) { MPIU_Strncpy( ring_msg, generic_err_msgs[generic_idx].long_name, MPI_MAX_ERROR_STRING ); } else { MPIU_Strncpy( ring_msg, generic_msg, MPI_MAX_ERROR_STRING ); } ring_msg[MPI_MAX_ERROR_STRING] = '\0'; /* Create a simple hash function of the message to serve as the sequence number */ ring_seq = 0; for (i=0; ring_msg[i]; i++) { ring_seq += (unsigned int) ring_msg[i]; } ring_seq %= ERROR_SPECIFIC_SEQ_SIZE; ErrorRing[ring_idx].id = error_class & ERROR_CLASS_MASK; ErrorRing[ring_idx].id |= (generic_idx + 1) << ERROR_GENERIC_SHIFT; ErrorRing[ring_idx].id |= ring_seq << ERROR_SPECIFIC_SEQ_SHIFT; ErrorRing[ring_idx].prev_error = lastcode; if (use_user_error_code) { ErrorRing[ring_idx].use_user_error_code = 1; ErrorRing[ring_idx].user_error_code = va_arg(Argp, int); } 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].fcname, MAX_FCNAME_LEN, "%s(%d)", fcname, line); ErrorRing[ring_idx].fcname[MAX_FCNAME_LEN] = '\0'; } else { ErrorRing[ring_idx].fcname[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; } /* va_end( Argp ); */ return err_code;}/* * Accessor routines for the predefined messages. These can be * used by the other routines (such as MPI_Error_string) to * access the messages in this file, or the messages that may be * available through any message catalog facility */static const char *get_class_msg( int error_class ){#if MPICH_ERROR_MSG_LEVEL > MPICH_ERROR_MSG_NONE if (error_class >= 0 && error_class < MPIR_MAX_ERROR_CLASS_INDEX) { return generic_err_msgs[class_to_index[error_class]].long_name; } else { return "Unknown error class"; }#else return "Error message texts are not available";#endif}void MPIR_Err_get_string( int errorcode, char * msg, int length, MPIR_Err_get_class_string_func_t fn ){ int error_class; int len, num_remaining = length; if (num_remaining == 0) num_remaining = MPI_MAX_ERROR_STRING; /* Convert the code to a string. The cases are: simple class. Find the corresponding string. <not done> if (user code) { go to code that extracts user error messages } else { is specific message code set and available? if so, use it else use generic code (lookup index in table of messages) } */ if (errorcode & ERROR_DYN_MASK) { /* This is a dynamically created error code (e.g., with MPI_Err_add_class) */ /* If a dynamic error code was created, the function to convert them into strings has been set. Check to see that it was; this is a safeguard against a bogus error code */ if (!MPIR_Process.errcode_to_string) { /* --BEGIN ERROR HANDLING-- */ if (MPIU_Strncpy(msg, "Undefined dynamic error code", num_remaining)) { msg[num_remaining - 1] = '\0'; } /* --END ERROR HANDLING-- */ } else { if (MPIU_Strncpy(msg, MPIR_Process.errcode_to_string( errorcode ), num_remaining)) { msg[num_remaining - 1] = '\0'; } } } else if ( (errorcode & ERROR_CLASS_MASK) == errorcode) { error_class = MPIR_ERR_GET_CLASS(errorcode); if (fn != NULL && error_class > MPICH_ERR_LAST_CLASS /*&& error_class < MPICH_ERR_MAX_EXT_CLASS*/) { fn(errorcode, msg, length); } else { if (MPIU_Strncpy(msg, get_class_msg( errorcode ), num_remaining)) { msg[num_remaining - 1] = '\0'; } } } else { /* print the class message first */ error_class = MPIR_ERR_GET_CLASS(errorcode); if (fn != NULL && error_class > MPICH_ERR_LAST_CLASS /*&& error_class < MPICH_ERR_MAX_EXT_CLASS*/) { fn(errorcode, msg, num_remaining); } else { MPIU_Strncpy(msg, get_class_msg(ERROR_GET_CLASS(errorcode)), num_remaining); } msg[num_remaining - 1] = '\0'; len = (int)strlen(msg); msg += len; num_remaining -= len; /* then print the stack or the last specific error message */ 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; MPIR_Err_print_stack_string_ext(errorcode, msg, num_remaining, fn); msg[num_remaining - 1] = '\0'; } else {# if MPICH_ERROR_MSG_LEVEL >= MPICH_ERROR_MSG_ALL { 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(); if (errorcode == MPI_SUCCESS) { goto fn_exit; } }# endif# if MPICH_ERROR_MSG_LEVEL > MPICH_ERROR_MSG_NONE { int generic_idx; generic_idx = ((errorcode & ERROR_GENERIC_MASK) >> ERROR_GENERIC_SHIFT) - 1; if (generic_idx >= 0) { MPIU_Snprintf(msg, num_remaining, ", %s", generic_err_msgs[generic_idx].long_name); msg[num_remaining - 1] = '\0'; goto fn_exit; } }# endif } }fn_exit: return;}#if 0void MPIR_Err_get_string_ext(int errorcode, char * msg, int maxlen, MPIR_Err_get_class_string_func_t fn){ int error_class; int ring_idx; int ring_seq; int generic_idx; /* Convert the code to a string. The cases are: simple class. Find the corresponding string. <not done> if (user code) { go to code that extracts user error messages } else { is specific message code set and available? if so, use it else use generic code (lookup index in table of messages) } */ if (errorcode & ERROR_DYN_MASK) { /* This is a dynamically created error code (e.g., with MPI_Err_add_class) */ if (!MPIR_Process.errcode_to_string) { if (MPIU_Strncpy(msg, "Undefined dynamic error code", MPI_MAX_ERROR_STRING)) { msg[MPI_MAX_ERROR_STRING - 1] = '\0'; } } else { if (MPIU_Strncpy(msg, MPIR_Process.errcode_to_string( errorcode ), MPI_MAX_ERROR_STRING)) { msg[MPI_MAX_ERROR_STRING - 1] = '\0'; } } } else if ( (errorcode & ERROR_CLASS_MASK) == errorcode) { error_class = MPIR_ERR_GET_CLASS(errorcode); if (error_class <= MPICH_ERR_LAST_CLASS) { /* code is a raw error class. Convert the class to an index */ if (MPIU_Strncpy(msg, get_class_msg( errorcode ), MPI_MAX_ERROR_STRING)) { msg[MPI_MAX_ERROR_STRING - 1] = '\0'; } } else { fn(errorcode, msg, maxlen); } } else { /* error code encodes a message. Find it and make sure that it is still valid (seq number matches the stored value in the error message ring). If the seq number is *not* valid, use the generic message. */ ring_idx = (errorcode & ERROR_SPECIFIC_INDEX_MASK) >> ERROR_SPECIFIC_INDEX_SHIFT; ring_seq = (errorcode & ERROR_SPECIFIC_SEQ_MASK) >> ERROR_SPECIFIC_SEQ_SHIFT; generic_idx = ((errorcode & ERROR_GENERIC_MASK) >> ERROR_GENERIC_SHIFT) - 1;# if MPICH_ERROR_MSG_LEVEL >= MPICH_ERROR_MSG_ALL { if (generic_idx >= 0) { int flag = FALSE; error_ring_mutex_lock(); { int ring_id; ring_id = errorcode & (ERROR_CLASS_MASK | ERROR_GENERIC_MASK | ERROR_SPECIFIC_SEQ_MASK); if (ErrorRing[ring_idx].id == ring_id) { if (MPIU_Strncpy(msg, ErrorRing[ring_idx].msg, MPI_MAX_ERROR_STRING)) { msg[MPI_MAX_ERROR_STRING - 1] = '\0'; } flag = TRUE; } } error_ring_mutex_unlock(); if (flag) { goto fn_exit; } } }# endif # if MPICH_ERROR_MSG_LEVEL > MPICH_ERROR_MSG_NONE { if (generic_idx >= 0) { if (MPIU_Strncpy(msg, generic_err_msgs[generic_idx].long_name, MPI_MAX_ERROR_STRING)) { msg[MPI_MAX_ERROR_STRING - 1] = '\0'; } goto fn_exit; } }# endif error_class = ERROR_GET_CLASS(errorcode); if (error_class <= MPICH_ERR_LAST_CLASS) { if (MPIU_Strncpy(msg, get_class_msg(error_class), MPI_MAX_ERROR_STRING)) { msg[MPI_MAX_ERROR_STRING - 1] = '\0'; } } else { /*MPIU_Snprintf(msg, MPI_MAX_ERROR_STRING, "Error code contains an invalid class (%d)", error_class);*/ fn(errorcode, msg, maxlen); } }fn_exit: return;}#endifvoid MPIR_Err_print_stack(FILE * fp, int errcode){# if MPICH_ERROR_MSG_LEVEL >= MPICH_ERROR_MSG_ALL { 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].fcname, ErrorRing[ring_idx].msg); errcode = ErrorRing[ring_idx].prev_error; } else { break; } } } error_ring_mutex_unlock(); if (errcode == MPI_SUCCESS) { goto fn_exit; } }# endif# if MPICH_ERROR_MSG_LEVEL > MPICH_ERROR_MSG_NONE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -