SST  15.1.0
StructuralSimulationToolkit
timeVortexPQ.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_IMPL_TIMEVORTEX_TIMEVORTEXPQ_H
13 #define SST_CORE_IMPL_TIMEVORTEX_TIMEVORTEXPQ_H
14 
15 #include "sst/core/activity.h"
16 #include "sst/core/eli/elementinfo.h"
17 #include "sst/core/threadsafe.h"
18 #include "sst/core/timeVortex.h"
19 
20 #include <atomic>
21 #include <cstdint>
22 #include <functional>
23 #include <queue>
24 #include <vector>
25 
26 namespace SST {
27 
28 class Output;
29 
30 namespace IMPL {
31 
32 
33 /**
34  * Primary Event Queue
35  */
36 template <bool TS>
38 {
39 
40 public:
41  // TimeVortexPQ();
42  explicit TimeVortexPQBase(Params& params);
43  TimeVortexPQBase() = delete;
45 
46  bool empty() override;
47  int size() override;
48  void insert(Activity* activity) override;
49  Activity* pop() override;
50  Activity* front() override;
51 
52  uint64_t getCurrentDepth() const override { return current_depth; }
53  uint64_t getMaxDepth() const override { return max_depth; }
54 
55  void dbg_print(Output& out) const override;
56 
57  void getContents(std::vector<Activity*>& activities) const override;
58 
59 private:
60  using dataType_t = std::priority_queue<Activity*, std::vector<Activity*>, Activity::greater<true, true, true>>;
61 
62  // Get a const reference to the underlying data
63  const std::vector<Activity*>& getContainer() const
64  {
65  struct UnderlyingContainer : dataType_t
66  {
67  using dataType_t::c; // access protected container
68  };
69  return static_cast<const UnderlyingContainer&>(data).c;
70  }
71 
72  // Data
73  dataType_t data;
74  uint64_t insertOrder;
75 
76  // Stats about usage
77  uint64_t max_depth;
78 
79  // Need current depth to be atomic if we are thread safe
80  std::conditional_t<TS, std::atomic<uint64_t>, uint64_t> current_depth;
81 
82  CACHE_ALIGNED(SST::Core::ThreadSafe::Spinlock, slock);
83 };
84 
85 
86 } // namespace IMPL
87 } // namespace SST
88 
89 #endif // SST_CORE_IMPL_TIMEVORTEX_TIMEVORTEXPQ_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
void getContents(std::vector< Activity *> &activities) const override
Get a copy of the contents of the TimeVortex.
Definition: timeVortexPQ.cc:112
void insert(Activity *activity) override
Insert a new activity into the queue.
Definition: timeVortexPQ.cc:62
Base class for all Activities in the SST Event Queue.
Definition: activity.h:47
Primary Event Queue.
Definition: timeVortex.h:31
Definition: action.cc:18
Activity * pop() override
Remove and return the next activity.
Definition: timeVortexPQ.cc:76
int size() override
Returns the number of activities in the queue.
Definition: timeVortexPQ.cc:52
Primary Event Queue.
Definition: timeVortexPQ.h:37
Definition: threadsafe.h:135
Class to use as the greater than operator for STL functions or sorting algorithms (used if you want t...
Definition: activity.h:108
Parameter store.
Definition: params.h:63
bool empty() override
Returns true if the queue is empty.
Definition: timeVortexPQ.cc:42
Activity * front() override
Returns the next activity.
Definition: timeVortexPQ.cc:89