|
PAPI
5.3.0.0
|
00001 /* 00002 * File: zero_fork.c 00003 * Author: Philip Mucci 00004 * mucci@cs.utk.edu 00005 * Mods: <your name here> 00006 * <your email address> 00007 */ 00008 00009 /* This file performs the following test: 00010 00011 PAPI_library_init() 00012 Add two events 00013 PAPI_start() 00014 fork() 00015 / \ 00016 parent child 00017 | PAPI_library_init() 00018 | Add two events 00019 | PAPI_start() 00020 | PAPI_stop() 00021 | 00022 fork()-----\ 00023 | child 00024 parent PAPI_library_init() 00025 | Add two events 00026 | PAPI_start() 00027 | PAPI_stop() 00028 | 00029 wait() 00030 wait() 00031 | 00032 PAPI_stop() 00033 00034 No validation is done 00035 */ 00036 00037 #include "papi_test.h" 00038 #include <sys/wait.h> 00039 00040 int EventSet1 = PAPI_NULL; 00041 int PAPI_event, mask1; 00042 int num_events1 = 2; 00043 long long elapsed_us, elapsed_cyc; 00044 long long **values; 00045 char event_name[PAPI_MAX_STR_LEN]; 00046 int retval, num_tests = 1; 00047 00048 void 00049 process_init( void ) 00050 { 00051 printf( "Process %d \n", ( int ) getpid( ) ); 00052 00053 /* Initialize PAPI library */ 00054 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00055 if ( retval != PAPI_VER_CURRENT ) { 00056 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00057 } 00058 00059 /* add PAPI_TOT_CYC and one of the events in 00060 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, 00061 depends on the availability of the event 00062 on the platform */ 00063 EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 ); 00064 00065 values = allocate_test_space( num_tests, num_events1 ); 00066 00067 retval = PAPI_event_code_to_name( PAPI_event, event_name ); 00068 if ( retval != PAPI_OK ) { 00069 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00070 } 00071 00072 elapsed_us = PAPI_get_real_usec( ); 00073 elapsed_cyc = PAPI_get_real_cyc( ); 00074 00075 retval = PAPI_start( EventSet1 ); 00076 if ( retval != PAPI_OK ) { 00077 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00078 } 00079 } 00080 00081 void 00082 process_fini( void ) 00083 { 00084 retval = PAPI_stop( EventSet1, values[0] ); 00085 if ( retval != PAPI_OK ) { 00086 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00087 } 00088 00089 elapsed_us = PAPI_get_real_usec( ) - elapsed_us; 00090 elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; 00091 00092 remove_test_events( &EventSet1, mask1 ); 00093 00094 printf( "Process %d %-12s : \t%lld\n", ( int ) getpid( ), event_name, 00095 values[0][1] ); 00096 printf( "Process %d PAPI_TOT_CYC : \t%lld\n", ( int ) getpid( ), 00097 values[0][0] ); 00098 printf( "Process %d Real usec : \t%lld\n", ( int ) getpid( ), 00099 elapsed_us ); 00100 printf( "Process %d Real cycles : \t%lld\n", ( int ) getpid( ), 00101 elapsed_cyc ); 00102 00103 free_test_space( values, num_tests ); 00104 00105 } 00106 00107 int 00108 main( int argc, char **argv ) 00109 { 00110 int flops1; 00111 int retval; 00112 00113 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00114 # if (defined(__ALPHA) && defined(__osf__)) 00115 test_skip( __FILE__, __LINE__, "main: fork not supported.", 0 ); 00116 #endif 00117 00118 printf( "This tests if PAPI_library_init(),2*fork(),PAPI_library_init() works.\n" ); 00119 /* Initialize PAPI for this process */ 00120 process_init( ); 00121 flops1 = 1000000; 00122 if ( fork( ) == 0 ) { 00123 /* Initialize PAPI for the child process */ 00124 process_init( ); 00125 /* Let the child process do work */ 00126 do_flops( flops1 ); 00127 /* Measure the child process */ 00128 process_fini( ); 00129 exit( 0 ); 00130 } 00131 flops1 = 2000000; 00132 if ( fork( ) == 0 ) { 00133 /* Initialize PAPI for the child process */ 00134 process_init( ); 00135 /* Let the child process do work */ 00136 do_flops( flops1 ); 00137 /* Measure the child process */ 00138 process_fini( ); 00139 exit( 0 ); 00140 } 00141 /* Let this process do work */ 00142 flops1 = 4000000; 00143 do_flops( flops1 ); 00144 00145 /* Wait for child to finish */ 00146 wait( &retval ); 00147 /* Wait for child to finish */ 00148 wait( &retval ); 00149 00150 /* Measure this process */ 00151 process_fini( ); 00152 00153 test_pass( __FILE__, NULL, 0 ); 00154 return 0; 00155 }