PAPI 7.1.0.0
Loading...
Searching...
No Matches
omptough.c File Reference
Include dependency graph for omptough.c:

Go to the source code of this file.

Macros

#define NITER   (100000)
 

Functions

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

Macro Definition Documentation

◆ NITER

#define NITER   (100000)

Definition at line 11 of file omptough.c.

Function Documentation

◆ main()

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

Definition at line 14 of file omptough.c.

15{
16 int i;
17 int ret;
18 int nthreads;
19 int *evtset;
20 int *ctrcode;
21
22 nthreads = omp_get_max_threads( );
23 evtset = ( int * ) malloc( sizeof ( int ) * nthreads );
24 ctrcode = ( int * ) malloc( sizeof ( int ) * nthreads );
25
26 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
27
29 if ( ret != PAPI_VER_CURRENT && ret > 0 ) {
30 fprintf( stderr, "PAPI library version mismatch '%s'\n",
31 PAPI_strerror( ret ) );
32 exit( 1 );
33 }
34
35 if ( ret < 0 ) {
36 fprintf( stderr, "PAPI initialization error '%s'\n",
37 PAPI_strerror( ret ) );
38 exit( 1 );
39 }
40
41 if ( ( ret =
42 PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self ) ) !=
43 PAPI_OK ) {
44 fprintf( stderr, "PAPI thread initialization error '%s'\n",
45 PAPI_strerror( ret ) );
46 exit( 1 );
47 }
48
49 for ( i = 0; i < nthreads; i++ ) {
50 evtset[i] = PAPI_NULL;
51
52 if ( ( ret = PAPI_event_name_to_code( "PAPI_TOT_INS", &ctrcode[i] ) )
53 != PAPI_OK ) {
54 fprintf( stderr, "PAPI evt-name-to-code error '%s'\n",
55 PAPI_strerror( ret ) );
56 }
57
58 }
59
60 for ( i = 0; i < NITER; i++ ) {
61#pragma omp parallel
62 {
63 int tid;
64 int pid;
65 tid = omp_get_thread_num( );
66
67 pid = pthread_self( );
68
69 if ( ( ret = PAPI_register_thread( ) ) != PAPI_OK ) {
70 if ( !TESTS_QUIET ) {
71 fprintf( stderr,
72 "[%5d] Error in register thread (tid=%d pid=%d) '%s'\n",
73 i, tid, pid, PAPI_strerror( ret ) );
74 test_fail( __FILE__, __LINE__, "omptough", 1 );
75 }
76 }
77
78 evtset[tid] = PAPI_NULL;
79 if ( ( ret = PAPI_create_eventset( &( evtset[tid] ) ) ) != PAPI_OK ) {
80 if ( !TESTS_QUIET ) {
81 fprintf( stderr,
82 "[%5d] Error creating eventset (tid=%d pid=%d) '%s'\n",
83 i, tid, pid, PAPI_strerror( ret ) );
84 test_fail( __FILE__, __LINE__, "omptough", 1 );
85 }
86 }
87
88
89 if ( ( ret =
90 PAPI_destroy_eventset( &( evtset[tid] ) ) ) != PAPI_OK ) {
91 if ( !TESTS_QUIET ) {
92 fprintf( stderr,
93 "[%5d] Error destroying eventset (tid=%d pid=%d) '%s'\n",
94 i, tid, pid, PAPI_strerror( ret ) );
95 evtset[tid] = PAPI_NULL;
96 test_fail( __FILE__, __LINE__, "omptough", 1 );
97 }
98 }
99
100 if ( ( ret = PAPI_unregister_thread( ) ) != PAPI_OK ) {
101 if ( !TESTS_QUIET ) {
102 fprintf( stderr,
103 "[%5d] Error in unregister thread (tid=%d pid=%d) ret='%s'\n",
104 i, tid, pid, PAPI_strerror( ret ) );
105 test_fail( __FILE__, __LINE__, "omptough", 1 );
106 }
107 }
108 }
109 }
110 test_pass( __FILE__ );
111
112 return 0;
113}
int i
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Notify PAPI that a thread has 'appeared'.
Returns a string describing the PAPI error code.
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
int TESTS_QUIET
Definition: test_utils.c:18
#define NITER
Definition: omptough.c:11
FILE * stderr
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
static int pid
Here is the call graph for this function: