626 "Cannot print data from TimerOutput while inside a timed section."));
633 unsigned int max_width = 0;
635 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
638 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(32));
639 const std::string extra_dash = std::string(max_width - 32,
'-');
640 const std::string extra_space = std::string(max_width - 32,
' ');
652 double total_cpu_time_in_sections = 0.;
654 total_cpu_time_in_sections += i.second.cpu_time();
656 const double section_overhead =
658 if (section_overhead > 0.0)
663 <<
"+---------------------------------------------"
664 << extra_dash <<
"+------------"
665 <<
"+------------+\n"
666 <<
"| Total CPU time elapsed since start "
667 << extra_space <<
"|";
668 out_stream << std::setw(10) << std::setprecision(3) << std::right;
671 << extra_space <<
"| "
678 <<
" | % of total |\n";
679 out_stream <<
"+---------------------------------" << extra_dash
680 <<
"+-----------+------------"
684 std::string name_out = i.first;
687 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
688 name_out.erase(0, pos_non_space);
689 name_out.resize(max_width,
' ');
691 const double section_cpu_time = i.second.cpu_time();
708 if (fraction > 0.001)
722 <<
"+---------------------------------" << extra_dash
724 <<
"------------+------------+\n"
727 if (section_overhead > 0.0)
730 <<
"Note: The sum of section times is " << section_overhead
731 <<
" seconds larger than the total time.\n"
732 <<
"(Timer function may have introduced too much overhead, or different\n"
733 <<
"section timers may have run at the same time.)" << std::endl;
743 <<
"+---------------------------------------------"
744 << extra_dash <<
"+------------"
745 <<
"+------------+\n"
746 <<
"| Total wallclock time elapsed since start "
747 << extra_space <<
"|";
748 out_stream << std::setw(10) << std::setprecision(3) << std::right;
751 << extra_space <<
"| "
758 out_stream <<
"+---------------------------------" << extra_dash
759 <<
"+-----------+------------"
763 std::string name_out = i.first;
766 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
767 name_out.erase(0, pos_non_space);
768 name_out.resize(max_width,
' ');
784 const double fraction =
786 if (fraction > 0.001)
800 <<
"+---------------------------------" << extra_dash
802 <<
"------------+------------+\n"
814 double total_cpu_time_in_sections = 0.;
816 total_cpu_time_in_sections += i.second.cpu_time();
818 const double section_overhead =
820 if (section_overhead > 0.0)
824 out_stream <<
"\n\n+---------------------------------------------"
826 <<
"------------+------------+"
827 <<
"------------+------------+" <<
'\n'
828 <<
"| Total CPU/wall time elapsed since start "
829 << extra_space <<
"|" << std::setw(10) << std::setprecision(3)
831 << extra_space <<
"|" << std::setw(10) << std::setprecision(3)
834 << extra_space <<
"|"
837 <<
"\n| Section " << extra_space
839 <<
" CPU time | % of total |"
840 <<
" wall time | % of total |"
841 <<
"\n+---------------------------------" << extra_dash
843 <<
"------------+------------+"
844 <<
"------------+------------+" << std::endl;
848 std::string name_out = i.first;
851 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
852 name_out.erase(0, pos_non_space);
853 name_out.resize(max_width,
' ');
861 const double section_cpu_time = i.second.cpu_time();
873 if (fraction > 0.001)
899 const double fraction =
901 if (fraction > 0.001)
917 out_stream <<
"+---------------------------------" << extra_dash
919 <<
"------------+------------+"
920 <<
"------------+------------+" << std::endl
926 <<
"Note: The sum of section times is " << section_overhead
927 <<
" seconds larger than the total time.\n"
928 <<
"(Timer function may have introduced too much overhead, or different\n"
929 <<
"section timers may have run at the same time.)" << std::endl;
937 const MPI_Comm mpi_communicator_statistics,
938 const double quantile)
const
942 "Cannot print data from TimerOutput while inside a timed section."));
944 Assert(quantile >= 0. && quantile <= 0.5,
945 ExcMessage(
"The quantile must be between 0 and 0.5"));
947#ifdef DEAL_II_WITH_MPI
956 const int ierr = MPI_Comm_compare(mpi_communicator_statistics,
961 Assert(result == MPI_IDENT || result == MPI_CONGRUENT ||
962 result == MPI_SIMILAR,
964 "The passed MPI communicator must contain the same processes as "
965 "the one used to construct the TimerOutput."));
975 std::vector<std::string> my_section_names;
976 my_section_names.reserve(
sections.size());
977 for (
const auto &[section, timer] :
sections)
978 my_section_names.push_back(section);
980 const std::vector<std::string> global_section_names =
982 mpi_communicator_statistics);
985 unsigned int max_width = 0;
986 for (
const auto &i : global_section_names)
987 max_width =
std::max(max_width,
static_cast<unsigned int>(i.size()));
990 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(17));
991 const std::string extra_dash = std::string(max_width - 17,
'-');
992 const std::string extra_space = std::string(max_width - 17,
' ');
995 const auto print_statistics = [&](
const double given_time) {
996 const unsigned int n_ranks =
998 if (n_ranks == 1 || quantile == 0.)
1003 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1006 out_stream <<
data.min_index << (n_ranks > 99999 ?
"" :
" ") <<
"|";
1007 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1009 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1012 out_stream <<
data.max_index << (n_ranks > 99999 ?
"" :
" ") <<
"|\n";
1018 const std::vector<double> receive_data =
1020 std::vector<double> result(9);
1025 std::vector<std::pair<double, unsigned int>> data_rank;
1026 data_rank.reserve(n_ranks);
1027 for (
unsigned int i = 0; i < n_ranks; ++i)
1029 data_rank.emplace_back(receive_data[i], i);
1030 result[4] += receive_data[i];
1032 result[4] /= n_ranks;
1033 std::sort(data_rank.begin(), data_rank.end());
1035 const unsigned int quantile_index =
1036 static_cast<unsigned int>(std::round(quantile * n_ranks));
1038 result[0] = data_rank[0].first;
1039 result[1] = data_rank[0].second;
1040 result[2] = data_rank[quantile_index].first;
1041 result[3] = data_rank[quantile_index].second;
1042 result[5] = data_rank[n_ranks - 1 - quantile_index].first;
1043 result[6] = data_rank[n_ranks - 1 - quantile_index].second;
1044 result[7] = data_rank[n_ranks - 1].first;
1045 result[8] = data_rank[n_ranks - 1].second;
1050 mpi_communicator_statistics);
1051 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1054 out_stream << static_cast<unsigned int>(result[1])
1055 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
1056 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1059 out_stream << static_cast<unsigned int>(result[3])
1060 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
1061 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1063 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1066 out_stream << static_cast<unsigned int>(result[6])
1067 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
1068 out_stream << std::setw(10) << std::setprecision(4) << std::right;
1071 out_stream << static_cast<unsigned int>(result[8])
1072 << (n_ranks > 99999 ?
"" :
" ") <<
"|\n";
1078 const unsigned int n_ranks =
1081 const std::string time_rank_column =
"------------------+";
1082 const std::string time_rank_space =
" |";
1086 <<
"+------------------------------" << extra_dash <<
"+"
1088 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1090 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1091 << time_rank_column <<
'\n'
1092 <<
"| Total wallclock time elapsed " << extra_space <<
"|";
1098 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
1100 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
1101 << time_rank_space <<
'\n';
1102 out_stream <<
"| Section " << extra_space <<
"| no. calls "
1103 <<
"| min time rank |";
1104 if (n_ranks > 1 && quantile > 0.)
1105 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
1106 << quantile <<
"-tile rank |";
1108 if (n_ranks > 1 && quantile > 0.)
1109 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
1110 << 1. - quantile <<
"-tile rank |";
1112 out_stream <<
"+------------------------------" << extra_dash <<
"+"
1114 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1116 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1117 << time_rank_column <<
'\n';
1119 for (
const auto &global_section_name : global_section_names)
1121 std::string name_out = global_section_name;
1122 const auto section_it =
sections.find(global_section_name);
1123 const bool entered_section_locally = (section_it !=
sections.end());
1126 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
1127 name_out.erase(0, pos_non_space);
1128 name_out.resize(max_width,
' ');
1132 const unsigned n_laps =
1133 entered_section_locally ? section_it->second.n_laps() : 0;
1137 const double wall_time =
1138 entered_section_locally ? section_it->second.wall_time() : 0.0;
1139 print_statistics(wall_time);
1141 out_stream <<
"+------------------------------" << extra_dash <<
"+"
1143 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1145 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1146 << time_rank_column <<
'\n';