2
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3
* University Research and Technology
4
* Corporation. All rights reserved.
5
* Copyright (c) 2004-2005 The University of Tennessee and The University
6
* of Tennessee Research Foundation. All rights
8
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9
* University of Stuttgart. All rights reserved.
10
* Copyright (c) 2004-2005 The Regents of the University of California.
11
* All rights reserved.
14
* Additional copyrights may follow
19
#define OMPI_BUILDING 0
20
#include "ompi_config.h"
28
#include "opal/sys/atomic.h"
33
#if OPAL_HAVE_ATOMIC_MATH_64
38
static void* atomic_math_test(void* arg)
40
int count = *((int*) arg);
43
for (i = 0 ; i < count ; ++i) {
44
opal_atomic_add_32(&val32, 5);
45
#if OPAL_HAVE_ATOMIC_MATH_64
46
opal_atomic_add_64(&val64, 6);
48
opal_atomic_add(&valint, 4);
56
atomic_math_test_th(int count, int thr_count)
59
#if OMPI_HAVE_POSIX_THREADS
63
th = (pthread_t *) malloc(thr_count * sizeof(pthread_t));
69
/* Ok to use a single instance of ip_union_t from the stack here
70
because a) we're passing the same count to all threads, and b)
71
we're waiting for all the threads to finish before leaving this
72
function, so there's no race condition of the instance
73
disappearing before the threads start. */
75
for (tid = 0; tid < thr_count; tid++) {
76
if (pthread_create(&th[tid], NULL, atomic_math_test,
77
(void*) &value) != 0) {
78
perror("pthread_create");
83
/* -- wait for the thread set to finish -- */
84
for (tid = 0; tid < thr_count; tid++) {
87
if (pthread_join(th[tid], &thread_return) != 0) {
88
perror("pthread_join");
98
atomic_math_test((void*) &value);
109
main(int argc, char *argv[])
115
printf("*** Incorrect number of arguments. Skipping test\n");
118
num_threads = atoi(argv[1]);
120
ret = atomic_math_test_th(TEST_REPS, num_threads);
121
if (ret == 77) return ret;
123
if (val32 != TEST_REPS * num_threads * 5) {
124
printf("opal_atomic_add32 failed. Expected %d, got %d.\n",
125
TEST_REPS * num_threads * 5, val32);
128
#if OPAL_HAVE_ATOMIC_MATH_64
129
if (val64 != TEST_REPS * num_threads * 6) {
130
/* Safe to case to (int) here because we know it's going to be
132
printf("opal_atomic_add32 failed. Expected %d, got %d.\n",
133
TEST_REPS * num_threads * 6, (int) val64);
137
printf(" * skipping 64 bit tests\n");
139
if (valint != TEST_REPS * num_threads * 4) {
140
printf("opal_atomic_add32 failed. Expected %d, got %d.\n",
141
TEST_REPS * num_threads * 4, valint);