PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ctests/locks_pthreads.c File Reference
Include dependency graph for ctests/locks_pthreads.c:

Go to the source code of this file.

Functions

void lockloop (int iters, volatile long long *mycount)
 
voidSlave (void *arg)
 
int main (int argc, char **argv)
 

Variables

volatile long long count = 0
 
volatile long long tmpcount = 0
 
volatile int num_iters = 0
 

Function Documentation

void lockloop ( int  iters,
volatile long long mycount 
)

Definition at line 14 of file ctests/locks_pthreads.c.

15 {
16  int i;
17  for ( i = 0; i < iters; i++ ) {
19  *mycount = *mycount + 1;
21  }
22 }
#define PAPI_USR1_LOCK
Definition: fpapi.h:82
int i
Definition: fileop.c:140
int PAPI_unlock(int lck)
Definition: papi.c:6295
int PAPI_lock(int lck)
Definition: papi.c:6275

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file ctests/locks_pthreads.c.

52 {
53  pthread_t slaves[MAX_THREADS];
54  int rc, i, nthr;
55  int retval;
56  const PAPI_hw_info_t *hwinfo = NULL;
57 
58  /* Set TESTS_QUIET variable */
59  tests_quiet( argc, argv );
60 
61  if ( ( retval =
63  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
64 
65  if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL )
66  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
67 
68  retval =
69  PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
70  if ( retval != PAPI_OK ) {
71  if ( retval == PAPI_ECMP )
72  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
73  else
74  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
75  }
76 
77  if ( hwinfo->ncpu > MAX_THREADS )
78  nthr = MAX_THREADS;
79  else
80  nthr = hwinfo->ncpu;
81 
82  printf( "Creating %d threads\n", nthr );
83 
84  for ( i = 0; i < nthr; i++ ) {
85  rc = pthread_create( &slaves[i], NULL, Slave, NULL );
86  if ( rc ) {
87  retval = PAPI_ESYS;
88  test_fail( __FILE__, __LINE__, "pthread_create", retval );
89  }
90  }
91 
92  for ( i = 0; i < nthr; i++ ) {
93  pthread_join( slaves[i], NULL );
94  }
95 
96  printf( "Expected: %lld Received: %lld\n", ( long long ) nthr * num_iters,
97  count );
98  if ( nthr * num_iters != count )
99  test_fail( __FILE__, __LINE__, "Thread Locks", 1 );
100 
101  test_pass( __FILE__, NULL, 0 );
102  exit( 1 );
103 }
Hardware info structure.
Definition: papi.h:775
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
volatile int num_iters
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
void * Slave(void *arg)
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_ECMP
Definition: fpapi.h:109
#define MAX_THREADS
Definition: test_utils.h:7
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
pthread_t
Definition: iozone.c:18557
#define PAPI_ESYS
Definition: fpapi.h:108
int rc
Definition: iozone.c:20281
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
ssize_t retval
Definition: libasync.c:338
void exit()
int ncpu
Definition: papi.h:776

Here is the call graph for this function:

void* Slave ( void arg)

Definition at line 25 of file ctests/locks_pthreads.c.

26 {
27  long long duration;
28 
29  ( void ) arg;
30 
31  sleep( 1 );
32  duration = PAPI_get_real_usec( );
33  lockloop( 10000, &tmpcount );
34  duration = PAPI_get_real_usec( ) - duration;
35 
36  /* First one here set's the number */
38  if ( num_iters == 0 ) {
39  printf( "10000 iterations took %lld us.\n", duration );
40  num_iters = ( int ) ( 10 * ( TIME_LIMIT_IN_US / duration ) );
41  printf( "Running %d iterations\n", num_iters );
42  }
44 
46  pthread_exit( NULL );
47 }
void lockloop(int iters, volatile long long *mycount)
sleep(1)
#define TIME_LIMIT_IN_US
Definition: test_utils.h:16
volatile int num_iters
int count
Definition: iozone.c:22422
#define PAPI_USR2_LOCK
Definition: fpapi.h:83
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
int PAPI_unlock(int lck)
Definition: papi.c:6295
int
Definition: iozone.c:18528
int PAPI_lock(int lck)
Definition: papi.c:6275
volatile long long tmpcount

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

volatile long long count = 0

Definition at line 9 of file ctests/locks_pthreads.c.

volatile int num_iters = 0

Definition at line 11 of file ctests/locks_pthreads.c.

volatile long long tmpcount = 0

Definition at line 10 of file ctests/locks_pthreads.c.