Index: openmp/trunk/runtime/src/kmp_runtime.c =================================================================== --- openmp/trunk/runtime/src/kmp_runtime.c +++ openmp/trunk/runtime/src/kmp_runtime.c @@ -5033,7 +5033,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]; @@ -5517,7 +5517,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 @@ -6955,20 +6955,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; }