example_multiple_components.c File Reference

This tests to see if the CPU component and Example component can be used simultaneously. More...

Include dependency graph for example_multiple_components.c:

Go to the source code of this file.

Defines

#define NUM_EVENTS   1

Functions

int main (int argc, char **argv)

Detailed Description

Author:
Vince Weaver vweaver1@eecs.utk.edu test if multiple components can be used at once

Definition in file example_multiple_components.c.


Define Documentation

#define NUM_EVENTS   1

Definition at line 21 of file example_multiple_components.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file example_multiple_components.c.

00024 {
00025 
00026         int retval;
00027     int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL;
00028     long long values1[NUM_EVENTS];
00029     long long values2[NUM_EVENTS];
00030     const PAPI_component_info_t *cmpinfo = NULL;
00031     int numcmp,cid,example_cid=-1;
00032     int code;
00033 
00034         /* Set TESTS_QUIET variable */
00035         tests_quiet( argc, argv );      
00036 
00037     /* PAPI Initialization */
00038     retval = PAPI_library_init( PAPI_VER_CURRENT );
00039     if ( retval != PAPI_VER_CURRENT ) {
00040        test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00041     }
00042 
00043     if (!TESTS_QUIET) {
00044        printf( "Testing simultaneous component use with PAPI %d.%d.%d\n",
00045             PAPI_VERSION_MAJOR( PAPI_VERSION ),
00046             PAPI_VERSION_MINOR( PAPI_VERSION ),
00047             PAPI_VERSION_REVISION( PAPI_VERSION ) );
00048     }
00049 
00050     /* Find our component */
00051 
00052     numcmp = PAPI_num_components();
00053     for( cid=0; cid<numcmp; cid++) {
00054        if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
00055           test_fail(__FILE__, __LINE__,
00056                            "PAPI_get_component_info failed\n", 0);
00057        }
00058        if (!TESTS_QUIET) {
00059           printf("\tComponent %d - %d events - %s\n", cid, 
00060              cmpinfo->num_native_events,
00061              cmpinfo->name);
00062        }
00063        if (strstr(cmpinfo->name,"example")) {
00064           /* FOUND! */
00065           example_cid=cid;
00066        }
00067     }
00068     
00069 
00070     if (example_cid<0) {
00071        test_skip(__FILE__, __LINE__,
00072              "Example component not found\n", 0);
00073     }
00074 
00075     if (!TESTS_QUIET) {
00076       printf("\nFound Example Component at id %d\n",example_cid);
00077     }
00078 
00079 
00080     /* Create an eventset for the Example component */
00081 
00082     retval = PAPI_create_eventset( &EventSet1 );
00083     if ( retval != PAPI_OK ) {
00084        test_fail( __FILE__, __LINE__,
00085               "PAPI_create_eventset() failed\n", retval );
00086     }
00087 
00088     retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
00089     if ( retval != PAPI_OK ) {
00090        test_fail( __FILE__, __LINE__, 
00091               "EXAMPLE_ZERO not found\n",retval );
00092     }
00093 
00094     retval = PAPI_add_event( EventSet1, code);
00095     if ( retval != PAPI_OK ) {
00096        test_fail( __FILE__, __LINE__,
00097               "PAPI_add_events failed\n", retval );
00098     }
00099 
00100 
00101     /* Create an eventset for the CPU component */
00102 
00103     retval = PAPI_create_eventset( &EventSet2 );
00104     if ( retval != PAPI_OK ) {
00105        test_fail( __FILE__, __LINE__,
00106               "PAPI_create_eventset() failed\n", retval );
00107     }
00108 
00109     retval = PAPI_event_name_to_code("PAPI_TOT_CYC", &code);
00110     if ( retval != PAPI_OK ) {
00111       test_skip( __FILE__, __LINE__, 
00112               "PAPI_TOT_CYC not available\n",retval );
00113     }
00114 
00115     retval = PAPI_add_event( EventSet2, code);
00116     if ( retval != PAPI_OK ) {
00117        test_skip( __FILE__, __LINE__,
00118               "NO CPU component found\n", retval );
00119     }
00120 
00121     if (!TESTS_QUIET) printf("\nStarting EXAMPLE_CONSTANT and PAPI_TOT_CYC at the same time\n");
00122 
00123     /* Start CPU component event */
00124     retval = PAPI_start( EventSet2 );
00125     if ( retval != PAPI_OK ) {
00126        test_fail( __FILE__, __LINE__, 
00127               "PAPI_start failed\n",retval );
00128     }
00129 
00130     /* Start example component */
00131     retval = PAPI_start( EventSet1 );
00132     if ( retval != PAPI_OK ) {
00133        test_fail( __FILE__, __LINE__, 
00134               "PAPI_start failed\n",retval );
00135     }
00136 
00137 
00138 
00139 
00140     /* Stop example component */
00141     retval = PAPI_stop( EventSet1, values1 );
00142     if ( retval != PAPI_OK ) {
00143        test_fail(  __FILE__, __LINE__, "PAPI_stop failed\n", retval);
00144     }
00145 
00146     /* Stop CPU component */
00147     retval = PAPI_stop( EventSet2, values2 );
00148     if ( retval != PAPI_OK ) {
00149        test_fail(  __FILE__, __LINE__, "PAPI_stop failed\n", retval);
00150     }
00151 
00152     if (!TESTS_QUIET) printf("Stopping EXAMPLE_CONSTANT and PAPI_TOT_CYC\n\n");
00153 
00154 
00155     if (!TESTS_QUIET) printf("Results from EXAMPLE_CONSTANT: %lld\n",values1[0]);
00156 
00157     if (values1[0]!=42) {
00158        test_fail(  __FILE__, __LINE__, "Result should be 42!\n", 0);
00159     }
00160 
00161     if (!TESTS_QUIET) printf("Results from PAPI_TOT_CYC: %lld\n\n",values2[0]);
00162 
00163     if (values2[0]<1) {
00164        test_fail(  __FILE__, __LINE__, "Result should greater than 0\n", 0);
00165     }
00166 
00167     /* Cleanup EventSets */
00168     retval = PAPI_cleanup_eventset(EventSet1);
00169     if (retval != PAPI_OK) {
00170        test_fail(  __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
00171     }
00172 
00173     retval = PAPI_cleanup_eventset(EventSet2);
00174     if (retval != PAPI_OK) {
00175        test_fail(  __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
00176     }
00177 
00178     /* Destroy EventSets */
00179     retval = PAPI_destroy_eventset(&EventSet2);
00180     if (retval != PAPI_OK) {
00181        test_fail(  __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
00182     }
00183 
00184     test_pass( __FILE__, NULL, 0 );
00185         
00186     return 0;
00187 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1