Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/sst/core/checkpointAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ CheckpointAction::execute()
void
CheckpointAction::createCheckpoint(Simulation_impl* sim)
{

if ( 0 == rank_.rank && 0 == rank_.thread ) {
const double now = sst_get_cpu_time();
sim->getSimulationOutput().output(
Expand Down Expand Up @@ -212,9 +213,11 @@ CheckpointAction::createCheckpoint(Simulation_impl* sim)
// No need to barrier here since rank 0 thread 0 will be the first
// to execute in the loop below and everything else will wait
for ( uint32_t r = 0; r < num_ranks.rank; ++r ) {

if ( r == rank_.rank ) {
// If this is my rank go ahead
for ( uint32_t t = 0; t < num_ranks.thread; ++t ) {

// If this is my thread go ahead
if ( t == rank_.thread ) {
sim->checkpoint_append_registry(directory + "/" + registry_name, filename);
Expand Down Expand Up @@ -254,6 +257,11 @@ CheckpointAction::createCheckpoint(Simulation_impl* sim)
SimTime_t
CheckpointAction::check(SimTime_t current_time)
{
#if 0
Simulation_impl* sim = Simulation_impl::getSimulation();
sim->getSimulationOutput().output(
"skk:T %d: checkpointAction.cc: check()\n", rank_.thread);
#endif
// The if-logic is a little weird, but it's trying to minimize the
// number of branches in the normal case of no checkpoint being
// initiated. This will also handle the case where both a sim and
Expand All @@ -271,6 +279,11 @@ CheckpointAction::check(SimTime_t current_time)
return next_sim_time_;
}

bool
CheckpointAction::getCheckpoint()
{
return generate_;
}
void
CheckpointAction::setCheckpoint()
{
Expand Down Expand Up @@ -331,6 +344,14 @@ initializeCheckpointInfrastructure(Config* cfg, bool rt_can_ckpt, int myRank)
std::string checkpoint_dir_name = "";

if ( myRank == 0 ) {
// Verify prefix format (no '/')
const std::string prefix = cfg->checkpoint_prefix();
size_t foundPos = prefix.find('/');
if ( foundPos != std::string::npos ) {
throw std::invalid_argument("Invalid checkpoint prefix: " + prefix);
}

// Create checkpoint directory path
SST::Util::Filesystem& fs = Simulation_impl::getSimulation()->filesystem;
checkpoint_dir_name = fs.createUniqueDirectory(cfg->checkpoint_prefix());
}
Expand Down
3 changes: 3 additions & 0 deletions src/sst/core/checkpointAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class CheckpointAction : public Action
*/
void insertIntoTimeVortex(Simulation_impl* sim);

/** Get checkpoint flag */
bool getCheckpoint();

/** Generate a checkpoint next time check() is called */
void setCheckpoint();

Expand Down
87 changes: 72 additions & 15 deletions src/sst/core/impl/interactive/cmdLineEditor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "sst/core/impl/interactive/cmdLineEditor.h"

#include "cmdLineEditor.h"

#include <algorithm>
#include <cerrno>
#include <cstring>
Expand Down Expand Up @@ -119,18 +121,52 @@ CmdLineEditor::selectMatches(const std::list<std::string>& list, const std::stri
newtoken = matches[0] + " ";
return true;
}
else if ( matches.size() > 0 ) {
// list all matching strings
writeStr("\n");
for ( const std::string& s : matches ) {
writeStr(s);
writeStr(" ");
}
writeStr("\n");
if ( matches.size() == 0 ) return false;

if ( tab_state == TAB_STATE::FILL_COMMON ) {
// find and fill in the longest common string
newtoken = findLongestCommonPrefix(matches);
tab_state = TAB_STATE::LIST_COMMON;
#ifdef _KEYB_DEBUG_
dbgFile << "tab_state <- LIST_COMMON" << std::endl;
#endif
return true;
}

// Handle TAB_STATE::LIST_COMMON)
writeStr("\n");
for ( const std::string& s : matches ) {
writeStr(s);
writeStr(" ");
}
writeStr("\n");

return false;
}

std::string
CmdLineEditor::findLongestCommonPrefix(const std::vector<std::string>& strings)
{
if ( strings.empty() ) return "";
const std::string& first_str = strings[0];
int prefix_length = 0;
for ( size_t i = 0; i < first_str.length(); ++i ) {
char currentChar = first_str[i];
bool allMatch = true;
for ( size_t j = 1; j < strings.size(); ++j ) {
if ( i >= strings[j].length() || strings[j][i] != currentChar ) {
allMatch = false;
break;
}
}
if ( allMatch )
prefix_length++;
else
break;
}
return first_str.substr(0, prefix_length);
}

void
CmdLineEditor::flush_bad_escape()
{
Expand Down Expand Up @@ -167,8 +203,8 @@ CmdLineEditor::auto_complete(std::string& cmd)
else if ( tokens.size() == 1 && !hasTrailingSpace ) {
// find all matching command strings starting with tokens[0]
std::vector<std::string> matches;
bool exact_match = selectMatches(cmdStrings, tokens[0], matches, cmd);
if ( exact_match ) {
bool fill_line = selectMatches(cmdStrings, tokens[0], matches, cmd);
if ( fill_line ) {
curpos = cmd.size() + prompt.size() + 1;
#ifdef _KEYB_DEBUG_
// dbgFile << "prompt&" << &prompt << "'" << prompt << "'(" << prompt.size() << ") "
Expand All @@ -195,8 +231,8 @@ CmdLineEditor::auto_complete(std::string& cmd)
else {
std::vector<std::string> matches;
std::string newtoken;
bool exact_match = selectMatches(listing, tokens[tokens.size() - 1], matches, newtoken);
if ( exact_match ) {
bool fill_line = selectMatches(listing, tokens[tokens.size() - 1], matches, newtoken);
if ( fill_line ) {
std::stringstream s;
for ( size_t i = 0; i < tokens.size() - 1; i++ )
s << tokens[i] << " ";
Expand Down Expand Up @@ -239,6 +275,9 @@ CmdLineEditor::getline(const std::vector<std::string>& cmdHistory, std::string&
writeStr(prompt_line.str());
curpos = history[index].size() + prompt.size() + 1;

// EOF
bool end_of_file = false;

// Start checking for keys
char c;
int bytesRead = 1;
Expand All @@ -247,6 +286,15 @@ CmdLineEditor::getline(const std::vector<std::string>& cmdHistory, std::string&
#ifdef _KEYB_DEBUG_
dbgFile << std::hex << (int)c << std::endl;
#endif
// Always reset TAB behavior if tab key not entered
if ( c != tab_char ) {
tab_state = TAB_STATE::FILL_COMMON;
#ifdef _KEYB_DEBUG_
dbgFile << "tab_state <- FILL_COMMON" << std::endl;
#endif
}

// Handle the key pressed
if ( c == lf_char ) {
// Done if line feed
break;
Expand Down Expand Up @@ -313,11 +361,16 @@ CmdLineEditor::getline(const std::vector<std::string>& cmdHistory, std::string&
redraw_line(history[index]);
}
else if ( c == ctrl_d ) {
// delete character at cursor
int position = curpos - prompt.size() - 1;
if ( position == 0 && history[index].size() == 0 ) {
// if the line is empty then quit (tactcomplabs/sst-core #32)
end_of_file = true;
break;
}
if ( position < 0 || position >= (int)history[index].size() ) {
continue;
continue; // Something went wrong
}
// delete the next character
history[index].erase(position, 1);
redraw_line(history[index]);
}
Expand Down Expand Up @@ -371,6 +424,10 @@ CmdLineEditor::getline(const std::vector<std::string>& cmdHistory, std::string&
this->restoreTermMode();

// set the new line info
newcmd = history[index];
if ( end_of_file )
newcmd = "quit";
else
newcmd = history[index];

writeStr("\n");
}
25 changes: 15 additions & 10 deletions src/sst/core/impl/interactive/cmdLineEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,26 @@ class CmdLineEditor
// debug helper
std::ofstream dbgFile;

// tab behaviors
enum TAB_STATE { FILL_COMMON, LIST_COMMON };

private:
termios originalTerm;
std::list<std::string> cmdStrings = {};
std::function<void(std::list<std::string>& callback)> listing_callback_ = nullptr;

int curpos = -1;
int checktty(int rc);
int setRawMode();
int restoreTermMode();
bool read2chars(char (&seq)[3]);
void move_cursor_left();
void move_cursor_right(int slen);
void auto_complete(std::string& cmd);
bool selectMatches(const std::list<std::string>& list, const std::string& searchfor,
std::vector<std::string>& matches, std::string& newcmd);
int curpos = -1;
TAB_STATE tab_state = TAB_STATE::FILL_COMMON;
int checktty(int rc);
int setRawMode();
int restoreTermMode();
bool read2chars(char (&seq)[3]);
void move_cursor_left();
void move_cursor_right(int slen);
void auto_complete(std::string& cmd);
bool selectMatches(const std::list<std::string>& list, const std::string& searchfor,
std::vector<std::string>& matches, std::string& newcmd);
std::string findLongestCommonPrefix(const std::vector<std::string>& strings);

private:
// yet more string helpers
Expand Down
Loading
Loading