13 #include "../interface/timer.h"    18   #define MAX_TOT_SYMBOLS_LEN 1000000    29                                  double const start_time_,
    30                                  double const start_excl_time_){
    63                   MPI_DOUBLE, MPI_SUM, comm);
    65                   MPI_DOUBLE, MPI_SUM, comm);
    67                   MPI_INT, MPI_SUM, comm);
    80       fprintf(output, 
"%s", 
name);
    86       fprintf(output, 
"%s", space);
    87       fprintf(output,
"%5d   %3d.%03d   %3d.%02d  %3d.%03d   %3d.%02d\n",
    92               ((
int)(10000.*(
total_time)/complete_time))%100,
   105   static std::vector<Function_timer> * function_timers = NULL;
   110     if (function_timers == NULL) {
   111       if (name[0] == 
'M' && name[1] == 
'P' && 
   112           name[2] == 
'I' && name[3] == 
'_'){
   120       function_timers = 
new std::vector<Function_timer>();
   121       function_timers->push_back(
Function_timer(name, MPI_Wtime(), 0.0)); 
   123       for (i=0; i<(int)function_timers->size(); i++){
   124         if (strcmp((*function_timers)[i].name, name) == 0){
   131       original = (index==0);
   133     if (index == (
int)function_timers->size()) {
   134       function_timers->push_back(
Function_timer(name, MPI_Wtime(), excl_time)); 
   145       (*function_timers)[index].start_time = MPI_Wtime();
   146       (*function_timers)[index].start_excl_time = 
excl_time;
   155       MPI_Finalized(&is_fin);
   157         double delta_time = MPI_Wtime() - (*function_timers)[index].start_time;
   158         (*function_timers)[index].acc_time += delta_time;
   159         (*function_timers)[index].acc_excl_time += delta_time - 
   160               (excl_time- (*function_timers)[index].start_excl_time); 
   161         excl_time = (*function_timers)[index].start_excl_time + delta_time;
   162         (*function_timers)[index].calls++;
   173     int rank, 
np, i, j, len_symbols, nrecv_symbols;
   176     MPI_Finalized(&is_fin);
   178     MPI_Comm_rank(comm, &rank);
   179     MPI_Comm_size(comm, &np);
   184     FILE * output = NULL;
   193       sprintf(filename, 
"profile.%s.",name);
   195       sprintf(filename+strlen(filename), 
"%d.", output_file_counter);
   196       output_file_counter++;
   201           for (off=strlen(main_argv[i]); off>=1; off--){
   202             if (main_argv[i][off-1] == 
'/') 
break;
   204           sprintf(filename+strlen(filename), 
"%s.", main_argv[i]+off);
   207       sprintf(filename+strlen(filename), 
"-p%d.out", np);
   211       printf(
"%s\n",filename);
   217       sprintf(heading,
"%s",part);
   219       sprintf(part,
"       inclusive         exclusive\n");
   220       strcat(heading,part);
   221       fprintf(output, 
"%s", heading);
   226       sprintf(heading,
"%s",part);
   227       sprintf(part, 
"calls        sec       %%"); 
   228       strcat(heading,part);
   229       sprintf(part, 
"       sec       %%\n"); 
   230       strcat(heading,part);
   231       fprintf(output, 
"%s", heading);
   235     for (i=0; i<(int)function_timers->size(); i++){
   236       sprintf(all_symbols+len_symbols, 
"%s", (*function_timers)[i].name);
   237       len_symbols += strlen((*function_timers)[i].name)+1;
   240       for (
int lp=1; lp<log2(np)+1; lp++){
   242         if (rank%gap == gap/2){
   243           PMPI_Send(&len_symbols, 1, MPI_INT, rank-gap/2, 1, comm);
   244           PMPI_Send(all_symbols, len_symbols, MPI_CHAR, rank-gap/2, 2, comm);
   246         if (rank%gap==0 && rank+gap/2<np){
   248           PMPI_Recv(&nrecv_symbols, 1, MPI_INT, rank+gap/2, 1, comm, &stat);
   249           PMPI_Recv(recv_symbols, nrecv_symbols, MPI_CHAR, rank+gap/2, 2, comm, &stat);
   250           for (i=0; i<nrecv_symbols; i+=strlen(recv_symbols+i)+1){
   252             while (j<len_symbols && strcmp(all_symbols+j, recv_symbols+i) != 0){
   253               j+=strlen(all_symbols+j)+1;
   257               sprintf(all_symbols+len_symbols, 
"%s", recv_symbols+i);
   258               len_symbols += strlen(recv_symbols+i)+1;
   263       PMPI_Bcast(&len_symbols, 1, MPI_INT, 0, comm);
   264       PMPI_Bcast(all_symbols, len_symbols, MPI_CHAR, 0, comm);
   266       while (j<len_symbols){
   267         Timer t(all_symbols+j);
   268         j+=strlen(all_symbols+j)+1;
   273     std::sort(function_timers->begin(), function_timers->end(),
comp_name);
   274     for (i=0; i<(int)function_timers->size(); i++){
   275       (*function_timers)[i].compute_totals(comm);
   277     std::sort(function_timers->begin(), function_timers->end());
   278     complete_time = (*function_timers)[0].total_time;
   280       for (i=0; i<(int)function_timers->size(); i++){
   281         (*function_timers)[i].print(output,comm,rank,np);
   296     if (set_contxt && original && !exited) {
   297       if (comm != MPI_COMM_WORLD){
   302       function_timers->clear();
   303       delete function_timers;
   304       function_timers = NULL;
   330     saved_function_timers = *function_timers;
   333     function_timers->clear();
   342     if (function_timers != NULL){
   343       function_timers->clear();
   344       delete function_timers;
   346     function_timers = 
new std::vector<Function_timer>();
   347     *function_timers = saved_function_timers;
   348     excl_time = save_excl_time;
 
void set_main_args(int argc, const char *const *argv)
Timer_epoch(char const *name_)
const char *const * main_argv
Function_timer(char const *name_, double const start_time_, double const start_excl_time_)
local process walltime measurement 
void * alloc(int64_t len)
alloc abstraction 
char name[MAX_NAME_LENGTH]
void print(FILE *output, MPI_Comm const comm, int const rank, int const np)
void set_context(MPI_Comm ctxt)
void compute_totals(MPI_Comm comm)
void print_timers(char const *name)
bool operator<(Function_timer const &w) const 
int cdealloc(void *ptr)
free abstraction 
bool comp_name(Function_timer const &w1, Function_timer const &w2)
#define MAX_TOT_SYMBOLS_LEN