Skip to content

Commit 0134bd9

Browse files
committed
WIP
1 parent 53cd7c5 commit 0134bd9

File tree

5 files changed

+116
-30
lines changed

5 files changed

+116
-30
lines changed

src/sst/core/impl/interactive/simpleDebug.cc

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ std::string SimpleDebugger::loggingFilePath = "sst-console.out";
3838
std::string SimpleDebugger::replayFilePath = "sst-console.in";
3939
bool SimpleDebugger::enLogging = false;
4040
bool SimpleDebugger::confirm = true;
41+
std::atomic<bool> SimpleDebugger::done{ false };
42+
std::atomic<unsigned> SimpleDebugger::tid_{ 0 };
43+
Core::ThreadSafe::Barrier SimpleDebugger::ic_barrier_;
44+
4145
SimpleDebugger::SimpleDebugger(Params& params) :
4246
InteractiveConsole()
4347
{
@@ -209,7 +213,11 @@ SimpleDebugger::SimpleDebugger(Params& params) :
209213
cmdLineEditor.set_cmd_strings(cmdStrings);
210214

211215
// Callback for directory listing strings
212-
cmdLineEditor.set_listing_callback([this](std::list<std::string>& vec) { get_listing_strings(vec); });
216+
//cmdLineEditor.set_listing_callback([this](std::list<std::string>& vec) { get_listing_strings(vec); });
217+
218+
// Thread sync
219+
RankInfo num_ranks = getNumRanks();
220+
ic_barrier_.resize(num_ranks.thread);
213221
}
214222

215223
SimpleDebugger::~SimpleDebugger()
@@ -255,10 +263,11 @@ SimpleDebugger::summary()
255263
int
256264
SimpleDebugger::execute(const std::string& msg)
257265
{
258-
RankInfo info = getRank();
266+
RankInfo info = getRank();
259267
RankInfo nRanks = getNumRanks();
268+
260269
printf("\n---- Rank%d:Thread%d: Entering interactive mode at time %" PRI_SIMTIME " \n", info.rank, info.thread,
261-
getCurrentSimCycle());
270+
getCurrentSimCycle());
262271
printf("%s\n", msg.c_str());
263272

264273
// Create a new ObjectMap
@@ -267,47 +276,59 @@ SimpleDebugger::execute(const std::string& msg)
267276
// Descend into the name_stack
268277
cd_name_stack();
269278

270-
done = false;
279+
#if 1
280+
done.store(false);
281+
#else
282+
done = false;
283+
#endif
271284
retState = DONE;
272285

273286
// Select the input source and next command line
274-
std::string line;
275-
while ( !done ) {
287+
//std::string line;
288+
static std::string line;
289+
bool squashLogging = false;
290+
while (!done.load()) {
291+
292+
#if 1
293+
//printf("\n---- Rank%d:Thread%d: Enter while loop\n", info.rank, info.thread);
294+
if (info.thread == 0) {
295+
#else
276296
try {
297+
#endif
277298
// User input prompt (except during user command)
278-
if ( eStack.size() == 0 ) std::cout << "> " << std::flush;
299+
if (eStack.size() == 0) std::cout << "> " << std::flush;
279300

280301
// Logging disable has edge cases for stack push/pop
281-
bool squashLogging = false;
302+
squashLogging = false;
282303

283304
// User input prompt
284305
// std::cout << "R" << info.rank << ":T" << info.thread << "> " << std::flush;
285306

286-
if ( !injectedCommand.str().empty() ) {
307+
if (!injectedCommand.str().empty()) {
287308
// Injected commands allow sst command line options to cause actions (currently only replay)
288309
line = injectedCommand.str();
289310
injectedCommand.str("");
290311
std::cout << line << std::endl;
291312
}
292-
else if ( eStack.size() > 0 ) {
313+
else if (eStack.size() > 0) {
293314
// Do no log internals of user defined command
294315
squashLogging = true;
295316
// Execute next instruction in a user defined command
296-
line = eState.next();
297-
if ( eState.ret() ) {
317+
line = eState.next();
318+
if (eState.ret()) {
298319
eState = eStack.top();
299320
eStack.pop();
300321
// back to normal command entry
301-
if ( eStack.size() == 0 ) cmdHistoryBuf.enable(true);
322+
if (eStack.size() == 0) cmdHistoryBuf.enable(true);
302323
}
303324
}
304-
else if ( replayFile.is_open() ) {
325+
else if (replayFile.is_open()) {
305326
// Replay commands from file
306-
if ( std::getline(replayFile, line) ) {
327+
if (std::getline(replayFile, line)) {
307328
std::cout << line << std::endl;
308329
}
309330
else {
310-
if ( replayFile.eof() )
331+
if (replayFile.eof())
311332
std::cout << "(Finished reading from " << replayFilePath << ")" << std::endl;
312333
else
313334
std::cout << "An error occured reading from " << replayFilePath << std::endl;
@@ -316,25 +337,42 @@ SimpleDebugger::execute(const std::string& msg)
316337
}
317338
else {
318339
// Standard Input
319-
if ( !std::cin ) std::cin.clear(); // fix corrupted input after process resumed
340+
if (!std::cin) std::cin.clear(); // fix corrupted input after process resumed
320341
std::cout.flush();
321-
if ( autoCompleteEnable && isatty(STDIN_FILENO) )
342+
std::cout.flush();
343+
if (autoCompleteEnable && isatty(STDIN_FILENO))
322344
cmdLineEditor.getline(cmdHistoryBuf.getBuffer(), line);
323345
else
324346
std::getline(std::cin, line);
325347
}
326348

349+
#if 1
350+
}
351+
ic_barrier_.wait();
352+
if (info.thread == tid_.load()) {
353+
printf("\n---- Rank%d:Thread%d: Dispatch command: %s\n",
354+
info.rank, info.thread, line.c_str());
355+
#endif
356+
327357
// We have a constructed command line. Ship it
328358
dispatch_cmd(line);
329-
330-
// Log commands if enabled and not executing a user defined command
331-
if ( enLogging && !squashLogging ) loggingFile << line.c_str() << std::endl;
332-
// This prevents logging the 'logging' command
333-
if ( loggingFile.is_open() ) enLogging = true;
359+
#if 1
360+
} // end TID command dispatch
361+
ic_barrier_.wait();
362+
if (info.thread == 0) {
363+
#endif
364+
// Log commands if enabled and not executing a user defined command
365+
if (enLogging && !squashLogging) loggingFile << line.c_str() << std::endl;
366+
// This prevents logging the 'logging' command
367+
if (loggingFile.is_open()) enLogging = true;
368+
#if 1 // skk
369+
} // end if thread 0
370+
#else
334371
}
335-
catch ( const std::runtime_error& e ) {
372+
catch (const std::runtime_error& e) {
336373
std::cout << "Parsing error. Ignoring " << line << std::endl;
337374
}
375+
#endif
338376
}
339377
// Save the position on the name_stack, and clear obj_
340378
save_name_stack();
@@ -605,7 +643,11 @@ SimpleDebugger::cmd_info(std::vector<std::string>& UNUSED(tokens))
605643
else {
606644
// Return to syncmanager to print summary for all threads
607645
retState = SUMMARY; // summary info
646+
#if 1
647+
done.store(true);
648+
#else
608649
done = true;
650+
#endif
609651
}
610652
}
611653
else {
@@ -648,10 +690,15 @@ SimpleDebugger::cmd_thread(std::vector<std::string>& tokens)
648690
return false;
649691
}
650692

651-
// If not current thread, set retState and done flag
693+
// If not current thread, retState and done flag
652694
if ( threadID != static_cast<int>(info.thread) ) {
695+
#if 1
696+
tid_.store(threadID);
697+
// Leave done as false now, just reset IC tid
698+
#else
653699
retState = threadID;
654700
done = true;
701+
#endif
655702
}
656703
return true;
657704
}
@@ -703,6 +750,13 @@ SimpleDebugger::get_listing_strings(std::list<std::string>& list)
703750
list.emplace_back(s.str());
704751
}
705752
list.sort();
753+
#if 1
754+
printf("get listing strings\n");
755+
for (auto& x : list) {
756+
std::cout << x << " ";
757+
}
758+
std::cout << std::endl;
759+
#endif
706760
}
707761

708762

@@ -951,8 +1005,11 @@ SimpleDebugger::cmd_run(std::vector<std::string>& tokens)
9511005
printf("Too many arguments for 'run <time>'\n");
9521006
return false;
9531007
}
954-
1008+
#if 1
1009+
done.store(true);
1010+
#else
9551011
done = true;
1012+
#endif
9561013
return true;
9571014
}
9581015

@@ -1927,7 +1984,11 @@ SimpleDebugger::cmd_exit(std::vector<std::string>& UNUSED(tokens))
19271984
else {
19281985
std::cout << "Exiting ObjectExplorer without clearning watchpoints\n";
19291986
}
1987+
#if 1
1988+
done.store(true);
1989+
#else
19301990
done = true;
1991+
#endif
19311992
return true;
19321993
}
19331994

@@ -1937,7 +1998,11 @@ bool
19371998
SimpleDebugger::cmd_shutdown(std::vector<std::string>& UNUSED(tokens))
19381999
{
19392000
simulationShutdown();
2001+
#if 1
2002+
done.store(true);
2003+
#else
19402004
done = true;
2005+
#endif
19412006
printf("Exiting ObjectExplorer and shutting down simulation\n");
19422007
return true;
19432008
}
@@ -2285,4 +2350,6 @@ CommandRegistry::addHelp(std::string key, std::vector<std::string>& vec)
22852350
}
22862351

22872352

2353+
2354+
22882355
} // namespace SST::IMPL::Interactive

src/sst/core/impl/interactive/simpleDebug.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class SimpleDebugger : public SST::InteractiveConsole
269269
std::deque<std::string> name_stack;
270270
271271
SST::Core::Serialization::ObjectMap* obj_ = nullptr;
272-
bool done = false;
272+
//bool done = false;
273+
static std::atomic<bool> done;
273274
int retState = -1; // -1 DONE, -2 SUMMARY, positive number is threadID
274275
275276
void save_name_stack();
@@ -369,6 +370,11 @@ class SimpleDebugger : public SST::InteractiveConsole
369370
// Verbosity controlled console printing
370371
uint32_t verbosity = 0;
371372
void msg(VERBOSITY_MASK mask, std::string message);
373+
374+
// Thread Control // skk
375+
static std::atomic<unsigned> tid_;
376+
//static std::string line;
377+
static Core::ThreadSafe::Barrier ic_barrier_;
372378
};
373379
374380
} // namespace SST::IMPL::Interactive

src/sst/core/simulation.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Simulation_impl::Simulation_impl(
337337
new CheckpointAction(&config, my_rank, this, timeLord.getTimeConverter(config.checkpoint_sim_period()));
338338
checkpoint_action_->insertIntoTimeVortex(this);
339339
}
340-
else {
340+
else { // skk Why do we insert checkpoint action for ALL threads with no time?
341341
checkpoint_action_ = new CheckpointAction(&config, my_rank, this, nullptr);
342342
checkpoint_action_->insertIntoTimeVortex(this);
343343
}
@@ -997,6 +997,11 @@ Simulation_impl::setup_interactive_mode()
997997
void
998998
Simulation_impl::run()
999999
{
1000+
#if 1 //SKK
1001+
1002+
sim_output.output("RUN: Rank: %d, Thread: %d\n", my_rank.rank, my_rank.thread);
1003+
1004+
#endif
10001005
#if SST_PERFORMANCE_INSTRUMENTING
10011006
std::string filename = "rank_" + std::to_string(my_rank.rank);
10021007
filename += "_thread_" + std::to_string(my_rank.thread);

src/sst/core/simulation_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class Simulation_impl
511511
clockMap_t clockMap;
512512
static Exit* m_exit;
513513
SimulatorHeartbeat* m_heartbeat = nullptr;
514-
CheckpointAction* checkpoint_action_;
514+
CheckpointAction* checkpoint_action_; // skk all threads share ckpt action?
515515
static std::string checkpoint_directory_;
516516
bool endSim = false;
517517
bool independent; // true if no links leave thread (i.e. no syncs required)
@@ -525,7 +525,7 @@ class Simulation_impl
525525
std::string interactive_type_ = "";
526526
std::string interactive_start_ = "";
527527
std::string replay_file_ = "";
528-
InteractiveConsole* interactive_ = nullptr;
528+
InteractiveConsole* interactive_ = nullptr; // skk all threads share IC
529529
bool enter_interactive_ = false;
530530
std::string interactive_msg_;
531531
SimTime_t stop_at_ = 0;

src/sst/core/sync/syncManager.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,15 @@ SyncManager::handleInteractiveConsole()
458458
ic_barrier_.wait();
459459
#endif
460460
// 4) Tj: Invoke IC for current thread, with ability to change to new thread
461+
462+
#if 1
463+
int result = sim_->interactive_->execute(sim_->interactive_msg_);
464+
handleShutdown(); // Check if console issued shutdown command
465+
#else
461466
unsigned int tid = current_ic_thread_.load();
462467
int ic_state = 0;
463468
while ( ic_state != InteractiveConsole::ICretcode::DONE ) {
469+
464470
if ( (rank_.thread == tid) && (sim_->interactive_ != nullptr) ) {
465471
// Invoke IC for the thread and capture return state
466472
int result = sim_->interactive_->execute(sim_->interactive_msg_);
@@ -474,6 +480,7 @@ SyncManager::handleInteractiveConsole()
474480
}
475481
}
476482
ic_barrier_.wait();
483+
477484
handleShutdown(); // Check if console issued shutdown command
478485
479486
tid = current_ic_thread_.load();
@@ -494,6 +501,7 @@ SyncManager::handleInteractiveConsole()
494501
current_ic_state_.store(0);
495502
} // if state == SUMMARY, print thread info summary
496503
}
504+
#endif
497505

498506
// 5) When done, clear interactive mask and enter interactive flags for next round
499507
if ( rank_.thread == 0 ) {

0 commit comments

Comments
 (0)