2005-01-28 00:08:35 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
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$
|
|
|
|
*/
|
|
|
|
|
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-28 00:08:35 +03:00
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREAD_H
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "include/sys/atomic.h"
|
2005-04-18 23:33:23 +04:00
|
|
|
|
|
|
|
#define TEST_REPS 500
|
2005-01-28 00:08:35 +03:00
|
|
|
|
|
|
|
int atomic_verbose = 0;
|
|
|
|
|
|
|
|
struct start_info {
|
|
|
|
int tid;
|
|
|
|
int count;
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock_t *lock;
|
2005-01-28 00:08:35 +03:00
|
|
|
};
|
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
static int atomic_spinlock_test(opal_atomic_lock_t *lock, int count, int id);
|
2005-02-15 01:07:08 +03:00
|
|
|
|
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2005-01-28 00:08:35 +03:00
|
|
|
static void* atomic_spinlock_start(void* arg)
|
|
|
|
{
|
|
|
|
struct start_info *data = (struct start_info*) arg;
|
|
|
|
|
2005-01-28 01:59:31 +03:00
|
|
|
return (void*) (unsigned long) atomic_spinlock_test(data->lock, data->count,
|
2005-01-28 00:08:35 +03:00
|
|
|
data->tid);
|
|
|
|
}
|
2005-02-15 01:07:08 +03:00
|
|
|
#endif
|
2005-01-28 00:08:35 +03:00
|
|
|
|
|
|
|
|
2005-04-18 23:52:39 +04:00
|
|
|
static int
|
2005-07-04 01:38:51 +04:00
|
|
|
atomic_spinlock_test_th(opal_atomic_lock_t *lock, int count, int id, int thr_count)
|
2005-01-28 00:08:35 +03:00
|
|
|
{
|
2005-01-28 02:11:01 +03:00
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2005-01-28 00:08:35 +03:00
|
|
|
pthread_t *th;
|
|
|
|
int tid, ret = 0;
|
|
|
|
struct start_info *data;
|
|
|
|
|
|
|
|
th = (pthread_t *) malloc(thr_count * sizeof(pthread_t));
|
|
|
|
if (!th) { perror("malloc"); exit(EXIT_FAILURE); }
|
|
|
|
data = (struct start_info *) malloc(thr_count * sizeof(struct start_info));
|
|
|
|
if (!th) { perror("malloc"); exit(EXIT_FAILURE); }
|
|
|
|
|
|
|
|
for (tid = 0; tid < thr_count; tid++) {
|
|
|
|
data[tid].tid = tid;
|
|
|
|
data[tid].count = count;
|
|
|
|
data[tid].lock = lock;
|
|
|
|
|
|
|
|
if (pthread_create(&th[tid], NULL, atomic_spinlock_start, (void *) &(data[tid])) != 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);
|
|
|
|
}
|
|
|
|
|
2005-01-28 01:59:31 +03:00
|
|
|
ret += (int) (unsigned long) thread_return;
|
2005-01-28 00:08:35 +03:00
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
free(th);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#else
|
|
|
|
return 77;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-18 23:52:39 +04:00
|
|
|
static int
|
2005-07-04 01:38:51 +04:00
|
|
|
atomic_spinlock_test(opal_atomic_lock_t *lock, int count, int id)
|
2005-01-28 00:08:35 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < count ; ++i) {
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock(lock);
|
2005-01-28 00:08:35 +03:00
|
|
|
if (atomic_verbose) { printf("id %03d has the lock (lock)\n", id); }
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(lock);
|
2005-01-28 00:08:35 +03:00
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
while (opal_atomic_trylock(lock)) { ; }
|
2005-01-28 00:08:35 +03:00
|
|
|
if (atomic_verbose) { printf("id %03d has the lock (trylock)\n", id); }
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(lock);
|
2005-01-28 00:08:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-18 23:33:23 +04:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ret = 77;
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_lock_t lock;
|
2005-04-18 23:33:23 +04:00
|
|
|
int num_threads = 1;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("*** Incorrect number of arguments. Skipping test\n");
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
num_threads = atoi(argv[1]);
|
|
|
|
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_init(&lock, OPAL_ATOMIC_UNLOCKED);
|
2005-04-18 23:33:23 +04:00
|
|
|
ret = atomic_spinlock_test_th(&lock, TEST_REPS, 0, num_threads);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|