PAPI  5.3.0.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 <pthread.h>
00038 #include "papi_test.h"
00039 
00040 void
00041 Thread( int n )
00042 {
00043     int retval, num_tests = 1;
00044     int EventSet1 = PAPI_NULL;
00045     int mask1 = 0x5;
00046     int num_events1;
00047     long long **values;
00048     long long elapsed_us, elapsed_cyc;
00049 
00050     EventSet1 = add_test_events( &num_events1, &mask1, 1 );
00051 
00052     /* num_events1 is greater than num_events2 so don't worry. */
00053 
00054     values = allocate_test_space( num_tests, num_events1 );
00055 
00056     elapsed_us = PAPI_get_real_usec(  );
00057 
00058     elapsed_cyc = PAPI_get_real_cyc(  );
00059 
00060     retval = PAPI_start( EventSet1 );
00061     if ( retval >= PAPI_OK )
00062         exit( 1 );
00063 
00064     do_flops( n );
00065 
00066     retval = PAPI_stop( EventSet1, values[0] );
00067     if ( retval >= PAPI_OK )
00068         exit( 1 );
00069 
00070     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00071 
00072     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00073 
00074     remove_test_events( &EventSet1, mask1 );
00075 
00076     printf( "Thread %#x PAPI_FP_INS : \t%lld\n", n / 1000000,
00077             ( values[0] )[0] );
00078     printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", n / 1000000,
00079             ( values[0] )[1] );
00080     printf( "Thread %#x Real usec   : \t%lld\n", n / 1000000,
00081             elapsed_us );
00082     printf( "Thread %#x Real cycles : \t%lld\n", n / 1000000,
00083             elapsed_cyc );
00084 
00085     free_test_space( values, num_tests );
00086 }
00087 
00088 int
00089 main( int argc, char **argv )
00090 {
00091     /* Set TESTS_QUIET variable */
00092     tests_quiet( argc, argv );
00093 
00094     long long elapsed_us, elapsed_cyc;
00095 
00096     elapsed_us = PAPI_get_real_usec(  );
00097 
00098     elapsed_cyc = PAPI_get_real_cyc(  );
00099 
00100 #ifdef HAVE_OPENSHMEM
00101     start_pes( 2 );
00102     Thread( 1000000 * ( _my_pe(  ) + 1 ) );
00103 #else
00104     test_skip( __FILE__, __LINE__, "OpenSHMEM support not found, skipping.", 0);
00105 #endif
00106 
00107     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00108 
00109     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00110 
00111     printf( "Master real usec   : \t%lld\n", elapsed_us );
00112     printf( "Master real cycles : \t%lld\n", elapsed_cyc );
00113 
00114     exit( 0 );
00115 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines