Skip to content

Commit f642e80

Browse files
authored
Moved primary component functions into BaseComponent, allowing (#1328)
SubComponents and ComponentExtensions access to the APIs. Updated Exit object. - BaseComponent now tracks current primary component exit state and provides errors and warnings when primaryComponent functions are called in unsupported ways - Exit object no longer tracks the components that are registered with it - Exit object is no longer serialized on checkpoint. A new Exit object is created on restart and Components will reregister with the Exit object on restart if they are in the DoNotEndSim state.
1 parent 8d54573 commit f642e80

35 files changed

+649
-509
lines changed

src/sst/core/baseComponent.cc

Lines changed: 149 additions & 80 deletions
Large diffs are not rendered by default.

src/sst/core/baseComponent.h

Lines changed: 219 additions & 45 deletions
Large diffs are not rendered by default.

src/sst/core/component.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,6 @@ Component::Component(ComponentId_t id) :
3131
// currentlyLoadingSubComponent = my_info;
3232
}
3333

34-
void
35-
Component::registerAsPrimaryComponent()
36-
{
37-
// Nop for now. Will put in complete semantics later
38-
}
39-
40-
void
41-
Component::primaryComponentDoNotEndSim()
42-
{
43-
int thread = Simulation_impl::getSimulation()->getRank().thread;
44-
Simulation_impl::getSimulation()->getExit()->refInc(getId(), thread);
45-
}
46-
47-
void
48-
Component::primaryComponentOKToEndSim()
49-
{
50-
int thread = Simulation_impl::getSimulation()->getRank().thread;
51-
Simulation_impl::getSimulation()->getExit()->refDec(getId(), thread);
52-
}
53-
5434

5535
void
5636
Component::serialize_order(SST::Core::Serialization::serializer& ser)

src/sst/core/component.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,47 +50,6 @@ class Component : public BaseComponent
5050
explicit Component(ComponentId_t id);
5151
virtual ~Component() override = default;
5252

53-
/** Register as a primary component, which allows the component to
54-
specify when it is and is not OK to end simulation. The
55-
simulator will not end simulation naturally (through use of
56-
the Exit object) while any primary component has specified
57-
primaryComponentDoNotEndSim(). However, it is still possible
58-
for Actions other than Exit to end simulation. Once all
59-
primary components have specified
60-
primaryComponentOKToEndSim(), the Exit object will trigger and
61-
end simulation.
62-
63-
This must be called during simulation wireup (i.e during the
64-
constructor for the component). By default, the state of the
65-
primary component is set to OKToEndSim.
66-
67-
If no component registers as a primary component, then the
68-
Exit object will not be used for that simulation and
69-
simulation termination must be accomplished through some other
70-
mechanism (e.g. --stopAt flag, or some other Action object).
71-
72-
@sa Component::primaryComponentDoNotEndSim()
73-
@sa Component::primaryComponentOKToEndSim()
74-
*/
75-
void registerAsPrimaryComponent();
76-
77-
/** Tells the simulation that it should not exit. The component
78-
will remain in this state until a call to
79-
primaryComponentOKToEndSim().
80-
81-
@sa Component::registerAsPrimaryComponent()
82-
@sa Component::primaryComponentOKToEndSim()
83-
*/
84-
void primaryComponentDoNotEndSim();
85-
86-
/** Tells the simulation that it is now OK to end simulation.
87-
Simulation will not end until all primary components have
88-
called this function.
89-
90-
@sa Component::registerAsPrimaryComponent()
91-
@sa Component::primaryComponentDoNotEndSim()
92-
*/
93-
void primaryComponentOKToEndSim();
9453

9554
void serialize_order(SST::Core::Serialization::serializer& ser) override;
9655
ImplementSerializable(SST::Component)

src/sst/core/componentExtension.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace SST {
1818
ComponentExtension::ComponentExtension(ComponentId_t id) :
1919
BaseComponent(id)
2020
{
21-
isExtension = true;
21+
setAsExtension();
2222
}
2323

2424
void

src/sst/core/componentInfo.cc

Lines changed: 1 addition & 4 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-
portModules(nullptr),
3231
stat_configs_(nullptr),
3332
enabled_stat_names_(nullptr),
3433
enabled_all_stats_(false),
@@ -49,7 +48,6 @@ ComponentInfo::ComponentInfo() :
4948
link_map(nullptr),
5049
component(nullptr),
5150
params(nullptr),
52-
portModules(nullptr),
5351
stat_configs_(nullptr),
5452
enabled_stat_names_(nullptr),
5553
enabled_all_stats_(false),
@@ -89,7 +87,6 @@ ComponentInfo::ComponentInfo(ComponentId_t id, ComponentInfo* parent_info, const
8987
link_map(nullptr),
9088
component(nullptr),
9189
params(/*new Params()*/ nullptr),
92-
portModules(nullptr),
9390
stat_configs_(nullptr),
9491
enabled_stat_names_(nullptr),
9592
enabled_all_stats_(false),
@@ -184,7 +181,7 @@ ComponentInfo::~ComponentInfo()
184181
{
185182
if ( link_map ) delete link_map;
186183
if ( component ) {
187-
component->my_info = nullptr;
184+
component->my_info_ = nullptr;
188185
delete component;
189186
}
190187

src/sst/core/exit.cc

Lines changed: 38 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -24,113 +24,68 @@ namespace SST {
2424

2525
Exit::Exit(int num_threads, bool single_rank) :
2626
Action(),
27-
// m_functor( new EventHandler<Exit,bool,Event*> (this,&Exit::handler ) ),
28-
num_threads(num_threads),
29-
m_refCount(0),
30-
end_time(0),
31-
single_rank(single_rank)
27+
num_threads_(num_threads),
28+
single_rank_(single_rank)
3229
{
3330
setPriority(EXITPRIORITY);
34-
m_thread_counts = new unsigned int[num_threads];
35-
for ( int i = 0; i < num_threads; i++ ) {
36-
m_thread_counts[i] = 0;
31+
thread_counts_ = new unsigned int[num_threads_];
32+
for ( int i = 0; i < num_threads_; i++ ) {
33+
thread_counts_[i] = 0;
3734
}
3835
}
3936

4037
Exit::~Exit()
4138
{
42-
m_idSet.clear();
39+
delete[] thread_counts_;
4340
}
4441

45-
bool
46-
Exit::refInc(ComponentId_t id, uint32_t thread)
42+
void
43+
Exit::refInc(uint32_t thread)
4744
{
48-
std::lock_guard<Spinlock> lock(slock);
49-
if ( m_idSet.find(id) != m_idSet.end() ) {
50-
// CompMap_t comp_map = Simulation_impl::getSimulation()->getComponentMap();
51-
// bool found_in_map = false;
52-
53-
// for(CompMap_t::iterator comp_map_itr = comp_map.begin();
54-
// comp_map_itr != comp_map.end();
55-
// ++comp_map_itr) {
56-
57-
// if(comp_map_itr->second->getId() == id) {
58-
// found_in_map = true;
59-
// break;
60-
// }
61-
// }
62-
63-
// if(found_in_map) {
64-
// _DBG( Exit, "component (%s) multiple increment\n",
65-
// Simulation_impl::getSimulation()->getComponent(id)->getName().c_str() );
66-
// } else {
67-
// _DBG( Exit, "component in construction increments exit multiple times.\n" );
68-
// }
69-
return true;
70-
}
71-
72-
m_idSet.insert(id);
73-
74-
++m_refCount;
75-
++m_thread_counts[thread];
76-
77-
return false;
45+
std::lock_guard<Spinlock> lock(slock_);
46+
++ref_count_;
47+
++thread_counts_[thread];
7848
}
7949

80-
bool
81-
Exit::refDec(ComponentId_t id, uint32_t thread)
50+
void
51+
Exit::refDec(uint32_t thread)
8252
{
83-
std::lock_guard<Spinlock> lock(slock);
84-
if ( m_idSet.find(id) == m_idSet.end() ) {
85-
Simulation_impl::getSimulation()->getSimulationOutput().verbose(CALL_INFO, 1, 1,
86-
"component (%s) multiple decrement\n",
87-
Simulation_impl::getSimulation()->getComponent(id)->getName().c_str());
88-
return true;
89-
}
90-
91-
if ( m_refCount == 0 ) {
92-
Simulation_impl::getSimulation()->getSimulationOutput().fatal(CALL_INFO, 1, "refCount is already 0\n");
93-
return true;
53+
std::lock_guard<Spinlock> lock(slock_);
54+
if ( ref_count_ == 0 ) {
55+
Simulation_impl::getSimulation()->getSimulationOutput().fatal(CALL_INFO, 1, "ref_count is already 0\n");
9456
}
9557

96-
m_idSet.erase(id);
58+
--ref_count_;
59+
--thread_counts_[thread];
9760

98-
--m_refCount;
99-
--m_thread_counts[thread];
100-
101-
if ( single_rank && num_threads == 1 && m_refCount == 0 ) {
102-
end_time = Simulation_impl::getSimulation()->getCurrentSimCycle();
61+
if ( single_rank_ && num_threads_ == 1 && ref_count_ == 0 ) {
62+
end_time_ = Simulation_impl::getSimulation()->getCurrentSimCycle();
10363
Simulation_impl* sim = Simulation_impl::getSimulation();
10464
sim->insertActivity(sim->getCurrentSimCycle() + 1, this);
10565
}
106-
else if ( m_thread_counts[thread] == 0 ) {
66+
else if ( thread_counts_[thread] == 0 ) {
10767
SimTime_t end_time_new = Simulation_impl::getSimulation()->getCurrentSimCycle();
108-
if ( end_time_new > end_time ) end_time = end_time_new;
68+
if ( end_time_new > end_time_ ) end_time_ = end_time_new;
10969
if ( Simulation_impl::getSimulation()->isIndependentThread() ) {
11070
// Need to exit just this thread, so we'll need to use a
11171
// StopAction
11272
Simulation_impl* sim = Simulation_impl::getSimulation();
11373
sim->insertActivity(sim->getCurrentSimCycle(), new StopAction());
11474
}
11575
}
116-
117-
return false;
11876
}
11977

12078
unsigned int
12179
Exit::getRefCount()
12280
{
123-
return m_refCount;
81+
return ref_count_;
12482
}
12583

12684
void
12785
Exit::execute()
12886
{
129-
check();
130-
13187
// Only gets put into queue once, no need to reschedule
132-
// SimTime_t next = Simulation_impl::getSimulation()->getCurrentSimCycle() + m_period->getFactor();
133-
// Simulation_impl::getSimulation()->insertActivity(next, this);
88+
check();
13489
}
13590

13691
SimTime_t
@@ -139,25 +94,25 @@ Exit::computeEndTime()
13994
#ifdef SST_CONFIG_HAVE_MPI
14095
// Do an all_reduce to get the end_time
14196
SimTime_t end_value;
142-
if ( !single_rank ) {
143-
MPI_Allreduce(&end_time, &end_value, 1, MPI_UINT64_T, MPI_MAX, MPI_COMM_WORLD);
144-
end_time = end_value;
97+
if ( !single_rank_ ) {
98+
MPI_Allreduce(&end_time_, &end_value, 1, MPI_UINT64_T, MPI_MAX, MPI_COMM_WORLD);
99+
end_time_ = end_value;
145100
}
146101
#endif
147-
if ( single_rank ) {
148-
endSimulation(end_time);
102+
if ( single_rank_ ) {
103+
endSimulation(end_time_);
149104
}
150-
return end_time;
105+
return end_time_;
151106
}
152107

153108
void
154109
Exit::check()
155110
{
156-
int value = (m_refCount > 0);
111+
int value = (ref_count_ > 0);
157112
int out;
158113

159114
#ifdef SST_CONFIG_HAVE_MPI
160-
if ( !single_rank ) {
115+
if ( !single_rank_ ) {
161116
MPI_Allreduce(&value, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
162117
}
163118
else {
@@ -166,44 +121,19 @@ Exit::check()
166121
#else
167122
out = value;
168123
#endif
169-
global_count = out;
124+
global_count_ = out;
170125
// If out is 0, then it's time to end
171126
if ( !out ) {
172127
computeEndTime();
173128
}
174-
// else {
175-
// // Reinsert into TimeVortex. We do this even when ending so that
176-
// // it will get deleted with the TimeVortex on termination. We do
177-
// // this in case we exit with a StopEvent instead. In that case,
178-
// // there is no way to know if the Exit object is deleted in the
179-
// // TimeVortex or not, so we just make sure it is always deleted
180-
// // there.
181-
// Simulation *sim = Simulation_impl::getSimulation();
182-
// SimTime_t next = sim->getCurrentSimCycle() +
183-
// sim->insertActivity( next, this );
184-
// }
185129
}
186130

187-
void
188-
Exit::serialize_order(SST::Core::Serialization::serializer& ser)
131+
std::string
132+
Exit::toString() const
189133
{
190-
Action::serialize_order(ser);
191-
192-
SST_SER(num_threads);
193-
194-
if ( ser.mode() == SST::Core::Serialization::serializer::UNPACK ) {
195-
m_thread_counts = new unsigned int[num_threads];
196-
}
197-
198-
for ( int i = 0; i < num_threads; i++ ) {
199-
SST_SER(m_thread_counts[i]);
200-
}
201-
202-
SST_SER(m_refCount);
203-
SST_SER(global_count);
204-
SST_SER(m_idSet);
205-
SST_SER(end_time);
206-
SST_SER(single_rank);
134+
std::stringstream buf;
135+
buf << "Exit Action to be delivered at " << getDeliveryTime() << " with priority " << getPriority();
136+
return buf.str();
207137
}
208138

209139
} // namespace SST

0 commit comments

Comments
 (0)