omptough.c File Reference

Include dependency graph for omptough.c:

Go to the source code of this file.

Defines

#define NITER   (100000)

Functions

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

Define Documentation

#define NITER   (100000)

Definition at line 9 of file omptough.c.


Function Documentation

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

Definition at line 12 of file omptough.c.

00013 {
00014     int i;
00015     int ret;
00016     int nthreads;
00017     int *evtset;
00018     int *ctrcode;
00019 
00020     nthreads = omp_get_max_threads(  );
00021     evtset = ( int * ) malloc( sizeof ( int ) * nthreads );
00022     ctrcode = ( int * ) malloc( sizeof ( int ) * nthreads );
00023 
00024     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00025 
00026     ret = PAPI_library_init( PAPI_VER_CURRENT );
00027     if ( ret != PAPI_VER_CURRENT && ret > 0 ) {
00028         fprintf( stderr, "PAPI library version mismatch '%s'\n",
00029                  PAPI_strerror( ret ) );
00030         exit( 1 );
00031     }
00032 
00033     if ( ret < 0 ) {
00034         fprintf( stderr, "PAPI initialization error '%s'\n",
00035                  PAPI_strerror( ret ) );
00036         exit( 1 );
00037     }
00038 
00039     if ( ( ret =
00040            PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self ) ) !=
00041          PAPI_OK ) {
00042         fprintf( stderr, "PAPI thread initialization error '%s'\n",
00043                  PAPI_strerror( ret ) );
00044         exit( 1 );
00045     }
00046 
00047     for ( i = 0; i < nthreads; i++ ) {
00048         evtset[i] = PAPI_NULL;
00049 
00050         if ( ( ret = PAPI_event_name_to_code( "PAPI_TOT_INS", &ctrcode[i] ) )
00051              != PAPI_OK ) {
00052             fprintf( stderr, "PAPI evt-name-to-code error '%s'\n",
00053                      PAPI_strerror( ret ) );
00054         }
00055 
00056     }
00057 
00058     for ( i = 0; i < NITER; i++ ) {
00059 #pragma omp parallel
00060         {
00061             int tid;
00062             int pid;
00063             tid = omp_get_thread_num(  );
00064 
00065             pid = pthread_self(  );
00066 
00067             if ( ( ret = PAPI_register_thread(  ) ) != PAPI_OK ) {
00068                 if ( !TESTS_QUIET ) {
00069                     fprintf( stderr,
00070                              "[%5d] Error in register thread (tid=%d pid=%d) '%s'\n",
00071                              i, tid, pid, PAPI_strerror( ret ) );
00072                     test_fail( __FILE__, __LINE__, "omptough", 1 );
00073                 }
00074             }
00075 
00076             evtset[tid] = PAPI_NULL;
00077             if ( ( ret = PAPI_create_eventset( &( evtset[tid] ) ) ) != PAPI_OK ) {
00078                 if ( !TESTS_QUIET ) {
00079                     fprintf( stderr,
00080                              "[%5d] Error creating eventset (tid=%d pid=%d) '%s'\n",
00081                              i, tid, pid, PAPI_strerror( ret ) );
00082                     test_fail( __FILE__, __LINE__, "omptough", 1 );
00083                 }
00084             }
00085 
00086 
00087             if ( ( ret =
00088                    PAPI_destroy_eventset( &( evtset[tid] ) ) ) != PAPI_OK ) {
00089                 if ( !TESTS_QUIET ) {
00090                     fprintf( stderr,
00091                              "[%5d] Error destroying eventset (tid=%d pid=%d) '%s'\n",
00092                              i, tid, pid, PAPI_strerror( ret ) );
00093                     evtset[tid] = PAPI_NULL;
00094                     test_fail( __FILE__, __LINE__, "omptough", 1 );
00095                 }
00096             }
00097 
00098             if ( ( ret = PAPI_unregister_thread(  ) ) != PAPI_OK ) {
00099                 if ( !TESTS_QUIET ) {
00100                     fprintf( stderr,
00101                              "[%5d] Error in unregister thread (tid=%d pid=%d) ret='%s'\n",
00102                              i, tid, pid, PAPI_strerror( ret ) );
00103                     test_fail( __FILE__, __LINE__, "omptough", 1 );
00104                 }
00105             }
00106         }
00107     }
00108     test_pass( __FILE__, NULL, 0 );
00109     exit( 1 );
00110 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1