2005-01-28 00:08:35 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-01-28 00:08:35 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2005-01-28 00:08:35 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
2005-01-27 04:39:55 +03:00
|
|
|
|
clean up the OMPI_BUILDING #define. Rather than being defined to 1 if
we are part of the source tree and not defined otherwise, we are going
with an always defined if ompi_config.h is included policy. If
ompi_config.h is included before mpi.h or before OMPI_BUILDING is set,
it will set OMPI_BUILDING to 1 and enable all the internal code that
is in ompi_config_bottom.h. Otherwise, it will only include the
system configuration data (enough for defining the C and C++ interfaces
to MPI, but not perturbing the user environment).
This should fix the problems with bool and the like that the Eclipse
folks were seeing. It also cleans up some build system hacks that
we had along the way.
Also, don't use int64_t as the default size of MPI_Offset, because it
requires us including stdint.h in mpi.h, which is something we really
shouldn't be doing.
And finally, fix a ROMIO Makefile that didn't set -DOMPI_BUILDING=1,
as ROMIO includes mpi.h, but not ompi_config.h
This commit was SVN r5430.
2005-04-19 07:51:20 +04:00
|
|
|
#define OMPI_BUILDING 0
|
2005-01-27 04:39:55 +03:00
|
|
|
#include "ompi_config.h"
|
2005-01-28 00:08:35 +03:00
|
|
|
|
2005-04-18 23:33:23 +04:00
|
|
|
#undef NDEBUG
|
|
|
|
#define DEBUG
|
|
|
|
|
2005-01-27 04:39:55 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#ifdef HAVE_PTHREAD_H
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* default options */
|
|
|
|
int nreps = 100;
|
|
|
|
int nthreads = 2;
|
|
|
|
int enable_verbose = 0;
|
|
|
|
|
|
|
|
volatile int32_t vol32;
|
|
|
|
int32_t val32;
|
|
|
|
int32_t old32;
|
|
|
|
int32_t new32;
|
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2005-01-27 04:39:55 +03:00
|
|
|
volatile int64_t vol64;
|
|
|
|
int64_t val64;
|
|
|
|
int64_t old64;
|
|
|
|
int64_t new64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
volatile int volint;
|
|
|
|
int valint;
|
|
|
|
int oldint;
|
|
|
|
int newint;
|
|
|
|
|
|
|
|
volatile void *volptr;
|
|
|
|
void *oldptr;
|
|
|
|
void *newptr;
|
|
|
|
|
|
|
|
|
2005-04-18 23:33:23 +04:00
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2005-01-27 04:39:55 +03:00
|
|
|
static void *thread_main(void *arg)
|
|
|
|
{
|
2005-01-28 01:59:31 +03:00
|
|
|
int rank = (int) (unsigned long) arg;
|
2005-01-27 04:39:55 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* thread tests */
|
|
|
|
|
|
|
|
for (i = 0; i < nreps; i++) {
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_add_32(&val32, 5);
|
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
|
|
|
opal_atomic_add_64(&val64, 5);
|
2005-01-27 04:39:55 +03:00
|
|
|
#endif
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_add(&valint, 5);
|
2005-01-27 04:39:55 +03:00
|
|
|
}
|
|
|
|
|
2005-01-28 01:59:31 +03:00
|
|
|
return (void *) (unsigned long) (rank + 1000);
|
2005-01-27 04:39:55 +03:00
|
|
|
}
|
2005-04-18 23:33:23 +04:00
|
|
|
#endif
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2005-01-28 02:11:01 +03:00
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2005-01-27 04:39:55 +03:00
|
|
|
int tid;
|
|
|
|
pthread_t *th;
|
2005-01-28 00:08:35 +03:00
|
|
|
#endif
|
2005-04-18 23:33:23 +04:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("*** Incorrect number of arguments. Skipping test\n");
|
|
|
|
return 77;
|
2005-01-27 04:39:55 +03:00
|
|
|
}
|
2005-04-18 23:33:23 +04:00
|
|
|
nthreads = atoi(argv[1]);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* first test single-threaded functionality */
|
|
|
|
|
|
|
|
/* -- cmpset 32-bit tests -- */
|
|
|
|
|
|
|
|
vol32 = 42, old32 = 42, new32 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_32(&vol32, old32, new32) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(vol32 == new32);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
vol32 = 42, old32 = 420, new32 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_32(&vol32, old32, new32) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(vol32 == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
vol32 = 42, old32 = 42, new32 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq_32(&vol32, old32, new32) == 1);
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(vol32 == new32);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
vol32 = 42, old32 = 420, new32 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq_32(&vol32, old32, new32) == 0);
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(vol32 == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
vol32 = 42, old32 = 42, new32 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel_32(&vol32, old32, new32) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(vol32 == new32);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
vol32 = 42, old32 = 420, new32 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel_32(&vol32, old32, new32) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(vol32 == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
/* -- cmpset 64-bit tests -- */
|
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2005-04-18 23:33:23 +04:00
|
|
|
vol64 = 42, old64 = 42, new64 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(1 == opal_atomic_cmpset_64(&vol64, old64, new64));
|
|
|
|
opal_atomic_rmb();
|
2005-04-18 23:33:23 +04:00
|
|
|
assert(new64 == vol64);
|
|
|
|
|
|
|
|
vol64 = 42, old64 = 420, new64 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_64(&vol64, old64, new64) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-04-18 23:33:23 +04:00
|
|
|
assert(vol64 == 42);
|
|
|
|
|
|
|
|
vol64 = 42, old64 = 42, new64 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq_64(&vol64, old64, new64) == 1);
|
2005-04-18 23:33:23 +04:00
|
|
|
assert(vol64 == new64);
|
|
|
|
|
|
|
|
vol64 = 42, old64 = 420, new64 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq_64(&vol64, old64, new64) == 0);
|
2005-04-18 23:33:23 +04:00
|
|
|
assert(vol64 == 42);
|
|
|
|
|
|
|
|
vol64 = 42, old64 = 42, new64 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel_64(&vol64, old64, new64) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-04-18 23:33:23 +04:00
|
|
|
assert(vol64 == new64);
|
|
|
|
|
|
|
|
vol64 = 42, old64 = 420, new64 = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel_64(&vol64, old64, new64) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-04-18 23:33:23 +04:00
|
|
|
assert(vol64 == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
#endif
|
|
|
|
/* -- cmpset int tests -- */
|
|
|
|
|
|
|
|
volint = 42, oldint = 42, newint = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset(&volint, oldint, newint) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volint ==newint);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volint = 42, oldint = 420, newint = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset(&volint, oldint, newint) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volint == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volint = 42, oldint = 42, newint = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq(&volint, oldint, newint) == 1);
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volint == newint);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volint = 42, oldint = 420, newint = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq(&volint, oldint, newint) == 0);
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volint == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volint = 42, oldint = 42, newint = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel(&volint, oldint, newint) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volint == newint);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volint = 42, oldint = 420, newint = 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel(&volint, oldint, newint) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volint == 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* -- cmpset ptr tests -- */
|
|
|
|
|
|
|
|
volptr = (void *) 42, oldptr = (void *) 42, newptr = (void *) 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_ptr(&volptr, oldptr, newptr) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volptr == newptr);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volptr = (void *) 42, oldptr = (void *) 420, newptr = (void *) 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_ptr(&volptr, oldptr, newptr) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volptr == (void *) 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volptr = (void *) 42, oldptr = (void *) 42, newptr = (void *) 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq_ptr(&volptr, oldptr, newptr) == 1);
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volptr == newptr);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volptr = (void *) 42, oldptr = (void *) 420, newptr = (void *) 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_acq_ptr(&volptr, oldptr, newptr) == 0);
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volptr == (void *) 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volptr = (void *) 42, oldptr = (void *) 42, newptr = (void *) 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel_ptr(&volptr, oldptr, newptr) == 1);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volptr == newptr);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
volptr = (void *) 42, oldptr = (void *) 420, newptr = (void *) 50;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_cmpset_rel_ptr(&volptr, oldptr, newptr) == 0);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert(volptr == (void *) 42);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
/* -- add_32 tests -- */
|
|
|
|
|
|
|
|
val32 = 42;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_add_32(&val32, 5) == (42 + 5));
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert((42 + 5) == val32);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
/* -- add_64 tests -- */
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2005-04-18 23:33:23 +04:00
|
|
|
val64 = 42;
|
2005-07-04 01:38:51 +04:00
|
|
|
assert(opal_atomic_add_64(&val64, 5) == (42 + 5));
|
|
|
|
opal_atomic_rmb();
|
2005-04-18 23:33:23 +04:00
|
|
|
assert((42 + 5) == val64);
|
2005-01-27 04:39:55 +03:00
|
|
|
#endif
|
|
|
|
/* -- add_int tests -- */
|
|
|
|
|
|
|
|
valint = 42;
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_add(&valint, 5);
|
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert((42 + 5) == valint);
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* threaded tests */
|
|
|
|
|
|
|
|
val32 = 0;
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2005-01-27 04:39:55 +03:00
|
|
|
val64 = 0ul;
|
|
|
|
#endif
|
|
|
|
valint = 0;
|
|
|
|
|
|
|
|
/* -- create the thread set -- */
|
2005-01-28 02:11:01 +03:00
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2005-01-27 04:39:55 +03:00
|
|
|
th = (pthread_t *) malloc(nthreads * sizeof(pthread_t));
|
|
|
|
if (!th) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
for (tid = 0; tid < nthreads; tid++) {
|
2005-01-28 01:59:31 +03:00
|
|
|
if (pthread_create(&th[tid], NULL, thread_main, (void *) (unsigned long) tid) != 0) {
|
2005-01-27 04:39:55 +03:00
|
|
|
perror("pthread_create");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -- wait for the thread set to finish -- */
|
|
|
|
|
|
|
|
for (tid = 0; tid < nthreads; tid++) {
|
|
|
|
void *thread_return;
|
|
|
|
|
|
|
|
if (pthread_join(th[tid], &thread_return) != 0) {
|
|
|
|
perror("pthread_join");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(th);
|
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert((5 * nthreads * nreps) == val32);
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
|
|
|
opal_atomic_rmb();
|
2005-04-18 23:33:23 +04:00
|
|
|
assert((5 * nthreads * nreps) == val64);
|
2005-01-27 04:39:55 +03:00
|
|
|
#endif
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_rmb();
|
2005-01-28 00:08:35 +03:00
|
|
|
assert((5 * nthreads * nreps) == valint);
|
|
|
|
#endif
|
2005-01-27 04:39:55 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|