2008-03-06 17:55:32 +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.
|
|
|
|
* 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 (c) 2008 Cisco Systems, Inc. All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2005-08-21 23:21:09 +04:00
|
|
|
|
2004-03-03 19:44:41 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2005-08-21 23:21:09 +04:00
|
|
|
|
2004-03-03 19:44:41 +03:00
|
|
|
#include "support.h"
|
2007-06-05 23:24:17 +04:00
|
|
|
#include "opal/runtime/opal.h"
|
2006-02-12 22:51:24 +03:00
|
|
|
#include "opal/constants.h"
|
2005-08-15 15:02:01 +04:00
|
|
|
#include "opal/threads/threads.h"
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/condition.h"
|
2006-02-12 22:51:24 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2004-03-03 19:44:41 +03:00
|
|
|
|
|
|
|
|
2009-05-07 00:11:28 +04:00
|
|
|
#if !OPAL_HAVE_THREAD_SUPPORT
|
2005-03-27 15:55:03 +04:00
|
|
|
|
|
|
|
/* If we don't have thread support, there's no point in running this
|
|
|
|
test */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
printf("OMPI was compiled without thread support -- skipping this test\n");
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Only have the body of this test if we have thread support */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_t mutex;
|
|
|
|
opal_condition_t thr1_cond;
|
|
|
|
opal_condition_t thr2_cond;
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-03-27 15:55:03 +04:00
|
|
|
static volatile int thr1_count = 0;
|
|
|
|
static volatile int thr2_count = 0;
|
2004-03-03 19:44:41 +03:00
|
|
|
|
|
|
|
|
2007-06-05 23:24:17 +04:00
|
|
|
#define TEST_COUNT 100000
|
2004-03-03 19:44:41 +03:00
|
|
|
|
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
static void* thr1_run(opal_object_t* obj)
|
2004-03-03 19:44:41 +03:00
|
|
|
{
|
|
|
|
int i;
|
2004-05-25 01:45:00 +04:00
|
|
|
clock_t c1, c2;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_lock(&mutex);
|
2004-05-25 01:45:00 +04:00
|
|
|
c1 = clock();
|
2004-03-03 19:44:41 +03:00
|
|
|
for(i=0; i<TEST_COUNT; i++) {
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_wait(&thr1_cond, &mutex);
|
|
|
|
opal_condition_signal(&thr2_cond);
|
2004-03-03 19:44:41 +03:00
|
|
|
thr1_count++;
|
|
|
|
}
|
2004-05-25 01:45:00 +04:00
|
|
|
c2 = clock();
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_unlock(&mutex);
|
2004-03-03 19:44:41 +03:00
|
|
|
fprintf(stderr, "thr1: time per iteration: %ld usec\n", (c2 - c1) / TEST_COUNT);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
static void* thr2_run(opal_object_t* obj)
|
2004-03-03 19:44:41 +03:00
|
|
|
{
|
|
|
|
int i;
|
2004-05-25 01:45:00 +04:00
|
|
|
clock_t c1, c2;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_lock(&mutex);
|
2004-05-25 01:45:00 +04:00
|
|
|
c1 = clock();
|
2004-03-03 19:44:41 +03:00
|
|
|
for(i=0; i<TEST_COUNT; i++) {
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_condition_signal(&thr1_cond);
|
|
|
|
opal_condition_wait(&thr2_cond, &mutex);
|
2004-03-03 19:44:41 +03:00
|
|
|
thr2_count++;
|
|
|
|
}
|
2004-05-25 01:45:00 +04:00
|
|
|
c2 = clock();
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_unlock(&mutex);
|
2004-03-03 19:44:41 +03:00
|
|
|
fprintf(stderr, "thr2: time per iteration: %ld usec\n", (c2 - c1) / TEST_COUNT);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
int rc;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_thread_t* thr1;
|
|
|
|
opal_thread_t* thr2;
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
test_init("opal_condition_t");
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2009-12-07 17:40:38 +03:00
|
|
|
rc = opal_init(&argc, &argv);
|
2008-03-06 17:55:32 +03:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
|
|
|
if (OPAL_SUCCESS != rc) {
|
|
|
|
test_finalize();
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-06-05 23:24:17 +04:00
|
|
|
opal_set_using_threads(true);
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OBJ_CONSTRUCT(&mutex, opal_mutex_t);
|
|
|
|
OBJ_CONSTRUCT(&thr1_cond, opal_condition_t);
|
|
|
|
OBJ_CONSTRUCT(&thr2_cond, opal_condition_t);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
thr1 = OBJ_NEW(opal_thread_t);
|
|
|
|
thr2 = OBJ_NEW(opal_thread_t);
|
2004-03-03 19:44:41 +03:00
|
|
|
thr1->t_run = thr1_run;
|
|
|
|
thr2->t_run = thr2_run;
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_start(thr1);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_start(thr2);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_join(thr1, NULL);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
test_verify_int(TEST_COUNT, thr1_count);
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_join(thr2, NULL);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
test_verify_int(TEST_COUNT, thr2_count);
|
|
|
|
|
2007-06-05 23:24:17 +04:00
|
|
|
opal_finalize();
|
|
|
|
|
2005-03-27 15:36:48 +04:00
|
|
|
return test_finalize();
|
2004-03-03 19:44:41 +03:00
|
|
|
}
|
|
|
|
|
2009-05-07 00:11:28 +04:00
|
|
|
#endif /* OPAL_HAVE_THREAD_SUPPORT */
|