PAPI  5.6.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 <stdio.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <sys/wait.h>
41 
42 #include "papi.h"
43 #include "papi_test.h"
44 
45 #include "do_loops.h"
46 
49 int num_events1 = 2;
51 long long **values;
53 int retval, num_tests = 1;
54 
55 void
56 process_init( void )
57 {
58  if (!TESTS_QUIET) printf( "Process %d \n", ( int ) getpid( ) );
59 
60  /* Initialize PAPI library */
62  if ( retval != PAPI_VER_CURRENT ) {
63  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
64  }
65 
66  /* add PAPI_TOT_CYC and one of the events in
67  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
68  depends on the availability of the event
69  on the platform */
71 
73 
75  if ( retval != PAPI_OK ) {
76  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
77  }
78 
81 
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85  }
86 }
87 
88 void
89 process_fini( void )
90 {
92  if ( retval != PAPI_OK ) {
93  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
94  }
95 
98 
100 
101  if (!TESTS_QUIET) {
102  printf( "Process %d %-12s : \t%lld\n", ( int ) getpid( ), event_name,
103  values[0][1] );
104  printf( "Process %d PAPI_TOT_CYC : \t%lld\n", ( int ) getpid( ),
105  values[0][0] );
106  printf( "Process %d Real usec : \t%lld\n", ( int ) getpid( ),
107  elapsed_us );
108  printf( "Process %d Real cycles : \t%lld\n", ( int ) getpid( ),
109  elapsed_cyc );
110  }
111 
113 
114 }
115 
116 int
117 main( int argc, char **argv )
118 {
119  int flops1;
120  int retval;
121 
122  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
123 # if (defined(__ALPHA) && defined(__osf__))
124  test_skip( __FILE__, __LINE__, "main: fork not supported.", 0 );
125 #endif
126 
127  if (!TESTS_QUIET) {
128  printf( "This tests if PAPI_library_init(),2*fork(),PAPI_library_init() works.\n" );
129  }
130  /* Initialize PAPI for this process */
131  process_init( );
132  flops1 = 1000000;
133  if ( fork( ) == 0 ) {
134  /* Initialize PAPI for the child process */
135  process_init( );
136  /* Let the child process do work */
137  do_flops( flops1 );
138  /* Measure the child process */
139  process_fini( );
140  exit( 0 );
141  }
142  flops1 = 2000000;
143  if ( fork( ) == 0 ) {
144  /* Initialize PAPI for the child process */
145  process_init( );
146  /* Let the child process do work */
147  do_flops( flops1 );
148  /* Measure the child process */
149  process_fini( );
150  exit( 0 );
151  }
152  /* Let this process do work */
153  flops1 = 4000000;
154  do_flops( flops1 );
155 
156  /* Wait for child to finish */
157  wait( &retval );
158  /* Wait for child to finish */
159  wait( &retval );
160 
161  /* Measure this process */
162  process_fini( );
163 
164  test_pass( __FILE__ );
165  return 0;
166 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
void process_init(void)
Definition: zero_fork.c:56
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
long long elapsed_cyc
Definition: zero_fork.c:50
int wait()
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:615
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
void process_fini(void)
Definition: zero_fork.c:89
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:50
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
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:201
int EventSet1
Definition: zero_fork.c:47