Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
missed one
[simgrid.git] / src / smpi / internals / smpi_global.cpp
index f876f6a..5e59e06 100644 (file)
@@ -42,6 +42,16 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (ke
 #include <boost/tokenizer.hpp>
 #include <boost/algorithm/string.hpp> /* trim_right / trim_left */
 
+#if SMPI_IFORT
+  extern "C" void for_rtl_init_ (int *, char **);
+  extern "C" void for_rtl_finish_ ();
+#elif SMPI_FLANG
+  extern "C" void __io_set_argc(int);
+  extern "C" void __io_set_argv(char **);
+#elif SMPI_GFORTRAN
+  extern "C" void _gfortran_set_args(int, char **);
+#endif
+
 #ifndef RTLD_DEEPBIND
 /* RTLD_DEEPBIND is a bad idea of GNU ld that obviously does not exist on other platforms
  * See https://www.akkadia.org/drepper/dsohowto.pdf
@@ -124,11 +134,11 @@ int smpi_process_index(){
 }
 
 void * smpi_process_get_user_data(){
-  return smpi_process()->get_user_data();
+  return Actor::self()->get_impl()->get_user_data();
 }
 
 void smpi_process_set_user_data(void *data){
-  return smpi_process()->set_user_data(data);
+  Actor::self()->get_impl()->set_user_data(data);
 }
 
 
@@ -417,13 +427,29 @@ typedef void (*smpi_fortran_entry_point_type)();
 static int smpi_run_entry_point(smpi_entry_point_type entry_point, std::vector<std::string> args)
 {
   char noarg[]   = {'\0'};
-  const int argc = args.size();
-  std::unique_ptr<char*[]> argv(new char*[argc + 1]);
+  int argc = args.size();
+  char** argv = new char*[argc + 1];
   for (int i = 0; i != argc; ++i)
-    argv[i] = args[i].empty() ? noarg : &args[i].front();
+    argv[i] = args[i].empty() ? noarg : xbt_strdup(&args[i].front());
   argv[argc] = nullptr;
+  simgrid::smpi::ActorExt::init(&argc, &argv);
+#if SMPI_IFORT
+  for_rtl_init_ (&argc, argv);
+#elif SMPI_FLANG
+  __io_set_argc(argc);
+  __io_set_argv(argv);
+#elif SMPI_GFORTRAN
+  _gfortran_set_args(argc, argv);
+#endif 
+  int res = entry_point(argc, argv);
+
+#if SMPI_IFORT
+  for_rtl_finish_ ();
+#endif
 
-  int res = entry_point(argc, argv.get());
+  for (int i = 0; i != argc; ++i)
+    xbt_free(argv[i]);
+  xbt_free(argv);
   if (res != 0){
     XBT_WARN("SMPI process did not return 0. Return value : %d", res);
     if (smpi_exit_status == 0)
@@ -439,7 +465,6 @@ static smpi_entry_point_type smpi_resolve_function(void* handle)
   smpi_fortran_entry_point_type entry_point_fortran = (smpi_fortran_entry_point_type)dlsym(handle, "user_main_");
   if (entry_point_fortran != nullptr) {
     return [entry_point_fortran](int argc, char** argv) {
-      smpi_process_init(&argc, &argv);
       entry_point_fortran();
       return 0;
     };
@@ -633,12 +658,12 @@ int smpi_main(const char* executable, int argc, char* argv[])
 
   // TODO This will not be executed in the case where smpi_main is not called,
   // e.g., not for smpi_msg_masterslave. This should be moved to another location
-  // that is always called -- maybe close to Actor::onCreation?
+  // that is always called -- maybe close to Actor::on_creation?
   simgrid::s4u::Host::on_creation.connect(
       [](simgrid::s4u::Host& host) { host.extension_set(new simgrid::smpi::Host(&host)); });
 
   // parse the platform file: get the host list
-  SIMIX_create_environment(argv[1]);
+  simgrid::s4u::Engine::get_instance()->load_platform(argv[1]);
   SIMIX_comm_set_copy_data_callback(smpi_comm_copy_buffer_callback);
 
   smpi_init_options();
@@ -648,7 +673,7 @@ int smpi_main(const char* executable, int argc, char* argv[])
     smpi_init_privatization_no_dlopen(executable);
 
   SMPI_init();
-  SIMIX_launch_application(argv[2]);
+  simgrid::s4u::Engine::get_instance()->load_deployment(argv[2]);
   SMPI_app_instance_register(smpi_default_instance_name.c_str(), nullptr,
                              process_data.size()); // This call has a side effect on process_count...
   MPI_COMM_WORLD = *smpi_deployment_comm_world(smpi_default_instance_name);
@@ -701,7 +726,6 @@ void SMPI_init(){
   smpi_init_options();
   smpi_global_init();
   smpi_check_options();
-  simgrid::s4u::on_simulation_end.connect(TRACE_smpi_release);
 }
 
 void SMPI_finalize(){