|
PAPI
5.0.1.0
|
00001 /* This file performs the following test: start, stop and timer 00002 functionality for 2 slave pthreads */ 00003 00004 #include <pthread.h> 00005 #include "papi_test.h" 00006 00007 static int processing = 1; 00008 00009 void * 00010 Thread( void *arg ) 00011 { 00012 int retval; 00013 void *arg2; 00014 retval = PAPI_register_thread( ); 00015 if ( retval != PAPI_OK ) 00016 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); 00017 00018 printf( "Thread 0x%x started, specific data is at %p\n", 00019 ( int ) pthread_self( ), arg ); 00020 00021 retval = PAPI_set_thr_specific( PAPI_USR1_TLS, arg ); 00022 if ( retval != PAPI_OK ) 00023 test_fail( __FILE__, __LINE__, "PAPI_set_thr_specific", retval ); 00024 00025 retval = PAPI_get_thr_specific( PAPI_USR1_TLS, &arg2 ); 00026 if ( retval != PAPI_OK ) 00027 test_fail( __FILE__, __LINE__, "PAPI_get_thr_specific", retval ); 00028 00029 if ( arg != arg2 ) 00030 test_fail( __FILE__, __LINE__, "set vs get specific", 0 ); 00031 00032 while ( processing ) { 00033 if ( *( ( int * ) arg ) == 500000 ) { 00034 sleep( 1 ); 00035 int i; 00036 PAPI_all_thr_spec_t data; 00037 data.num = 10; 00038 data.id = 00039 ( unsigned long * ) malloc( ( size_t ) data.num * 00040 sizeof ( unsigned long ) ); 00041 data.data = 00042 ( void ** ) malloc( ( size_t ) data.num * sizeof ( void * ) ); 00043 00044 retval = 00045 PAPI_get_thr_specific( PAPI_USR1_TLS | PAPI_TLS_ALL_THREADS, 00046 ( void ** ) &data ); 00047 if ( retval != PAPI_OK ) 00048 test_fail( __FILE__, __LINE__, "PAPI_get_thr_specific", 00049 retval ); 00050 00051 if ( data.num != 5 ) 00052 test_fail( __FILE__, __LINE__, "data.num != 5", 0 ); 00053 00054 for ( i = 0; i < data.num; i++ ) 00055 printf( "Entry %d, Thread 0x%lx, Data Pointer %p, Value %d\n", 00056 i, data.id[i], data.data[i], *( int * ) data.data[i] ); 00057 00058 processing = 0; 00059 } 00060 } 00061 00062 retval = PAPI_unregister_thread( ); 00063 if ( retval != PAPI_OK ) 00064 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval ); 00065 return ( NULL ); 00066 } 00067 00068 int 00069 main( int argc, char **argv ) 00070 { 00071 pthread_t e_th, f_th, g_th, h_th; 00072 int flops1, flops2, flops3, flops4, flops5; 00073 int retval, rc; 00074 pthread_attr_t attr; 00075 00076 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00077 00078 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00079 if ( retval != PAPI_VER_CURRENT ) 00080 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00081 00082 retval = 00083 PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ); 00084 if ( retval != PAPI_OK ) { 00085 if ( retval == PAPI_ECMP ) 00086 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval ); 00087 else 00088 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval ); 00089 } 00090 00091 pthread_attr_init( &attr ); 00092 #ifdef PTHREAD_CREATE_UNDETACHED 00093 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED ); 00094 #endif 00095 #ifdef PTHREAD_SCOPE_SYSTEM 00096 retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); 00097 if ( retval != 0 ) 00098 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval ); 00099 #endif 00100 00101 flops1 = 1000000; 00102 rc = pthread_create( &e_th, &attr, Thread, ( void * ) &flops1 ); 00103 if ( rc ) { 00104 retval = PAPI_ESYS; 00105 test_fail( __FILE__, __LINE__, "pthread_create", retval ); 00106 } 00107 flops2 = 2000000; 00108 rc = pthread_create( &f_th, &attr, Thread, ( void * ) &flops2 ); 00109 if ( rc ) { 00110 retval = PAPI_ESYS; 00111 test_fail( __FILE__, __LINE__, "pthread_create", retval ); 00112 } 00113 00114 flops3 = 4000000; 00115 rc = pthread_create( &g_th, &attr, Thread, ( void * ) &flops3 ); 00116 if ( rc ) { 00117 retval = PAPI_ESYS; 00118 test_fail( __FILE__, __LINE__, "pthread_create", retval ); 00119 } 00120 00121 flops4 = 8000000; 00122 rc = pthread_create( &h_th, &attr, Thread, ( void * ) &flops4 ); 00123 if ( rc ) { 00124 retval = PAPI_ESYS; 00125 test_fail( __FILE__, __LINE__, "pthread_create", retval ); 00126 } 00127 00128 pthread_attr_destroy( &attr ); 00129 flops5 = 500000; 00130 Thread( &flops5 ); 00131 pthread_join( h_th, NULL ); 00132 pthread_join( g_th, NULL ); 00133 pthread_join( f_th, NULL ); 00134 pthread_join( e_th, NULL ); 00135 00136 test_pass( __FILE__, NULL, 0 ); 00137 pthread_exit( NULL ); 00138 exit( 1 ); 00139 }