Skip to content

Commit

Permalink
Merge pull request sstsimulator#1105 from sstsimulator/devel
Browse files Browse the repository at this point in the history
Automatically Merged using SST Master Branch Merger
  • Loading branch information
sst-autotester authored Jul 20, 2024
2 parents 2f7b13d + a62f11c commit ca6de4f
Show file tree
Hide file tree
Showing 51 changed files with 1,784 additions and 197 deletions.
31 changes: 0 additions & 31 deletions src/sst/core/baseComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,37 +1091,6 @@ class SubComponentSlotInfo
namespace Core {
namespace Serialization {

template <class T>
class serialize_impl<Statistic<T>*>
{
template <class A>
friend class serialize;
void operator()(Statistic<T>*& s, serializer& ser)
{
// For sizer and pack, only need to get the information needed
// to create a NullStatistic on unpack.
switch ( ser.mode() ) {
case serializer::SIZER:
case serializer::PACK:
{
BaseComponent* comp = s->getComponent();
ser& comp;
break;
}
case serializer::UNPACK:
{
Params params;
BaseComponent* comp;
ser& comp;
s = Factory::getFactory()->CreateWithParams<Statistic<T>>(
"sst.NullStatistic", params, comp, "", "", params);
break;
}
}
}
};


namespace pvt {

void size_basecomponent(serializable_base* s, serializer& ser);
Expand Down
4 changes: 0 additions & 4 deletions src/sst/core/componentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class ConfigStatistic;
class Simulation_impl;
class TimeConverter;

namespace Statistics {
class StatisticInfo;
}

class ComponentInfo
{

Expand Down
20 changes: 17 additions & 3 deletions src/sst/core/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,16 @@ main(int argc, char* argv[])
buffer = new char[size];
fs.read(buffer, size);

std::string cpt_lib_path, cpt_timebase, cpt_output_directory;
std::string cpt_output_core_prefix, cpt_debug_file, cpt_prefix;
int cpt_output_verbose = 0;
std::string cpt_lib_path;
std::string cpt_timebase;
std::string cpt_output_directory;
std::string cpt_output_core_prefix;
std::string cpt_debug_file;
std::string cpt_prefix;
int cpt_output_verbose = 0;
std::map<std::string, uint32_t> cpt_params_key_map;
std::vector<std::string> cpt_params_key_map_reverse;
uint32_t cpt_params_next_key_id;

ser.start_unpacking(buffer, size);
ser& cpt_num_ranks;
Expand All @@ -779,6 +786,9 @@ main(int argc, char* argv[])
ser& cpt_output_verbose;
ser& cpt_debug_file;
ser& cpt_prefix;
ser& cpt_params_key_map;
ser& cpt_params_key_map_reverse;
ser& cpt_params_next_key_id;

fs.close();
delete[] buffer;
Expand All @@ -800,6 +810,10 @@ main(int argc, char* argv[])
Output::setWorldSize(world_size.rank, world_size.thread, myrank);
g_output = Output::setDefaultObject(cfg.output_core_prefix(), cfg.verbose(), 0, Output::STDOUT);
Simulation_impl::getTimeLord()->init(cfg.timeBase());

Params::keyMap = cpt_params_key_map;
Params::keyMapReverse = cpt_params_key_map_reverse;
Params::nextKeyID = cpt_params_next_key_id;
}

// Check to see if the config file exists
Expand Down
174 changes: 147 additions & 27 deletions src/sst/core/output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <atomic>
#include <cerrno>
#include <cinttypes>
#include <cstdlib>
#include <cstring>
#include <string>

// System Headers
#ifdef HAVE_EXECINFO_H
Expand Down Expand Up @@ -521,64 +524,181 @@ thread_local std::vector<char> TraceFunction::indent_array(100, ' ');
thread_local int TraceFunction::trace_level = 0;

TraceFunction::TraceFunction(uint32_t line, const char* file, const char* func, bool print_sim_info, bool activate) :
line(line),
file(file),
function(func),
indent_length(2),
active(activate)
line_(line),
file_(file),
function_(func),
indent_length_(2),
active_(activate && global_active_)
{
if ( !active ) return;
if ( !active_ ) return;
if ( print_sim_info ) {
RankInfo ri = Simulation_impl::getSimulation()->getNumRanks();
if ( ri.rank > 1 || ri.thread > 1 ) { output_obj.init("@R, @I (@t): " /*prefix*/, 0, 0, Output::STDOUT); }
Simulation_impl* sim = nullptr;
try {
sim = Simulation_impl::getSimulation();
}
catch ( std::out_of_range& e ) {
// do nothing
}

if ( sim ) {
RankInfo ri = sim->getNumRanks();
if ( ri.rank > 1 || ri.thread > 1 ) { output_obj_.init("@x (@t): " /*prefix*/, 0, 0, Output::STDOUT); }
else {
output_obj_.init("(@t): ", 0, 0, Output::STDOUT);
}
}
else {
output_obj.init("(@t): ", 0, 0, Output::STDOUT);
output_obj_.init("" /*prefix*/, 0, 0, Output::STDOUT);
}
// rank = Simulation_impl::getSimulation()->getRank().rank;
// thread = Simulation_impl::getSimulation()->getRank().thread;
}
else {
output_obj.init("" /*prefix*/, 0, 0, Output::STDOUT);
output_obj_.init("" /*prefix*/, 0, 0, Output::STDOUT);
}

// Set up the indent
int indent = trace_level * indent_length;
int indent = trace_level * indent_length_;
indent_array[indent] = '\0';
output_obj.output(line, file, func, "%s%s enter function\n", indent_array.data(), function.c_str());
indent_array[indent] = ' ';
output_obj_.output(line_, file, func, "%s%s enter function\n", indent_array.data(), function_.c_str());
indent_array[indent] = indent_marker_;
fflush(stdout);
trace_level++;
}

TraceFunction::~TraceFunction()
{
if ( !active ) return;
if ( !active_ ) return;
trace_level--;
int indent = trace_level * indent_length;
int indent = trace_level * indent_length_;
indent_array[indent] = '\0';
output_obj.output(
line, file.c_str(), function.c_str(), "%s%s exit function\n", indent_array.data(), function.c_str());
output_obj_.output(
line_, file_.c_str(), function_.c_str(), "%s%s exit function\n", indent_array.data(), function_.c_str());
indent_array[indent] = ' ';
fflush(stdout);
}

void
TraceFunction::output(const char* format, ...) const
{
if ( !active ) return;
if ( !active_ ) return;
// Need to add the indent
char buf[200];
char* buf = new char[200];

int indent = trace_level * indent_length;
int indent = trace_level * indent_length_;
indent_array[indent] = '\0';
snprintf(buf, 200, "%s%s", indent_array.data(), format);
std::string message(indent_array.data());

va_list args;
va_start(args, format);
size_t n = vsnprintf(buf, 200, format, args);
va_end(args);

if ( n >= 200 ) {
// Generated string longer than buffer
delete[] buf;
buf = new char[n + 1];
va_start(args, format);
vsnprintf(buf, n + 1, format, args);
va_end(args);
}

// Look for \n and print each line individually. We do this so we
// can put the correct indent in and so that the prefix prints
// correctly.
size_t start_index = 0;
for ( size_t i = 0; i < n - 1; ++i ) {
if ( buf[i] == '\n' ) {
// Terminate string here, then change it back after printing
buf[i] = '\0';
output_obj_.outputprintf(
line_, file_.c_str(), function_.c_str(), "%s%s\n", indent_array.data(), &buf[start_index]);
buf[i] = '\n';
start_index = i + 1;
}
}

// Print the rest of the string
output_obj_.outputprintf(line_, file_.c_str(), function_.c_str(), "%s%s", indent_array.data(), &buf[start_index]);

delete[] buf;

indent_array[indent] = ' ';

va_list arg;
va_start(arg, format);
output_obj.outputprintf(line, file.c_str(), function.c_str(), buf, arg);
va_end(arg);
// output_obj_.outputprintf(line_, file_.c_str(), function_.c_str(), "%s", message.c_str());
// Since this class is for debug, force a flush after every output
fflush(stdout);
}

// void
// TraceFunction::output(const char* format, ...) const
// {
// if ( !active_ ) return;
// // Need to add the indent
// char* buf = new char[200];

// int indent = trace_level * indent_length_;
// indent_array[indent] = '\0';
// std::string message(indent_array.data());

// va_list args;
// va_start(args, format);
// size_t n = vsnprintf(buf, 200, format, args);
// va_end(args);

// if ( n >= 200 ) {
// // Generated string longer than buffer
// delete[] buf;
// buf = new char[n + 1];
// va_start(args, format);
// vsnprintf(buf, n+1, format, args);
// va_end(args);
// }

// // Replace all \n's with \n + indent_array to indent any new lines
// // in the string (unless the \n is the last character in the
// // string)
// size_t start_index = 0;
// for ( size_t i = 0; i < n - 1; ++i ) {
// if ( buf[i] == '\n' ) {
// message.append(&buf[start_index], i - start_index + 1);
// message.append(indent_array.data());
// start_index = i + 1;
// }
// }
// message.append(&buf[start_index], n - start_index);
// delete[] buf;

// indent_array[indent] = ' ';

// output_obj_.outputprintf(line_, file_.c_str(), function_.c_str(), "%s", message.c_str());
// fflush(stdout);
// }


// Functions to check for proper environment variable to turn on output
// for TraceFunction
bool
is_trace_function_active()
{
const char* var = getenv("SST_TRACEFUNCTION_ACTIVATE");
if ( var ) { return true; }
else {
return false;
}
}

char
get_indent_marker()
{
const char* var = getenv("SST_TRACEFUNCTION_INDENT_MARKER");
if ( var ) {
if ( strlen(var) > 0 )
return var[0];
else
return '|';
}
return ' ';
}

bool TraceFunction::global_active_ = is_trace_function_active();
char TraceFunction::indent_marker_ = get_indent_marker();
} // namespace SST
Loading

0 comments on commit ca6de4f

Please sign in to comment.