Ignore:
Timestamp:
01/17/25 15:18:37 (3 weeks ago)
Author:
hshepherd
Message:

Port across changes from the patching - Not yet tested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS2/dev/hshepherd/reduce_output_log/src/client.cpp

    r2503 r2704  
    1313#include "buffer_client.hpp" 
    1414#include "string_tools.hpp" 
     15#include "timestats.hpp" 
    1516 
    1617namespace xios 
     
    261262    } 
    262263 
     264        std::vector<double> CClient::collate_timings(std::string timing_param) 
     265    { 
     266      int myrank, comm_size; 
     267      MPI_Comm_rank(intraComm, &myrank); 
     268      MPI_Comm_size(intraComm, &comm_size); 
     269 
     270      std::vector<double> collated_results; 
     271      MPI_Barrier(intraComm); 
     272      if (myrank == 0) { 
     273        double recv_val = 0.; 
     274        collated_results.push_back(CTimer::get(timing_param).getCumulatedTime()); 
     275        for (int i = 1; i < comm_size; i++) { 
     276          MPI_Recv(&recv_val, 1, MPI_DOUBLE, i, 0, intraComm, MPI_STATUS_IGNORE); 
     277          collated_results.push_back(recv_val); 
     278        } 
     279      } else { 
     280        double snd_val = CTimer::get(timing_param).getCumulatedTime(); 
     281        MPI_Send(&snd_val, 1, MPI_DOUBLE, 0, 0, intraComm); 
     282      } 
     283      MPI_Barrier(intraComm); 
     284      return collated_results; 
     285    } 
     286 
     287    void CClient::present_collated_timings(void) 
     288    { 
     289      std::vector<double> blocking_times = collate_timings("Blocking time"); 
     290      // we need to suspend the XIOS init/finalize timer briefly to gather the measurements 
     291      CTimer::get("XIOS init/finalize").suspend(); 
     292      std::vector<double> init_final_times = collate_timings("XIOS init/finalize"); 
     293      CTimer::get("XIOS init/finalize").resume(); 
     294      std::vector<double> ratio = percentage_ratio_vec_double(blocking_times, init_final_times); 
     295      if (rank_ == 0) { 
     296        int n_ranks; 
     297        MPI_Comm_size(intraComm, &n_ranks); 
     298         
     299        report(0) << " Performance metrics across all client ranks" << endl; 
     300        report(0) << "     Collating from " << n_ranks << " ranks" << endl; 
     301        write_summary_timings(blocking_times, "Time spent waiting for free buffer"); 
     302        write_summary_timings(ratio, "Waiting ratio (percentage)"); 
     303      } 
     304    } 
     305 
     306    void CClient::write_summary_timings(std::vector<double>& collated_results, 
     307                                        std::string results_label) 
     308    { 
     309      report(0) << "  " << results_label << " average " << calc_mean_double(collated_results) << endl; 
     310      report(0) << "  " << results_label << " std dev " << calc_std_double(collated_results) << endl; 
     311      report(0) << "  " << results_label << " min " << calc_min_double(collated_results) << endl; 
     312      report(0) << "  " << results_label << " max " << calc_max_double(collated_results) << endl; 
     313    } 
    263314 
    264315    void CClient::finalize(void) 
     
    266317      int rank ; 
    267318      int msg=0 ; 
     319 
     320      // Do our collated summary 
     321      present_collated_timings(); 
     322      MPI_Barrier(intraComm); 
    268323 
    269324      MPI_Comm_rank(intraComm,&rank) ; 
     
    294349       
    295350      info(20) << "Client side context is finalized"<<endl ; 
     351 
     352      if (CXios::reduceLogFiles) report(0) << "Performance summary from the first rank in this intraComm." << endl; 
     353 
    296354      report(0) <<" Performance report : Whole time from XIOS init and finalize: "<< CTimer::get("XIOS init/finalize").getCumulatedTime()<<" s"<<endl ; 
    297355      report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ; 
     
    354412 
    355413    /*! 
     414    * \brief Check to see if we are on a rank for which we an output file 
     415    * If reduced output is selected we only write from a single client 
     416    * rank 
     417    */ 
     418    bool CClient::writeLogFromRank() 
     419    { 
     420      bool do_write = false; 
     421      if (!CXios::reduceLogFiles) 
     422      { 
     423        return true; 
     424      } 
     425      if (rank_ == 0) 
     426      { 
     427        do_write = true; 
     428      } 
     429      return do_write; 
     430    } 
     431 
     432    /*! 
    356433    * \brief Open a file stream to write the info logs 
    357434    * Open a file stream with a specific file name suffix+rank 
     
    359436    * \param fileName [in] protype file name 
    360437    */ 
    361     void CClient::openInfoStream(const StdString& fileName) 
    362     { 
    363       std::filebuf* fb = m_infoStream.rdbuf(); 
    364       openStream(fileName, ".out", fb); 
    365  
    366       info.write2File(fb); 
    367       report.write2File(fb); 
     438        void CClient::openInfoStream(const StdString& fileName) 
     439    { 
     440      if (writeLogFromRank()) 
     441      { 
     442        std::filebuf* fb = m_infoStream.rdbuf(); 
     443        openStream(fileName, ".out", fb); 
     444 
     445        info.write2File(fb); 
     446        report.write2File(fb); 
     447      } 
    368448    } 
    369449 
     
    371451    void CClient::openInfoStream() 
    372452    { 
    373       info.write2StdOut(); 
    374       report.write2StdOut(); 
     453      if (writeLogFromRank()) 
     454      { 
     455        info.write2StdOut(); 
     456        report.write2StdOut(); 
     457      } 
    375458    } 
    376459 
     
    378461    void CClient::closeInfoStream() 
    379462    { 
    380       if (m_infoStream.is_open()) m_infoStream.close(); 
    381     } 
     463      if (writeLogFromRank()) 
     464      { 
     465        if (m_infoStream.is_open()) m_infoStream.close(); 
     466      } 
     467    } 
     468 
    382469 
    383470    /*! 
     
    389476    void CClient::openErrorStream(const StdString& fileName) 
    390477    { 
    391       std::filebuf* fb = m_errorStream.rdbuf(); 
    392       openStream(fileName, ".err", fb); 
    393  
    394       error.write2File(fb); 
     478      if (writeLogFromRank()) 
     479      { 
     480        std::filebuf* fb = m_errorStream.rdbuf(); 
     481        openStream(fileName, ".err", fb); 
     482 
     483        error.write2File(fb); 
     484      } 
    395485    } 
    396486 
     
    398488    void CClient::openErrorStream() 
    399489    { 
    400       error.write2StdErr(); 
     490      if (writeLogFromRank()) 
     491      { 
     492        error.write2StdErr(); 
     493      } 
    401494    } 
    402495 
     
    404497    void CClient::closeErrorStream() 
    405498    { 
    406       if (m_errorStream.is_open()) m_errorStream.close(); 
     499      if (writeLogFromRank()) 
     500      { 
     501        if (m_errorStream.is_open()) m_errorStream.close(); 
     502      } 
    407503    } 
    408504} 
Note: See TracChangeset for help on using the changeset viewer.