[Openmp-commits] [PATCH] D14732: Fix honoring of OMP_THREAD_LIMIT in the teams construct
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Mon Nov 16 14:36:03 PST 2015
jlpeyton created this revision.
jlpeyton added reviewers: AndreyChurbanov, tlwilmar, hfinkel.
jlpeyton added a subscriber: openmp-commits.
jlpeyton set the repository for this revision to rL LLVM.
Fix for crash in the teams construct in case user sets OMP_THREAD_LIMIT to a number less than the number of processors. Now the number of threads will be silently reduced if the user didn't specify teams parameters or with a warning if the user specified teams parameters conflicting with OMP_THREAD_LIMIT.
Repository:
rL LLVM
http://reviews.llvm.org/D14732
Files:
runtime/src/kmp_runtime.c
Index: runtime/src/kmp_runtime.c
===================================================================
--- runtime/src/kmp_runtime.c
+++ runtime/src/kmp_runtime.c
@@ -5029,7 +5029,7 @@
__kmp_initialize_info( team->t.t_threads[ f ], team, f, __kmp_gtid_from_tid( f, team ) );
if (level) { // set th_task_state for new threads in nested hot team
// __kmp_initialize_info() no longer zeroes th_task_state, so we should only need to set the
- // th_task_state for the new threads. th_task_state for master thread will not be accurate until
+ // th_task_state for the new threads. th_task_state for master thread will not be accurate until
// after this in __kmp_fork_call(), so we look to the master's memo_stack to get the correct value.
for (f=old_nproc; f < team->t.t_nproc; ++f)
team->t.t_threads[f]->th.th_task_state = team->t.t_threads[0]->th.th_task_state_memo_stack[level];
@@ -5511,7 +5511,7 @@
this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
// Initialize OMPT task id for implicit task.
int tid = __kmp_tid_from_gtid(gtid);
- (*pteam)->t.t_implicit_task_taskdata[tid].ompt_task_info.task_id =
+ (*pteam)->t.t_implicit_task_taskdata[tid].ompt_task_info.task_id =
__ompt_task_id_new(tid);
}
#endif
@@ -6949,20 +6949,49 @@
kmp_info_t *thr = __kmp_threads[gtid];
KMP_DEBUG_ASSERT(num_teams >= 0);
KMP_DEBUG_ASSERT(num_threads >= 0);
- if( num_teams == 0 ) {
+
+ 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 ( !__kmp_reserve_warn ) {
+ __kmp_reserve_warn = 1;
+ __kmp_msg(
+ kmp_ms_warning,
+ KMP_MSG( CantFormThrTeam, num_teams, __kmp_max_nth ),
+ KMP_HNT( Unset_ALL_THREADS ),
+ __kmp_msg_null
+ );
+ }
+ num_teams = __kmp_max_nth;
}
// Set number of teams (number of threads in the outer "parallel" of the teams)
thr->th.th_set_nproc = thr->th.th_teams_size.nteams = num_teams;
// Remember the number of threads for inner parallel regions
- if( num_threads > 0 ) {
- thr->th.th_teams_size.nth = num_threads;
- } else {
+ if( num_threads == 0 ) {
if( !TCR_4(__kmp_init_middle) )
__kmp_middle_initialize(); // get __kmp_avail_proc calculated
- thr->th.th_teams_size.nth = __kmp_avail_proc / num_teams;
+ num_threads = __kmp_avail_proc / num_teams;
+ if( num_teams * num_threads > __kmp_max_nth ) {
+ // adjust num_threads w/o warning as it is not user setting
+ num_threads = __kmp_max_nth / num_teams;
+ }
+ } else {
+ if( num_teams * num_threads > __kmp_max_nth ) {
+ int new_threads = __kmp_max_nth / num_teams;
+ if ( !__kmp_reserve_warn ) { // user asked for too many threads
+ __kmp_reserve_warn = 1; // that conflicts with OMP_THREAD_LIMIT
+ __kmp_msg(
+ kmp_ms_warning,
+ KMP_MSG( CantFormThrTeam, num_threads, new_threads ),
+ KMP_HNT( Unset_ALL_THREADS ),
+ __kmp_msg_null
+ );
+ }
+ num_threads = new_threads;
+ }
}
+ thr->th.th_teams_size.nth = num_threads;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14732.40344.patch
Type: text/x-patch
Size: 3617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20151116/ef7eaf78/attachment.bin>
More information about the Openmp-commits
mailing list