535 unsigned int max_width = 0;
537 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
540 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(32));
541 const std::string extra_dash = std::string(max_width - 32,
'-');
542 const std::string extra_space = std::string(max_width - 32,
' ');
555 double check_time = 0.;
557 check_time += i.second.total_cpu_time;
565 <<
"+---------------------------------------------"
566 << extra_dash <<
"+------------"
567 <<
"+------------+\n"
568 <<
"| Total CPU time elapsed since start "
569 << extra_space <<
"|";
570 out_stream << std::setw(10) << std::setprecision(3) << std::right;
573 << extra_space <<
"| "
580 <<
" | % of total |\n";
581 out_stream <<
"+---------------------------------" << extra_dash
582 <<
"+-----------+------------"
586 std::string name_out = i.first;
589 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
590 name_out.erase(0, pos_non_space);
591 name_out.resize(max_width,
' ');
599 out_stream << i.second.total_cpu_time <<
"s |";
606 const double fraction =
608 if (fraction > 0.001)
622 <<
"+---------------------------------" << extra_dash
624 <<
"------------+------------+\n"
630 <<
"Note: The sum of counted times is " << time_gap
631 <<
" seconds larger than the total time.\n"
632 <<
"(Timer function may have introduced too much overhead, or different\n"
633 <<
"section timers may have run at the same time.)" << std::endl;
643 <<
"+---------------------------------------------"
644 << extra_dash <<
"+------------"
645 <<
"+------------+\n"
646 <<
"| Total wallclock time elapsed since start "
647 << extra_space <<
"|";
648 out_stream << std::setw(10) << std::setprecision(3) << std::right;
651 << extra_space <<
"| "
658 out_stream <<
"+---------------------------------" << extra_dash
659 <<
"+-----------+------------"
663 std::string name_out = i.first;
666 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
667 name_out.erase(0, pos_non_space);
668 name_out.resize(max_width,
' ');
676 out_stream << i.second.total_wall_time <<
"s |";
684 const double fraction =
686 if (fraction > 0.001)
700 <<
"+---------------------------------" << extra_dash
702 <<
"------------+------------+\n"
715 double check_time = 0.;
718 check_time += i.second.total_cpu_time;
725 out_stream <<
"\n\n+---------------------------------------------"
727 <<
"------------+------------+"
728 <<
"------------+------------+" <<
'\n'
729 <<
"| Total CPU/wall time elapsed since start "
730 << extra_space <<
"|" << std::setw(10) << std::setprecision(3)
732 << extra_space <<
"|" << std::setw(10) << std::setprecision(3)
735 << extra_space <<
"|"
738 <<
"\n| Section " << extra_space
740 <<
" CPU time | % of total |"
741 <<
" wall time | % of total |"
742 <<
"\n+---------------------------------" << extra_dash
744 <<
"------------+------------+"
745 <<
"------------+------------+" << std::endl;
749 std::string name_out = i.first;
752 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
753 name_out.erase(0, pos_non_space);
754 name_out.resize(max_width,
' ');
764 out_stream << i.second.total_cpu_time <<
"s |";
771 const double fraction =
773 if (fraction > 0.001)
791 out_stream << i.second.total_wall_time <<
"s |";
799 const double fraction =
801 if (fraction > 0.001)
817 out_stream <<
"+---------------------------------" << extra_dash
819 <<
"------------+------------+"
820 <<
"------------+------------+" << std::endl
826 <<
"Note: The sum of counted times is " << time_gap
827 <<
" seconds larger than the total time.\n"
828 <<
"(Timer function may have introduced too much overhead, or different\n"
829 <<
"section timers may have run at the same time.)" << std::endl;
837 const double quantile)
const
845 Assert(quantile >= 0. && quantile <= 0.5,
846 ExcMessage(
"The quantile must be between 0 and 0.5"));
849 unsigned int max_width = 0;
851 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
854 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(17));
855 const std::string extra_dash = std::string(max_width - 17,
'-');
856 const std::string extra_space = std::string(max_width - 17,
' ');
859 const auto print_statistics = [&](
const double given_time) {
861 if (n_ranks == 1 || quantile == 0.)
866 out_stream << std::setw(10) << std::setprecision(4) << std::right;
870 out_stream << std::setw(10) << std::setprecision(4) << std::right;
872 out_stream << std::setw(10) << std::setprecision(4) << std::right;
880 std::vector<double> receive_data(my_rank == 0 ? n_ranks : 0);
881 std::vector<double> result(9);
882#ifdef DEAL_II_WITH_MPI
883 int ierr = MPI_Gather(&given_time,
896 std::vector<std::pair<double, unsigned int>> data_rank;
897 data_rank.reserve(n_ranks);
898 for (
unsigned int i = 0; i < n_ranks; ++i)
900 data_rank.emplace_back(receive_data[i], i);
901 result[4] += receive_data[i];
903 result[4] /= n_ranks;
904 std::sort(data_rank.begin(), data_rank.end());
906 const unsigned int quantile_index =
907 static_cast<unsigned int>(std::round(quantile * n_ranks));
909 result[0] = data_rank[0].first;
910 result[1] = data_rank[0].second;
911 result[2] = data_rank[quantile_index].first;
912 result[3] = data_rank[quantile_index].second;
913 result[5] = data_rank[n_ranks - 1 - quantile_index].first;
914 result[6] = data_rank[n_ranks - 1 - quantile_index].second;
915 result[7] = data_rank[n_ranks - 1].first;
916 result[8] = data_rank[n_ranks - 1].second;
918 ierr = MPI_Bcast(result.data(), 9, MPI_DOUBLE, 0, mpi_comm);
921 out_stream << std::setw(10) << std::setprecision(4) << std::right;
924 out_stream << static_cast<unsigned int>(result[1])
925 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
926 out_stream << std::setw(10) << std::setprecision(4) << std::right;
929 out_stream << static_cast<unsigned int>(result[3])
930 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
931 out_stream << std::setw(10) << std::setprecision(4) << std::right;
933 out_stream << std::setw(10) << std::setprecision(4) << std::right;
936 out_stream << static_cast<unsigned int>(result[6])
937 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
938 out_stream << std::setw(10) << std::setprecision(4) << std::right;
941 out_stream << static_cast<unsigned int>(result[8])
942 << (n_ranks > 99999 ?
"" :
" ") <<
"|\n";
950 const std::string time_rank_column =
"------------------+";
951 const std::string time_rank_space =
" |";
955 <<
"+------------------------------" << extra_dash <<
"+"
957 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
959 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
960 << time_rank_column <<
'\n'
961 <<
"| Total wallclock time elapsed " << extra_space <<
"|";
967 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
969 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
970 << time_rank_space <<
'\n';
971 out_stream <<
"| Section " << extra_space <<
"| no. calls "
972 <<
"| min time rank |";
973 if (n_ranks > 1 && quantile > 0.)
974 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
975 << quantile <<
"-tile rank |";
977 if (n_ranks > 1 && quantile > 0.)
978 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
979 << 1. - quantile <<
"-tile rank |";
981 out_stream <<
"+------------------------------" << extra_dash <<
"+"
983 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
985 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
986 << time_rank_column <<
'\n';
989 std::string name_out = i.first;
992 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
993 name_out.erase(0, pos_non_space);
994 name_out.resize(max_width,
' ');
1000 print_statistics(i.second.total_wall_time);
1002 out_stream <<
"+------------------------------" << extra_dash <<
"+"
1004 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1006 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1007 << time_rank_column <<
'\n';