PAPI 7.1.0.0
Loading...
Searching...
No Matches
inherit.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
5
6#if defined(_AIX) || defined (__FreeBSD__) || defined (__APPLE__)
7#include <sys/wait.h> /* ARGH! */
8#else
9#include <wait.h>
10#endif
11
12#include "papi.h"
13#include "papi_test.h"
14
15#include "do_loops.h"
16
17int
18main( int argc, char **argv )
19{
20 int retval, pid, status, EventSet = PAPI_NULL;
21 long long int values[] = {0,0};
22 PAPI_option_t opt;
23 char event_name[BUFSIZ];
24 int quiet;
25
26 quiet=tests_quiet( argc, argv );
27
29 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
30
32 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
33
35 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
36
37 memset( &opt, 0x0, sizeof ( PAPI_option_t ) );
40 if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) {
41 if ( retval == PAPI_ECMP) {
42 test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
43 } else if (retval == PAPI_EPERM) {
44 test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
45 } else {
46 test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );
47 }
48 }
49
50 if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK ) {
51 if (!quiet) printf("Trouble finding PAPI_TOT_CYC\n");
52 test_skip( __FILE__, __LINE__, "PAPI_query_event", retval );
53 }
54
56 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
57
58 strcpy(event_name,"PAPI_FP_INS");
60 if (retval == PAPI_ENOEVNT) {
61 strcpy(event_name,"PAPI_TOT_INS");
63 }
64
65 if ( retval != PAPI_OK ) {
66 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
67 }
68
69 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
70 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
71
72 pid = fork( );
73 if ( pid == 0 ) {
75 exit( 0 );
76 }
77 if ( waitpid( pid, &status, 0 ) == -1 ) {
78 perror( "waitpid()" );
79 exit( 1 );
80 }
81
82 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
83 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
84
85 if (!quiet) {
86 printf( "Test case inherit: parent starts, child works, parent stops.\n" );
87 printf( "------------------------------------------------------------\n" );
88
89 printf( "Test run : \t1\n" );
90 printf( "%s : \t%lld\n", event_name, values[1] );
91 printf( "PAPI_TOT_CYC: \t%lld\n", values[0] );
92 printf( "------------------------------------------------------------\n" );
93
94 printf( "Verification:\n" );
95 printf( "Row 1 at least %d\n", NUM_FLOPS );
96 printf( "Row 2 greater than row 1\n");
97 }
98
99 if ( values[1] < 100 ) {
100 test_fail( __FILE__, __LINE__, event_name, 1 );
101 }
102
103 if ( (!strcmp(event_name,"PAPI_FP_INS")) && (values[1] < NUM_FLOPS)) {
104 test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 );
105 }
106
107 test_pass( __FILE__ );
108
109 return 0;
110
111}
add PAPI preset or native hardware event to an event set
add PAPI preset or native hardware event by name to an EventSet
Assign a component index to an existing but empty EventSet.
Create a new empty PAPI EventSet.
initialize the PAPI library.
Query if PAPI event exists.
Set PAPI library or event set options.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_EPERM
Definition: f90papi.h:112
#define PAPI_INHERIT
Definition: f90papi.h:76
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_INHERIT_ALL
Definition: f90papi.h:237
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void do_flops(int n)
Definition: multiplex.c:23
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
static int pid
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
PAPI_inherit_option_t inherit
Definition: papi.h:846
int retval
Definition: zero_fork.c:53