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