Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce scope for variables.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 13 Feb 2023 15:09:47 +0000 (16:09 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 13 Feb 2023 15:50:49 +0000 (16:50 +0100)
src/instr/instr_config.cpp
src/instr/instr_interface.cpp
src/instr/instr_private.hpp
src/smpi/include/private.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_memory.cpp
src/smpi/internals/smpi_shared.cpp
src/smpi/internals/smpi_utils.cpp
src/surf/network_ns3.cpp
src/surf/xml/surfxml_parseplatf.cpp
src/surf/xml/surfxml_sax_cb.cpp

index 19d9e9e..c13fdff 100644 (file)
@@ -20,7 +20,7 @@ XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used fo
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
 
 std::ofstream tracing_file;
-std::map<const simgrid::instr::Container*, std::ofstream*> tracing_files; // TI specific
+static std::map<const simgrid::instr::Container*, std::ofstream*> tracing_files; // TI specific
 
 constexpr char OPT_TRACING_BASIC[]             = "tracing/basic";
 constexpr char OPT_TRACING_COMMENT_FILE[]      = "tracing/comment-file";
@@ -206,7 +206,7 @@ void TRACE_help()
 namespace simgrid::instr {
 static bool trace_active = false;
 TraceFormat trace_format = TraceFormat::Paje;
-int trace_precision;
+static int trace_precision;
 
 /*************
  * Callbacks *
index 4ff4120..106acd4 100644 (file)
@@ -17,11 +17,11 @@ enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
 
-std::set<std::string, std::less<>> created_categories;
-std::set<std::string, std::less<>> declared_marks;
-std::set<std::string, std::less<>> user_host_variables;
-std::set<std::string, std::less<>> user_vm_variables;
-std::set<std::string, std::less<>> user_link_variables;
+static std::set<std::string, std::less<>> created_categories;
+static std::set<std::string, std::less<>> declared_marks;
+static std::set<std::string, std::less<>> user_host_variables;
+static std::set<std::string, std::less<>> user_vm_variables;
+static std::set<std::string, std::less<>> user_link_variables;
 
 static void instr_user_variable(double time, const std::string& resource, const std::string& variable_name,
                                 const std::string& parent_type, double value, InstrUserVariable what,
index c6b35da..091bbcc 100644 (file)
@@ -40,7 +40,6 @@ void dump_header(bool basic, bool display_sizes);
  */
 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
 extern TraceFormat trace_format;
-extern int trace_precision;
 extern double last_timestamp_to_dump;
 
 void init();
@@ -233,12 +232,6 @@ public:
 
 XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc);
 
-extern XBT_PRIVATE std::set<std::string, std::less<>> created_categories;
-extern XBT_PRIVATE std::set<std::string, std::less<>> declared_marks;
-extern XBT_PRIVATE std::set<std::string, std::less<>> user_host_variables;
-extern XBT_PRIVATE std::set<std::string, std::less<>> user_vm_variables;
-extern XBT_PRIVATE std::set<std::string, std::less<>> user_link_variables;
-
 /* from instr_config.c */
 XBT_PRIVATE bool TRACE_needs_platform();
 XBT_PRIVATE bool TRACE_is_enabled();
index 4440cc7..2133849 100644 (file)
@@ -118,9 +118,6 @@ XBT_PRIVATE bool smpi_cfg_display_alloc();
 // utilities
 XBT_PRIVATE void smpi_init_options_internal(bool called_by_smpi_main);
 
-extern XBT_PRIVATE char* smpi_data_exe_start; // start of the data+bss segment of the executable
-extern XBT_PRIVATE size_t smpi_data_exe_size; // size of the data+bss segment of the executable
-
 XBT_PRIVATE bool smpi_switch_data_segment(simgrid::s4u::ActorPtr actor, const void* addr = nullptr);
 
 XBT_PRIVATE void smpi_prepare_global_memory_segment();
index 13e44ca..fce781e 100644 (file)
@@ -72,7 +72,7 @@ std::map</* computation unit name */ std::string, papi_process_data, std::less<>
 std::unordered_map<std::string, double> location2speedup;
 
 static int smpi_exit_status = 0;
-xbt_os_timer_t global_timer;
+static xbt_os_timer_t global_timer;
 static std::vector<std::string> privatize_libs_paths;
 
 // No instance gets manually created; check also the smpirun.in script as
index b9b81f6..d2d121e 100644 (file)
@@ -26,9 +26,9 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SMPI");
 
-char* smpi_data_exe_start = nullptr;
-size_t smpi_data_exe_size = 0;
-SmpiPrivStrategies smpi_privatize_global_variables;
+static char* smpi_data_exe_start = nullptr; // start of the data+bss segment of the executable
+static size_t smpi_data_exe_size = 0;       // size of the data+bss segment of the executable
+static SmpiPrivStrategies smpi_privatize_global_variables;
 static void* smpi_data_exe_copy;
 
 // Initialized by smpi_prepare_global_memory_segment().
index 95067dd..10ab0ad 100644 (file)
@@ -58,7 +58,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_shared, smpi, "Logging specific to SMPI (shared memory macros)");
 
-namespace{
+namespace {
 /** Some location in the source code
  *
  *  This information is used by SMPI_SHARED_MALLOC to allocate  some shared memory for all simulated processes.
@@ -94,7 +94,7 @@ std::map<std::string, void*, std::less<>> calls;
 int smpi_shared_malloc_bogusfile           = -1;
 int smpi_shared_malloc_bogusfile_huge_page = -1;
 unsigned long smpi_shared_malloc_blocksize = 1UL << 20;
-}
+} // namespace
 
 void smpi_shared_destroy()
 {
index 94060e9..4624971 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
 
-extern std::string surf_parsed_filename;
-extern int surf_parse_lineno;
-
-namespace simgrid::smpi::utils {
+namespace {
 
 double total_benched_time=0;
 unsigned long total_malloc_size=0;
@@ -41,7 +38,7 @@ struct current_buffer_metadata_t {
 };
 
 alloc_metadata_t max_malloc;
-F2C* current_handle = nullptr;
+simgrid::smpi::F2C* current_handle = nullptr;
 current_buffer_metadata_t current_buffer1;
 current_buffer_metadata_t current_buffer2;
 
@@ -49,6 +46,10 @@ std::unordered_map<const void*, alloc_metadata_t> allocs;
 
 std::unordered_map<int, std::vector<std::string>> collective_calls;
 
+} // namespace
+
+namespace simgrid::smpi::utils {
+
 void add_benched_time(double time){
   total_benched_time += time;
 }
index 5ab5965..8f1d008 100644 (file)
@@ -51,8 +51,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns
 extern std::map<std::string, SgFlow*, std::less<>> flow_from_sock;
 extern std::map<std::string, ns3::ApplicationContainer, std::less<>> sink_from_sock;
 
-static ns3::InternetStackHelper stack;
-
 static int number_of_links    = 1;
 static int number_of_networks = 1;
 
@@ -67,6 +65,7 @@ static std::string transformIpv4Address(ns3::Ipv4Address from)
 
 NetPointNs3::NetPointNs3()
 {
+  static ns3::InternetStackHelper stack;
   stack.Install(ns3_node_);
 }
 
index 5cfc7f2..5477468 100644 (file)
@@ -17,11 +17,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 
 /* Trace related stuff */
 XBT_PRIVATE std::unordered_map<std::string, simgrid::kernel::profile::Profile*> traces_set_list;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_host_avail;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_host_speed;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_avail;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_bw;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_lat;
+static std::unordered_map<std::string, std::string> trace_connect_list_host_avail;
+static std::unordered_map<std::string, std::string> trace_connect_list_host_speed;
+static std::unordered_map<std::string, std::string> trace_connect_list_link_avail;
+static std::unordered_map<std::string, std::string> trace_connect_list_link_bw;
+static std::unordered_map<std::string, std::string> trace_connect_list_link_lat;
 
 void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect)
 {
index 567a2b2..af1ae59 100644 (file)
@@ -29,7 +29,7 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
 
 std::string surf_parsed_filename; // Currently parsed file (for the error messages)
-std::vector<simgrid::s4u::LinkInRoute> parsed_link_list; /* temporary store of current link list of a route */
+static std::vector<simgrid::s4u::LinkInRoute> parsed_link_list; /* temporary store of current link list of a route */
 
 /* Helping functions */
 void surf_parse_assert(bool cond, const std::string& msg)
@@ -127,9 +127,9 @@ static void explodesRadical(const std::string& radicals, std::vector<int>* explo
 
 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
 
-std::vector<std::unordered_map<std::string, std::string>> property_sets;
+static std::vector<std::unordered_map<std::string, std::string>> property_sets;
 
-FILE *surf_file_to_parse = nullptr;
+static FILE* surf_file_to_parse = nullptr;
 
 /* Stuff relative to storage */
 void STag_surfxml_storage()
@@ -826,7 +826,7 @@ void ETag_surfxml_argument(){/* Nothing to do */}
 void ETag_surfxml_model___prop(){/* Nothing to do */}
 
 /* Open and Close parse file */
-YY_BUFFER_STATE surf_input_buffer;
+static YY_BUFFER_STATE surf_input_buffer;
 
 void surf_parse_open(const std::string& file)
 {