Skip to content

Commit 05becbc

Browse files
committed
Fix multithreaded shutdown
1 parent 7f6e470 commit 05becbc

File tree

6 files changed

+36
-29
lines changed

6 files changed

+36
-29
lines changed

src/sst/core/interactiveConsole.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ InteractiveConsole::getComponentObjectMap()
115115
void
116116
InteractiveConsole::simulationShutdown()
117117
{
118-
//Simulation_impl::getSimulation()->endSimulation();
119-
Simulation_impl::getSimulation()->signalShutdown(false);
118+
//Simulation_impl::getSimulation()->endSimulation(); // Only works for single thread
119+
std::cout << "Simulation shutdown\n";
120+
Simulation_impl::getSimulation()->signalShutdown(false); // Works for single thread, hangs for multithread
121+
//Simulation_impl::getSimulation()->setShutdown(false); // doesn't work for single thread - just keeps running
120122
}
121123

122124

src/sst/core/interactiveConsole.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class InteractiveConsole
5757
InteractiveConsole() = default;
5858
virtual ~InteractiveConsole() = default;
5959

60+
enum ICretcode {
61+
DONE = -1,
62+
SUMMARY = -2
63+
};
6064
/** Called by TimeVortex to trigger checkpoint on simulation clock interval - not used in parallel simulation */
6165
virtual int execute(const std::string& msg) = 0;
6266
/** Called by SyncManager to get summary info for each thread */

src/sst/core/simulation.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,29 +1142,23 @@ Simulation_impl::signalShutdown(bool abnormal)
11421142
else {
11431143
shutdown_mode_ = SHUTDOWN_CLEAN;
11441144
}
1145-
#if 1
1146-
endSim = true;
1147-
#else
1145+
11481146
if (num_ranks.rank == 1 && num_ranks.thread == 1) {
1147+
// Set endsim right away if serial
11491148
endSim = true;
11501149
}
11511150
else {
1152-
// skk
1151+
// Otherwise handle shutdown in sync
11531152
enter_shutdown_ = true;
11541153
}
1155-
#endif
1154+
11561155
}
11571156

11581157
void
1159-
Simulation_impl::setShutdown(bool abnormal)
1158+
Simulation_impl::setEndSim()
11601159
{
1161-
if (abnormal) {
1162-
shutdown_mode_ = SHUTDOWN_SIGNAL;
1163-
}
1164-
else {
1165-
shutdown_mode_ = SHUTDOWN_CLEAN;
1166-
}
1167-
enter_shutdown_ = true;
1160+
// Called from sync
1161+
endSim = true;
11681162
}
11691163

11701164
// If this version is called, we need to set the end time in the exit

src/sst/core/simulation_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class Simulation_impl
484484
* Called when action needs to terminate SST
485485
* sets a flag to trigger shutdown at sync, but doesn't endSim
486486
*/
487-
void setShutdown(bool abnormal);
487+
void setEndSim();
488488

489489
/** Normal Shutdown
490490
*/

src/sst/core/sync/syncManager.cc

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,13 @@ void
374374
SyncManager::handleShutdown() {
375375

376376
//ic_barrier_.wait(); // SKK This one may not be necessary...
377-
if (num_ranks_.thread > 1) {
378377
#if 0
379378
// Check for shutdown
380379
Output& out = sim_->getSimulationOutput();
381-
out.output("skk:syncmgr:execute: T%d:endSim=%d, shutdown_mode=%d\n", rank_.thread, sim_->endSim, sim_->shutdown_mode_);
380+
out.output("skk:syncmgr:handleShutdown:Before T%d:endSim=%d, shutdown_mode=%d, enter_shutdown=%d, \n",
381+
rank_.thread, sim_->endSim, sim_->shutdown_mode_, sim_->enter_shutdown_);
382382
#endif
383-
//if (sim_->endSim == true) {
383+
// If my thread enter_shutdown_ is true, then set shared enter_shutdown
384384
if (sim_->enter_shutdown_ == true) {
385385
enter_shutdown_.fetch_or(true);
386386
endSim_.fetch_or(true);
@@ -390,9 +390,9 @@ SyncManager::handleShutdown() {
390390
}
391391
ic_barrier_.wait();
392392
if (endSim_ == true) {
393-
sim_->signalShutdown(shutdown_mode_.load());
393+
sim_->setEndSim();
394+
394395
}
395-
}
396396
}
397397

398398
void
@@ -403,7 +403,7 @@ SyncManager::handleInteractiveConsole()
403403
// Handle interactive console
404404
if (num_ranks_.thread > 1) {
405405

406-
// 1) Check enter interactive and set mask if needed
406+
// 1) Check enter interactive and set mask if needed (could use mask to show triggers)
407407
if (sim_->enter_interactive_ == true) {
408408
unsigned bit = 1UL << rank_.thread;
409409
enter_interactive_mask_.fetch_or(bit);
@@ -412,8 +412,11 @@ SyncManager::handleInteractiveConsole()
412412

413413
// If enter interactive set for any thread
414414
unsigned ic_mask = enter_interactive_mask_.load();
415-
//out.output("skk:syncmgr:execute: T%d: check enter_interactive_=%d\n", rank_.thread, sim_->enter_interactive_);
416-
//out.output("skk:syncmgr:execute: T%d: enter_interactive_mask_=0x%x\n", rank_.thread, ic_mask);
415+
#if 0
416+
Output& out = sim_->getSimulationOutput();
417+
out.output("skk:syncmgr:execute: T%d: check enter_interactive_=%d\n", rank_.thread, sim_->enter_interactive_);
418+
out.output("skk:syncmgr:execute: T%d: enter_interactive_mask_=0x%x\n", rank_.thread, ic_mask);
419+
#endif
417420
if (ic_mask) {
418421
// 2) Print list of threads and whether triggered
419422
for (uint32_t tindex = 0; tindex < num_ranks_.thread; tindex++) {
@@ -429,7 +432,7 @@ SyncManager::handleInteractiveConsole()
429432
else {
430433
std::cout << " (Not Triggered)\n";
431434
}
432-
#if 0 // Print component summary - will be at whatever level was last (maybe print PWD instead?)
435+
#if 0 // Print component summary? - will be at whatever level was last (maybe print PWD instead?)
433436
if (sim_->interactive_ != nullptr) {
434437
sim_->interactive_->summary();
435438
}
@@ -456,13 +459,14 @@ SyncManager::handleInteractiveConsole()
456459
#endif
457460

458461
// 4) Tj: Invoke IC for current thread, with ability to change to new thread
459-
int tid = current_ic_thread_.load();
462+
unsigned int tid = current_ic_thread_.load();
460463
int ic_state = 0;// interactive_state_.load();
461464
while (ic_state != -1) {
462465
if ((rank_.thread == tid) && (sim_->interactive_ != nullptr)) {
466+
// Invoke IC for the thread
463467
int result = sim_->interactive_->execute(sim_->interactive_msg_);
464468

465-
if (result >= 0) { // change thread
469+
if (result >= 0) { // change thread to threadID <result>
466470
current_ic_thread_.store(result);
467471
current_ic_state_.store(0);
468472
}
@@ -471,6 +475,7 @@ SyncManager::handleInteractiveConsole()
471475
}
472476
}
473477
ic_barrier_.wait();
478+
handleShutdown(); // Check if console issued shutdown command
474479
tid = current_ic_thread_.load();
475480
ic_state = current_ic_state_.load();
476481
//out.output("T%d: tid %d, ic_state %d\n", rank_.thread, tid, ic_state);
@@ -611,7 +616,7 @@ SyncManager::execute()
611616
// Handle signals for multi-threaded runs/no MPI
612617
if ( num_ranks_.rank == 1 ) {
613618
signals_received = threadSync_->getSignals(sig_end, sig_usr, sig_alrm);
614-
#if 0
619+
#if 1
615620
Output& out = sim_->getSimulationOutput();
616621
out.output("skk:syncmgr:execute: T%d: sig_end=%d, sig_usr=%d, sig_alrm=%d, received=%d\n",
617622
rank_.thread, sig_end, sig_usr, sig_alrm, signals_received);

src/sst/core/watchPoint.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ void
408408
WatchPoint::simulationShutdown()
409409
{
410410
//Simulation_impl::getSimulation()->signalShutdown(false); // only works for serial mode
411-
Simulation_impl::getSimulation()->setShutdown(false);
411+
Simulation_impl::getSimulation()->signalShutdown(false);
412+
std::cout << "wp simulation shutdown\n";
413+
//Simulation_impl::getSimulation()->setShutdown(false);
412414
}
413415

414416
void

0 commit comments

Comments
 (0)