PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero_fork.c
Go to the documentation of this file.
1 /*
2 * File: zero_fork.c
3 * Author: Philip Mucci
4 * mucci@cs.utk.edu
5 * Mods: <your name here>
6 * <your email address>
7 */
8 
9 /* This file performs the following test:
10 
11  PAPI_library_init()
12  Add two events
13  PAPI_start()
14  fork()
15  / \
16  parent child
17  | PAPI_library_init()
18  | Add two events
19  | PAPI_start()
20  | PAPI_stop()
21  |
22  fork()-----\
23  | child
24  parent PAPI_library_init()
25  | Add two events
26  | PAPI_start()
27  | PAPI_stop()
28  |
29  wait()
30  wait()
31  |
32  PAPI_stop()
33 
34  No validation is done
35  */
36 
37 #include "papi_test.h"
38 #include <sys/wait.h>
39 
42 int num_events1 = 2;
44 long long **values;
46 int retval, num_tests = 1;
47 
48 void
49 process_init( void )
50 {
51  printf( "Process %d \n", ( int ) getpid( ) );
52 
53  /* Initialize PAPI library */
55  if ( retval != PAPI_VER_CURRENT ) {
56  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
57  }
58 
59  /* add PAPI_TOT_CYC and one of the events in
60  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
61  depends on the availability of the event
62  on the platform */
64 
66 
68  if ( retval != PAPI_OK ) {
69  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
70  }
71 
74 
76  if ( retval != PAPI_OK ) {
77  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
78  }
79 }
80 
81 void
82 process_fini( void )
83 {
85  if ( retval != PAPI_OK ) {
86  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
87  }
88 
91 
93 
94  printf( "Process %d %-12s : \t%lld\n", ( int ) getpid( ), event_name,
95  values[0][1] );
96  printf( "Process %d PAPI_TOT_CYC : \t%lld\n", ( int ) getpid( ),
97  values[0][0] );
98  printf( "Process %d Real usec : \t%lld\n", ( int ) getpid( ),
99  elapsed_us );
100  printf( "Process %d Real cycles : \t%lld\n", ( int ) getpid( ),
101  elapsed_cyc );
102 
104 
105 }
106 
107 int
108 main( int argc, char **argv )
109 {
110  int flops1;
111  int retval;
112 
113  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
114 # if (defined(__ALPHA) && defined(__osf__))
115  test_skip( __FILE__, __LINE__, "main: fork not supported.", 0 );
116 #endif
117 
118  printf( "This tests if PAPI_library_init(),2*fork(),PAPI_library_init() works.\n" );
119  /* Initialize PAPI for this process */
120  process_init( );
121  flops1 = 1000000;
122  if ( fork( ) == 0 ) {
123  /* Initialize PAPI for the child process */
124  process_init( );
125  /* Let the child process do work */
126  do_flops( flops1 );
127  /* Measure the child process */
128  process_fini( );
129  exit( 0 );
130  }
131  flops1 = 2000000;
132  if ( fork( ) == 0 ) {
133  /* Initialize PAPI for the child process */
134  process_init( );
135  /* Let the child process do work */
136  do_flops( flops1 );
137  /* Measure the child process */
138  process_fini( );
139  exit( 0 );
140  }
141  /* Let this process do work */
142  flops1 = 4000000;
143  do_flops( flops1 );
144 
145  /* Wait for child to finish */
146  wait( &retval );
147  /* Wait for child to finish */
148  wait( &retval );
149 
150  /* Measure this process */
151  process_fini( );
152 
153  test_pass( __FILE__, NULL, 0 );
154  return 0;
155 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int mask1
Definition: zero_fork.c:41
int PAPI_event[2]
Definition: data_range.c:24
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_NULL
Definition: papi.h:290
int num_events1
Definition: zero_fork.c:42
void process_init(void)
Definition: zero_fork.c:49
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
long long elapsed_cyc
Definition: zero_fork.c:43
int wait()
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:131
void process_fini(void)
Definition: zero_fork.c:82
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
long long PAPI_get_real_cyc(void)
Definition: papi.c:6143
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
int EventSet1
Definition: zero_fork.c:40