PAPI  5.0.1.0
zero_shmem.c
Go to the documentation of this file.
00001 /* This file performs the following test: start, stop and timer
00002 functionality for 2 slave OMP threads
00003 
00004    - It attempts to use the following two counters. It may use less
00005 depending on hardware counter resource limitations. These are counted
00006 in the default counting domain and default granularity, depending on
00007 the platform. Usually this is the user domain (PAPI_DOM_USER) and
00008 thread context (PAPI_GRN_THR).
00009 
00010      + PAPI_FP_INS
00011      + PAPI_TOT_CYC
00012 
00013 Each of 2 slave pthreads:
00014    - Get cyc.
00015    - Get us.
00016    - Start counters
00017    - Do flops
00018    - Stop and read counters
00019    - Get us.
00020    - Get cyc.
00021 
00022 Master pthread:
00023    - Get us.
00024    - Get cyc.
00025    - Fork threads
00026    - Wait for threads to exit
00027    - Get us.
00028    - Get cyc.
00029 */
00030 
00031 #include <stdio.h>
00032 #include <unistd.h>
00033 #include <errno.h>
00034 #include <sys/types.h>
00035 #include <memory.h>
00036 #include <malloc.h>
00037 #include "papi_test.h"
00038 
00039 void
00040 Thread( int n )
00041 {
00042     int retval, num_tests = 1, tmp;
00043     int EventSet1 = PAPI_NULL;
00044     int mask1 = 0x5;
00045     int num_events1;
00046     long long **values;
00047     long long elapsed_us, elapsed_cyc;
00048 
00049     EventSet1 = add_test_events( &num_events1, &mask1 );
00050 
00051     /* num_events1 is greater than num_events2 so don't worry. */
00052 
00053     values = allocate_test_space( num_tests, num_events1 );
00054 
00055     elapsed_us = PAPI_get_real_usec(  );
00056 
00057     elapsed_cyc = PAPI_get_real_cyc(  );
00058 
00059     retval = PAPI_start( EventSet1 );
00060     if ( retval >= PAPI_OK )
00061         exit( 1 );
00062 
00063     do_flops( n );
00064 
00065     retval = PAPI_stop( EventSet1, values[0] );
00066     if ( retval >= PAPI_OK )
00067         exit( 1 );
00068 
00069     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00070 
00071     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00072 
00073     remove_test_events( &EventSet1, mask1 );
00074 
00075     printf( "Thread 0x%x PAPI_FP_INS : \t%lld\n", pthread_self(  ),
00076             ( values[0] )[0] );
00077     printf( "Thread 0x%x PAPI_TOT_CYC: \t%lld\n", pthread_self(  ),
00078             ( values[0] )[1] );
00079     printf( "Thread 0x%x Real usec   : \t%lld\n", pthread_self(  ),
00080             elapsed_us );
00081     printf( "Thread 0x%x Real cycles : \t%lld\n", pthread_self(  ),
00082             elapsed_cyc );
00083 
00084     free_test_space( values, num_tests );
00085 }
00086 
00087 int
00088 main(  )
00089 {
00090     int i, rc;
00091     long long elapsed_us, elapsed_cyc;
00092 
00093     elapsed_us = PAPI_get_real_usec(  );
00094 
00095     elapsed_cyc = PAPI_get_real_cyc(  );
00096 
00097     start_pes( 2 );
00098     Thread( 1000000 * ( _my_pe(  ) + 1 ) );
00099 
00100     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00101 
00102     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00103 
00104     printf( "Master real usec   : \t%lld\n", elapsed_us );
00105     printf( "Master real cycles : \t%lld\n", elapsed_cyc );
00106 
00107     exit( 0 );
00108 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines