Skip to content

Commit 8728718

Browse files
authored
TimeConverter updates (#1307)
* Update TimeConverter to include checks for initialization. Add TimeConverter version of Link::setDefaultTimeBase(). * Updated more of core to use TimeConverter instead of TimeConverter*
1 parent 3a9608f commit 8728718

18 files changed

+127
-78
lines changed

src/sst/core/activity.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <cstring>
2323
#include <errno.h>
2424
#include <sstream>
25-
#include <unordered_map>
2625

2726
// Default Priority Settings
2827
#define INTERACTIVEPRIOIRTY 0

src/sst/core/baseComponent.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ BaseComponent::~BaseComponent()
102102
}
103103

104104
void
105-
BaseComponent::setDefaultTimeBaseForLinks(TimeConverter* tc)
105+
BaseComponent::setDefaultTimeBaseForLinks(TimeConverter tc)
106106
{
107107
LinkMap* myLinks = my_info->getLinkMap();
108108
if ( nullptr != myLinks ) {
@@ -314,8 +314,8 @@ BaseComponent::configureLink_impl(const std::string& name, SimTime_t time_base,
314314
my_info->link_map = myLinks;
315315
}
316316
myLinks->insertLink(name, tmp);
317-
// Need to set the link's defaultTimeBase to nullptr
318-
tmp->setDefaultTimeBase(nullptr);
317+
// Need to set the link's defaultTimeBase to uninitialized
318+
tmp->resetDefaultTimeBase();
319319

320320
// Need to see if I got any port_modules, if so, need
321321
// to add them to my_info->portModules
@@ -391,8 +391,8 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
391391
SimTime_t factor = 0;
392392
if ( nullptr != time_base )
393393
factor = time_base->getFactor();
394-
else if ( my_info->defaultTimeBase != nullptr )
395-
factor = my_info->defaultTimeBase->getFactor();
394+
else if ( my_info->defaultTimeBase.isInitialized() )
395+
factor = my_info->defaultTimeBase.getFactor();
396396

397397
return configureLink_impl(name, factor, handler);
398398
}
@@ -420,7 +420,7 @@ BaseComponent::configureLink(const std::string& name, const UnitAlgebra& time_ba
420420
Link*
421421
BaseComponent::configureLink(const std::string& name, Event::HandlerBase* handler)
422422
{
423-
SimTime_t factor = my_info->defaultTimeBase ? my_info->defaultTimeBase->getFactor() : 0;
423+
SimTime_t factor = my_info->defaultTimeBase ? my_info->defaultTimeBase.getFactor() : 0;
424424
return configureLink_impl(name, factor, handler);
425425
}
426426

@@ -726,6 +726,19 @@ BaseComponent::getSubComponentSlotInfo(const std::string& name, bool fatalOnEmpt
726726
return info;
727727
}
728728

729+
TimeConverter*
730+
BaseComponent::getDefaultTimeBase()
731+
{
732+
return Simulation_impl::getTimeLord()->getTimeConverter(my_info->defaultTimeBase.getFactor());
733+
}
734+
735+
736+
const TimeConverter*
737+
BaseComponent::getDefaultTimeBase() const
738+
{
739+
return Simulation_impl::getTimeLord()->getTimeConverter(my_info->defaultTimeBase.getFactor());
740+
}
741+
729742
bool
730743
BaseComponent::doesSubComponentExist(const std::string& type)
731744
{

src/sst/core/baseComponent.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class BaseComponent : public SST::Core::Serialization::serializable_base
161161
Return the simulated time since the simulation began in the
162162
default timebase
163163
*/
164-
inline SimTime_t getCurrentSimTime() const { return getCurrentSimTime(*(my_info->defaultTimeBase)); }
164+
inline SimTime_t getCurrentSimTime() const { return getCurrentSimTime(my_info->defaultTimeBase); }
165165

166166
/**
167167
Return the simulated time since the simulation began in
@@ -879,7 +879,7 @@ class BaseComponent : public SST::Core::Serialization::serializable_base
879879

880880
void configureAllowedStatParams(SST::Params& params);
881881

882-
void setDefaultTimeBaseForLinks(TimeConverter* tc);
882+
void setDefaultTimeBaseForLinks(TimeConverter tc);
883883

884884
void pushValidParams(Params& params, const std::string& type);
885885

@@ -935,12 +935,21 @@ class BaseComponent : public SST::Core::Serialization::serializable_base
935935

936936
bool isUser() { return my_info->isUser(); }
937937

938-
/** Manually set the default detaulTimeBase */
939-
void setDefaultTimeBase(TimeConverter* tc) { my_info->defaultTimeBase = tc; }
938+
/** Manually set the default defaultTimeBase */
939+
[[deprecated("Use of shared TimeConverter objects is deprecated. Use 'setDefaultTimeBase(TimeConverter tc)' "
940+
"(i.e., no TimeConverter pointer) instead.")]] void
941+
setDefaultTimeBase(TimeConverter* tc)
942+
{
943+
my_info->defaultTimeBase = tc;
944+
}
940945

941-
TimeConverter* getDefaultTimeBase() { return my_info->defaultTimeBase; }
946+
/** Manually set the default defaultTimeBase */
947+
void setDefaultTimeBase(TimeConverter tc) { my_info->defaultTimeBase = tc; }
942948

943-
const TimeConverter* getDefaultTimeBase() const { return my_info->defaultTimeBase; }
949+
// Can change this back to inline once we move completely away
950+
// from TimeConverter*
951+
TimeConverter* getDefaultTimeBase(); // { return my_info->defaultTimeBase; }
952+
const TimeConverter* getDefaultTimeBase() const; // { return my_info->defaultTimeBase; }
944953

945954
bool doesSubComponentExist(const std::string& type);
946955

src/sst/core/componentInfo.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ComponentInfo::ComponentInfo(ComponentId_t id, const std::string& name) :
2828
link_map(nullptr),
2929
component(nullptr),
3030
params(nullptr),
31-
defaultTimeBase(nullptr),
3231
portModules(nullptr),
3332
stat_configs_(nullptr),
3433
enabled_stat_names_(nullptr),
@@ -50,7 +49,6 @@ ComponentInfo::ComponentInfo() :
5049
link_map(nullptr),
5150
component(nullptr),
5251
params(nullptr),
53-
defaultTimeBase(nullptr),
5452
portModules(nullptr),
5553
stat_configs_(nullptr),
5654
enabled_stat_names_(nullptr),
@@ -92,7 +90,6 @@ ComponentInfo::ComponentInfo(
9290
link_map(nullptr),
9391
component(nullptr),
9492
params(/*new Params()*/ nullptr),
95-
defaultTimeBase(nullptr),
9693
portModules(nullptr),
9794
stat_configs_(nullptr),
9895
enabled_stat_names_(nullptr),
@@ -116,8 +113,7 @@ ComponentInfo::ComponentInfo(
116113
type(ccomp->type),
117114
link_map(link_map),
118115
component(nullptr),
119-
params(&ccomp->params), // Inaccessible after construction
120-
defaultTimeBase(nullptr),
116+
params(&ccomp->params), // Inaccessible after construction
121117
portModules(&ccomp->portModules), // Inaccessible after construction
122118
enabled_all_stats_(ccomp->enabledAllStats),
123119
statLoadLevel(ccomp->statLoadLevel),
@@ -178,10 +174,10 @@ ComponentInfo::ComponentInfo(ComponentInfo&& o) :
178174
slot_num(o.slot_num),
179175
share_flags(o.share_flags)
180176
{
181-
o.parent_info = nullptr;
182-
o.link_map = nullptr;
183-
o.component = nullptr;
184-
o.defaultTimeBase = nullptr;
177+
o.parent_info = nullptr;
178+
o.link_map = nullptr;
179+
o.component = nullptr;
180+
o.defaultTimeBase.reset();
185181
}
186182

187183
ComponentInfo::~ComponentInfo()
@@ -390,7 +386,7 @@ ComponentInfo::hasLinks() const
390386
//// Functions for testing serialization
391387

392388
ComponentInfo::ComponentInfo(
393-
ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter* tv) :
389+
ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter tv) :
394390
id_(id),
395391
parent_info(nullptr),
396392
name(name),
@@ -411,7 +407,7 @@ ComponentInfo::ComponentInfo(
411407
{}
412408

413409
ComponentInfo*
414-
ComponentInfo::test_addSubComponentInfo(const std::string& name, const std::string& slot_name, TimeConverter* tv)
410+
ComponentInfo::test_addSubComponentInfo(const std::string& name, const std::string& slot_name, TimeConverter tv)
415411
{
416412
// Get next id, which is stored only in the ultimate parent
417413
ComponentInfo* real_comp = this;
@@ -432,7 +428,7 @@ ComponentInfo::test_printComponentInfoHierarchy(int indent)
432428
for ( int i = 0; i < indent; ++i )
433429
printf(" ");
434430
printf("id = %" PRIu64 ", name = %s, slot_name = %s", id_, name.c_str(), slot_name.c_str());
435-
if ( defaultTimeBase != nullptr ) printf(", defaultTimeBase = %" PRI_SIMTIME, defaultTimeBase->getFactor());
431+
if ( defaultTimeBase.isInitialized() ) printf(", defaultTimeBase = %" PRI_SIMTIME, defaultTimeBase.getFactor());
436432
if ( parent_info != nullptr ) printf(", parent_id = %" PRIu64, parent_info->id_);
437433
printf("\n");
438434

src/sst/core/componentInfo.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "sst/core/params.h"
1616
#include "sst/core/serialization/serializer_fwd.h"
1717
#include "sst/core/sst_types.h"
18+
#include "sst/core/timeConverter.h"
1819

1920
#include <functional>
2021
#include <map>
@@ -32,7 +33,6 @@ class ConfigComponent;
3233
class ConfigStatistic;
3334

3435
class Simulation_impl;
35-
class TimeConverter;
3636

3737
namespace Core::Serialization::pvt {
3838
class SerializeBaseComponentHelper;
@@ -110,7 +110,7 @@ class ComponentInfo
110110
*/
111111
Params* params;
112112

113-
TimeConverter* defaultTimeBase;
113+
TimeConverter defaultTimeBase;
114114

115115
std::map<std::string, std::vector<ConfigPortModule>>* portModules = nullptr;
116116
std::map<StatisticId_t, ConfigStatistic>* stat_configs_ = nullptr;
@@ -271,10 +271,11 @@ class ComponentInfo
271271
/**
272272
(DO NOT USE) Constructor used only for serialization testing
273273
*/
274-
ComponentInfo(ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter* tv = nullptr);
274+
ComponentInfo(
275+
ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter tv = TimeConverter());
275276

276277
ComponentInfo*
277-
test_addSubComponentInfo(const std::string& name, const std::string& slot_name, TimeConverter* tv = nullptr);
278+
test_addSubComponentInfo(const std::string& name, const std::string& slot_name, TimeConverter tv = TimeConverter());
278279

279280
void test_printComponentInfoHierarchy(int index = 0);
280281
};

src/sst/core/link.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,12 @@ Link::setDefaultTimeBase(TimeConverter* tc)
870870
defaultTimeBase = tc->getFactor();
871871
}
872872

873+
void
874+
Link::setDefaultTimeBase(TimeConverter tc)
875+
{
876+
defaultTimeBase = tc.getFactor();
877+
}
878+
873879
TimeConverter*
874880
Link::getDefaultTimeBase()
875881
{

src/sst/core/link.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,14 @@ class alignas(64) Link
229229
/** Manually set the default defaultTimeBase
230230
* @param tc TimeConverter object for the timebase
231231
*/
232-
void setDefaultTimeBase(TimeConverter* tc);
232+
[[deprecated("Use of shared TimeConverter objects is deprecated. Use 'setDefaultTimeBase(TimeConverter tc)', "
233+
"(i.e., no pointer) instead.")]] void
234+
setDefaultTimeBase(TimeConverter* tc);
233235

234-
/** Manually set the default time base
235-
* @param factor SimTime_T defining the timebase factor
236+
/** Manually set the default defaultTimeBase
237+
* @param tc TimeConverter object for the timebase
236238
*/
237-
void setDefaultTimeBase(SimTime_t factor) { defaultTimeBase = factor; }
239+
void setDefaultTimeBase(TimeConverter tc);
238240

239241
/** Return the default Time Base for this link
240242
* @return the default Time Base for this link
@@ -385,6 +387,14 @@ class alignas(64) Link
385387
using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
386388
ToolList* attached_tools;
387389

390+
/** Manually set the default time base
391+
* @param factor SimTime_T defining the timebase factor
392+
*/
393+
void setDefaultTimeBase(SimTime_t factor) { defaultTimeBase = factor; }
394+
395+
/** Set the default time base fo uninitialized */
396+
void resetDefaultTimeBase() { defaultTimeBase = 0; }
397+
388398

389399
#ifdef __SST_DEBUG_EVENT_TRACKING__
390400
std::string comp;

src/sst/core/main.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ start_simulation(uint32_t tid, SimThreadInfo_t& info, Core::ThreadSafe::Barrier&
457457
if ( !restart ) {
458458
double start_build = sst_get_cpu_time();
459459

460-
461460
barrier.wait();
462461

463462
sim->processGraphInfo(*info.graph, info.myRank, info.min_part);

src/sst/core/simulation.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Simulation_impl::getEndSimTime() const
9393

9494
/** Simulation_impl functions **/
9595

96-
TimeConverter*
96+
TimeConverter
9797
Simulation_impl::minPartToTC(SimTime_t cycles) const
9898
{
9999
return getTimeLord()->getTimeConverter(cycles);
@@ -1975,7 +1975,7 @@ Simulation_impl::printSimulationState()
19751975
sim_output.output("currentSimCycle: %" PRIu64 "\n", currentSimCycle);
19761976
// sim_output.output("threadMinPartTC: %" PRIu64 "\n", threadMinPartTC->getFactor());
19771977
sim_output.output("minPart: %" PRIu64 "\n", minPart);
1978-
sim_output.output("minPartTC: %" PRIu64 "\n", minPartTC->getFactor());
1978+
sim_output.output("minPartTC: %" PRIu64 "\n", minPartTC.getFactor());
19791979
for ( auto i : interThreadLatencies ) {
19801980
tmp_str = tmp_str + " " + std::to_string(i);
19811981
}
@@ -2139,7 +2139,7 @@ Core::ThreadSafe::Barrier Simulation_impl::exitBarrier;
21392139
Core::ThreadSafe::Barrier Simulation_impl::finishBarrier;
21402140
std::mutex Simulation_impl::simulationMutex;
21412141
Core::ThreadSafe::Spinlock Simulation_impl::cross_thread_lock;
2142-
TimeConverter* Simulation_impl::minPartTC = nullptr;
2142+
TimeConverter Simulation_impl::minPartTC;
21432143
SimTime_t Simulation_impl::minPart;
21442144
std::string Simulation_impl::checkpoint_directory_ = "";
21452145

src/sst/core/simulation_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class Simulation_impl
230230

231231
SimTime_t getInterThreadMinLatency() const { return interThreadMinLatency; }
232232

233-
static TimeConverter* getMinPartTC() { return minPartTC; }
233+
static TimeConverter getMinPartTC() { return minPartTC; }
234234

235235
LinkMap* getComponentLinkMap(ComponentId_t id) const
236236
{
@@ -348,7 +348,7 @@ class Simulation_impl
348348
/** Get a handle to a TimeConverter
349349
* @param cycles Frequency which is the base of the TimeConverter
350350
*/
351-
TimeConverter* minPartToTC(SimTime_t cycles) const;
351+
TimeConverter minPartToTC(SimTime_t cycles) const;
352352

353353
std::string initializeCheckpointInfrastructure(const std::string& prefix);
354354
void scheduleCheckpoint();
@@ -427,10 +427,10 @@ class Simulation_impl
427427

428428
TimeVortex* timeVortex;
429429
std::string timeVortexType; // Required for checkpoint
430-
TimeConverter* threadMinPartTC; // Unused...?
430+
TimeConverter threadMinPartTC; // Unused...?
431431
Activity* current_activity;
432432
static SimTime_t minPart;
433-
static TimeConverter* minPartTC;
433+
static TimeConverter minPartTC;
434434
std::vector<SimTime_t> interThreadLatencies;
435435
SimTime_t interThreadMinLatency;
436436
SyncManager* syncManager;

0 commit comments

Comments
 (0)