Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright notices
[simgrid.git] / src / simix / smx_deployment.c
index 5cb246b..bb3b90b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007, 2009-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@ extern int surf_parse_lineno;
 
 static void parse_process(sg_platf_process_cbarg_t process)
 {
 
 static void parse_process(sg_platf_process_cbarg_t process)
 {
-  smx_host_t host = SIMIX_host_get_by_name(process->host);
+  sg_host_t host = sg_host_by_name(process->host);
   if (!host)
     THROWF(arg_error, 0, "Host '%s' unknown", process->host);
   parse_code = SIMIX_get_registered_function(process->function);
   if (!host)
     THROWF(arg_error, 0, "Host '%s' unknown", process->host);
   parse_code = SIMIX_get_registered_function(process->function);
@@ -36,12 +36,29 @@ static void parse_process(sg_platf_process_cbarg_t process)
   smx_process_arg_t arg = NULL;
   smx_process_t process_created = NULL;
 
   smx_process_arg_t arg = NULL;
   smx_process_t process_created = NULL;
 
+  arg = xbt_new0(s_smx_process_arg_t, 1);
+  arg->code = parse_code;
+  arg->data = NULL;
+  arg->hostname = sg_host_name(host);
+  arg->argc = process->argc;
+  arg->argv = xbt_new(char *,process->argc);
+  int i;
+  for (i=0; i<process->argc; i++)
+    arg->argv[i] = xbt_strdup(process->argv[i]);
+  arg->name = xbt_strdup(arg->argv[0]);
+  arg->kill_time = kill_time;
+  arg->properties = current_property_set;
+  if (!sg_host_simix(host)->boot_processes) {
+    sg_host_simix(host)->boot_processes = xbt_dynar_new(sizeof(smx_process_arg_t), _SIMIX_host_free_process_arg);
+  }
+  xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
+
   if (start_time > SIMIX_get_clock()) {
     arg = xbt_new0(s_smx_process_arg_t, 1);
     arg->name = (char*)(process->argv)[0];
     arg->code = parse_code;
     arg->data = NULL;
   if (start_time > SIMIX_get_clock()) {
     arg = xbt_new0(s_smx_process_arg_t, 1);
     arg->name = (char*)(process->argv)[0];
     arg->code = parse_code;
     arg->data = NULL;
-    arg->hostname = host->name;
+    arg->hostname = sg_host_name(host);
     arg->argc = process->argc;
     arg->argv = (char**)(process->argv);
     arg->kill_time = kill_time;
     arg->argc = process->argc;
     arg->argv = (char**)(process->argv);
     arg->kill_time = kill_time;
@@ -51,23 +68,23 @@ static void parse_process(sg_platf_process_cbarg_t process)
            arg->hostname, start_time);
     SIMIX_timer_set(start_time, &SIMIX_process_create_from_wrapper, arg);
   } else {                      // start_time <= SIMIX_get_clock()
            arg->hostname, start_time);
     SIMIX_timer_set(start_time, &SIMIX_process_create_from_wrapper, arg);
   } else {                      // start_time <= SIMIX_get_clock()
-    XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], host->name);
+    XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], sg_host_name(host));
 
     if (simix_global->create_process_function)
 
     if (simix_global->create_process_function)
-      simix_global->create_process_function(&process_created,
+      process_created = simix_global->create_process_function(
                                             (char*)(process->argv)[0],
                                             parse_code,
                                             NULL,
                                             (char*)(process->argv)[0],
                                             parse_code,
                                             NULL,
-                                            host->name,
+                                            sg_host_name(host),
                                             kill_time,
                                             process->argc,
                                             (char**)(process->argv),
                                             current_property_set,
                                             kill_time,
                                             process->argc,
                                             (char**)(process->argv),
                                             current_property_set,
-                                            auto_restart);
+                                            auto_restart, NULL);
     else
     else
-      simcall_process_create(&process_created, (char*)(process->argv)[0], parse_code, NULL, host->name, kill_time, process->argc,
+      process_created = simcall_process_create((char*)(process->argv)[0], parse_code, NULL, sg_host_name(host), kill_time, process->argc,
           (char**)process->argv, current_property_set,auto_restart);
           (char**)process->argv, current_property_set,auto_restart);
-
+    
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
     if (!process_created) {
       return;
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
     if (!process_created) {
       return;
@@ -76,6 +93,11 @@ static void parse_process(sg_platf_process_cbarg_t process)
   current_property_set = NULL;
 }
 
   current_property_set = NULL;
 }
 
+void SIMIX_init_application(void){
+  surf_parse_reset_callbacks();
+  sg_platf_process_add_cb(parse_process);
+}
+
 /**
  * \brief An application deployer.
  *
 /**
  * \brief An application deployer.
  *
@@ -92,22 +114,19 @@ static void parse_process(sg_platf_process_cbarg_t process)
  */
 void SIMIX_launch_application(const char *file)
 {
  */
 void SIMIX_launch_application(const char *file)
 {
-  xbt_ex_t e;
-
   _XBT_GNUC_UNUSED int parse_status;
   xbt_assert(simix_global,
               "SIMIX_global_init has to be called before SIMIX_launch_application.");
 
   _XBT_GNUC_UNUSED int parse_status;
   xbt_assert(simix_global,
               "SIMIX_global_init has to be called before SIMIX_launch_application.");
 
-  surf_parse_reset_callbacks();
-
-  sg_platf_process_add_cb(parse_process);
+  SIMIX_init_application();
 
   surf_parse_open(file);
   TRY {
     parse_status = surf_parse();
     surf_parse_close();
     xbt_assert(!parse_status, "Parse error at %s:%d", file,surf_parse_lineno);
 
   surf_parse_open(file);
   TRY {
     parse_status = surf_parse();
     surf_parse_close();
     xbt_assert(!parse_status, "Parse error at %s:%d", file,surf_parse_lineno);
-  } CATCH(e) {
+  }
+  CATCH_ANONYMOUS {
     XBT_ERROR("Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
         file, surf_parse_lineno);
     RETHROW;
     XBT_ERROR("Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
         file, surf_parse_lineno);
     RETHROW;
@@ -175,13 +194,12 @@ void SIMIX_process_set_function(const char *process_host,
                                 double process_start_time,
                                 double process_kill_time)
 {
                                 double process_start_time,
                                 double process_kill_time)
 {
-  s_sg_platf_process_cbarg_t process;
-  memset(&process,0,sizeof(process));
+  s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER;
 
 
-  smx_host_t host = SIMIX_host_get_by_name(process_host);
+  sg_host_t host = sg_host_by_name(process_host);
   if (!host)
     THROWF(arg_error, 0, "Host '%s' unknown", process_host);
   if (!host)
     THROWF(arg_error, 0, "Host '%s' unknown", process_host);
-  process.host = host->name;
+  process.host = sg_host_name(host);
 
   process.argc = 1 + xbt_dynar_length(arguments);
   process.argv = (const char**)xbt_new(char *, process.argc + 1);
 
   process.argc = 1 + xbt_dynar_length(arguments);
   process.argv = (const char**)xbt_new(char *, process.argc + 1);
@@ -201,8 +219,6 @@ void SIMIX_process_set_function(const char *process_host,
   process.host = process_host;
   process.kill_time = process_kill_time;
   process.start_time = process_start_time;
   process.host = process_host;
   process.kill_time = process_kill_time;
   process.start_time = process_start_time;
-  process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
-  process.properties = NULL;
 
   sg_platf_new_process(&process);
 }
 
   sg_platf_new_process(&process);
 }