Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:44

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 celeritas/user/StepTimes.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string>
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/AuxInterface.hh"
0014 #include "corecel/data/AuxStateVec.hh"
0015 
0016 namespace celeritas
0017 {
0018 class AuxParamsRegistry;
0019 struct StepTimesState;
0020 
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Manage state data for recording step times.
0024  *
0025  * This class allocates thread-local state data that can be used to record the
0026  * time of each step on each stream over the run. Because the class that
0027  * invokes the sequence of steps should be shared across threads, the step
0028  * times are stored as auxiliary data rather than locally in that class.
0029  */
0030 class StepTimes : public AuxParamsInterface
0031 {
0032   public:
0033     //!@{
0034     //! \name Type aliases
0035     using SPAuxParamsRegistry = std::shared_ptr<AuxParamsRegistry>;
0036     using VecDbl = std::vector<double>;
0037     //!@}
0038 
0039   public:
0040     // Construct and add to the aux registry
0041     static std::shared_ptr<StepTimes> make_and_insert(
0042         SPAuxParamsRegistry const&, std::string label);
0043 
0044     // Construct from ID and label
0045     StepTimes(AuxId, std::string label);
0046 
0047     //!@{
0048     //! \name Aux interface
0049 
0050     //! Short name for the aux data
0051     std::string_view label() const final { return label_; }
0052     //! Index of this class instance in its registry
0053     AuxId aux_id() const final { return aux_id_; }
0054     // Build core state data for a stream
0055     UPState create_state(MemSpace, StreamId, size_type) const final;
0056     //!@}
0057 
0058     // Access the state
0059     StepTimesState const& state(AuxStateVec const&) const;
0060     StepTimesState& state(AuxStateVec&) const;
0061 
0062   private:
0063     AuxId aux_id_;
0064     std::string label_;
0065 };
0066 
0067 //---------------------------------------------------------------------------//
0068 /*!
0069  * Step times on each thread.
0070  */
0071 struct StepTimesState : public AuxStateInterface
0072 {
0073     StepTimes::VecDbl time;
0074 };
0075 
0076 //---------------------------------------------------------------------------//
0077 }  // namespace celeritas