- smx_process_arg_t arg = *(smx_process_arg_t*)data;
- for (int i = 0; i < arg->argc; i++)
- xbt_free(arg->argv[i]);
- xbt_free(arg->argv);
- xbt_free(arg->name);
- xbt_free(arg);
-}
-/**
- * \brief Add a process to the list of the processes that the host will restart when it comes back
- * This function add a process to the list of the processes that will be restarted when the host comes
- * back. It is expected that this function is called when the host is down.
- * The processes will only be restarted once, meaning that you will have to register the process
- * again to restart the process again.
- */
-void SIMIX_host_add_auto_restart_process(sg_host_t host,
- const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- double kill_time,
- int argc, char **argv,
- xbt_dict_t properties,
- int auto_restart)
-{
- if (!sg_host_simix(host)->auto_restart_processes) {
- sg_host_simix(host)->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg);
- }
- smx_process_arg_t arg = xbt_new(s_smx_process_arg_t,1);
- arg->name = xbt_strdup(name);
- arg->code = code;
- arg->data = data;
- arg->hostname = hostname;
- arg->kill_time = kill_time;
- arg->argc = argc;
-
- arg->argv = xbt_new(char*,argc + 1);
-
- for (int i = 0; i < argc; i++)
- arg->argv[i] = xbt_strdup(argv[i]);
- arg->argv[argc] = NULL;
-
- arg->properties = properties;
- arg->auto_restart = auto_restart;
-
- if( host->isOff() && !xbt_dict_get_or_null(watched_hosts_lib,sg_host_get_name(host))){
- xbt_dict_set(watched_hosts_lib,sg_host_get_name(host),host,NULL);
- XBT_DEBUG("Push host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_get_name(host));
- }
- xbt_dynar_push_as(sg_host_simix(host)->auto_restart_processes,smx_process_arg_t,arg);
-}
-/**
- * \brief Restart the list of processes that have been registered to the host
- */
-void SIMIX_host_autorestart(sg_host_t host)
-{
- unsigned int cpt;
- smx_process_arg_t arg;
- xbt_dynar_t process_list = sg_host_simix(host)->auto_restart_processes;
- if (!process_list)
- return;
-
- xbt_dynar_foreach (process_list, cpt, arg) {
-
- XBT_DEBUG("Restarting Process %s(%s) right now", arg->argv[0], arg->hostname);
- if (simix_global->create_process_function) {
- simix_global->create_process_function(arg->argv[0],
- arg->code,
- NULL,
- arg->hostname,
- arg->kill_time,
- arg->argc,
- arg->argv,
- arg->properties,
- arg->auto_restart,
- NULL);
- } else {
- simcall_process_create(arg->argv[0],
- (xbt_main_func_t) arg->code,
- NULL,
- arg->hostname,
- arg->kill_time,
- arg->argc,
- arg->argv,
- arg->properties,
- arg->auto_restart);
-
- }
- /* arg->argv is used by the process created above. Hide it to
- * _SIMIX_host_free_process_arg() which is called by xbt_dynar_reset()
- * below. */
- arg->argc = 0;
- arg->argv = NULL;
- }
- xbt_dynar_reset(process_list);
-}
-
-smx_synchro_t simcall_HANDLER_execution_start(smx_simcall_t simcall,
- const char* name, double flops_amount, double priority, double bound, unsigned long affinity_mask) {
- return SIMIX_execution_start(simcall->issuer, name,flops_amount,priority,bound,affinity_mask);
-}
-smx_synchro_t SIMIX_execution_start(smx_process_t issuer, const char *name,
- double flops_amount, double priority, double bound, unsigned long affinity_mask){
-
- /* alloc structures and initialize */
- simgrid::simix::Exec *exec = new simgrid::simix::Exec();
- exec->name = xbt_strdup(name);
- exec->state = SIMIX_RUNNING;
- exec->host = issuer->host;
-
- /* set surf's action */
- if (!MC_is_active() && !MC_record_replay_is_active()) {
-
- exec->surf_exec = issuer->host->pimpl_cpu->execution_start(flops_amount);
- exec->surf_exec->setData(exec);
- exec->surf_exec->setPriority(priority);
-
- if (bound != 0)
- static_cast<simgrid::surf::CpuAction*>(exec->surf_exec)->setBound(bound);
-
- if (affinity_mask != 0) {
- /* just a double check to confirm that this host is the host where this task is running. */
- xbt_assert(exec->host == issuer->host);
- static_cast<simgrid::surf::CpuAction*>(exec->surf_exec)
- ->setAffinity(issuer->host->pimpl_cpu, affinity_mask);
- }
- }
-
- XBT_DEBUG("Create execute synchro %p: %s", exec, exec->name);
-
- return exec;
-}
-
-smx_synchro_t SIMIX_execution_parallel_start(const char *name,
- int host_nb, sg_host_t *host_list,
- double *flops_amount, double *bytes_amount,
- double amount, double rate){
-
- sg_host_t *host_list_cpy = NULL;
- int i;
-
- /* alloc structures and initialize */
- simgrid::simix::Exec *exec = new simgrid::simix::Exec();
- exec->name = xbt_strdup(name);
- exec->state = SIMIX_RUNNING;
- exec->host = nullptr; /* FIXME: do we need the list of hosts? */
-
- /* set surf's synchro */
- host_list_cpy = xbt_new0(sg_host_t, host_nb);
- for (i = 0; i < host_nb; i++)
- host_list_cpy[i] = host_list[i];