+static int execute_command(const char * const argv[])
+{
+ pid_t pid;
+ int status;
+ if (posix_spawnp(&pid, argv[0], nullptr, nullptr, (char* const*) argv, environ) != 0)
+ return 127;
+ if (waitpid(pid, &status, 0) != pid)
+ return 127;
+ return status;
+}
+
+typedef std::function<int(int argc, char *argv[])> smpi_entry_point_type;
+typedef int (* smpi_c_entry_point_type)(int argc, char **argv);
+typedef void (* smpi_fortran_entry_point_type)(void);
+
+static int smpi_run_entry_point(smpi_entry_point_type entry_point, std::vector<std::string> args)
+{
+ const int argc = args.size();
+ std::unique_ptr<char*[]> argv(new char*[argc + 1]);
+ for (int i = 0; i != argc; ++i)
+ argv[i] = args[i].empty() ? const_cast<char*>(""): &args[i].front();
+ argv[argc] = nullptr;
+
+ int res = entry_point(argc, argv.get());
+ if (res != 0){
+ XBT_WARN("SMPI process did not return 0. Return value : %d", res);
+ smpi_process()->set_return_value(res);
+ }
+ return 0;
+}
+
+// TODO, remove the number of functions involved here
+static smpi_entry_point_type smpi_resolve_function(void* handle)
+{
+ smpi_fortran_entry_point_type entry_point2 =
+ (smpi_fortran_entry_point_type) dlsym(handle, "user_main_");
+ if (entry_point2 != nullptr) {
+ // fprintf(stderr, "EP user_main_=%p\n", entry_point2);
+ return [entry_point2](int argc, char** argv) {
+ smpi_process_init(&argc, &argv);
+ entry_point2();
+ return 0;
+ };
+ }
+
+ smpi_c_entry_point_type entry_point = (smpi_c_entry_point_type) dlsym(handle, "main");
+ if (entry_point != nullptr) {
+ // fprintf(stderr, "EP main=%p\n", entry_point);
+ return entry_point;
+ }
+
+ return smpi_entry_point_type();
+}
+
+int smpi_main(const char* executable, int argc, char *argv[])