542 unsigned int max_width = 0;
544 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
547 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(32));
548 const std::string extra_dash = std::string(max_width - 32,
'-');
549 const std::string extra_space = std::string(max_width - 32,
' ');
562 double check_time = 0.;
564 check_time += i.second.total_cpu_time;
572 <<
"+---------------------------------------------"
573 << extra_dash <<
"+------------"
574 <<
"+------------+\n"
575 <<
"| Total CPU time elapsed since start "
576 << extra_space <<
"|";
577 out_stream << std::setw(10) << std::setprecision(3) << std::right;
580 << extra_space <<
"| "
587 <<
" | % of total |\n";
588 out_stream <<
"+---------------------------------" << extra_dash
589 <<
"+-----------+------------"
593 std::string name_out = i.first;
596 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
597 name_out.erase(0, pos_non_space);
598 name_out.resize(max_width,
' ');
606 out_stream << i.second.total_cpu_time <<
"s |";
613 const double fraction =
615 if (fraction > 0.001)
629 <<
"+---------------------------------" << extra_dash
631 <<
"------------+------------+\n"
637 <<
"Note: The sum of counted times is " << time_gap
638 <<
" seconds larger than the total time.\n"
639 <<
"(Timer function may have introduced too much overhead, or different\n"
640 <<
"section timers may have run at the same time.)" << std::endl;
650 <<
"+---------------------------------------------"
651 << extra_dash <<
"+------------"
652 <<
"+------------+\n"
653 <<
"| Total wallclock time elapsed since start "
654 << extra_space <<
"|";
655 out_stream << std::setw(10) << std::setprecision(3) << std::right;
658 << extra_space <<
"| "
665 out_stream <<
"+---------------------------------" << extra_dash
666 <<
"+-----------+------------"
670 std::string name_out = i.first;
673 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
674 name_out.erase(0, pos_non_space);
675 name_out.resize(max_width,
' ');
683 out_stream << i.second.total_wall_time <<
"s |";
691 const double fraction =
693 if (fraction > 0.001)
707 <<
"+---------------------------------" << extra_dash
709 <<
"------------+------------+\n"
722 double check_time = 0.;
725 check_time += i.second.total_cpu_time;
732 out_stream <<
"\n\n+---------------------------------------------"
734 <<
"------------+------------+"
735 <<
"------------+------------+" <<
'\n'
736 <<
"| Total CPU/wall time elapsed since start "
737 << extra_space <<
"|" << std::setw(10) << std::setprecision(3)
741 << extra_space <<
"|"
744 <<
"\n| Section " << extra_space
746 <<
" CPU time | % of total |"
747 <<
" wall time | % of total |"
748 <<
"\n+---------------------------------" << extra_dash
750 <<
"------------+------------+"
751 <<
"------------+------------+" << std::endl;
755 std::string name_out = i.first;
758 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
759 name_out.erase(0, pos_non_space);
760 name_out.resize(max_width,
' ');
770 out_stream << i.second.total_cpu_time <<
"s |";
777 const double fraction =
779 if (fraction > 0.001)
797 out_stream << i.second.total_wall_time <<
"s |";
805 const double fraction =
807 if (fraction > 0.001)
823 out_stream <<
"+---------------------------------" << extra_dash
825 <<
"------------+------------+"
826 <<
"------------+------------+" << std::endl
832 <<
"Note: The sum of counted times is " << time_gap
833 <<
" seconds larger than the total time.\n"
834 <<
"(Timer function may have introduced too much overhead, or different\n"
835 <<
"section timers may have run at the same time.)" << std::endl;
843 const double quantile)
const
851 Assert(quantile >= 0. && quantile <= 0.5,
852 ExcMessage(
"The quantile must be between 0 and 0.5"));
855 unsigned int max_width = 0;
857 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
860 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(17));
861 const std::string extra_dash = std::string(max_width - 17,
'-');
862 const std::string extra_space = std::string(max_width - 17,
' ');
865 const auto print_statistics = [&](
const double given_time) {
867 if (n_ranks == 1 || quantile == 0.)
872 out_stream << std::setw(10) << std::setprecision(4) << std::right;
876 out_stream << std::setw(10) << std::setprecision(4) << std::right;
878 out_stream << std::setw(10) << std::setprecision(4) << std::right;
886 std::vector<double> receive_data(my_rank == 0 ? n_ranks : 0);
887 std::vector<double> result(9);
888#ifdef DEAL_II_WITH_MPI
889 int ierr = MPI_Gather(&given_time,
902 std::vector<std::pair<double, unsigned int>> data_rank;
903 data_rank.reserve(n_ranks);
904 for (
unsigned int i = 0; i < n_ranks; ++i)
906 data_rank.emplace_back(receive_data[i], i);
907 result[4] += receive_data[i];
909 result[4] /= n_ranks;
910 std::sort(data_rank.begin(), data_rank.end());
912 const unsigned int quantile_index =
913 static_cast<unsigned int>(std::round(quantile * n_ranks));
915 result[0] = data_rank[0].first;
916 result[1] = data_rank[0].second;
917 result[2] = data_rank[quantile_index].first;
918 result[3] = data_rank[quantile_index].second;
919 result[5] = data_rank[n_ranks - 1 - quantile_index].first;
920 result[6] = data_rank[n_ranks - 1 - quantile_index].second;
921 result[7] = data_rank[n_ranks - 1].first;
922 result[8] = data_rank[n_ranks - 1].second;
924 ierr = MPI_Bcast(result.data(), 9, MPI_DOUBLE, 0, mpi_comm);
927 out_stream << std::setw(10) << std::setprecision(4) << std::right;
930 out_stream << static_cast<unsigned int>(result[1])
931 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
932 out_stream << std::setw(10) << std::setprecision(4) << std::right;
935 out_stream << static_cast<unsigned int>(result[3])
936 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
937 out_stream << std::setw(10) << std::setprecision(4) << std::right;
939 out_stream << std::setw(10) << std::setprecision(4) << std::right;
942 out_stream << static_cast<unsigned int>(result[6])
943 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
944 out_stream << std::setw(10) << std::setprecision(4) << std::right;
947 out_stream << static_cast<unsigned int>(result[8])
948 << (n_ranks > 99999 ?
"" :
" ") <<
"|\n";
956 const std::string time_rank_column =
"------------------+";
957 const std::string time_rank_space =
" |";
961 <<
"+------------------------------" << extra_dash <<
"+"
963 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
965 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
966 << time_rank_column <<
'\n'
967 <<
"| Total wallclock time elapsed " << extra_space <<
"|";
973 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
975 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
976 << time_rank_space <<
'\n';
977 out_stream <<
"| Section " << extra_space <<
"| no. calls "
978 <<
"| min time rank |";
979 if (n_ranks > 1 && quantile > 0.)
980 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
981 << quantile <<
"-tile rank |";
983 if (n_ranks > 1 && quantile > 0.)
984 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
985 << 1. - quantile <<
"-tile rank |";
987 out_stream <<
"+------------------------------" << extra_dash <<
"+"
989 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
991 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
992 << time_rank_column <<
'\n';
995 std::string name_out = i.first;
998 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
999 name_out.erase(0, pos_non_space);
1000 name_out.resize(max_width,
' ');
1006 print_statistics(i.second.total_wall_time);
1008 out_stream <<
"+------------------------------" << extra_dash <<
"+"
1010 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1012 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1013 << time_rank_column <<
'\n';