pthrtough2.c File Reference

Include dependency graph for pthrtough2.c:

Go to the source code of this file.

Defines

#define NITER   2000

Functions

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

Define Documentation

#define NITER   2000

Definition at line 6 of file pthrtough2.c.


Function Documentation

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

Definition at line 32 of file pthrtough2.c.

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

Here is the call graph for this function:

void* Thread ( void *  data  ) 

Definition at line 9 of file pthrtough2.c.

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

Here is the call graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1