Skip to content

Commit

Permalink
Add new envirable KMP_TEAMS_THREAD_LIMIT
Browse files Browse the repository at this point in the history
This change adds a new environment variable, KMP_TEAMS_THREAD_LIMIT, which is
used to set a new global variable, __kmp_teams_max_nth, which is checked when
determining the size and quantity of teams that will be created in the teams
construct. Specifically, it is a limit on the total number of threads in a given
teams construct. It differentiates the limits for the teams construct from the
limits for regular parallel regions (KMP_DEVICE_THREAD_LIMIT/__kmp_max_nth and
OMP_THREAD_LIMIT/__kmp_cg_max_nth). When each individual team is formed, it is
still subject to those limits. After the clauses to the teams construct are
parsed and calculated, we check to make sure we are within this limit, and if
not, reduce num_threads per team and/or number of teams, accordingly. The
default value is set to the number of available processors on the system.

Patch by Terry Wilmarth

Differential Revision: https://reviews.llvm.org/D36009

llvm-svn: 309874
  • Loading branch information
jpeyton52 committed Aug 2, 2017
1 parent 0d7ac5f commit 4f90c82
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions openmp/runtime/src/i18n/en_US.txt
Expand Up @@ -38,7 +38,7 @@ Language "English"
Country "USA"
LangId "1033"
Version "2"
Revision "20161216"
Revision "20170327"



Expand Down Expand Up @@ -433,7 +433,7 @@ SubmitBugReport "Please submit a bug report with this message, comp
OBSOLETE "Check NLSPATH environment variable, its value is \"%1$s\"."
ChangeStackLimit "Please try changing the shell stack limit or adjusting the "
"OMP_STACKSIZE environment variable."
Unset_ALL_THREADS "Consider unsetting KMP_DEVICE_THREAD_LIMIT (KMP_ALL_THREADS) and OMP_THREAD_LIMIT (if either is set)."
Unset_ALL_THREADS "Consider unsetting KMP_DEVICE_THREAD_LIMIT (KMP_ALL_THREADS), KMP_TEAMS_THREAD_LIMIT, and OMP_THREAD_LIMIT (if any are set)."
Set_ALL_THREADPRIVATE "Consider setting KMP_ALL_THREADPRIVATE to a value larger than %1$d."
PossibleSystemLimitOnThreads "This could also be due to a system-related limit on the number of threads."
DuplicateLibrary "This means that multiple copies of the OpenMP runtime have been "
Expand Down
1 change: 1 addition & 0 deletions openmp/runtime/src/kmp.h
Expand Up @@ -2868,6 +2868,7 @@ extern int __kmp_sys_max_nth; /* system-imposed maximum number of threads */
extern int __kmp_max_nth;
// maximum total number of concurrently-existing threads in a contention group
extern int __kmp_cg_max_nth;
extern int __kmp_teams_max_nth; // max threads used in a teams construct
extern int __kmp_threads_capacity; /* capacity of the arrays __kmp_threads and
__kmp_root */
extern int __kmp_dflt_team_nth; /* default number of threads in a parallel
Expand Down
1 change: 1 addition & 0 deletions openmp/runtime/src/kmp_global.cpp
Expand Up @@ -136,6 +136,7 @@ size_t __kmp_sys_min_stksize = KMP_MIN_STKSIZE;
int __kmp_sys_max_nth = KMP_MAX_NTH;
int __kmp_max_nth = 0;
int __kmp_cg_max_nth = 0;
int __kmp_teams_max_nth = 0;
int __kmp_threads_capacity = 0;
int __kmp_dflt_team_nth = 0;
int __kmp_dflt_team_nth_ub = 0;
Expand Down
20 changes: 12 additions & 8 deletions openmp/runtime/src/kmp_runtime.cpp
Expand Up @@ -6413,6 +6413,10 @@ static void __kmp_do_serial_initialize(void) {
}
__kmp_max_nth = __kmp_sys_max_nth;
__kmp_cg_max_nth = __kmp_sys_max_nth;
__kmp_teams_max_nth = __kmp_xproc; // set a "reasonable" default
if (__kmp_teams_max_nth > __kmp_sys_max_nth) {
__kmp_teams_max_nth = __kmp_sys_max_nth;
}

// Three vars below moved here from __kmp_env_initialize() "KMP_BLOCKTIME"
// part
Expand Down Expand Up @@ -6989,14 +6993,14 @@ void __kmp_push_num_teams(ident_t *id, int gtid, int num_teams,

if (num_teams == 0)
num_teams = 1; // default number of teams is 1.
if (num_teams > __kmp_max_nth) { // if too many teams requested?
if (num_teams > __kmp_teams_max_nth) { // if too many teams requested?
if (!__kmp_reserve_warn) {
__kmp_reserve_warn = 1;
__kmp_msg(kmp_ms_warning,
KMP_MSG(CantFormThrTeam, num_teams, __kmp_max_nth),
KMP_MSG(CantFormThrTeam, num_teams, __kmp_teams_max_nth),
KMP_HNT(Unset_ALL_THREADS), __kmp_msg_null);
}
num_teams = __kmp_max_nth;
num_teams = __kmp_teams_max_nth;
}
// Set number of teams (number of threads in the outer "parallel" of the
// teams)
Expand All @@ -7007,15 +7011,15 @@ void __kmp_push_num_teams(ident_t *id, int gtid, int num_teams,
if (!TCR_4(__kmp_init_middle))
__kmp_middle_initialize(); // get __kmp_avail_proc calculated
num_threads = __kmp_avail_proc / num_teams;
if (num_teams * num_threads > __kmp_max_nth) {
if (num_teams * num_threads > __kmp_teams_max_nth) {
// adjust num_threads w/o warning as it is not user setting
num_threads = __kmp_max_nth / num_teams;
num_threads = __kmp_teams_max_nth / num_teams;
}
} else {
if (num_teams * num_threads > __kmp_max_nth) {
int new_threads = __kmp_max_nth / num_teams;
if (num_teams * num_threads > __kmp_teams_max_nth) {
int new_threads = __kmp_teams_max_nth / num_teams;
if (!__kmp_reserve_warn) { // user asked for too many threads
__kmp_reserve_warn = 1; // that conflicts with KMP_DEVICE_THREAD_LIMIT
__kmp_reserve_warn = 1; // that conflicts with KMP_TEAMS_THREAD_LIMIT
__kmp_msg(kmp_ms_warning,
KMP_MSG(CantFormThrTeam, num_threads, new_threads),
KMP_HNT(Unset_ALL_THREADS), __kmp_msg_null);
Expand Down
14 changes: 14 additions & 0 deletions openmp/runtime/src/kmp_settings.cpp
Expand Up @@ -612,6 +612,18 @@ static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
__kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
} // __kmp_stg_print_thread_limit

// -----------------------------------------------------------------------------
// KMP_TEAMS_THREAD_LIMIT
static void __kmp_stg_parse_teams_thread_limit(char const *name,
char const *value, void *data) {
__kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
} // __kmp_stg_teams_thread_limit

static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
char const *name, void *data) {
__kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
} // __kmp_stg_print_teams_thread_limit

// -----------------------------------------------------------------------------
// KMP_BLOCKTIME

Expand Down Expand Up @@ -4402,6 +4414,8 @@ static kmp_setting_t __kmp_stg_table[] = {
#endif
{"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
__kmp_stg_print_thread_limit, NULL, 0, 0},
{"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
__kmp_stg_print_teams_thread_limit, NULL, 0, 0},
{"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
__kmp_stg_print_wait_policy, NULL, 0, 0},
{"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
Expand Down

0 comments on commit 4f90c82

Please sign in to comment.