|
PAPI
5.0.1.0
|
00001 /* From Dave McNamara at PSRV. Thanks! */ 00002 00003 /* If an event is countable but you've exhausted the counter resources 00004 and you try to add an event, it seems subsequent PAPI_start and/or 00005 PAPI_stop will causes a Seg. Violation. 00006 00007 I got around this by calling PAPI to get the # of countable events, 00008 then making sure that I didn't try to add more than these number of 00009 events. I still have a problem if someone adds Level 2 cache misses 00010 and then adds FLOPS 'cause I didn't count FLOPS as actually requiring 00011 2 counters. */ 00012 00013 #include "papi_test.h" 00014 00015 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00016 00017 int 00018 main( int argc, char **argv ) 00019 { 00020 double c, a = 0.999, b = 1.001; 00021 int n = 1000; 00022 int EventSet = PAPI_NULL; 00023 int retval; 00024 int j = 0, i; 00025 long long g1[3]; 00026 00027 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00028 00029 if ( ( retval = 00030 PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00031 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00032 00033 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) 00034 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00035 00036 if ( PAPI_query_event( PAPI_BR_CN ) == PAPI_OK ) 00037 j++; 00038 00039 if ( j == 1 && 00040 ( retval = PAPI_add_event( EventSet, PAPI_BR_CN ) ) != PAPI_OK ) { 00041 if ( retval != PAPI_ECNFLCT ) 00042 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00043 } 00044 00045 i = j; 00046 if ( PAPI_query_event( PAPI_TOT_CYC ) == PAPI_OK ) 00047 j++; 00048 00049 if ( j == ( i + 1 ) && 00050 ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) { 00051 if ( retval != PAPI_ECNFLCT ) 00052 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00053 } 00054 00055 i = j; 00056 if ( PAPI_query_event( PAPI_TOT_INS ) == PAPI_OK ) 00057 j++; 00058 00059 if ( j == ( i + 1 ) && 00060 ( retval = PAPI_add_event( EventSet, PAPI_TOT_INS ) ) != PAPI_OK ) { 00061 if ( retval != PAPI_ECNFLCT ) 00062 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00063 } 00064 00065 if ( j ) { 00066 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) 00067 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00068 00069 for ( i = 0; i < n; i++ ) { 00070 c = a * b; 00071 } 00072 if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c); 00073 if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK ) 00074 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00075 } 00076 test_pass( __FILE__, NULL, 0 ); 00077 exit( 1 ); 00078 }