Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 3f4c51a

Browse files
committed
Force honoring nthreads-var and thread-limit-var inside teams construct on host
This patch fixes https://bugs.llvm.org/show_bug.cgi?id=42906, via adding adjustment of number of threads on enter to the teams construct on host according to user settings. This allows to pass checks and avoid assertions at time of team of threads creation. Patch by Andrey Churbanov Differential Revision: https://reviews.llvm.org/D66351 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@369430 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3eae253 commit 3f4c51a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

runtime/src/kmp_runtime.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7192,19 +7192,32 @@ void __kmp_push_num_teams(ident_t *id, int gtid, int num_teams,
71927192
thr->th.th_set_nproc = thr->th.th_teams_size.nteams = num_teams;
71937193

71947194
// Remember the number of threads for inner parallel regions
7195+
if (!TCR_4(__kmp_init_middle))
7196+
__kmp_middle_initialize(); // get internal globals calculated
7197+
KMP_DEBUG_ASSERT(__kmp_avail_proc);
7198+
KMP_DEBUG_ASSERT(__kmp_dflt_team_nth);
71957199
if (num_threads == 0) {
7196-
if (!TCR_4(__kmp_init_middle))
7197-
__kmp_middle_initialize(); // get __kmp_avail_proc calculated
71987200
num_threads = __kmp_avail_proc / num_teams;
7201+
// adjust num_threads w/o warning as it is not user setting
7202+
// num_threads = min(num_threads, nthreads-var, thread-limit-var)
7203+
// no thread_limit clause specified - do not change thread-limit-var ICV
7204+
if (num_threads > __kmp_dflt_team_nth) {
7205+
num_threads = __kmp_dflt_team_nth; // honor nthreads-var ICV
7206+
}
7207+
if (num_threads > thr->th.th_current_task->td_icvs.thread_limit) {
7208+
num_threads = thr->th.th_current_task->td_icvs.thread_limit;
7209+
} // prevent team size to exceed thread-limit-var
71997210
if (num_teams * num_threads > __kmp_teams_max_nth) {
7200-
// adjust num_threads w/o warning as it is not user setting
72017211
num_threads = __kmp_teams_max_nth / num_teams;
72027212
}
72037213
} else {
72047214
// This thread will be the master of the league masters
72057215
// Store new thread limit; old limit is saved in th_cg_roots list
72067216
thr->th.th_current_task->td_icvs.thread_limit = num_threads;
7207-
7217+
// num_threads = min(num_threads, nthreads-var)
7218+
if (num_threads > __kmp_dflt_team_nth) {
7219+
num_threads = __kmp_dflt_team_nth; // honor nthreads-var ICV
7220+
}
72087221
if (num_teams * num_threads > __kmp_teams_max_nth) {
72097222
int new_threads = __kmp_teams_max_nth / num_teams;
72107223
if (!__kmp_reserve_warn) { // user asked for too many threads

0 commit comments

Comments
 (0)