Skip to content

Commit 6308978

Browse files
shintaro-iwasakihppritcha
authored andcommitted
qthreads module
some argobots cleanup Signed-off-by: Howard Pritchard <[email protected]>
1 parent 6af3f71 commit 6308978

38 files changed

+915
-433
lines changed

opal/mca/threads/argobots/threads_argobots.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
* $HEADER$
2424
*/
2525

26-
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H
27-
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H 1
26+
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H
27+
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H
2828

2929
#include <abt.h>
3030

31-
static inline void ensure_init_argobots(void) {
32-
if (ABT_initialized() != 0)
33-
ABT_init(0, 0);
31+
static inline void opal_threads_argobots_ensure_init(void)
32+
{
33+
if (ABT_initialized() != 0) {
34+
ABT_init(0, 0);
35+
}
3436
}
3537

3638
#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H */

opal/mca/threads/argobots/threads_argobots_component.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int opal_threads_argobots_open(void);
3333

3434
const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = {
3535
/* First, the mca_component_t struct containing meta information
36-
about the component itself */
36+
* about the component itself */
3737
.threadsc_version = {
3838
OPAL_THREADS_BASE_VERSION_1_0_0,
3939

@@ -52,6 +52,6 @@ const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = {
5252

5353
int opal_threads_argobots_open(void)
5454
{
55-
ensure_init_argobots();
55+
opal_threads_argobots_ensure_init();
5656
return OPAL_SUCCESS;
5757
}

opal/mca/threads/argobots/threads_argobots_condition.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
34
* University Research and Technology
@@ -22,14 +23,12 @@
2223

2324
#include "opal/mca/threads/condition.h"
2425

25-
2626
static void opal_condition_construct(opal_condition_t *c)
2727
{
2828
c->c_waiting = 0;
2929
c->c_signaled = 0;
3030
}
3131

32-
3332
static void opal_condition_destruct(opal_condition_t *c)
3433
{
3534
}

opal/mca/threads/argobots/threads_argobots_event.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
#include <abt.h>
1919

20-
static void *
21-
evthread_argobots_lock_alloc(unsigned locktype)
20+
static void *evthread_argobots_lock_alloc(unsigned locktype)
2221
{
2322
ABT_mutex lock;
2423
if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) {
@@ -33,15 +32,13 @@ evthread_argobots_lock_alloc(unsigned locktype)
3332
return lock;
3433
}
3534

36-
static void
37-
evthread_argobots_lock_free(void *_lock, unsigned locktype)
35+
static void evthread_argobots_lock_free(void *_lock, unsigned locktype)
3836
{
3937
ABT_mutex lock = _lock;
4038
ABT_mutex_free(&lock);
4139
}
4240

43-
static int
44-
evthread_argobots_lock(unsigned mode, void *_lock)
41+
static int evthread_argobots_lock(unsigned mode, void *_lock)
4542
{
4643
int ret;
4744
ABT_mutex lock = _lock;
@@ -53,8 +50,7 @@ evthread_argobots_lock(unsigned mode, void *_lock)
5350
return ret;
5451
}
5552

56-
static int
57-
evthread_argobots_unlock(unsigned mode, void *_lock)
53+
static int evthread_argobots_unlock(unsigned mode, void *_lock)
5854
{
5955
ABT_mutex lock = _lock;
6056
int ret = ABT_mutex_unlock(lock);
@@ -63,43 +59,40 @@ evthread_argobots_unlock(unsigned mode, void *_lock)
6359
return ret;
6460
}
6561

66-
static unsigned long
67-
evthread_argobots_get_id(void)
62+
static unsigned long evthread_argobots_get_id(void)
6863
{
6964
ABT_thread thr;
7065
ABT_thread_self(&thr);
7166
return (unsigned long)((intptr_t)thr);
7267
}
7368

74-
static void *
75-
evthread_argobots_cond_alloc(unsigned condflags)
69+
static void *evthread_argobots_cond_alloc(unsigned condflags)
7670
{
7771
ABT_cond cond;
7872
ABT_cond_create(&cond);
7973
return cond;
8074
}
8175

82-
static void
83-
evthread_argobots_cond_free(void *_cond)
76+
static void evthread_argobots_cond_free(void *_cond)
8477
{
8578
ABT_cond cond = _cond;
8679
ABT_cond_free(&cond);
8780
}
8881

89-
static int
90-
evthread_argobots_cond_signal(void *_cond, int broadcast)
82+
static int evthread_argobots_cond_signal(void *_cond, int broadcast)
9183
{
9284
ABT_cond cond = _cond;
9385
int r;
94-
if (broadcast)
86+
if (broadcast) {
9587
r = ABT_cond_broadcast(cond);
96-
else
88+
} else {
9789
r = ABT_cond_signal(cond);
90+
}
9891
return r ? -1 : 0;
9992
}
10093

101-
static int
102-
evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv)
94+
static int evthread_argobots_cond_wait(void *_cond, void *_lock,
95+
const struct timeval *tv)
10396
{
10497
int r;
10598
ABT_cond cond = _cond;
@@ -111,19 +104,21 @@ evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv)
111104
evutil_gettimeofday(&now, NULL);
112105
evutil_timeradd(&now, tv, &abstime);
113106
ts.tv_sec = abstime.tv_sec;
114-
ts.tv_nsec = abstime.tv_usec*1000;
107+
ts.tv_nsec = abstime.tv_usec * 1000;
115108
r = ABT_cond_timedwait(cond, lock, &ts);
116-
if (r != 0)
109+
if (r != 0) {
117110
return 1;
118-
else
111+
} else {
119112
return 0;
113+
}
120114
} else {
121115
r = ABT_cond_wait(cond, lock);
122116
return r ? -1 : 0;
123117
}
124118
}
125119

126-
void opal_event_use_threads(void) {
120+
void opal_event_use_threads(void)
121+
{
127122
struct evthread_lock_callbacks cbs = {
128123
EVTHREAD_LOCK_API_VERSION,
129124
EVTHREAD_LOCKTYPE_RECURSIVE,
@@ -139,7 +134,7 @@ void opal_event_use_threads(void) {
139134
evthread_argobots_cond_signal,
140135
evthread_argobots_cond_wait
141136
};
142-
ensure_init_argobots();
137+
opal_threads_argobots_ensure_init();
143138
evthread_set_lock_callbacks(&cbs);
144139
evthread_set_condition_callbacks(&cond_cbs);
145140
evthread_set_id_callback(evthread_argobots_get_id);

opal/mca/threads/argobots/threads_argobots_module.c

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
34
* University Research and Technology
@@ -17,6 +18,7 @@
1718
*
1819
* $HEADER$
1920
*/
21+
2022
#include <unistd.h>
2123

2224
#include "opal/mca/threads/argobots/threads_argobots.h"
@@ -51,47 +53,53 @@ OBJ_CLASS_INSTANCE(opal_thread_t,
5153
opal_object_t,
5254
opal_thread_construct, NULL);
5355

54-
static inline ABT_thread opal_thread_get_argobots_self(void) {
56+
static inline ABT_thread opal_thread_get_argobots_self(void)
57+
{
5558
ABT_thread self;
5659
ABT_thread_self(&self);
5760
return self;
5861
}
5962

60-
static void opal_thread_argobots_wrapper(void *arg) {
61-
opal_thread_t *t = (opal_thread_t *) arg;
62-
t->t_ret = ((void*(*)(void*)) t->t_run)(t);
63+
static void opal_thread_argobots_wrapper(void *arg)
64+
{
65+
opal_thread_t *t = (opal_thread_t *)arg;
66+
t->t_ret = ((void *(*)(void *))t->t_run)(t);
6367
}
6468

6569
opal_thread_t *opal_thread_get_self(void)
6670
{
67-
ensure_init_argobots();
71+
opal_threads_argobots_ensure_init();
6872
opal_thread_t *t = OBJ_NEW(opal_thread_t);
6973
t->t_handle = opal_thread_get_argobots_self();
7074
return t;
7175
}
7276

7377
bool opal_thread_self_compare(opal_thread_t *t)
7478
{
75-
ensure_init_argobots();
76-
return t->t_handle == opal_thread_get_argobots_self();
79+
opal_threads_argobots_ensure_init();
80+
return opal_thread_get_argobots_self() == t->t_handle;
7781
}
7882

79-
int opal_thread_join(opal_thread_t *t, void **thr_return) {
80-
ensure_init_argobots();
83+
int opal_thread_join(opal_thread_t *t, void **thr_return)
84+
{
85+
opal_threads_argobots_ensure_init();
8186
int rc = ABT_thread_free(&t->t_handle);
82-
if (thr_return)
87+
if (thr_return) {
8388
*thr_return = t->t_ret;
89+
}
8490
t->t_handle = ABT_THREAD_NULL;
85-
return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR;
91+
return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR;
8692
}
8793

88-
void opal_thread_set_main() {
89-
ensure_init_argobots();
94+
void opal_thread_set_main()
95+
{
96+
opal_threads_argobots_ensure_init();
9097
opal_main_thread = opal_thread_get_argobots_self();
9198
}
9299

93-
int opal_thread_start(opal_thread_t *t) {
94-
ensure_init_argobots();
100+
int opal_thread_start(opal_thread_t *t)
101+
{
102+
opal_threads_argobots_ensure_init();
95103
int rc;
96104
if (OPAL_ENABLE_DEBUG) {
97105
if (NULL == t->t_run || t->t_handle != ABT_THREAD_NULL) {
@@ -105,32 +113,35 @@ int opal_thread_start(opal_thread_t *t) {
105113
opal_thread_argobots_wrapper, t,
106114
ABT_THREAD_ATTR_NULL, &t->t_handle);
107115

108-
return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR;
116+
return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR;
109117
}
110118

111119
opal_class_t opal_thread_t_class;
112120

113121
int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
114122
{
115-
ensure_init_argobots();
123+
opal_threads_argobots_ensure_init();
116124
int rc;
117125
rc = ABT_key_create(destructor, key);
118126
if ((0 == rc) && (opal_thread_get_argobots_self() == opal_main_thread)) {
119-
opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value));
127+
opal_tsd_key_values = (struct opal_tsd_key_value *)
128+
realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) *
129+
sizeof(struct opal_tsd_key_value));
120130
opal_tsd_key_values[opal_tsd_key_values_count].key = *key;
121131
opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor;
122-
opal_tsd_key_values_count ++;
132+
opal_tsd_key_values_count++;
123133
}
124134
return rc;
125135
}
126136

127137
int opal_tsd_keys_destruct(void)
128138
{
129-
ensure_init_argobots();
139+
opal_threads_argobots_ensure_init();
130140
int i;
131-
void * ptr;
132-
for (i=0; i<opal_tsd_key_values_count; i++) {
133-
if(OPAL_SUCCESS == opal_tsd_getspecific(opal_tsd_key_values[i].key, &ptr)) {
141+
void *ptr;
142+
for (i = 0; i < opal_tsd_key_values_count; i++) {
143+
if (OPAL_SUCCESS ==
144+
opal_tsd_getspecific(opal_tsd_key_values[i].key, &ptr)) {
134145
if (NULL != opal_tsd_key_values[i].destructor) {
135146
opal_tsd_key_values[i].destructor(ptr);
136147
opal_tsd_setspecific(opal_tsd_key_values[i].key, NULL);

opal/mca/threads/argobots/threads_argobots_mutex.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
*/
3838
bool opal_uses_threads = false;
3939

40-
static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) {
41-
ensure_init_argobots();
40+
static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex)
41+
{
42+
opal_threads_argobots_ensure_init();
4243
p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL;
4344
p_mutex->m_recursive = 0;
4445
#if OPAL_ENABLE_DEBUG
@@ -49,15 +50,18 @@ static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) {
4950
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
5051
}
5152

52-
static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) {
53-
ensure_init_argobots();
54-
if (OPAL_ABT_MUTX_NULL != p_mutex->m_lock_argobots)
53+
static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex)
54+
{
55+
opal_threads_argobots_ensure_init();
56+
if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) {
5557
ABT_mutex_free(&p_mutex->m_lock_argobots);
58+
}
5659
}
5760

5861
static void mca_threads_argobots_recursive_mutex_constructor
59-
(opal_recursive_mutex_t *p_mutex) {
60-
ensure_init_argobots();
62+
(opal_recursive_mutex_t *p_mutex)
63+
{
64+
opal_threads_argobots_ensure_init();
6165
p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL;
6266
p_mutex->m_recursive = 1;
6367
#if OPAL_ENABLE_DEBUG
@@ -69,10 +73,12 @@ static void mca_threads_argobots_recursive_mutex_constructor
6973
}
7074

7175
static void mca_threads_argobots_recursive_mutex_desctructor
72-
(opal_recursive_mutex_t *p_mutex) {
73-
ensure_init_argobots();
74-
if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots)
76+
(opal_recursive_mutex_t *p_mutex)
77+
{
78+
opal_threads_argobots_ensure_init();
79+
if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) {
7580
ABT_mutex_free(&p_mutex->m_lock_argobots);
81+
}
7682
}
7783

7884
OBJ_CLASS_INSTANCE(opal_mutex_t,

0 commit comments

Comments
 (0)