Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:27:19

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file accel/TimeOutput.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <unordered_map>
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/io/OutputInterface.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Collect timing results and output at the end of a run.
0020  *
0021  * Setup time and total time are always recorded. Event time is recorded if \c
0022  * BeginOfEventAction and \c EndOfEventAction are called. The accumulated
0023  * action times are recorded when running on the host or on the device with
0024  * synchronization enabled.
0025  *
0026  * All results are in units of seconds.
0027  */
0028 class TimeOutput final : public OutputInterface
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using MapStrReal = std::unordered_map<std::string, real_type>;
0034     //!@}
0035 
0036   public:
0037     // Construct with number of CPU threads
0038     explicit TimeOutput(size_type num_threads);
0039 
0040     //!@{
0041     //! \name Output interface
0042 
0043     //! Category of data to write
0044     Category category() const final { return Category::result; }
0045     //! Key for the entry inside the category.
0046     std::string_view label() const final { return "time"; }
0047     // Write output to the given JSON object
0048     void output(JsonPimpl*) const final;
0049     //!@}
0050 
0051     // Record the accumulated action times
0052     void RecordActionTime(MapStrReal&& time);
0053 
0054     // Record the time for the event
0055     void RecordEventTime(real_type time);
0056 
0057     // Record the Celeritas setup time
0058     void RecordSetupTime(real_type time);
0059 
0060     // Record the total time for the run
0061     void RecordTotalTime(real_type time);
0062 
0063   private:
0064     using VecReal = std::vector<real_type>;
0065 
0066     std::vector<MapStrReal> action_time_;
0067     std::vector<VecReal> event_time_;
0068     real_type setup_time_;
0069     real_type total_time_;
0070 };
0071 
0072 //---------------------------------------------------------------------------//
0073 }  // namespace celeritas