2005-04-18 23:33:23 +04: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.
|
2014-10-16 05:47:32 +04:00
|
|
|
* Copyright (c) 2004-2014 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-04-18 23:33:23 +04:00
|
|
|
* 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.
|
2010-07-28 18:20:58 +04:00
|
|
|
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
2005-04-18 23:33:23 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
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
|
2010-07-28 18:20:58 +04:00
|
|
|
#include "opal_config.h"
|
2005-04-18 23:33:23 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_PTHREAD_H
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2005-04-18 23:33:23 +04:00
|
|
|
|
|
|
|
#define TEST_REPS 500
|
|
|
|
|
|
|
|
int32_t val32 = 0;
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2005-04-18 23:33:23 +04:00
|
|
|
int64_t val64 = 0;
|
|
|
|
#endif
|
|
|
|
int valint = 0;
|
|
|
|
|
|
|
|
static void* atomic_math_test(void* arg)
|
|
|
|
{
|
2005-05-12 06:44:20 +04:00
|
|
|
int count = *((int*) arg);
|
2005-04-18 23:33:23 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < count ; ++i) {
|
2014-10-16 05:47:32 +04:00
|
|
|
(void)opal_atomic_add_32(&val32, 5);
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2014-10-16 05:47:32 +04:00
|
|
|
(void)opal_atomic_add_64(&val64, 6);
|
2005-04-18 23:33:23 +04:00
|
|
|
#endif
|
2014-10-16 05:47:32 +04:00
|
|
|
(void)opal_atomic_add(&valint, 4);
|
2005-04-18 23:33:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
atomic_math_test_th(int count, int thr_count)
|
|
|
|
{
|
2005-05-12 06:44:20 +04:00
|
|
|
int value;
|
2009-05-07 00:11:28 +04:00
|
|
|
#if OPAL_HAVE_POSIX_THREADS
|
2005-04-18 23:33:23 +04:00
|
|
|
pthread_t *th;
|
|
|
|
int tid, ret = 0;
|
|
|
|
|
|
|
|
th = (pthread_t *) malloc(thr_count * sizeof(pthread_t));
|
2005-05-11 03:28:31 +04:00
|
|
|
if (!th) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2005-04-18 23:33:23 +04:00
|
|
|
|
2005-05-11 03:28:31 +04:00
|
|
|
/* Ok to use a single instance of ip_union_t from the stack here
|
|
|
|
because a) we're passing the same count to all threads, and b)
|
|
|
|
we're waiting for all the threads to finish before leaving this
|
|
|
|
function, so there's no race condition of the instance
|
|
|
|
disappearing before the threads start. */
|
2005-05-12 06:44:20 +04:00
|
|
|
value = count;
|
2005-04-18 23:33:23 +04:00
|
|
|
for (tid = 0; tid < thr_count; tid++) {
|
2005-05-12 06:44:20 +04:00
|
|
|
if (pthread_create(&th[tid], NULL, atomic_math_test,
|
|
|
|
(void*) &value) != 0) {
|
2005-04-18 23:33:23 +04:00
|
|
|
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
|
2005-05-12 06:44:20 +04:00
|
|
|
value = count;
|
2005-04-18 23:33:23 +04:00
|
|
|
if (thr_count == 1) {
|
2005-05-12 06:44:20 +04:00
|
|
|
atomic_math_test((void*) &value);
|
2005-04-18 23:33:23 +04:00
|
|
|
} 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;
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_mb();
|
2005-04-18 23:33:23 +04:00
|
|
|
if (val32 != TEST_REPS * num_threads * 5) {
|
2005-07-04 01:38:51 +04:00
|
|
|
printf("opal_atomic_add32 failed. Expected %d, got %d.\n",
|
2005-04-18 23:33:23 +04:00
|
|
|
TEST_REPS * num_threads * 5, val32);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2005-07-04 01:38:51 +04:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
2005-04-18 23:33:23 +04:00
|
|
|
if (val64 != TEST_REPS * num_threads * 6) {
|
2005-05-11 03:28:31 +04:00
|
|
|
/* Safe to case to (int) here because we know it's going to be
|
|
|
|
a small value */
|
2005-07-04 01:38:51 +04:00
|
|
|
printf("opal_atomic_add32 failed. Expected %d, got %d.\n",
|
2005-05-11 03:28:31 +04:00
|
|
|
TEST_REPS * num_threads * 6, (int) val64);
|
2005-04-18 23:33:23 +04:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
printf(" * skipping 64 bit tests\n");
|
|
|
|
#endif
|
|
|
|
if (valint != TEST_REPS * num_threads * 4) {
|
2005-07-04 01:38:51 +04:00
|
|
|
printf("opal_atomic_add32 failed. Expected %d, got %d.\n",
|
2005-04-18 23:33:23 +04:00
|
|
|
TEST_REPS * num_threads * 4, valint);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|