Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MCA param for multithread opal_progress(). #5241

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions opal/runtime/opal_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ bool opal_leave_pinned_pipeline = false;
bool opal_abort_print_stack = false;
int opal_abort_delay = 0;

int opal_max_thread_in_progress = 1;

static bool opal_register_done = false;

int opal_register_params(void)
Expand Down Expand Up @@ -360,6 +362,12 @@ int opal_register_params(void)
MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, OPAL_INFO_LVL_3,
MCA_BASE_VAR_SCOPE_READONLY, &mca_base_env_list_internal);

/* Number of threads allowed in opal_progress. This might increase multithreaded performance. */
(void)mca_base_var_register ("opal", "opal", NULL, "max_thread_in_progress",
"Number of thread allowed in opal_progress. Default: 1",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_8,
MCA_BASE_VAR_SCOPE_READONLY, &opal_max_thread_in_progress);

/* The ddt engine has a few parameters */
ret = opal_datatype_register_params();
if (OPAL_SUCCESS != ret) {
Expand Down
9 changes: 7 additions & 2 deletions opal/threads/wait_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT;
static ompi_wait_sync_t* wait_sync_list = NULL;

static opal_atomic_int32_t num_thread_in_progress = 0;

#define WAIT_SYNC_PASS_OWNERSHIP(who) \
do { \
pthread_mutex_lock( &(who)->lock); \
Expand Down Expand Up @@ -63,7 +65,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
* - our sync has been triggered.
*/
check_status:
if( sync != wait_sync_list ) {
if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) {
pthread_cond_wait(&sync->condition, &sync->lock);

/**
Expand All @@ -79,11 +81,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
/* either promoted, or spurious wakeup ! */
goto check_status;
}

pthread_mutex_unlock(&sync->lock);

OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1);
while(sync->count > 0) { /* progress till completion */
opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */
}
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1);

assert(sync == wait_sync_list);

i_am_done:
Expand Down
2 changes: 2 additions & 0 deletions opal/threads/wait_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

BEGIN_C_DECLS

extern int opal_max_thread_in_progress;

typedef struct ompi_wait_sync_t {
opal_atomic_int32_t count;
int32_t status;
Expand Down