SST 15.0
Structural Simulation Toolkit
expon.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_RNG_EXPON_H
13#define SST_CORE_RNG_EXPON_H
14
15#include "distrib.h"
16#include "math.h"
17#include "mersenne.h"
18#include "rng.h"
19
20namespace SST::RNG {
21
22/**
23 \class ExponentialDistribution expon.h "sst/core/rng/expon.h"
24
25 Creates an exponential distribution for use within SST. This distribution is the same across
26 platforms and compilers.
27*/
29{
30
31public:
32 /**
33 Creates an exponential distribution with a specific lambda
34 \param mn The lambda of the exponential distribution
35 */
36 explicit ExponentialDistribution(const double mn) :
38 {
39
40 lambda = mn;
42 deleteDistrib = true;
43 }
44
45 /**
46 Creates an exponential distribution with a specific lambda and a base random number generator
47 \param mn The lambda of the exponential distribution
48 \param baseDist The base random number generator to take the distribution from.
49 */
50 ExponentialDistribution(const double mn, Random* baseDist) :
52 {
53
54 lambda = mn;
55 baseDistrib = baseDist;
56 deleteDistrib = false;
57 }
58
59 /**
60 Destroys the exponential distribution
61 */
63 {
64 if ( deleteDistrib ) {
65 delete baseDistrib;
66 }
67 }
68
69 /**
70 Gets the next (random) double value in the distribution
71 \return The next random double from the distribution
72 */
73 double getNextDouble() override
74 {
75 const double next = baseDistrib->nextUniform();
76 return log(1 - next) / (-1 * lambda);
77 }
78
79 /**
80 Gets the lambda with which the distribution was created
81 \return The lambda which the user created the distribution with
82 */
83 double getLambda() { return lambda; }
84
85 /**
86 Default constructor. FOR SERIALIZATION ONLY.
87 */
91
92 /**
93 Serialization function for checkpoint
94 */
96 {
97 SST_SER(lambda);
98 SST_SER(baseDistrib);
99 SST_SER(deleteDistrib);
100 }
101
102 /**
103 Serialization macro
104 */
105 ImplementSerializable(SST::RNG::ExponentialDistribution)
106
107protected:
108 /**
109 Sets the lambda of the exponential distribution.
110 */
111 double lambda;
112 /**
113 Sets the base random number generator for the distribution.
114 */
116
117 /**
118 Controls whether the base distribution should be deleted when this class is destructed.
119 */
121};
122
123} // namespace SST::RNG
124
125using SSTExponentialDistribution = SST::RNG::ExponentialDistribution;
126
127#endif // SST_CORE_RNG_EXPON_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Creates an exponential distribution for use within SST.
Definition expon.h:29
ImplementSerializable(SST::RNG::ExponentialDistribution) protected Random * baseDistrib
Serialization macro.
Definition expon.h:105
double getLambda()
Gets the lambda with which the distribution was created.
Definition expon.h:83
void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization function for checkpoint.
Definition expon.h:95
ExponentialDistribution(const double mn)
Creates an exponential distribution with a specific lambda.
Definition expon.h:36
bool deleteDistrib
Controls whether the base distribution should be deleted when this class is destructed.
Definition expon.h:120
~ExponentialDistribution()
Destroys the exponential distribution.
Definition expon.h:62
double getNextDouble() override
Gets the next (random) double value in the distribution.
Definition expon.h:73
ExponentialDistribution()
Default constructor.
Definition expon.h:88
ExponentialDistribution(const double mn, Random *baseDist)
Creates an exponential distribution with a specific lambda and a base random number generator.
Definition expon.h:50
Implements a Mersenne-based RNG for use in the SST core or components.
Definition mersenne.h:34
RandomDistribution()
Creates the base (abstract) class of a distribution.
Definition distrib.h:41
Implements the base class for random number generators for the SST core.
Definition rng.h:29