/usr/share/doc/papi-examples/ctests/mpifirst.c is in papi-examples 5.3.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | /* This file performs the following test: start, read, stop and again functionality
- It attempts to use the following three counters. It may use less depending on
hardware counter resource limitations. These are counted in the default counting
domain and default granularity, depending on the platform. Usually this is
the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
+ PAPI_FP_INS or PAPI_TOT_INS if PAPI_FP_INS doesn't exist
+ PAPI_TOT_CYC
- Start counters
- Do flops
- Read counters
- Reset counters
- Do flops
- Read counters
- Do flops
- Read counters
- Do flops
- Stop and read counters
- Read counters
*/
#include "papi_test.h"
extern int TESTS_QUIET; /* Declared in test_utils.c */
int
main( int argc, char **argv )
{
int retval, num_tests = 5, num_events, tmp;
long long **values;
int EventSet = PAPI_NULL;
int PAPI_event, mask;
char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
MPI_Init( argc, argv );
retval = PAPI_library_init( PAPI_VER_CURRENT );
if ( retval != PAPI_VER_CURRENT )
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
/* query and set up the right instruction to monitor */
if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
PAPI_event = PAPI_FP_INS;
mask = MASK_FP_INS | MASK_TOT_CYC;
} else {
PAPI_event = PAPI_TOT_INS;
mask = MASK_TOT_INS | MASK_TOT_CYC;
}
retval = PAPI_event_code_to_name( PAPI_event, event_name );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
EventSet = add_test_events( &num_events, &mask );
values = allocate_test_space( num_tests, num_events );
retval = PAPI_start( EventSet );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_start", retval );
do_flops( NUM_FLOPS );
retval = PAPI_read( EventSet, values[0] );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
retval = PAPI_reset( EventSet );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
do_flops( NUM_FLOPS );
retval = PAPI_read( EventSet, values[1] );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
do_flops( NUM_FLOPS );
retval = PAPI_read( EventSet, values[2] );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
do_flops( NUM_FLOPS );
retval = PAPI_stop( EventSet, values[3] );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
retval = PAPI_read( EventSet, values[4] );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
remove_test_events( &EventSet, mask );
if ( !TESTS_QUIET ) {
printf( "Test case 1: Non-overlapping start, stop, read.\n" );
printf( "-----------------------------------------------\n" );
tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
printf( "Default domain is: %d (%s)\n", tmp,
stringify_all_domains( tmp ) );
tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
printf( "Default granularity is: %d (%s)\n", tmp,
stringify_granularity( tmp ) );
printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
printf
( "-------------------------------------------------------------------------\n" );
printf( "Test type : \t1\t\t2\t\t3\t\t4\t\t5\n" );
sprintf( add_event_str, "%s : ", event_name );
printf( TAB5, add_event_str,
( values[0] )[0], ( values[1] )[0], ( values[2] )[0],
( values[3] )[0], ( values[4] )[0] );
printf( TAB5, "PAPI_TOT_CYC: ", ( values[0] )[1], ( values[1] )[1],
( values[2] )[1], ( values[3] )[1], ( values[4] )[1] );
printf
( "-------------------------------------------------------------------------\n" );
printf( "Verification:\n" );
printf( "Column 1 approximately equals column 2\n" );
printf( "Column 3 approximately equals 2 * column 2\n" );
printf( "Column 4 approximately equals 3 * column 2\n" );
printf( "Column 4 exactly equals column 5\n" );
}
{
long long min, max;
min = ( long long ) ( values[1][0] * .9 );
max = ( long long ) ( values[1][0] * 1.1 );
if ( values[0][0] > max || values[0][0] < min ||
values[2][0] > ( 2 * max )
|| values[2][0] < ( 2 * min ) || values[3][0] > ( 3 * max )
|| values[3][0] < ( 3 * min )
|| values[3][0] != values[4][0] ) {
printf( "min: " );
printf( LLDFMT, min );
printf( "max: " );
printf( LLDFMT, max );
printf( "1st: " );
printf( LLDFMT, values[0][0] );
printf( "2nd: " );
printf( LLDFMT, values[1][0] );
printf( "3rd: " );
printf( LLDFMT, values[2][0] );
printf( "4th: " );
printf( LLDFMT, values[3][0] );
printf( "5th: " );
printf( LLDFMT, values[4][0] );
printf( "\n" );
test_fail( __FILE__, __LINE__, event_name, 1 );
}
min = ( long long ) ( values[1][1] * .9 );
max = ( long long ) ( values[1][1] * 1.1 );
if ( values[0][1] > max || values[0][1] < min ||
values[2][1] > ( 2 * max )
|| values[2][1] < ( 2 * min ) || values[3][1] > ( 3 * max )
|| values[3][1] < ( 3 * min )
|| values[3][1] != values[4][1] ) {
test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC", 1 );
}
}
test_pass( __FILE__, values, num_tests );
MPI_Finalize( );
exit( 1 );
}
|