mpifirst.c File Reference

Include dependency graph for mpifirst.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Variables

int TESTS_QUIET

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file mpifirst.c.

00028 {
00029     int retval, num_tests = 5, num_events, tmp;
00030     long long **values;
00031     int EventSet = PAPI_NULL;
00032     int PAPI_event, mask;
00033     char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
00034 
00035 
00036     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00037 
00038     MPI_Init( argc, argv );
00039 
00040     retval = PAPI_library_init( PAPI_VER_CURRENT );
00041     if ( retval != PAPI_VER_CURRENT )
00042         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00043 
00044     /* query and set up the right instruction to monitor */
00045     if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
00046         PAPI_event = PAPI_FP_INS;
00047         mask = MASK_FP_INS | MASK_TOT_CYC;
00048     } else {
00049         PAPI_event = PAPI_TOT_INS;
00050         mask = MASK_TOT_INS | MASK_TOT_CYC;
00051     }
00052 
00053     retval = PAPI_event_code_to_name( PAPI_event, event_name );
00054     if ( retval != PAPI_OK )
00055         test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00056     sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
00057 
00058     EventSet = add_test_events( &num_events, &mask );
00059 
00060     values = allocate_test_space( num_tests, num_events );
00061 
00062     retval = PAPI_start( EventSet );
00063     if ( retval != PAPI_OK )
00064         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00065 
00066     do_flops( NUM_FLOPS );
00067 
00068     retval = PAPI_read( EventSet, values[0] );
00069     if ( retval != PAPI_OK )
00070         test_fail( __FILE__, __LINE__, "PAPI_read", retval );
00071 
00072     retval = PAPI_reset( EventSet );
00073     if ( retval != PAPI_OK )
00074         test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
00075 
00076     do_flops( NUM_FLOPS );
00077 
00078     retval = PAPI_read( EventSet, values[1] );
00079     if ( retval != PAPI_OK )
00080         test_fail( __FILE__, __LINE__, "PAPI_read", retval );
00081 
00082     do_flops( NUM_FLOPS );
00083 
00084     retval = PAPI_read( EventSet, values[2] );
00085     if ( retval != PAPI_OK )
00086         test_fail( __FILE__, __LINE__, "PAPI_read", retval );
00087 
00088     do_flops( NUM_FLOPS );
00089 
00090     retval = PAPI_stop( EventSet, values[3] );
00091     if ( retval != PAPI_OK )
00092         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00093 
00094     retval = PAPI_read( EventSet, values[4] );
00095     if ( retval != PAPI_OK )
00096         test_fail( __FILE__, __LINE__, "PAPI_read", retval );
00097 
00098     remove_test_events( &EventSet, mask );
00099 
00100     if ( !TESTS_QUIET ) {
00101         printf( "Test case 1: Non-overlapping start, stop, read.\n" );
00102         printf( "-----------------------------------------------\n" );
00103         tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
00104         printf( "Default domain is: %d (%s)\n", tmp,
00105                 stringify_all_domains( tmp ) );
00106         tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
00107         printf( "Default granularity is: %d (%s)\n", tmp,
00108                 stringify_granularity( tmp ) );
00109         printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
00110         printf
00111             ( "-------------------------------------------------------------------------\n" );
00112 
00113         printf( "Test type   : \t1\t\t2\t\t3\t\t4\t\t5\n" );
00114         sprintf( add_event_str, "%s : ", event_name );
00115         printf( TAB5, add_event_str,
00116                 ( values[0] )[0], ( values[1] )[0], ( values[2] )[0],
00117                 ( values[3] )[0], ( values[4] )[0] );
00118         printf( TAB5, "PAPI_TOT_CYC: ", ( values[0] )[1], ( values[1] )[1],
00119                 ( values[2] )[1], ( values[3] )[1], ( values[4] )[1] );
00120         printf
00121             ( "-------------------------------------------------------------------------\n" );
00122 
00123         printf( "Verification:\n" );
00124         printf( "Column 1 approximately equals column 2\n" );
00125         printf( "Column 3 approximately equals 2 * column 2\n" );
00126         printf( "Column 4 approximately equals 3 * column 2\n" );
00127         printf( "Column 4 exactly equals column 5\n" );
00128     }
00129 
00130     {
00131         long long min, max;
00132         min = ( long long ) ( values[1][0] * .9 );
00133         max = ( long long ) ( values[1][0] * 1.1 );
00134 
00135         if ( values[0][0] > max || values[0][0] < min ||
00136              values[2][0] > ( 2 * max )
00137              || values[2][0] < ( 2 * min ) || values[3][0] > ( 3 * max )
00138              || values[3][0] < ( 3 * min )
00139              || values[3][0] != values[4][0] ) {
00140             printf( "min: " );
00141             printf( LLDFMT, min );
00142             printf( "max: " );
00143             printf( LLDFMT, max );
00144             printf( "1st: " );
00145             printf( LLDFMT, values[0][0] );
00146             printf( "2nd: " );
00147             printf( LLDFMT, values[1][0] );
00148             printf( "3rd: " );
00149             printf( LLDFMT, values[2][0] );
00150             printf( "4th: " );
00151             printf( LLDFMT, values[3][0] );
00152             printf( "5th: " );
00153             printf( LLDFMT, values[4][0] );
00154             printf( "\n" );
00155             test_fail( __FILE__, __LINE__, event_name, 1 );
00156         }
00157 
00158         min = ( long long ) ( values[1][1] * .9 );
00159         max = ( long long ) ( values[1][1] * 1.1 );
00160         if ( values[0][1] > max || values[0][1] < min ||
00161              values[2][1] > ( 2 * max )
00162              || values[2][1] < ( 2 * min ) || values[3][1] > ( 3 * max )
00163              || values[3][1] < ( 3 * min )
00164              || values[3][1] != values[4][1] ) {
00165             test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC", 1 );
00166         }
00167     }
00168     test_pass( __FILE__, values, num_tests );
00169 
00170     MPI_Finalize(  );
00171     exit( 1 );
00172 }

Here is the call graph for this function:


Variable Documentation

Definition at line 11 of file test_utils.c.


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1