opal/sync: remove usage of OPAL_ENABLE_MULTI_THREADS
The OPAL_ENABLE_MULTI_THREADS macro is always defined as 1. This was causing us to always use the multi-thread path for synchronization objects. The code has been updated to use the opal_using_threads() function. When MPI_THREAD_MULTIPLE support is disabled at build time (2.x only) this function is a macro evaluating to false so the compiler will optimize out the MT-path in this case. The OPAL_ATOMIC_ADD_32 macro has been removed and replaced by the existing OPAL_THREAD_ADD32 macro. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
Этот коммит содержится в:
родитель
679a66ccc8
Коммит
143a93f379
@ -416,8 +416,8 @@ static inline int ompi_request_complete(ompi_request_t* request, bool with_signa
|
||||
|
||||
if( OPAL_LIKELY(with_signal) ) {
|
||||
if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) {
|
||||
ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWP_PTR(&request->req_complete,
|
||||
REQUEST_COMPLETED);
|
||||
ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWAP_PTR(&request->req_complete,
|
||||
REQUEST_COMPLETED);
|
||||
/* In the case where another thread concurrently changed the request to REQUEST_PENDING */
|
||||
if( REQUEST_PENDING != tmp_sync )
|
||||
wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR);
|
||||
|
@ -324,6 +324,20 @@ OPAL_THREAD_ADD_SIZE_T(volatile size_t *addr, int delta)
|
||||
#endif
|
||||
|
||||
|
||||
static inline void *opal_thread_swap_ptr (volatile void *ptr, void *newvalue)
|
||||
{
|
||||
if (opal_using_threads ()) {
|
||||
return opal_atomic_swap_ptr (ptr, newvalue);
|
||||
}
|
||||
|
||||
void *old = ((void **) ptr)[0];
|
||||
((void **) ptr)[0] = newvalue;
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
#define OPAL_ATOMIC_SWAP_PTR(x, y) opal_thread_swap_ptr (x, y)
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* OPAL_MUTEX_H */
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Copyright (c) 2014-2016 The University of Tennessee and The University
|
||||
* of Tennessee Research Foundation. All rights
|
||||
* reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -21,15 +23,6 @@ static ompi_wait_sync_t* wait_sync_list = NULL;
|
||||
pthread_mutex_unlock( &(who)->lock); \
|
||||
} while(0)
|
||||
|
||||
|
||||
int sync_wait_st(ompi_wait_sync_t *sync)
|
||||
{
|
||||
while(sync->count > 0) {
|
||||
opal_progress();
|
||||
}
|
||||
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
|
||||
}
|
||||
|
||||
int sync_wait_mt(ompi_wait_sync_t *sync)
|
||||
{
|
||||
if(sync->count <= 0)
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Copyright (c) 2014-2016 The University of Tennessee and The University
|
||||
* of Tennessee Research Foundation. All rights
|
||||
* reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -27,50 +29,44 @@ typedef struct ompi_wait_sync_t {
|
||||
#define REQUEST_PENDING (void*)0L
|
||||
#define REQUEST_COMPLETED (void*)1L
|
||||
|
||||
#if OPAL_ENABLE_MULTI_THREADS
|
||||
|
||||
#define OPAL_ATOMIC_ADD_32(a,b) opal_atomic_add_32(a,b)
|
||||
#define OPAL_ATOMIC_SWP_PTR(a,b) opal_atomic_swap_ptr(a,b)
|
||||
#define SYNC_WAIT(sync) sync_wait_mt(sync)
|
||||
#define PTHREAD_COND_INIT(a,b) pthread_cond_init(a,b)
|
||||
#define PTHREAD_MUTEX_INIT(a,b) pthread_mutex_init(a,b)
|
||||
#define SYNC_WAIT(sync) (opal_using_threads() ? sync_wait_mt (sync) : sync_wait_st (sync))
|
||||
#define PTHREAD_COND_INIT(a,b) (opal_using_threads() ? pthread_cond_init (a,b) : 0)
|
||||
#define PTHREAD_MUTEX_INIT(a,b) (opal_using_threads() ? pthread_mutex_init (a,b) : 0)
|
||||
|
||||
#define WAIT_SYNC_RELEASE(sync) \
|
||||
do { \
|
||||
if (opal_using_threads()) { \
|
||||
pthread_cond_destroy(&(sync)->condition); \
|
||||
pthread_mutex_destroy(&(sync)->lock); \
|
||||
} while(0)
|
||||
}
|
||||
|
||||
#define WAIT_SYNC_SIGNAL(sync) \
|
||||
do { \
|
||||
if (opal_using_threads()) { \
|
||||
pthread_mutex_lock(&(sync->lock)); \
|
||||
pthread_cond_signal(&sync->condition); \
|
||||
pthread_mutex_unlock(&(sync->lock)); \
|
||||
} while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define OPAL_ATOMIC_ADD_32(a,b) (*(a) += (b))
|
||||
#define OPAL_ATOMIC_SWP_PTR(a,b) *(a) = (b)
|
||||
#define PTHREAD_COND_INIT(a,b)
|
||||
#define PTHREAD_MUTEX_INIT(a,b)
|
||||
#define SYNC_WAIT(sync) sync_wait_st(sync)
|
||||
#define WAIT_SYNC_RELEASE(sync)
|
||||
#define WAIT_SYNC_SIGNAL(sync)
|
||||
|
||||
#endif /* OPAL_ENABLE_MULTI_THREADS */
|
||||
}
|
||||
|
||||
OPAL_DECLSPEC int sync_wait_mt(ompi_wait_sync_t *sync);
|
||||
OPAL_DECLSPEC int sync_wait_st(ompi_wait_sync_t *sync);
|
||||
static inline int sync_wait_st (ompi_wait_sync_t *sync)
|
||||
{
|
||||
while (sync->count > 0) {
|
||||
opal_progress();
|
||||
}
|
||||
|
||||
#define WAIT_SYNC_INIT(sync,c) \
|
||||
do { \
|
||||
(sync)->count = c; \
|
||||
(sync)->next = NULL; \
|
||||
(sync)->prev = NULL; \
|
||||
(sync)->status = 0; \
|
||||
PTHREAD_COND_INIT(&(sync)->condition, NULL); \
|
||||
PTHREAD_MUTEX_INIT(&(sync)->lock, NULL); \
|
||||
return sync->status;
|
||||
}
|
||||
|
||||
|
||||
#define WAIT_SYNC_INIT(sync,c) \
|
||||
do { \
|
||||
(sync)->count = c; \
|
||||
(sync)->next = NULL; \
|
||||
(sync)->prev = NULL; \
|
||||
(sync)->status = 0; \
|
||||
if (opal_using_threads()) { \
|
||||
PTHREAD_COND_INIT(&(sync)->condition, NULL); \
|
||||
PTHREAD_MUTEX_INIT(&(sync)->lock, NULL); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
@ -82,12 +78,13 @@ OPAL_DECLSPEC int sync_wait_st(ompi_wait_sync_t *sync);
|
||||
static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status)
|
||||
{
|
||||
if( OPAL_LIKELY(OPAL_SUCCESS == status) ) {
|
||||
if( 0 != (OPAL_ATOMIC_ADD_32(&sync->count, -updates)) ) {
|
||||
if( 0 != (OPAL_THREAD_ADD32(&sync->count, -updates)) ) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
OPAL_ATOMIC_CMPSET_32(&(sync->count), 0, 0);
|
||||
sync->status = -1;
|
||||
/* this is an error path so just use the atomic */
|
||||
opal_atomic_swap_32 (&sync->count, 0);
|
||||
sync->status = OPAL_ERROR;
|
||||
}
|
||||
WAIT_SYNC_SIGNAL(sync);
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user