PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
omptough.c
Go to the documentation of this file.
1 #include <pthread.h>
2 #include <stdlib.h>
3 #include <malloc.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <omp.h>
7 
8 #include "papi.h"
9 #include "papi_test.h"
10 
11 #define NITER (100000)
12 
13 int
14 main( int argc, char *argv[] )
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 }
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_NULL
Definition: papi.h:292
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
long long ret
Definition: iozone.c:1346
char ** argv
Definition: iozone.c:1610
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
static int pid
#define NITER
Definition: omptough.c:11
void *long long tid
Definition: iozone.c:18586
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_unregister_thread(void)
Definition: papi.c:244
int TESTS_QUIET
Definition: test_utils.c:18
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.
void exit()