+smx_synchro_t SIMIX_host_execute(const char *name,
+ smx_host_t host, double flops_amount, double priority, double bound, unsigned long affinity_mask){
+
+ /* alloc structures and initialize */
+ smx_synchro_t synchro = xbt_mallocator_get(simix_global->synchro_mallocator);
+ synchro->type = SIMIX_SYNC_EXECUTE;
+ synchro->name = xbt_strdup(name);
+ synchro->state = SIMIX_RUNNING;
+ synchro->execution.host = host;
+ synchro->category = NULL;
+
+ /* set surf's action */
+ if (!MC_is_active() && !MC_record_replay_is_active()) {
+
+ synchro->execution.surf_exec = surf_workstation_execute(host, flops_amount);
+ surf_action_set_data(synchro->execution.surf_exec, synchro);
+ surf_action_set_priority(synchro->execution.surf_exec, priority);
+
+ /* Note (hypervisor): for multicore, the bound value being passed to the
+ * surf layer should not be zero (i.e., unlimited). It should be the
+ * capacity of a CPU core. */
+ if (bound == 0)
+ surf_cpu_action_set_bound(synchro->execution.surf_exec, SIMIX_host_get_speed(host));
+ else
+ surf_cpu_action_set_bound(synchro->execution.surf_exec, bound);
+
+ if (affinity_mask != 0) {
+ /* just a double check to confirm that this host is the host where this task is running. */
+ xbt_assert(synchro->execution.host == host);
+ surf_cpu_action_set_affinity(synchro->execution.surf_exec, host, affinity_mask);
+ }
+ }
+
+ XBT_DEBUG("Create execute synchro %p: %s", synchro, synchro->name);
+
+ return synchro;
+}
+
+smx_synchro_t SIMIX_host_parallel_execute(const char *name,
+ int host_nb, smx_host_t *host_list,
+ double *flops_amount, double *bytes_amount,
+ double amount, double rate){
+
+ void **workstation_list = NULL;
+ int i;
+
+ /* alloc structures and initialize */
+ smx_synchro_t synchro = xbt_mallocator_get(simix_global->synchro_mallocator);
+ synchro->type = SIMIX_SYNC_PARALLEL_EXECUTE;
+ synchro->name = xbt_strdup(name);
+ synchro->state = SIMIX_RUNNING;
+ synchro->execution.host = NULL; /* FIXME: do we need the list of hosts? */
+ synchro->category = NULL;
+
+ /* set surf's synchro */
+ workstation_list = xbt_new0(void *, host_nb);
+ for (i = 0; i < host_nb; i++)
+ workstation_list[i] = surf_workstation_resource_priv(host_list[i]);
+
+
+ /* FIXME: what happens if host_list contains VMs and PMs. If
+ * execute_parallel_task() does not change the state of the model, we can mix
+ * them. */
+ surf_model_t ws_model = surf_resource_model(host_list[0], SURF_WKS_LEVEL);
+ for (i = 1; i < host_nb; i++) {
+ surf_model_t ws_model_tmp = surf_resource_model(host_list[i], SURF_WKS_LEVEL);
+ if (ws_model_tmp != ws_model) {
+ XBT_CRITICAL("mixing VMs and PMs is not supported");
+ DIE_IMPOSSIBLE;
+ }
+ }
+
+ /* set surf's synchro */
+ if (!MC_is_active() && !MC_record_replay_is_active()) {
+ synchro->execution.surf_exec =
+ surf_workstation_model_execute_parallel_task((surf_workstation_model_t)surf_workstation_model,
+ host_nb, workstation_list, flops_amount, bytes_amount, rate);
+
+ surf_action_set_data(synchro->execution.surf_exec, synchro);
+ }
+ XBT_DEBUG("Create parallel execute synchro %p", synchro);
+
+ return synchro;
+}
+
+void SIMIX_host_execution_destroy(smx_synchro_t synchro){
+ XBT_DEBUG("Destroy synchro %p", synchro);
+
+ if (synchro->execution.surf_exec) {
+ surf_action_unref(synchro->execution.surf_exec);
+ synchro->execution.surf_exec = NULL;
+ }
+ xbt_free(synchro->name);
+ xbt_mallocator_release(simix_global->synchro_mallocator, synchro);
+}
+
+void SIMIX_host_execution_cancel(smx_synchro_t synchro){
+ XBT_DEBUG("Cancel synchro %p", synchro);
+
+ if (synchro->execution.surf_exec)
+ surf_action_cancel(synchro->execution.surf_exec);
+}
+
+double SIMIX_host_execution_get_remains(smx_synchro_t synchro){
+ double result = 0.0;
+
+ if (synchro->state == SIMIX_RUNNING)
+ result = surf_action_get_remains(synchro->execution.surf_exec);
+
+ return result;
+}
+
+e_smx_state_t SIMIX_host_execution_get_state(smx_synchro_t synchro){
+ return synchro->state;
+}
+
+void SIMIX_host_execution_set_priority(smx_synchro_t synchro, double priority){
+
+ if(synchro->execution.surf_exec)
+ surf_action_set_priority(synchro->execution.surf_exec, priority);
+}
+
+void SIMIX_host_execution_set_bound(smx_synchro_t synchro, double bound){
+
+ if(synchro->execution.surf_exec)
+ surf_cpu_action_set_bound(synchro->execution.surf_exec, bound);
+}
+
+void SIMIX_host_execution_set_affinity(smx_synchro_t synchro, smx_host_t host, unsigned long mask){
+ xbt_assert(synchro->type == SIMIX_SYNC_EXECUTE);
+
+ if (synchro->execution.surf_exec) {
+ /* just a double check to confirm that this host is the host where this task is running. */
+ xbt_assert(synchro->execution.host == host);
+ surf_cpu_action_set_affinity(synchro->execution.surf_exec, host, mask);
+ }
+}
+
+void simcall_HANDLER_host_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro){
+
+ XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state);
+
+ /* Associate this simcall to the synchro */
+ xbt_fifo_push(synchro->simcalls, simcall);
+ simcall->issuer->waiting_synchro = synchro;
+
+ /* set surf's synchro */
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ synchro->state = SIMIX_DONE;
+ SIMIX_execution_finish(synchro);
+ return;
+ }
+
+ /* If the synchro is already finished then perform the error handling */
+ if (synchro->state != SIMIX_RUNNING)
+ SIMIX_execution_finish(synchro);
+}
+
+void SIMIX_host_execution_suspend(smx_synchro_t synchro)