PAPI 7.1.0.0
Loading...
Searching...
No Matches
pthrtough.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <pthread.h>
5
6#include "papi.h"
7#include "papi_test.h"
8
9#define NITER 1000
10
11void *
12Thread( void *data )
13{
14 int i, ret, evtset;
15
16 ( void ) data;
17
18 for ( i = 0; i < NITER; i++ ) {
19 if ( ( ret = PAPI_register_thread( ) ) != PAPI_OK )
20 test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
21
22 evtset = PAPI_NULL;
23 if ( ( ret = PAPI_create_eventset( &evtset ) ) != PAPI_OK )
24 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
25
26 if ( ( ret = PAPI_destroy_eventset( &evtset ) ) != PAPI_OK )
27 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
28
29 if ( ( ret = PAPI_unregister_thread( ) ) != PAPI_OK )
30 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
31 }
32 return ( NULL );
33}
34
35int
36main( int argc, char *argv[] )
37{
38 int j;
39 pthread_t *th = NULL;
40 pthread_attr_t attr;
41 int ret;
42 long nthr;
43 const PAPI_hw_info_t *hwinfo;
44
45 tests_quiet( argc, argv ); /*Set TESTS_QUIET variable */
46
48 if ( ret != PAPI_VER_CURRENT )
49 test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
50
51 if ( ( ret =
52 PAPI_thread_init( ( unsigned
53 long ( * )( void ) ) ( pthread_self ) ) ) !=
54 PAPI_OK )
55 test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
56
57 pthread_attr_init( &attr );
58#ifdef PTHREAD_CREATE_UNDETACHED
59 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
60#endif
61#ifdef PTHREAD_SCOPE_SYSTEM
62 ret=pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
63 if ( ret != 0 )
64 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", ret );
65
66#endif
67
68 if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL )
69 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
70
71 nthr = hwinfo->ncpu;
72
73 if ( !TESTS_QUIET ) {
74 printf( "Creating %ld threads for %d iterations each of:\n", nthr,
75 NITER );
76 printf( "\tregister\n" );
77 printf( "\tcreate_eventset\n" );
78 printf( "\tdestroy_eventset\n" );
79 printf( "\tunregister\n" );
80 }
81
82 th = ( pthread_t * ) malloc( ( size_t ) nthr * sizeof ( pthread_t ) );
83 if ( th == NULL )
84 test_fail( __FILE__, __LINE__, "malloc", PAPI_ESYS );
85
86 for ( j = 0; j < nthr; j++ ) {
87 ret = pthread_create( &th[j], &attr, &Thread, NULL );
88 if ( ret ) {
89 free(th);
90 test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
91 }
92 }
93
94 for ( j = 0; j < nthr; j++ ) {
95 pthread_join( th[j], NULL );
96 }
97
98 free(th);
99 test_pass( __FILE__ );
100
101 return 0;
102
103}
int i
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
get information about the system hardware
initialize the PAPI library.
Notify PAPI that a thread has 'appeared'.
Initialize thread support in the PAPI library.
Notify PAPI that a thread has 'disappeared'.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_ESYS
Definition: f90papi.h:136
int TESTS_QUIET
Definition: test_utils.c:18
Return codes and api definitions.
unsigned long int pthread_t
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
#define NITER
Definition: pthrtough.c:9
void * Thread(void *data)
Definition: pthrtough.c:12
Hardware info structure.
Definition: papi.h:774
int ncpu
Definition: papi.h:775