540 unsigned int max_width = 0;
542 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
545 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(32));
546 const std::string extra_dash = std::string(max_width - 32,
'-');
547 const std::string extra_space = std::string(max_width - 32,
' ');
560 double check_time = 0.;
562 check_time += i.second.total_cpu_time;
570 <<
"+---------------------------------------------"
571 << extra_dash <<
"+------------"
572 <<
"+------------+\n"
573 <<
"| Total CPU time elapsed since start "
574 << extra_space <<
"|";
575 out_stream << std::setw(10) << std::setprecision(3) << std::right;
578 << extra_space <<
"| "
585 <<
" | % of total |\n";
586 out_stream <<
"+---------------------------------" << extra_dash
587 <<
"+-----------+------------"
591 std::string name_out = i.first;
594 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
595 name_out.erase(0, pos_non_space);
596 name_out.resize(max_width,
' ');
604 out_stream << i.second.total_cpu_time <<
"s |";
611 const double fraction =
613 if (fraction > 0.001)
627 <<
"+---------------------------------" << extra_dash
629 <<
"------------+------------+\n"
635 <<
"Note: The sum of counted times is " << time_gap
636 <<
" seconds larger than the total time.\n"
637 <<
"(Timer function may have introduced too much overhead, or different\n"
638 <<
"section timers may have run at the same time.)" << std::endl;
648 <<
"+---------------------------------------------"
649 << extra_dash <<
"+------------"
650 <<
"+------------+\n"
651 <<
"| Total wallclock time elapsed since start "
652 << extra_space <<
"|";
653 out_stream << std::setw(10) << std::setprecision(3) << std::right;
656 << extra_space <<
"| "
663 out_stream <<
"+---------------------------------" << extra_dash
664 <<
"+-----------+------------"
668 std::string name_out = i.first;
671 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
672 name_out.erase(0, pos_non_space);
673 name_out.resize(max_width,
' ');
681 out_stream << i.second.total_wall_time <<
"s |";
689 const double fraction =
691 if (fraction > 0.001)
705 <<
"+---------------------------------" << extra_dash
707 <<
"------------+------------+\n"
720 double check_time = 0.;
723 check_time += i.second.total_cpu_time;
730 out_stream <<
"\n\n+---------------------------------------------"
732 <<
"------------+------------+"
733 <<
"------------+------------+" <<
'\n'
734 <<
"| Total CPU/wall time elapsed since start "
735 << extra_space <<
"|" << std::setw(10) << std::setprecision(3)
739 << extra_space <<
"|"
742 <<
"\n| Section " << extra_space
744 <<
" CPU time | % of total |"
745 <<
" wall time | % of total |"
746 <<
"\n+---------------------------------" << extra_dash
748 <<
"------------+------------+"
749 <<
"------------+------------+" << std::endl;
753 std::string name_out = i.first;
756 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
757 name_out.erase(0, pos_non_space);
758 name_out.resize(max_width,
' ');
768 out_stream << i.second.total_cpu_time <<
"s |";
775 const double fraction =
777 if (fraction > 0.001)
795 out_stream << i.second.total_wall_time <<
"s |";
803 const double fraction =
805 if (fraction > 0.001)
821 out_stream <<
"+---------------------------------" << extra_dash
823 <<
"------------+------------+"
824 <<
"------------+------------+" << std::endl
830 <<
"Note: The sum of counted times is " << time_gap
831 <<
" seconds larger than the total time.\n"
832 <<
"(Timer function may have introduced too much overhead, or different\n"
833 <<
"section timers may have run at the same time.)" << std::endl;
841 const double quantile)
const
849 Assert(quantile >= 0. && quantile <= 0.5,
850 ExcMessage(
"The quantile must be between 0 and 0.5"));
853 unsigned int max_width = 0;
855 max_width =
std::max(max_width,
static_cast<unsigned int>(i.first.size()));
858 max_width =
std::max(max_width + 1,
static_cast<unsigned int>(17));
859 const std::string extra_dash = std::string(max_width - 17,
'-');
860 const std::string extra_space = std::string(max_width - 17,
' ');
863 const auto print_statistics = [&](
const double given_time) {
865 if (n_ranks == 1 || quantile == 0.)
870 out_stream << std::setw(10) << std::setprecision(4) << std::right;
874 out_stream << std::setw(10) << std::setprecision(4) << std::right;
876 out_stream << std::setw(10) << std::setprecision(4) << std::right;
884 std::vector<double> receive_data(my_rank == 0 ? n_ranks : 0);
885 std::vector<double> result(9);
886#ifdef DEAL_II_WITH_MPI
887 int ierr = MPI_Gather(&given_time,
900 std::vector<std::pair<double, unsigned int>> data_rank;
901 data_rank.reserve(n_ranks);
902 for (
unsigned int i = 0; i < n_ranks; ++i)
904 data_rank.emplace_back(receive_data[i], i);
905 result[4] += receive_data[i];
907 result[4] /= n_ranks;
908 std::sort(data_rank.begin(), data_rank.end());
910 const unsigned int quantile_index =
911 static_cast<unsigned int>(std::round(quantile * n_ranks));
913 result[0] = data_rank[0].first;
914 result[1] = data_rank[0].second;
915 result[2] = data_rank[quantile_index].first;
916 result[3] = data_rank[quantile_index].second;
917 result[5] = data_rank[n_ranks - 1 - quantile_index].first;
918 result[6] = data_rank[n_ranks - 1 - quantile_index].second;
919 result[7] = data_rank[n_ranks - 1].first;
920 result[8] = data_rank[n_ranks - 1].second;
922 ierr = MPI_Bcast(result.data(), 9, MPI_DOUBLE, 0, mpi_comm);
925 out_stream << std::setw(10) << std::setprecision(4) << std::right;
929 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
930 out_stream << std::setw(10) << std::setprecision(4) << std::right;
934 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
935 out_stream << std::setw(10) << std::setprecision(4) << std::right;
937 out_stream << std::setw(10) << std::setprecision(4) << std::right;
941 << (n_ranks > 99999 ?
"" :
" ") <<
"|";
942 out_stream << std::setw(10) << std::setprecision(4) << std::right;
946 << (n_ranks > 99999 ?
"" :
" ") <<
"|\n";
954 const std::string time_rank_column =
"------------------+";
955 const std::string time_rank_space =
" |";
959 <<
"+------------------------------" << extra_dash <<
"+"
961 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
963 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
964 << time_rank_column <<
'\n'
965 <<
"| Total wallclock time elapsed " << extra_space <<
"|";
971 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
973 << (n_ranks > 1 && quantile > 0. ? time_rank_space :
"")
974 << time_rank_space <<
'\n';
975 out_stream <<
"| Section " << extra_space <<
"| no. calls "
976 <<
"| min time rank |";
977 if (n_ranks > 1 && quantile > 0.)
978 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
979 << quantile <<
"-tile rank |";
981 if (n_ranks > 1 && quantile > 0.)
982 out_stream <<
" " << std::setw(5) << std::setprecision(2) << std::right
983 << 1. - quantile <<
"-tile rank |";
985 out_stream <<
"+------------------------------" << extra_dash <<
"+"
987 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
989 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
990 << time_rank_column <<
'\n';
993 std::string name_out = i.first;
996 unsigned int pos_non_space = name_out.find_first_not_of(
' ');
997 name_out.erase(0, pos_non_space);
998 name_out.resize(max_width,
' ');
1004 print_statistics(i.second.total_wall_time);
1006 out_stream <<
"+------------------------------" << extra_dash <<
"+"
1008 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1010 << (n_ranks > 1 && quantile > 0. ? time_rank_column :
"")
1011 << time_rank_column <<
'\n';