Index: openmp/trunk/runtime/src/kmp_csupport.cpp =================================================================== --- openmp/trunk/runtime/src/kmp_csupport.cpp +++ openmp/trunk/runtime/src/kmp_csupport.cpp @@ -382,7 +382,15 @@ va_list ap; va_start(ap, microtask); +#if KMP_STATS_ENABLED KMP_COUNT_BLOCK(OMP_TEAMS); + stats_state_e previous_state = KMP_GET_THREAD_STATE(); + if (previous_state == stats_state_e::SERIAL_REGION) { + KMP_EXCHANGE_PARTITIONED_TIMER(OMP_teams_overhead); + } else { + KMP_PUSH_PARTITIONED_TIMER(OMP_teams_overhead); + } +#endif // remember teams entry point and nesting level this_thr->th.th_teams_microtask = microtask; @@ -442,6 +450,13 @@ this_thr->th.th_teams_level = 0; *(kmp_int64 *)(&this_thr->th.th_teams_size) = 0L; va_end(ap); +#if KMP_STATS_ENABLED + if (previous_state == stats_state_e::SERIAL_REGION) { + KMP_EXCHANGE_PARTITIONED_TIMER(OMP_serial); + } else { + KMP_POP_PARTITIONED_TIMER(); + } +#endif // KMP_STATS_ENABLED } #endif /* OMP_40_ENABLED */ Index: openmp/trunk/runtime/src/kmp_dispatch.cpp =================================================================== --- openmp/trunk/runtime/src/kmp_dispatch.cpp +++ openmp/trunk/runtime/src/kmp_dispatch.cpp @@ -283,6 +283,12 @@ } } +#if KMP_STATS_ENABLED + if (KMP_MASTER_GTID(gtid)) { + KMP_COUNT_VALUE(OMP_loop_dynamic_total_iterations, tc); + } +#endif + pr->u.p.lb = lb; pr->u.p.ub = ub; pr->u.p.st = st; Index: openmp/trunk/runtime/src/kmp_runtime.cpp =================================================================== --- openmp/trunk/runtime/src/kmp_runtime.cpp +++ openmp/trunk/runtime/src/kmp_runtime.cpp @@ -2285,9 +2285,25 @@ team->t.t_id, team->t.t_pkfn)); } // END of timer KMP_fork_call block +#if KMP_STATS_ENABLED && OMP_40_ENABLED + // If beginning a teams construct, then change thread state + stats_state_e previous_state = KMP_GET_THREAD_STATE(); + if (!ap) { + KMP_SET_THREAD_STATE(stats_state_e::TEAMS_REGION); + } +#endif + if (!team->t.t_invoke(gtid)) { KMP_ASSERT2(0, "cannot invoke microtask for MASTER thread"); } + +#if KMP_STATS_ENABLED && OMP_40_ENABLED + // If was beginning of a teams construct, then reset thread state + if (!ap) { + KMP_SET_THREAD_STATE(previous_state); + } +#endif + KA_TRACE(20, ("__kmp_fork_call: T#%d(%d:0) done microtask = %p\n", gtid, team->t.t_id, team->t.t_pkfn)); KMP_MB(); /* Flush all pending memory write invalidates. */ @@ -7106,21 +7122,33 @@ } #endif - { - KMP_TIME_PARTITIONED_BLOCK(OMP_parallel); - KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK); - rc = - __kmp_invoke_microtask((microtask_t)TCR_SYNC_PTR(team->t.t_pkfn), gtid, - tid, (int)team->t.t_argc, (void **)team->t.t_argv +#if KMP_STATS_ENABLED + stats_state_e previous_state = KMP_GET_THREAD_STATE(); + if (previous_state == stats_state_e::TEAMS_REGION) { + KMP_PUSH_PARTITIONED_TIMER(OMP_teams); + } else { + KMP_PUSH_PARTITIONED_TIMER(OMP_parallel); + } + KMP_SET_THREAD_STATE(IMPLICIT_TASK); +#endif + + rc = __kmp_invoke_microtask((microtask_t)TCR_SYNC_PTR(team->t.t_pkfn), gtid, + tid, (int)team->t.t_argc, (void **)team->t.t_argv #if OMPT_SUPPORT - , - exit_runtime_p + , + exit_runtime_p #endif - ); + ); #if OMPT_SUPPORT - *exit_runtime_p = NULL; + *exit_runtime_p = NULL; #endif + +#if KMP_STATS_ENABLED + if (previous_state == stats_state_e::TEAMS_REGION) { + KMP_SET_THREAD_STATE(previous_state); } + KMP_POP_PARTITIONED_TIMER(); +#endif #if USE_ITT_BUILD if (__itt_stack_caller_create_ptr) { Index: openmp/trunk/runtime/src/kmp_sched.cpp =================================================================== --- openmp/trunk/runtime/src/kmp_sched.cpp +++ openmp/trunk/runtime/src/kmp_sched.cpp @@ -38,6 +38,29 @@ //------------------------------------------------------------------------- #endif +#if KMP_STATS_ENABLED +#define KMP_STATS_LOOP_END(stat) \ + { \ + kmp_int64 t; \ + kmp_int64 u = (kmp_int64)(*pupper); \ + kmp_int64 l = (kmp_int64)(*plower); \ + kmp_int64 i = (kmp_int64)incr; \ + if (i == 1) { \ + t = u - l + 1; \ + } else if (i == -1) { \ + t = l - u + 1; \ + } else if (i > 0) { \ + t = (u - l) / i + 1; \ + } else { \ + t = (l - u) / (-i) + 1; \ + } \ + KMP_COUNT_VALUE(stat, t); \ + KMP_POP_PARTITIONED_TIMER(); \ + } +#else +#define KMP_STATS_LOOP_END(stat) /* Nothing */ +#endif + template static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid, kmp_int32 schedtype, kmp_int32 *plastiter, @@ -151,6 +174,7 @@ &(task_info->task_data), 0, codeptr); } #endif + KMP_STATS_LOOP_END(OMP_loop_static_iterations); return; } @@ -202,6 +226,7 @@ &(task_info->task_data), *pstride, codeptr); } #endif + KMP_STATS_LOOP_END(OMP_loop_static_iterations); return; } nth = team->t.t_nproc; @@ -231,6 +256,7 @@ &(task_info->task_data), *pstride, codeptr); } #endif + KMP_STATS_LOOP_END(OMP_loop_static_iterations); return; } @@ -246,6 +272,12 @@ trip_count = (UT)(*plower - *pupper) / (-incr) + 1; } +#if KMP_STATS_ENABLED + if (KMP_MASTER_GTID(gtid)) { + KMP_COUNT_VALUE(OMP_loop_static_total_iterations, trip_count); + } +#endif + if (__kmp_env_consistency_check) { /* tripcount overflow? */ if (trip_count == 0 && *pupper != *plower) { @@ -388,26 +420,7 @@ } #endif -#if KMP_STATS_ENABLED - { - kmp_int64 t; - kmp_int64 u = (kmp_int64)(*pupper); - kmp_int64 l = (kmp_int64)(*plower); - kmp_int64 i = (kmp_int64)incr; - /* compute trip count */ - if (i == 1) { - t = u - l + 1; - } else if (i == -1) { - t = l - u + 1; - } else if (i > 0) { - t = (u - l) / i + 1; - } else { - t = (l - u) / (-i) + 1; - } - KMP_COUNT_VALUE(OMP_loop_static_iterations, t); - KMP_POP_PARTITIONED_TIMER(); - } -#endif + KMP_STATS_LOOP_END(OMP_loop_static_iterations); return; } @@ -419,6 +432,8 @@ typename traits_t::signed_t incr, typename traits_t::signed_t chunk) { KMP_COUNT_BLOCK(OMP_DISTRIBUTE); + KMP_PUSH_PARTITIONED_TIMER(OMP_distribute); + KMP_PUSH_PARTITIONED_TIMER(OMP_distribute_scheduling); typedef typename traits_t::unsigned_t UT; typedef typename traits_t::signed_t ST; kmp_uint32 tid; @@ -648,6 +663,7 @@ } #endif KE_TRACE(10, ("__kmpc_dist_for_static_init: T#%d return\n", gtid)); + KMP_STATS_LOOP_END(OMP_distribute_iterations); return; } Index: openmp/trunk/runtime/src/kmp_stats.h =================================================================== --- openmp/trunk/runtime/src/kmp_stats.h +++ openmp/trunk/runtime/src/kmp_stats.h @@ -69,7 +69,8 @@ TASKYIELD, TASKGROUP, IMPLICIT_TASK, - EXPLICIT_TASK + EXPLICIT_TASK, + TEAMS_REGION }; /*! @@ -137,10 +138,14 @@ macro (OMP_worker_thread_life, stats_flags_e::logEvent, arg) \ macro (OMP_parallel, stats_flags_e::logEvent, arg) \ macro (OMP_parallel_overhead, stats_flags_e::logEvent, arg) \ + macro (OMP_teams, stats_flags_e::logEvent, arg) \ + macro (OMP_teams_overhead, stats_flags_e::logEvent, arg) \ macro (OMP_loop_static, 0, arg) \ macro (OMP_loop_static_scheduling, 0, arg) \ macro (OMP_loop_dynamic, 0, arg) \ macro (OMP_loop_dynamic_scheduling, 0, arg) \ + macro (OMP_distribute, 0, arg) \ + macro (OMP_distribute_scheduling, 0, arg) \ macro (OMP_critical, 0, arg) \ macro (OMP_critical_wait, 0, arg) \ macro (OMP_single, 0, arg) \ @@ -163,8 +168,14 @@ arg) \ macro (OMP_loop_static_iterations, \ stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \ + macro (OMP_loop_static_total_iterations, \ + stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \ macro (OMP_loop_dynamic_iterations, \ stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \ + macro (OMP_loop_dynamic_total_iterations, \ + stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \ + macro (OMP_distribute_iterations, \ + stats_flags_e::noUnits | stats_flags_e::noTotal, arg) \ KMP_FOREACH_DEVELOPER_TIMER(macro, arg) // clang-format on Index: openmp/trunk/runtime/src/kmp_stats.cpp =================================================================== --- openmp/trunk/runtime/src/kmp_stats.cpp +++ openmp/trunk/runtime/src/kmp_stats.cpp @@ -546,7 +546,6 @@ // of __kmp_stats_global_output void kmp_stats_output_module::init() { - fprintf(stderr, "*** Stats enabled OpenMP* runtime ***\n"); char *statsFileName = getenv("KMP_STATS_FILE"); eventsFileName = getenv("KMP_STATS_EVENTS_FILE"); plotFileName = getenv("KMP_STATS_PLOT_FILE");