Skip to content

Commit 252637b

Browse files
committed
address some feedback from PR reviews
Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent 00f789b commit 252637b

23 files changed

+293
-79
lines changed

opal/mca/threads/README

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
MCA THREADING FRAMEWORKS:
3+
-------------------------
4+
This MCA framework makes it possible to integrate new threading frameworks with the OpenMPI runtime.
5+
6+
BACKGROUND
7+
----------
8+
There has been a lot of interest in integrating alternative threading models, in particular lightweight threading models with MPI implementations. Open MPI's modular component architecture seems like an ideal architecture for this sort of integration (in fact it was, Open MPI used to support Solaris and Windows threads).
9+
10+
Recently there has been interest in integrating MPI with lightweight tasking layers, which led to work reviving and modernizing the old modular threading code but with an emphasis on integrating lightweight threading models.
11+
12+
SELECTING A THREADING MODEL
13+
---------------------------
14+
15+
The threading model is chosen via the configure option --with-threads=<threading_model>. This will choose a compile time threading model as well as compiling the relevant MCA.
16+
17+
IMPLEMENTATION
18+
--------------
19+
The MCA for threading libraries is implemented in two places, once as a set of .h files in mca/threads/<threading_model>/threads_<threading_model>_{threads,mutex,tsd}.h which are defined inline to the main thread implementation and also as an mca component that is loaded at runtime.
20+
21+
For performance reasons, in particular synchonization overhead, it is not possible to implement a threading model as a traditional MCA. This means --at least in the short term-- that threading models are chosen at compile time rather than runtime options, using mechanisms similar to OpenMPI's libevent integration.
22+
23+
The .h files are meant to be run on the fast path containing inline synchonization functions (threads_<threading_model>_mutex.h, thread local storage (threads_<threading_model>_tsd.h) and the opal_thread structure (threads_<threading_model>_thread.h).
24+
25+
The rest of the threading implementation follows the normal MCA model:
26+
27+
* threads_<threading_model>_component.c describes the version of the module and specifies the module open behavior (the threading model initialization goes here).
28+
29+
* threads_<threading_model>_condition.c defines an instance of opal_condition_t which is used by condition.h to define Open MPI specific condition variables.
30+
31+
* threads_<threading_model>_event.c defines an interface to Open MPI's libevent hooks. It allows the threading module to use threading model specific memory allocation and synchronization structures with Open MPI's libevent integration.
32+
33+
* threads_<threading_model>_module.c defines the interface to opal's thread handle. It provides ways of comparing threads, getting the value of a thread via its handle and the implementation of thread local storage.
34+
35+
* threads_<threading_model>_mutex.c provides a slow path interface to creating and destroying mutices dynamically via mca allocation. They can also be defined statically using the .h fast path interface.
36+
37+
* threads_<threading_model>_wait_sync.c provides condition variable like waiting capability that ensures MPI progress while it waits.
38+
39+
TODO
40+
----
41+
Libevent integration with lightweight threading models is a work in progress. The current Open MPI libevent library assumes preemption and does not yield by default. Lightweight threading libraries typically require tasks to be cooperative and to voluntarily yield after some time.
42+
43+
Open MPI itself needs to be altered to use a common yielding model instead of usleep(3).

opal/mca/threads/argobots/owner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# status: e.g. active, maintenance, unmaintained
55
#
66
owner: SNL
7-
status: unmaintained
7+
status: active

opal/mca/threads/argobots/threads_argobots.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
* University Research and Technology
5+
* Corporation. All rights reserved.
6+
* Copyright (c) 2004-2005 The University of Tennessee and The University
7+
* of Tennessee Research Foundation. All rights
8+
* reserved.
9+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
* University of Stuttgart. All rights reserved.
11+
* Copyright (c) 2004-2005 The Regents of the University of California.
12+
* All rights reserved.
13+
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
14+
* reserved.
15+
* Copyright (c) 2015 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
18+
*
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
125

226
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H
327
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H 1

opal/mca/threads/argobots/threads_argobots_event.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
4+
*
5+
* $COPYRIGHT$
6+
*
7+
* Additional copyrights may follow
8+
*
9+
* $HEADER$
10+
*/
111

212
#include "opal/mca/threads/threads.h"
313
#include "opal/mca/threads/argobots/threads_argobots.h"

opal/mca/threads/argobots/threads_argobots_module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12+
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
13+
*
1214
* $COPYRIGHT$
1315
*
1416
* Additional copyrights may follow
@@ -122,7 +124,7 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
122124
return rc;
123125
}
124126

125-
int opal_tsd_keys_destruct()
127+
int opal_tsd_keys_destruct(void)
126128
{
127129
ensure_init_argobots();
128130
int i;

opal/mca/threads/argobots/threads_argobots_mutex.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "opal_config.h"
2828

2929
#include <errno.h>
30-
#include <pthread.h>
3130

3231
#include "opal/mca/threads/mutex.h"
3332
#include "opal/mca/threads/argobots/threads_argobots_mutex.h"
@@ -52,7 +51,7 @@ static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) {
5251

5352
static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) {
5453
ensure_init_argobots();
55-
if (p_mutex->m_lock_argobots != OPAL_ABT_MUTEX_NULL)
54+
if (OPAL_ABT_MUTX_NULL != p_mutex->m_lock_argobots)
5655
ABT_mutex_free(&p_mutex->m_lock_argobots);
5756
}
5857

@@ -72,7 +71,7 @@ static void mca_threads_argobots_recursive_mutex_constructor
7271
static void mca_threads_argobots_recursive_mutex_desctructor
7372
(opal_recursive_mutex_t *p_mutex) {
7473
ensure_init_argobots();
75-
if (p_mutex->m_lock_argobots != OPAL_ABT_MUTEX_NULL)
74+
if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots)
7675
ABT_mutex_free(&p_mutex->m_lock_argobots);
7776
}
7877

opal/mca/threads/argobots/threads_argobots_mutex.h

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ struct opal_mutex_t {
6868
opal_atomic_lock_t m_lock_atomic;
6969
};
7070

71-
typedef struct opal_argobots_mutex_t opal_pthread_mutex_t;
72-
typedef struct opal_argobots_mutex_t opal_pthread_recursive_mutex_t;
71+
typedef struct opal_argobots_mutex_t int;
7372

7473
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
7574
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
@@ -95,29 +94,13 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
9594
}
9695
#endif
9796

98-
#if defined(OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
99-
100-
#if OPAL_ENABLE_DEBUG
10197
#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
10298
{ \
10399
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
104100
.m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
105101
.m_recursive = 1, \
106-
.m_lock_debug = 0, \
107-
.m_lock_file = NULL, \
108-
.m_lock_line = 0, \
109102
.m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
110103
}
111-
#else
112-
#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
113-
{ \
114-
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
115-
.m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
116-
.m_recursive = 1, \
117-
.m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
118-
}
119-
#endif
120-
121104
#endif
122105

123106
/************************************************************************
@@ -127,7 +110,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
127110
************************************************************************/
128111

129112
static inline void opal_mutex_create(struct opal_mutex_t *m) {
130-
while (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL) {
113+
while (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) {
131114
ABT_mutex abt_mutex;
132115
if (m->m_recursive) {
133116
ABT_mutex_attr abt_mutex_attr;
@@ -152,7 +135,7 @@ static inline void opal_mutex_create(struct opal_mutex_t *m) {
152135
static inline int opal_mutex_trylock(opal_mutex_t *m)
153136
{
154137
ensure_init_argobots();
155-
if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL)
138+
if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots)
156139
opal_mutex_create(m);
157140
#if OPAL_ENABLE_DEBUG
158141
int ret = ABT_mutex_trylock(m->m_lock_argobots);
@@ -170,7 +153,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m)
170153
static inline void opal_mutex_lock(opal_mutex_t *m)
171154
{
172155
ensure_init_argobots();
173-
if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL)
156+
if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots)
174157
opal_mutex_create(m);
175158
#if OPAL_ENABLE_DEBUG
176159
int ret = ABT_mutex_lock(m->m_lock_argobots);
@@ -187,7 +170,7 @@ static inline void opal_mutex_lock(opal_mutex_t *m)
187170
static inline void opal_mutex_unlock(opal_mutex_t *m)
188171
{
189172
ensure_init_argobots();
190-
if (m->m_lock_argobots == OPAL_ABT_MUTEX_NULL)
173+
if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots)
191174
opal_mutex_create(m);
192175
#if OPAL_ENABLE_DEBUG
193176
int ret = ABT_mutex_unlock(m->m_lock_argobots);
@@ -259,7 +242,7 @@ typedef ABT_cond opal_cond_t;
259242

260243
static inline void opal_cond_create(opal_cond_t *cond) {
261244
ensure_init_argobots();
262-
while (*cond == OPAL_ABT_COND_NULL) {
245+
while (OPAL_ABT_COND_NULL == *cond) {
263246
ABT_cond new_cond;
264247
ABT_cond_create(&new_cond);
265248
void *null_ptr = OPAL_ABT_COND_NULL;
@@ -280,28 +263,28 @@ static inline int opal_cond_init(opal_cond_t *cond) {
280263

281264
static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) {
282265
ensure_init_argobots();
283-
if (*cond == OPAL_ABT_COND_NULL)
266+
if (OPAL_ABT_COND_NULL == *cond)
284267
opal_cond_create(cond);
285268
return ABT_cond_wait(*cond, lock->m_lock_argobots);
286269
}
287270

288271
static inline int opal_cond_broadcast(opal_cond_t *cond) {
289272
ensure_init_argobots();
290-
if (*cond == OPAL_ABT_COND_NULL)
273+
if (OPAL_ABT_COND_NULL == *cond)
291274
opal_cond_create(cond);
292275
return ABT_cond_broadcast(*cond);
293276
}
294277

295278
static inline int opal_cond_signal(opal_cond_t *cond) {
296279
ensure_init_argobots();
297-
if (*cond == OPAL_ABT_COND_NULL)
280+
if (OPAL_ABT_COND_NULL == *cond)
298281
opal_cond_create(cond);
299282
return ABT_cond_signal(*cond);
300283
}
301284

302285
static inline int opal_cond_destroy(opal_cond_t *cond) {
303286
ensure_init_argobots();
304-
if (*cond != OPAL_ABT_COND_NULL)
287+
if (OPAL_ABT_COND_NULL != *cond)
305288
ABT_cond_free(cond);
306289
return 0;
307290
}

opal/mca/threads/argobots/threads_argobots_threads.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
* University Research and Technology
5+
* Corporation. All rights reserved.
6+
* Copyright (c) 2004-2005 The University of Tennessee and The University
7+
* of Tennessee Research Foundation. All rights
8+
* reserved.
9+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
* University of Stuttgart. All rights reserved.
11+
* Copyright (c) 2004-2005 The Regents of the University of California.
12+
* All rights reserved.
13+
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
14+
* reserved.
15+
* Copyright (c) 2015 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
18+
*
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
125

226
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H
327
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H 1

opal/mca/threads/argobots/threads_argobots_tsd.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
* University Research and Technology
5+
* Corporation. All rights reserved.
6+
* Copyright (c) 2004-2005 The University of Tennessee and The University
7+
* of Tennessee Research Foundation. All rights
8+
* reserved.
9+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
* University of Stuttgart. All rights reserved.
11+
* Copyright (c) 2004-2005 The Regents of the University of California.
12+
* All rights reserved.
13+
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
14+
* reserved.
15+
* Copyright (c) 2015 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
18+
*
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
25+
126

227
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H
328
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H 1

opal/mca/threads/argobots/threads_argobots_wait_sync.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
* University Research and Technology
5+
* Corporation. All rights reserved.
6+
* Copyright (c) 2004-2005 The University of Tennessee and The University
7+
* of Tennessee Research Foundation. All rights
8+
* reserved.
9+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
* University of Stuttgart. All rights reserved.
11+
* Copyright (c) 2004-2005 The Regents of the University of California.
12+
* All rights reserved.
13+
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
14+
* reserved.
15+
* Copyright (c) 2015 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
18+
*
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
25+
126

227
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H
328
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H 1

0 commit comments

Comments
 (0)