@@ -38,6 +38,10 @@ std::string SimpleDebugger::loggingFilePath = "sst-console.out";
3838std::string SimpleDebugger::replayFilePath = " sst-console.in" ;
3939bool SimpleDebugger::enLogging = false ;
4040bool 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+
4145SimpleDebugger::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
215223SimpleDebugger::~SimpleDebugger ()
@@ -255,10 +263,11 @@ SimpleDebugger::summary()
255263int
256264SimpleDebugger::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
19371998SimpleDebugger::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
0 commit comments