pthrtough.c File Reference

Include dependency graph for pthrtough.c:

Go to the source code of this file.

Defines

#define NITER   1000

Functions

void * Thread (void *data)
int main (int argc, char *argv[])

Define Documentation

#define NITER   1000

Definition at line 6 of file pthrtough.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 33 of file pthrtough.c.

00034 {
00035     int j;
00036     pthread_t *th = NULL;
00037     pthread_attr_t attr;
00038     int ret;
00039     long nthr;
00040     const PAPI_hw_info_t *hwinfo;
00041 
00042     tests_quiet( argc, argv );  /*Set TESTS_QUIET variable */
00043 
00044     ret = PAPI_library_init( PAPI_VER_CURRENT );
00045     if ( ret != PAPI_VER_CURRENT )
00046         test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
00047 
00048     if ( ( ret =
00049            PAPI_thread_init( ( unsigned
00050                                long ( * )( void ) ) ( pthread_self ) ) ) !=
00051          PAPI_OK )
00052         test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
00053 
00054     pthread_attr_init( &attr );
00055 #ifdef PTHREAD_CREATE_UNDETACHED
00056     pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
00057 #endif
00058 #ifdef PTHREAD_SCOPE_SYSTEM
00059     ret=pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
00060     if ( ret != 0 )
00061        test_skip( __FILE__, __LINE__, "pthread_attr_setscope", ret );
00062 
00063 #endif
00064 
00065     if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
00066         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
00067 
00068     nthr = hwinfo->ncpu;
00069 
00070     if ( !TESTS_QUIET ) {
00071         printf( "Creating %ld threads for %d iterations each of:\n", nthr,
00072                 NITER );
00073         printf( "\tregister\n" );
00074         printf( "\tcreate_eventset\n" );
00075         printf( "\tdestroy_eventset\n" );
00076         printf( "\tunregister\n" );
00077     }
00078 
00079     th = ( pthread_t * ) malloc( ( size_t ) nthr * sizeof ( pthread_t ) );
00080     if ( th == NULL )
00081         test_fail( __FILE__, __LINE__, "malloc", PAPI_ESYS );
00082 
00083     for ( j = 0; j < nthr; j++ ) {
00084         ret = pthread_create( &th[j], &attr, &Thread, NULL );
00085         if ( ret )
00086             test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
00087     }
00088 
00089     for ( j = 0; j < nthr; j++ ) {
00090         pthread_join( th[j], NULL );
00091     }
00092 
00093     test_pass( __FILE__, NULL, 0 );
00094     exit( 1 );
00095 }

Here is the call graph for this function:

void* Thread ( void *  data  ) 

Definition at line 9 of file pthrtough.c.

00010 {
00011     int i, ret, evtset;
00012 
00013     ( void ) data;
00014 
00015     for ( i = 0; i < NITER; i++ ) {
00016         if ( ( ret = PAPI_register_thread(  ) ) != PAPI_OK )
00017             test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
00018 
00019         evtset = PAPI_NULL;
00020         if ( ( ret = PAPI_create_eventset( &evtset ) ) != PAPI_OK )
00021             test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
00022 
00023         if ( ( ret = PAPI_destroy_eventset( &evtset ) ) != PAPI_OK )
00024             test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
00025 
00026         if ( ( ret = PAPI_unregister_thread(  ) ) != PAPI_OK )
00027             test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
00028     }
00029     return ( NULL );
00030 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1