SST  14.1.0
StructuralSimulationToolkit
timeVortexPQ.h
1 // Copyright 2009-2024 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-2024, 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/eli/elementinfo.h"
16 #include "sst/core/timeVortex.h"
17 
18 #include <functional>
19 #include <queue>
20 #include <vector>
21 
22 namespace SST {
23 
24 class Output;
25 
26 namespace IMPL {
27 
28 
29 /**
30  * Primary Event Queue
31  */
32 template <bool TS>
34 {
35 
36 public:
37  // TimeVortexPQ();
38  TimeVortexPQBase(Params& params);
39  TimeVortexPQBase(); // For serialization only
41 
42  bool empty() override;
43  int size() override;
44  void insert(Activity* activity) override;
45  Activity* pop() override;
46  Activity* front() override;
47 
48  /** Print the state of the TimeVortex */
49  void print(Output& out) const override;
50 
51  uint64_t getCurrentDepth() const override { return current_depth; }
52  uint64_t getMaxDepth() const override { return max_depth; }
53 
54  void dbg_print(Output& out) override;
55 
56  void serialize_order(SST::Core::Serialization::serializer& ser) override;
57 
58  virtual void fixup_handlers() override;
59 
60 private:
61  typedef std::priority_queue<Activity*, std::vector<Activity*>, Activity::greater<true, true, true>> dataType_t;
62 
63  template <class T, class S, class C>
64  S& getContainer(std::priority_queue<T, S, C>& q)
65  {
66  struct UnderlyingContainer : std::priority_queue<T, S, C>
67  {
68  static S& getUnderlyingContainer(std::priority_queue<T, S, C>& q) { return q.*&UnderlyingContainer::c; }
69  };
70  return UnderlyingContainer::getUnderlyingContainer(q);
71  }
72 
73  // Data
74  dataType_t data;
75  uint64_t insertOrder;
76 
77  // Stats about usage
78  uint64_t max_depth;
79 
80  // Need current depth to be atomic if we are thread safe
81  typename std::conditional<TS, std::atomic<uint64_t>, uint64_t>::type current_depth;
82 
83  CACHE_ALIGNED(SST::Core::ThreadSafe::Spinlock, slock);
84 };
85 
86 
87 } // namespace IMPL
88 } // namespace SST
89 
90 #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:53
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
void insert(Activity *activity) override
Insert a new activity into the queue.
Definition: timeVortexPQ.cc:67
Base class for all Activities in the SST Event Queue.
Definition: activity.h:46
Primary Event Queue.
Definition: timeVortex.h:27
Definition: action.cc:18
Activity * pop() override
Remove and return the next activity.
Definition: timeVortexPQ.cc:79
int size() override
Returns the number of activities in the queue.
Definition: timeVortexPQ.cc:57
Primary Event Queue.
Definition: timeVortexPQ.h:33
Definition: threadsafe.h:121
void print(Output &out) const override
Print the state of the TimeVortex.
Definition: timeVortexPQ.cc:102
Class to use as the greater than operator for STL functions or sorting algorithms (used if you want t...
Definition: activity.h:103
Parameter store.
Definition: params.h:55
bool empty() override
Returns true if the queue is empty.
Definition: timeVortexPQ.cc:47
Activity * front() override
Returns the next activity.
Definition: timeVortexPQ.cc:92