Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
missed one
[simgrid.git] / src / smpi / internals / smpi_global.cpp
index a8f461b..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
@@ -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;
     };