@@ -24,113 +24,68 @@ namespace SST {
2424
2525Exit::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
4037Exit::~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
12078unsigned int
12179Exit::getRefCount ()
12280{
123- return m_refCount ;
81+ return ref_count_ ;
12482}
12583
12684void
12785Exit::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
13691SimTime_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
153108void
154109Exit::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