PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
51long long **values;
54
55void
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
88void
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
116int
117main( 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}
Convert a numeric hardware event code to a name.
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:640
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int main()
Definition: pernode.c:20
int EventSet1
Definition: zero_fork.c:47
int num_events1
Definition: zero_fork.c:49
int mask1
Definition: zero_fork.c:48
long long elapsed_cyc
Definition: zero_fork.c:50
int PAPI_event
Definition: zero_fork.c:48
long long elapsed_us
Definition: zero_fork.c:50
int num_tests
Definition: zero_fork.c:53
char event_name[PAPI_MAX_STR_LEN]
Definition: zero_fork.c:52
int retval
Definition: zero_fork.c:53
void process_fini(void)
Definition: zero_fork.c:89
void process_init(void)
Definition: zero_fork.c:56
long long ** values
Definition: zero_fork.c:51