PAPI  5.0.1.0
zero_smp.c
Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /* This file performs the following test: start, stop and timer
00004 functionality for 2 slave native SMP threads
00005 
00006    - It attempts to use the following two counters. It may use less
00007 depending on hardware counter resource limitations. These are counted
00008 in the default counting domain and default granularity, depending on
00009 the platform. Usually this is the user domain (PAPI_DOM_USER) and
00010 thread context (PAPI_GRN_THR).
00011 
00012      + PAPI_FP_INS
00013      + PAPI_TOT_CYC
00014 
00015 Each of 2 slave pthreads:
00016    - Get cyc.
00017    - Get us.
00018    - Start counters
00019    - Do flops
00020    - Stop and read counters
00021    - Get us.
00022    - Get cyc.
00023 
00024 Master pthread:
00025    - Get us.
00026    - Get cyc.
00027    - Fork threads
00028    - Wait for threads to exit
00029    - Get us.
00030    - Get cyc.
00031 */
00032 
00033 
00034 #include "papi_test.h"
00035 
00036 #if defined(sun) && defined(sparc)
00037 #include <thread.h>
00038 #elif defined(mips) && defined(sgi) && defined(unix)
00039 #include <mpc.h>
00040 #elif defined(_AIX)
00041 #include <pthread.h>
00042 #endif
00043 
00044 
00045 void
00046 Thread( int t, int n )
00047 {
00048     int retval, num_tests = 1;
00049     int EventSet1 = PAPI_NULL;
00050     int PAPI_event, mask1;
00051     int num_events1;
00052     long long **values;
00053     long long elapsed_us, elapsed_cyc;
00054     char event_name[PAPI_MAX_STR_LEN];
00055 
00056     /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
00057        PAPI_TOT_INS, depending on the availability of the event on the
00058        platform */
00059     EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
00060 
00061     retval = PAPI_event_code_to_name( PAPI_event, event_name );
00062     if ( retval != PAPI_OK )
00063         test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00064 
00065     values = allocate_test_space( num_tests, num_events1 );
00066 
00067     retval = PAPI_start( EventSet1 );
00068     if ( retval != PAPI_OK )
00069         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00070 
00071     elapsed_us = PAPI_get_real_usec(  );
00072 
00073     elapsed_cyc = PAPI_get_real_cyc(  );
00074 
00075     do_flops( n );
00076 
00077     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00078 
00079     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00080 
00081     retval = PAPI_stop( EventSet1, values[0] );
00082     if ( retval != PAPI_OK )
00083         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00084 
00085     remove_test_events( &EventSet1, mask1 );
00086 
00087     if ( !TESTS_QUIET ) {
00088         printf( "Thread 0x%x %-12s : \t%lld\n", t, event_name,
00089                 values[0][1] );
00090         printf( "Thread 0x%x PAPI_TOT_CYC : \t%lld\n", t, 
00091             values[0][0] );
00092     }
00093 
00094     free_test_space( values, num_tests );
00095     if ( !TESTS_QUIET ) {
00096         printf( "Thread 0x%x Real usec    : \t%lld\n", t, elapsed_us );
00097         printf( "Thread 0x%x Real cycles  : \t%lld\n", t, elapsed_cyc );
00098     }
00099     PAPI_unregister_thread(  );
00100 }
00101 
00102 int
00103 main( int argc, char **argv )
00104 {
00105     int i, retval;
00106     long long elapsed_us, elapsed_cyc;
00107 
00108     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00109 
00110     retval = PAPI_library_init( PAPI_VER_CURRENT );
00111     if ( retval != PAPI_VER_CURRENT )
00112         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00113 
00114     elapsed_us = PAPI_get_real_usec(  );
00115 
00116     elapsed_cyc = PAPI_get_real_cyc(  );
00117 
00118 #if defined(_AIX)
00119     retval =
00120         PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
00121     if ( retval != PAPI_OK ) {
00122         if ( retval == PAPI_ECMP )
00123             test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
00124         else
00125             test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
00126     }
00127 #pragma ibm parallel_loop
00128 #elif defined(sgi) && defined(mips)
00129     retval =
00130         PAPI_thread_init( ( unsigned long ( * )( void ) ) ( mp_my_threadnum ) );
00131     if ( retval != PAPI_OK ) {
00132         test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
00133     }
00134 #pragma parallel
00135 #pragma local(i)
00136 #pragma pfor
00137 #elif defined(sun) && defined(sparc)
00138     retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( thr_self ) );
00139     if ( retval != PAPI_OK ) {
00140         test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
00141     }
00142 #pragma MP taskloop private(i)
00143 #else
00144 #error "Architecture not included in this test file yet."
00145 #endif
00146     for ( i = 1; i < 3; i++ )
00147         Thread( i, 10000000 * i );
00148 
00149     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00150 
00151     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00152 
00153     if ( !TESTS_QUIET ) {
00154         printf( "Master real usec   : \t%lld\n", elapsed_us );
00155         printf( "Master real cycles : \t%lld\n", elapsed_cyc );
00156     }
00157     test_pass( __FILE__, NULL, 0 );
00158     exit( 1 );
00159 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines