X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e41099ae20756bd6d3d3b01b14bdede95b6821cc..d6ce3162b34f0a964b8844368b9d86df4f1cf89b:/src/simix/smx_action.c diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index 213f6485bf..681da73274 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -24,33 +24,43 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_action, simix, * \param rate Communication rate between hosts. * \return A new SIMIX action * */ -smx_action_t SIMIX_action_communicate(smx_host_t sender,smx_host_t receiver,char * name, double size, double rate) +smx_action_t SIMIX_action_communicate(smx_host_t sender, + smx_host_t receiver, const char *name, + double size, double rate) { - /* check if the host is active */ - if ( surf_workstation_resource->extension_public->get_state(sender->simdata->host)!=SURF_CPU_ON) { - THROW1(network_error,0,"Host %s failed, you cannot call this function",sender->name); - } - if ( surf_workstation_resource->extension_public->get_state(receiver->simdata->host)!=SURF_CPU_ON) { - THROW1(network_error,0,"Host %s failed, you cannot call this function",receiver->name); - } - - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - act->name = xbt_strdup(name); - simdata->source = sender; - - - simdata->surf_action = surf_workstation_resource->extension_public-> - communicate(sender->simdata->host, - receiver->simdata->host, size, rate); - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); - - return act; + /* check if the host is active */ + if (surf_workstation_model->extension_public-> + get_state(sender->simdata->host) != SURF_CPU_ON) { + THROW1(network_error, 0, + "Host %s failed, you cannot call this function", sender->name); + } + if (surf_workstation_model->extension_public-> + get_state(receiver->simdata->host) != SURF_CPU_ON) { + THROW1(network_error, 0, + "Host %s failed, you cannot call this function", + receiver->name); + } + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + act->name = xbt_strdup(name); + simdata->source = sender; + + + simdata->surf_action = surf_workstation_model->extension_public-> + communicate(sender->simdata->host, + receiver->simdata->host, size, rate); + surf_workstation_model->common_public->action_set_data(simdata-> + surf_action, + act); + + DEBUG1("Create communicate action %p", act); + return act; } /** \brief Creates a new SIMIX action to execute an action. @@ -61,30 +71,36 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender,smx_host_t receiver,char * \param amount Task amount (in bytes) * \return A new SIMIX action * */ -smx_action_t SIMIX_action_execute(smx_host_t host, char * name, double amount) +smx_action_t SIMIX_action_execute(smx_host_t host, char *name, + double amount) { - /* check if the host is active */ - if ( surf_workstation_resource->extension_public->get_state(host->simdata->host)!=SURF_CPU_ON) { - THROW1(host_error,0,"Host %s failed, you cannot call this function",host->name); - } - - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - simdata->source = host; - act-> name = xbt_strdup(name); - - /* set communication */ - simdata->surf_action = surf_workstation_resource->extension_public-> - execute(host->simdata->host, amount); - - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); - - return act; + /* check if the host is active */ + if (surf_workstation_model->extension_public-> + get_state(host->simdata->host) != SURF_CPU_ON) { + THROW1(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + simdata->source = host; + act->name = xbt_strdup(name); + + /* set communication */ + simdata->surf_action = surf_workstation_model->extension_public-> + execute(host->simdata->host, amount); + + surf_workstation_model->common_public->action_set_data(simdata-> + surf_action, + act); + + DEBUG1("Create execute action %p", act); + return act; } /** \brief Creates a new sleep SIMIX action. @@ -94,31 +110,36 @@ smx_action_t SIMIX_action_execute(smx_host_t host, char * name, double amount) * \param duration Time duration of the sleep. * \return A new SIMIX action * */ -smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) -{ - char name[] = "sleep"; - - /* check if the host is active */ - if ( surf_workstation_resource->extension_public->get_state(host->simdata->host)!=SURF_CPU_ON) { - THROW1(host_error,0,"Host %s failed, you cannot call this function",host->name); - } - - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - simdata->source = host; - act->name = xbt_strdup(name); - - simdata->surf_action = surf_workstation_resource->extension_public-> - sleep(host->simdata->host, duration); - - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); - - return act; +smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) +{ + char name[] = "sleep"; + + /* check if the host is active */ + if (surf_workstation_model->extension_public-> + get_state(host->simdata->host) != SURF_CPU_ON) { + THROW1(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + simdata->source = host; + act->name = xbt_strdup(name); + + simdata->surf_action = surf_workstation_model->extension_public-> + sleep(host->simdata->host, duration); + + surf_workstation_model->common_public->action_set_data(simdata-> + surf_action, + act); + + DEBUG1("Create sleep action %p", act); + return act; } /** @@ -131,8 +152,11 @@ void SIMIX_action_cancel(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - if(action->simdata->surf_action) { - surf_workstation_resource->common_public->action_cancel(action->simdata->surf_action); + DEBUG1("Cancel action %p", action); + if (action->simdata->surf_action) { + surf_workstation_model->common_public->action_cancel(action-> + simdata-> + surf_action); } return; } @@ -146,11 +170,12 @@ void SIMIX_action_cancel(smx_action_t action) */ void SIMIX_action_set_priority(smx_action_t action, double priority) { - xbt_assert0( (action != NULL) && (action->simdata != NULL), "Invalid parameter" ); + xbt_assert0((action != NULL) + && (action->simdata != NULL), "Invalid parameter"); - surf_workstation_resource->common_public-> - set_priority(action->simdata->surf_action, priority); - return; + surf_workstation_model->common_public-> + set_priority(action->simdata->surf_action, priority); + return; } /** @@ -161,22 +186,25 @@ void SIMIX_action_set_priority(smx_action_t action, double priority) */ void SIMIX_action_destroy(smx_action_t action) { + xbt_assert0((action != NULL), "Invalid parameter"); - xbt_assert0((action != NULL), "Invalid parameter"); - - xbt_assert1((xbt_fifo_size(action->cond_list)==0), - "Conditional list not empty %d. There is a problem. Cannot destroy it now!", xbt_fifo_size(action->cond_list)); + xbt_assert1((xbt_fifo_size(action->cond_list) == 0), + "Conditional list not empty %d. There is a problem. Cannot destroy it now!", + xbt_fifo_size(action->cond_list)); - if(action->name) xbt_free(action->name); + DEBUG1("Destroy action %p", action); + if (action->name) + xbt_free(action->name); - xbt_fifo_free(action->cond_list); + xbt_fifo_free(action->cond_list); - if(action->simdata->surf_action) - action->simdata->surf_action->resource_type->common_public->action_free(action->simdata->surf_action); + if (action->simdata->surf_action) + action->simdata->surf_action->model_type->common_public-> + action_free(action->simdata->surf_action); - xbt_free(action->simdata); - xbt_free(action); - return; + xbt_free(action->simdata); + xbt_free(action); + return; } /** @@ -186,11 +214,39 @@ void SIMIX_action_destroy(smx_action_t action) * \param action SIMIX action * \param cond SIMIX cond */ -void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) +void SIMIX_register_action_to_condition(smx_action_t action, + smx_cond_t cond) { - xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters"); + xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); + + DEBUG2("Register action %p to cond %p", action, cond); + __SIMIX_cond_display_actions(cond); + xbt_fifo_push(cond->actions, action); + __SIMIX_cond_display_actions(cond); + DEBUG2("Register condition %p to action %p", cond, action); + __SIMIX_action_display_conditions(action); + xbt_fifo_push(action->cond_list, cond); + __SIMIX_action_display_conditions(action); +} - xbt_fifo_push(cond->actions,action); +/** + * \brief Unset an action to a condition. + * + * Destroys the "links" from the condition to this action. + * \param action SIMIX action + * \param cond SIMIX cond + */ +void SIMIX_unregister_action_to_condition(smx_action_t action, + smx_cond_t cond) +{ + xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); + + __SIMIX_cond_display_actions(cond); + xbt_fifo_remove_all(cond->actions, action); + __SIMIX_cond_display_actions(cond); + __SIMIX_action_display_conditions(action); + xbt_fifo_remove_all(action->cond_list, cond); + __SIMIX_action_display_conditions(action); } /** @@ -199,8 +255,73 @@ void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) * \param action The SIMIX action * \return Remains cost */ -double SIMIX_action_get_remains(smx_action_t action) +double SIMIX_action_get_remains(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return action->simdata->surf_action->remains; + return action->simdata->surf_action->remains; +} + +smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, + smx_host_t *host_list, + double *computation_amount, + double *communication_amount, + double amount, double rate) +{ + void **workstation_list = NULL; + int i; + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + act->name = xbt_strdup(name); + + /* set action */ + + workstation_list = xbt_new0(void *,host_nb); + for (i = 0; i < host_nb; i++) + workstation_list[i] = host_list[i]->simdata->host; + + simdata->surf_action = + surf_workstation_model->extension_public-> + execute_parallel_task(host_nb, workstation_list, + computation_amount, communication_amount, + amount, rate); + + surf_workstation_model->common_public->action_set_data(simdata-> + surf_action, + act); + + return act; +} + +e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) +{ + xbt_assert0((action != NULL), "Invalid parameter"); + return surf_workstation_model->common_public-> + action_get_state(action->simdata->surf_action); + +} + +void __SIMIX_cond_display_actions(smx_cond_t cond) +{ + xbt_fifo_item_t item = NULL; + smx_action_t action = NULL; + + DEBUG1("Actions for condition %p", cond); + xbt_fifo_foreach(cond->actions, item, action, smx_action_t) + DEBUG1("\t %p", action); +} + +void __SIMIX_action_display_conditions(smx_action_t action) +{ + xbt_fifo_item_t item = NULL; + smx_cond_t cond = NULL; + + DEBUG1("Conditions for action %p", action); + xbt_fifo_foreach(action->cond_list, item, cond, smx_cond_t) + DEBUG1("\t %p", cond); }