Skip to content

Commit 3dc1629

Browse files
author
Thananon Patinyasakdikul
authored
Merge pull request #5241 from thananon/opal_progress
Add MCA param for multithread opal_progress().
2 parents 30b6435 + 4e23fed commit 3dc1629

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

opal/runtime/opal_params.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ bool opal_leave_pinned_pipeline = false;
7676
bool opal_abort_print_stack = false;
7777
int opal_abort_delay = 0;
7878

79+
int opal_max_thread_in_progress = 1;
80+
7981
static bool opal_register_done = false;
8082

8183
int opal_register_params(void)
@@ -360,6 +362,12 @@ int opal_register_params(void)
360362
MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, OPAL_INFO_LVL_3,
361363
MCA_BASE_VAR_SCOPE_READONLY, &mca_base_env_list_internal);
362364

365+
/* Number of threads allowed in opal_progress. This might increase multithreaded performance. */
366+
(void)mca_base_var_register ("opal", "opal", NULL, "max_thread_in_progress",
367+
"Number of thread allowed in opal_progress. Default: 1",
368+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_8,
369+
MCA_BASE_VAR_SCOPE_READONLY, &opal_max_thread_in_progress);
370+
363371
/* The ddt engine has a few parameters */
364372
ret = opal_datatype_register_params();
365373
if (OPAL_SUCCESS != ret) {

opal/threads/wait_sync.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT;
1818
static ompi_wait_sync_t* wait_sync_list = NULL;
1919

20+
static opal_atomic_int32_t num_thread_in_progress = 0;
21+
2022
#define WAIT_SYNC_PASS_OWNERSHIP(who) \
2123
do { \
2224
pthread_mutex_lock( &(who)->lock); \
@@ -63,7 +65,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
6365
* - our sync has been triggered.
6466
*/
6567
check_status:
66-
if( sync != wait_sync_list ) {
68+
if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) {
6769
pthread_cond_wait(&sync->condition, &sync->lock);
6870

6971
/**
@@ -79,11 +81,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
7981
/* either promoted, or spurious wakeup ! */
8082
goto check_status;
8183
}
82-
8384
pthread_mutex_unlock(&sync->lock);
85+
86+
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1);
8487
while(sync->count > 0) { /* progress till completion */
8588
opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */
8689
}
90+
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1);
91+
8792
assert(sync == wait_sync_list);
8893

8994
i_am_done:

opal/threads/wait_sync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
BEGIN_C_DECLS
2727

28+
extern int opal_max_thread_in_progress;
29+
2830
typedef struct ompi_wait_sync_t {
2931
opal_atomic_int32_t count;
3032
int32_t status;

0 commit comments

Comments
 (0)