PAPI 7.1.0.0
Loading...
Searching...
No Matches
ctests/locks_pthreads.c File Reference
Include dependency graph for ctests/locks_pthreads.c:

Go to the source code of this file.

Macros

#define MAX_THREADS   256
 
#define APPR_TOTAL_ITER   1000000
 

Functions

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

Variables

volatile long long count = 0
 
volatile long long tmpcount = 0
 
volatile long long thread_iter = 0
 
static int quiet =0
 

Macro Definition Documentation

◆ APPR_TOTAL_ITER

#define APPR_TOTAL_ITER   1000000

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

◆ MAX_THREADS

#define MAX_THREADS   256

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

Function Documentation

◆ lockloop()

void lockloop ( int  iters,
volatile long long mycount 
)

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

26{
27 int i;
28 for ( i = 0; i < iters; i++ ) {
30 *mycount = *mycount + 1;
32 }
33}
int i
Lock one of two mutex variables defined in papi.h.
Unlock one of the mutex variables defined in papi.h.
#define PAPI_USR1_LOCK
Definition: f90papi.h:197
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

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

54{
55 pthread_t slaves[MAX_THREADS];
56 int rc, i, nthr;
57 int retval;
58 const PAPI_hw_info_t *hwinfo = NULL;
59
60 /* Set TESTS_QUIET variable */
61 quiet = tests_quiet( argc, argv );
62
64 if (retval != PAPI_VER_CURRENT ) {
65 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
66 }
67
68 hwinfo = PAPI_get_hardware_info( );
69 if (hwinfo == NULL ) {
70 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
71 }
72
73 retval = PAPI_thread_init((unsigned long (*)(void)) ( pthread_self ) );
74 if ( retval != PAPI_OK ) {
75 if ( retval == PAPI_ECMP ) {
76 test_skip( __FILE__, __LINE__,
77 "PAPI_thread_init", retval );
78 }
79 else {
80 test_fail( __FILE__, __LINE__,
81 "PAPI_thread_init", retval );
82 }
83 }
84
85 if ( hwinfo->ncpu > MAX_THREADS ) {
86 nthr = MAX_THREADS;
87 }
88 else {
89 nthr = hwinfo->ncpu;
90 }
91
92 /* Scale the per thread work to keep the serial runtime about the same. */
93 thread_iter = APPR_TOTAL_ITER/sqrt(nthr);
94
95 if (!quiet) {
96 printf( "Creating %d threads, %lld lock/unlock\n",
97 nthr , thread_iter);
98 }
99
100 for ( i = 0; i < nthr; i++ ) {
101 rc = pthread_create( &slaves[i], NULL, Slave, NULL );
102 if ( rc ) {
104 test_fail( __FILE__, __LINE__,
105 "pthread_create", retval );
106 }
107 }
108
109 for ( i = 0; i < nthr; i++ ) {
110 pthread_join( slaves[i], NULL );
111 }
112
113 if (!quiet) {
114 printf( "Expected: %lld Received: %lld\n",
115 ( long long ) nthr * thread_iter,
116 count );
117 }
118
119 if ( nthr * thread_iter != count ) {
120 test_fail( __FILE__, __LINE__, "Thread Locks", 1 );
121 }
122
123 test_pass( __FILE__ );
124
125 return 0;
126
127}
get information about the system hardware
initialize the PAPI library.
Initialize thread support in the PAPI library.
static int quiet
#define MAX_THREADS
volatile long long count
void * Slave(void *arg)
volatile long long thread_iter
#define APPR_TOTAL_ITER
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_ECMP
Definition: f90papi.h:214
unsigned long int pthread_t
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
rc
Definition: pscanf.h:23
Hardware info structure.
Definition: papi.h:774
int ncpu
Definition: papi.h:775
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ Slave()

void * Slave ( void *  arg)

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

37{
38 long long duration;
39
40 duration = PAPI_get_real_usec( );
42 duration = PAPI_get_real_usec( ) - duration;
43
44 if (!quiet) {
45 printf("%f lock/unlocks per us\n",
46 (float)thread_iter/(float)duration);
47 }
48 pthread_exit( arg );
49}
get real time counter value in microseconds
void lockloop(int iters, volatile long long *mycount)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ count

volatile long long count = 0

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

◆ quiet

int quiet =0
static

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

◆ thread_iter

volatile long long thread_iter = 0

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

◆ tmpcount

volatile long long tmpcount = 0

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