X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ff0019a9ce0b8b717b8d14f0907004adc804f5c2..e631fc4ebfccaf24508e14216a9138669a635c6a:/src/simix/smx_user.c diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index c0198ab3ed..3ea1f92f17 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -214,7 +214,7 @@ smx_action_t simcall_host_parallel_execute(const char *name, xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i); for (j = 0 ; j < host_nb ; ++j) { xbt_assert(isfinite(communication_amount[i + host_nb * j]), - "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j); + "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j); } } @@ -343,6 +343,7 @@ e_smx_state_t simcall_host_execution_wait(smx_action_t execution) * \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL. * It can be retrieved with the function \ref simcall_process_get_data. * \param hostname name of the host where the new agent is executed. + * \param kill_time time when the process is killed * \param argc first argument passed to \a code * \param argv second argument passed to \a code * \param properties the properties of the process @@ -351,8 +352,10 @@ void simcall_process_create(smx_process_t *process, const char *name, xbt_main_func_t code, void *data, const char *hostname, + double kill_time, int argc, char **argv, - xbt_dict_t properties) + xbt_dict_t properties, + int auto_restart) { smx_simcall_t simcall = SIMIX_simcall_mine(); @@ -362,9 +365,11 @@ void simcall_process_create(smx_process_t *process, const char *name, simcall->process_create.code = code; simcall->process_create.data = data; simcall->process_create.hostname = hostname; + simcall->process_create.kill_time = kill_time; simcall->process_create.argc = argc; simcall->process_create.argv = argv; simcall->process_create.properties = properties; + simcall->process_create.auto_restart = auto_restart; SIMIX_simcall_push(simcall->issuer); } @@ -518,6 +523,23 @@ void simcall_process_set_data(smx_process_t process, void *data) } } +/** + * \brief Set the kill time of a process. + * \param process a process + * \param kill_time a double + */ +void simcall_process_set_kill_time(smx_process_t process, double kill_time) +{ + + if (kill_time > SIMIX_get_clock()) { + if (simix_global->kill_process_function) { + XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name, + process->smx_host->name); + SIMIX_timer_set(kill_time, simix_global->kill_process_function, process); + } + } +} + /** * \brief Return the location on which an agent is running. * @@ -588,15 +610,42 @@ xbt_dict_t simcall_process_get_properties(smx_process_t process) SIMIX_simcall_push(simcall->issuer); return simcall->process_get_properties.result; } +/** + * \brief Add an on_exit function + * Add an on_exit function which will be executed when the process exits/is killed. + */ +XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data) { + smx_simcall_t simcall = SIMIX_simcall_mine(); + + simcall->call = SIMCALL_PROCESS_ON_EXIT; + simcall->process_on_exit.process = process; + simcall->process_on_exit.fun = fun; + simcall->process_on_exit.data = data; + SIMIX_simcall_push(simcall->issuer); +} +/** + * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up. + * Will restart the process when the host comes back up if auto_restart is set to 1. + */ + +XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart) { + smx_simcall_t simcall = SIMIX_simcall_mine(); + + simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET; + simcall->process_auto_restart.process = process; + simcall->process_auto_restart.auto_restart = auto_restart; + + SIMIX_simcall_push(simcall->issuer); +} /** \brief Creates a new sleep SIMIX action. * * This function creates a SURF action and allocates the data necessary * to create the SIMIX action. It can raise a host_error exception if the * host crashed. The default SIMIX name of the action is "sleep". * - * \param duration Time duration of the sleep. - * \return A result telling whether the sleep was successful + * \param duration Time duration of the sleep. + * \return A result telling whether the sleep was successful */ e_smx_state_t simcall_process_sleep(double duration) { @@ -697,7 +746,7 @@ smx_action_t simcall_rdv_get_head(smx_rdv_t rdv) void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), void *data, + int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout) { /* checking for infinite values */ @@ -732,7 +781,7 @@ void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate, smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void (*clean_fun)(void *), void *data, int detached) @@ -761,7 +810,7 @@ smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate, } void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, - int (*match_fun)(void *, void *), void *data, double timeout) + int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout) { xbt_assert(isfinite(timeout), "timeout is not finite!"); xbt_assert(rdv, "No rendez-vous point defined for recv"); @@ -788,7 +837,7 @@ void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, } smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, - int (*match_fun)(void *, void *), void *data) + int (*match_fun)(void *, void *, smx_action_t), void *data) { xbt_assert(rdv, "No rendez-vous point defined for irecv"); @@ -984,6 +1033,10 @@ int simcall_comm_is_latency_bounded(smx_action_t comm) smx_mutex_t simcall_mutex_init(void) { + if(!simix_global) { + fprintf(stderr,"You must run MSG_init or gras_init before using MSG or GRAS\n"); // I would have loved using xbt_die but I can't since it is not initialized yet... :) + abort(); + } smx_simcall_t simcall = SIMIX_simcall_mine(); simcall->call = SIMCALL_MUTEX_INIT; @@ -1079,8 +1132,6 @@ void simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout) { - xbt_ex_t e; - xbt_assert(isfinite(timeout), "timeout is not finite!"); smx_simcall_t simcall = SIMIX_simcall_mine(); @@ -1090,20 +1141,7 @@ void simcall_cond_wait_timeout(smx_cond_t cond, simcall->cond_wait_timeout.mutex = mutex; simcall->cond_wait_timeout.timeout = timeout; - TRY { - SIMIX_simcall_push(simcall->issuer); - } - CATCH(e) { - switch (e.category) { - case timeout_error: - simcall->issuer->waiting_action = NULL; // FIXME: should clean ? - break; - default: - break; - } - RETHROW; - xbt_ex_free(e); - } + SIMIX_simcall_push(simcall->issuer); } void simcall_cond_broadcast(smx_cond_t cond) @@ -1193,12 +1231,11 @@ int simcall_sem_get_capacity(smx_sem_t sem) return simcall->sem_get_capacity.result; } -size_t simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream) +double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream) { smx_simcall_t simcall = SIMIX_simcall_mine(); simcall->call = SIMCALL_FILE_READ; - simcall->file_read.storage = storage; simcall->file_read.ptr = ptr; simcall->file_read.size = size; simcall->file_read.nmemb = nmemb; @@ -1208,12 +1245,11 @@ size_t simcall_file_read(const char* storage, void* ptr, size_t size, size_t nme return simcall->file_read.result; } -size_t simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream) +size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream) { smx_simcall_t simcall = SIMIX_simcall_mine(); simcall->call = SIMCALL_FILE_WRITE; - simcall->file_write.storage = storage; simcall->file_write.ptr = ptr; simcall->file_write.size = size; simcall->file_write.nmemb = nmemb; @@ -1223,12 +1259,12 @@ size_t simcall_file_write(const char* storage, const void* ptr, size_t size, siz return simcall->file_write.result; } -smx_file_t simcall_file_open(const char* storage, const char* path, const char* mode) +smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode) { smx_simcall_t simcall = SIMIX_simcall_mine(); simcall->call = SIMCALL_FILE_OPEN; - simcall->file_open.storage = storage; + simcall->file_open.mount = mount; simcall->file_open.path = path; simcall->file_open.mode = mode; SIMIX_simcall_push(simcall->issuer); @@ -1236,23 +1272,21 @@ smx_file_t simcall_file_open(const char* storage, const char* path, const char* return simcall->file_open.result; } -int simcall_file_close(const char* storage, smx_file_t fp) +int simcall_file_close(smx_file_t fp) { smx_simcall_t simcall = SIMIX_simcall_mine(); simcall->call = SIMCALL_FILE_CLOSE; - simcall->file_close.storage = storage; simcall->file_close.fp = fp; SIMIX_simcall_push(simcall->issuer); return simcall->file_close.result; } -int simcall_file_stat(const char* storage, smx_file_t fd, s_file_stat_t *buf) +int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf) { smx_simcall_t simcall = SIMIX_simcall_mine(); simcall->call = SIMCALL_FILE_STAT; - simcall->file_stat.storage = storage; simcall->file_stat.fd = fd; SIMIX_simcall_push(simcall->issuer);