Skip to content

Commit

Permalink
Fix global initialization order in main
Browse files Browse the repository at this point in the history
Fix uninitialized pointer error in sync
  • Loading branch information
gvoskuilen committed May 10, 2024
1 parent 34727aa commit 0210218
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 38 deletions.
82 changes: 47 additions & 35 deletions src/sst/core/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,14 @@ start_graph_creation(
}
}
#endif

// Delete the model generator
if ( modelGen ) {
delete modelGen;
modelGen = nullptr;
}

if ( myRank.rank == 0 || cfg.parallel_load() ) {
graph->postCreationCleanup();

// Check config graph to see if there are structural errors.
if ( graph->checkForStructuralErrors() ) {
g_output.fatal(CALL_INFO, 1, "Structure errors found in the ConfigGraph.\n");
}
}

return sst_get_cpu_time() - start_graph_gen;
return start_graph_gen;
}

static double
Expand Down Expand Up @@ -798,39 +790,23 @@ main(int argc, char* argv[])
if ( !cfg.wasOptionSetOnCmdLine("verbose") ) cfg.verbose_ = cpt_output_verbose;
if ( !cfg.wasOptionSetOnCmdLine("debug-file") ) cfg.debugFile_ = cpt_debug_file;
if ( !cfg.wasOptionSetOnCmdLine("checkpoint-prefix") ) cfg.checkpoint_prefix_ = cpt_prefix;
}

// Set the debug output location
Output::setFileName(cfg.debugFile() != "/dev/null" ? cfg.debugFile() : "sst_output");
////// Initialize global data //////


// If we are doing a parallel load with a file per rank, add the
// rank number to the file name before the extension
if ( cfg.parallel_load() && cfg.parallel_load_mode_multi() && world_size.rank != 1 ) {
addRankToFileName(cfg.configFile_, myRank.rank);
// These are initialized after graph creation in the non-restart path
world_size.thread = cfg.num_threads();
Output::setFileName(cfg.debugFile() != "/dev/null" ? cfg.debugFile() : "sst_output");
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());
}

// Check to see if the config file exists
cfg.checkConfigFile();

// Create the factory. This may be needed to load an external model definition
Factory* factory = new Factory(cfg.getLibPath());

////// Initialize global data //////

// Set the number of threads
world_size.thread = cfg.num_threads();

/* Build objects needed for startup */
Output::setWorldSize(world_size.rank, world_size.thread, myrank);
g_output = Output::setDefaultObject(cfg.output_core_prefix(), cfg.verbose(), 0, Output::STDOUT);

g_output.verbose(
CALL_INFO, 1, 0, "#main() My rank is (%u.%u), on %u/%u nodes/threads\n", myRank.rank, myRank.thread,
world_size.rank, world_size.thread);

// Need to initialize TimeLord
Simulation_impl::getTimeLord()->init(cfg.timeBase());

if ( restart && (cfg.num_ranks() != cpt_num_ranks || cfg.num_threads() != cpt_num_threads) ) {
g_output.fatal(
CALL_INFO, 1,
Expand All @@ -850,8 +826,43 @@ main(int argc, char* argv[])
// Get the memory before we create the graph
const uint64_t pre_graph_create_rss = maxGlobalMemSize();

double graph_gen_time = start_graph_creation(graph, cfg, factory, world_size, myRank);
double start_graph_gen = start_graph_creation(graph, cfg, factory, world_size, myRank);

////// Initialize global data //////
// Config is updated from SDL, initialize globals

// Set the number of threads
world_size.thread = cfg.num_threads();

// If we are doing a parallel load with a file per rank, add the
// rank number to the file name before the extension
if ( cfg.parallel_load() && cfg.parallel_load_mode_multi() && world_size.rank != 1 ) {
addRankToFileName(cfg.configFile_, myRank.rank);
}

// Create global output object
Output::setFileName(cfg.debugFile() != "/dev/null" ? cfg.debugFile() : "sst_output");
Output::setWorldSize(world_size.rank, world_size.thread, myrank);
g_output = Output::setDefaultObject(cfg.output_core_prefix(), cfg.verbose(), 0, Output::STDOUT);

g_output.verbose(
CALL_INFO, 1, 0, "#main() My rank is (%u.%u), on %u/%u nodes/threads\n", myRank.rank, myRank.thread,
world_size.rank, world_size.thread);

// TimeLord must be initialized prior to postCreationCleanup() call
Simulation_impl::getTimeLord()->init(cfg.timeBase());

// Cleanup after graph creation
if ( myRank.rank == 0 || cfg.parallel_load() ) {

graph->postCreationCleanup();

// Check config graph to see if there are structural errors.
if ( graph->checkForStructuralErrors() ) {
g_output.fatal(CALL_INFO, 1, "Structure errors found in the ConfigGraph.\n");
}
}
double graph_gen_time = sst_get_cpu_time() - start_graph_gen;

// If verbose level is high enough, compute the total number
// components in the simulation. NOTE: if parallel-load is
Expand All @@ -875,6 +886,7 @@ main(int argc, char* argv[])
}

////// End ConfigGraph Creation //////

#ifdef SST_CONFIG_HAVE_MPI
// If we did a parallel load, check to make sure that all the
// ranks have the same thread count set (the python can change the
Expand Down
8 changes: 5 additions & 3 deletions src/sst/core/sync/syncManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RankSync : public SST::Core::Serialization::serializable
{
public:
RankSync(RankInfo num_ranks) : num_ranks(num_ranks) { link_maps.resize(num_ranks.rank); }
RankSync() {}
RankSync() : max_period(nullptr) {}
virtual ~RankSync() {}

/** Register a Link which this Sync Object is responsible for */
Expand Down Expand Up @@ -87,7 +87,7 @@ class RankSync : public SST::Core::Serialization::serializable
class ThreadSync : public SST::Core::Serialization::serializable
{
public:
ThreadSync() {}
ThreadSync() : max_period(nullptr) {}
virtual ~ThreadSync() {}

virtual void before() = 0;
Expand All @@ -113,7 +113,9 @@ class ThreadSync : public SST::Core::Serialization::serializable
}
ImplementVirtualSerializable(SST::ThreadSync)

protected : SimTime_t nextSyncTime;
protected :

SimTime_t nextSyncTime;
TimeConverter* max_period;

void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
Expand Down

0 comments on commit 0210218

Please sign in to comment.