|
  Error Handling
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ViewsFrom PAPIDocs
PAPI ERROR HANDLINGERROR CODESAll of the functions contained in the PAPI library return standardized error codes in which the values that are greater than or equal to zero indicate success and those that are less than zero indicate failure, as shown in the table below:
CONVERTING ERROR CODES TO ERROR MESSAGESError codes can be converted to error messages by calling the following low-level functions: C:
PAPI_perror(''code, destination, length'')
PAPI_strerror(''code'')
Fortan:
PAPIF_perror(''code'', ''destination'', check)
ARGUMENTS''code'' -- the error code to interpret ''*''''destination'' -- "the error message in quotes" ''length'' -- either 0 or strlen(destination) PAPI_perror fills the string, destination', with the error message corresponding to the error code (code). The function copies length worth of the error description string corresponding to code into destination. The resulting string is always null terminated. If length is 0, then the string is printed to stderr. PAPI_strerror returns a pointer to the error message corresponding to the error code (code). If the call fails, the function returns a NULL pointer. Otherwise, a non-NULL pointer is returned. Note that this function is not implemented in Fortran. In the following code example, PAPI_perror is used to convert error codes to error messages:
#include <papi.h>
#include <stdio.h>
main()
{
int EventSet = PAPI_NULL;
int native = 0x0;
char error_str[PAPI_MAX_STR_LEN];
/* Initialize the PAPI library */
retval = PAPI_library_init(PAPI_VER_CURRENT);
if (retval != PAPI_VER_CURRENT && retval > 0) {
fprintf(stderr,"PAPI library version mismatch!\n");
exit(1);
}
if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK) {
fprintf(stderr, "PAPI error %d: %s\n",retval, PAPI_strerror(retval));
exit(1);
}
/* Add Total Instructions Executed to our EventSet */
if ((retval = PAPI_add_event(&EventSet, PAPI_TOT_INS)) != PAPI_OK) {
PAPI_perror(retval,error_str,PAPI_MAX_STR_LEN);
fprintf(stderr,"PAPI_error %d: %s\n",retval,error_str);
exit(1);
}
/* Add POWER4 native event */
retval = PAPI_event_name_to_code(“PM_LD_MISS_L1”, &native);
if ((retval = PAPI_add_event(&EventSet, native)) != PAPI_OK) {
/* Dump error string directly to stderr. */
PAPI_perror(retval,NULL,NULL);
exit(1);
}
/* Start counting */
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
handle_error(retval);
}
OUTPUT:Invalid argument
Notice that the above output was generated from the last call to'PAPI_perror'. On success, PAPI_perror returns PAPI_OK and on error, a non-zero error code is returned. |