1
1
openmpi/test/asm/atomic_math.c
Brian Barrett 0964152893 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 03:51:20 +00:00

132 строки
3.0 KiB
C

/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* All rights reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#define OMPI_BUILDING 0
#include "ompi_config.h"
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include "include/sys/atomic.h"
#define TEST_REPS 500
int32_t val32 = 0;
#if OMPI_HAVE_ATOMIC_MATH_64
int64_t val64 = 0;
#endif
int valint = 0;
static void* atomic_math_test(void* arg)
{
int count = (int) (unsigned long) arg;
int i;
for (i = 0 ; i < count ; ++i) {
ompi_atomic_add_32(&val32, 5);
#if OMPI_HAVE_ATOMIC_MATH_64
ompi_atomic_add_64(&val64, 6);
#endif
ompi_atomic_add(&valint, 4);
}
return NULL;
}
static int
atomic_math_test_th(int count, int thr_count)
{
#if OMPI_HAVE_POSIX_THREADS
pthread_t *th;
int tid, ret = 0;
th = (pthread_t *) malloc(thr_count * sizeof(pthread_t));
if (!th) { perror("malloc"); exit(EXIT_FAILURE); }
for (tid = 0; tid < thr_count; tid++) {
if (pthread_create(&th[tid], NULL, atomic_math_test, (void*) count) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
}
/* -- wait for the thread set to finish -- */
for (tid = 0; tid < thr_count; tid++) {
void *thread_return;
if (pthread_join(th[tid], &thread_return) != 0) {
perror("pthread_join");
exit(EXIT_FAILURE);
}
}
free(th);
return ret;
#else
if (thr_count == 1) {
atomic_math_test((void*) count);
} else {
return 77;
}
#endif
return 0;
}
int
main(int argc, char *argv[])
{
int ret = 77;
int num_threads = 1;
if (argc != 2) {
printf("*** Incorrect number of arguments. Skipping test\n");
return 77;
}
num_threads = atoi(argv[1]);
ret = atomic_math_test_th(TEST_REPS, num_threads);
if (ret == 77) return ret;
ompi_atomic_mb();
if (val32 != TEST_REPS * num_threads * 5) {
printf("ompi_atomic_add32 failed. Expected %d, got %d.\n",
TEST_REPS * num_threads * 5, val32);
ret = 1;
}
#if OMPI_HAVE_ATOMIC_MATH_64
if (val64 != TEST_REPS * num_threads * 6) {
printf("ompi_atomic_add32 failed. Expected %d, got %d.\n",
TEST_REPS * num_threads * 6, val64);
ret = 1;
}
#else
printf(" * skipping 64 bit tests\n");
#endif
if (valint != TEST_REPS * num_threads * 4) {
printf("ompi_atomic_add32 failed. Expected %d, got %d.\n",
TEST_REPS * num_threads * 4, valint);
ret = 1;
}
return ret;
}