X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/34c9e08888fae4fc39aa22502070b37c0ab8a5d6..6e5457a22be7df9fa12847d3f18c43c4619bc3e2:/src/simix/smx_user.c diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 1b75a462a9..fb7560746e 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1,4 +1,17 @@ +/* smx_user.c - public interface to simix */ + +/* Copyright (c) 2010, 2011. Da SimGrid team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ +#define _SVID_SOURCE /* strdup */ +#define _ISO_C99_SOURCE /* isfinite() */ +#define _ISOC99_SOURCE /* isfinite() */ +#include /* isfinite() */ + #include "private.h" +#include "mc/mc.h" + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix); @@ -150,14 +163,20 @@ void SIMIX_req_host_set_data(smx_host_t host, void *data) * \return A new SIMIX execution action */ smx_action_t SIMIX_req_host_execute(const char *name, smx_host_t host, - double computation_amount) + double computation_amount, + double priority) { + /* checking for infinite values */ + xbt_assert(isfinite(computation_amount), "computation_amount is not finite!"); + xbt_assert(isfinite(priority), "priority is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_HOST_EXECUTE; req->host_execute.name = name; req->host_execute.host = host; req->host_execute.computation_amount = computation_amount; + req->host_execute.priority = priority; SIMIX_request_push(); return req->host_execute.result; } @@ -183,6 +202,19 @@ smx_action_t SIMIX_req_host_parallel_execute(const char *name, double amount, double rate) { + int i,j; + /* checking for infinite values */ + for (i = 0 ; i < host_nb ; ++i) { + 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); + } + } + + xbt_assert(isfinite(amount), "amount is not finite!"); + xbt_assert(isfinite(rate), "rate is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_HOST_PARALLEL_EXECUTE; @@ -268,6 +300,9 @@ e_smx_state_t SIMIX_req_host_execution_get_state(smx_action_t execution) */ void SIMIX_req_host_execution_set_priority(smx_action_t execution, double priority) { + /* checking for infinite values */ + xbt_assert(isfinite(priority), "priority is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_HOST_EXECUTION_SET_PRIORITY; @@ -277,24 +312,26 @@ void SIMIX_req_host_execution_set_priority(smx_action_t execution, double priori } /** - * \brief Waits for the completion of an execution action. + * \brief Waits for the completion of an execution action and destroy it. * * \param execution The execution action */ -void SIMIX_req_host_execution_wait(smx_action_t execution) +e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution) { smx_req_t req = SIMIX_req_mine(); req->call = REQ_HOST_EXECUTION_WAIT; req->host_execution_wait.execution = execution; SIMIX_request_push(); + return req->host_execution_wait.result; } /** * \brief Creates and runs a new SIMIX process. * - * The structure and the corresponding threada are created and put in the list of ready processes. + * The structure and the corresponding thread are created and put in the list of ready processes. * + * \param process the process created will be stored in this pointer * \param name a name for the process. It is for user-level information and can be NULL. * \param code the main function of the process * \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. @@ -303,18 +340,18 @@ void SIMIX_req_host_execution_wait(smx_action_t execution) * \param argc first argument passed to \a code * \param argv second argument passed to \a code * \param properties the properties of the process - * \return The new process */ -smx_process_t SIMIX_req_process_create(const char *name, - xbt_main_func_t code, - void *data, - const char *hostname, - int argc, char **argv, - xbt_dict_t properties) +void SIMIX_req_process_create(smx_process_t *process, const char *name, + xbt_main_func_t code, + void *data, + const char *hostname, + int argc, char **argv, + xbt_dict_t properties) { smx_req_t req = SIMIX_req_mine(); req->call = REQ_PROCESS_CREATE; + req->process_create.process = process; req->process_create.name = name; req->process_create.code = code; req->process_create.data = data; @@ -323,7 +360,6 @@ smx_process_t SIMIX_req_process_create(const char *name, req->process_create.argv = argv; req->process_create.properties = properties; SIMIX_request_push(); - return req->process_create.result; } /** \brief Kills a SIMIX process. @@ -341,6 +377,28 @@ void SIMIX_req_process_kill(smx_process_t process) SIMIX_request_push(); } +/** \brief Kills all SIMIX processes. + */ +void SIMIX_req_process_killall(void) +{ + smx_req_t req = SIMIX_req_mine(); + + req->call = REQ_PROCESS_KILLALL; + SIMIX_request_push(); +} + +/** \brief Cleans up a SIMIX process. + * \param process poor victim (must have already been killed) + */ +void SIMIX_req_process_cleanup(smx_process_t process) +{ + smx_req_t req = SIMIX_req_mine(); + + req->call = REQ_PROCESS_CLEANUP; + req->process_cleanup.process = process; + SIMIX_request_push(); +} + /** * \brief Migrates an agent to another location. * @@ -350,13 +408,12 @@ void SIMIX_req_process_kill(smx_process_t process) * \param source name of the previous host * \param dest name of the new host */ -void SIMIX_req_process_change_host(smx_process_t process, const char *source, const char *dest) +void SIMIX_req_process_change_host(smx_process_t process, smx_host_t dest) { smx_req_t req = SIMIX_req_mine(); req->call = REQ_PROCESS_CHANGE_HOST; req->process_change_host.process = process; - req->process_change_host.source = source; req->process_change_host.dest = dest; SIMIX_request_push(); } @@ -371,6 +428,8 @@ void SIMIX_req_process_change_host(smx_process_t process, const char *source, co */ void SIMIX_req_process_suspend(smx_process_t process) { + xbt_assert(process, "Invalid parameters"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_PROCESS_SUSPEND; @@ -418,6 +477,11 @@ int SIMIX_req_process_count(void) */ void* SIMIX_req_process_get_data(smx_process_t process) { + if (process == SIMIX_process_self()) { + /* avoid a request if this function is called by the process itself */ + return SIMIX_process_self_get_data(); + } + smx_req_t req = SIMIX_req_mine(); req->call = REQ_PROCESS_GET_DATA; @@ -435,12 +499,19 @@ void* SIMIX_req_process_get_data(smx_process_t process) */ void SIMIX_req_process_set_data(smx_process_t process, void *data) { - smx_req_t req = SIMIX_req_mine(); + if (process == SIMIX_process_self()) { + /* avoid a request if this function is called by the process itself */ + SIMIX_process_self_set_data(data); + } + else { - req->call = REQ_PROCESS_SET_DATA; - req->process_set_data.process = process; - req->process_set_data.data = data; - SIMIX_request_push(); + smx_req_t req = SIMIX_req_mine(); + + req->call = REQ_PROCESS_SET_DATA; + req->process_set_data.process = process; + req->process_set_data.data = data; + SIMIX_request_push(); + } } /** @@ -469,6 +540,11 @@ smx_host_t SIMIX_req_process_get_host(smx_process_t process) */ const char* SIMIX_req_process_get_name(smx_process_t process) { + if (process == SIMIX_process_self()) { + /* avoid a request if this function is called by the process itself */ + return process->name; + } + smx_req_t req = SIMIX_req_mine(); req->call = REQ_PROCESS_GET_NAME; @@ -520,6 +596,9 @@ xbt_dict_t SIMIX_req_process_get_properties(smx_process_t process) */ e_smx_state_t SIMIX_req_process_sleep(double duration) { + /* checking for infinite values */ + xbt_assert(isfinite(duration), "duration is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_PROCESS_SLEEP; @@ -561,13 +640,19 @@ void SIMIX_req_rdv_destroy(smx_rdv_t rdv) smx_rdv_t SIMIX_req_rdv_get_by_name(const char *name) { - xbt_assert0(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)"); - smx_req_t req = SIMIX_req_mine(); + xbt_assert(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)"); + /* FIXME: this is a horrible lost of performance, so we hack it out by + * skipping the request (for now). It won't work on distributed but + * probably we will change MSG for that. */ +/* + smx_req_t req = SIMIX_req_mine(); req->call = REQ_RDV_GEY_BY_NAME; req->rdv_get_by_name.name = name; SIMIX_request_push(); - return req->rdv_get_by_name.result; + return req->rdv_get_by_name.result;*/ + + return SIMIX_rdv_get_by_name(name); } /** @@ -605,13 +690,53 @@ smx_action_t SIMIX_req_rdv_get_head(smx_rdv_t rdv) return req->rdv_get_head.result; } +void SIMIX_req_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, + double timeout) +{ + /* checking for infinite values */ + xbt_assert(isfinite(task_size), "task_size is not finite!"); + xbt_assert(isfinite(rate), "rate is not finite!"); + xbt_assert(isfinite(timeout), "timeout is not finite!"); + + xbt_assert(rdv, "No rendez-vous point defined for send"); + + if (MC_IS_ENABLED) { + /* the model-checker wants two separate requests */ + smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate, + src_buff, src_buff_size, match_fun, data, 0); + SIMIX_req_comm_wait(comm, timeout); + } + else { + smx_req_t req = SIMIX_req_mine(); + + req->call = REQ_COMM_SEND; + req->comm_send.rdv = rdv; + req->comm_send.task_size = task_size; + req->comm_send.rate = rate; + req->comm_send.src_buff = src_buff; + req->comm_send.src_buff_size = src_buff_size; + req->comm_send.match_fun = match_fun; + req->comm_send.data = data; + req->comm_send.timeout = timeout; + + SIMIX_request_push(); + } +} + smx_action_t SIMIX_req_comm_isend(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 *), void *data, + int detached) { - smx_req_t req = SIMIX_req_mine(); + /* checking for infinite values */ + xbt_assert(isfinite(task_size), "task_size is not finite!"); + xbt_assert(isfinite(rate), "rate is not finite!"); + + xbt_assert(rdv, "No rendez-vous point defined for isend"); - xbt_assert0(rdv, "No rendez-vous point defined for isend"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_COMM_ISEND; req->comm_isend.rdv = rdv; @@ -621,17 +746,45 @@ smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate, req->comm_isend.src_buff_size = src_buff_size; req->comm_isend.match_fun = match_fun; req->comm_isend.data = data; + req->comm_isend.detached = detached; SIMIX_request_push(); return req->comm_isend.result; } +void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, + int (*match_fun)(void *, void *), void *data, double timeout) +{ + xbt_assert(isfinite(timeout), "timeout is not finite!"); + xbt_assert(rdv, "No rendez-vous point defined for recv"); + + if (MC_IS_ENABLED) { + /* the model-checker wants two separate requests */ + smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size, + match_fun, data); + SIMIX_req_comm_wait(comm, timeout); + } + else { + smx_req_t req = SIMIX_req_mine(); + + req->call = REQ_COMM_RECV; + req->comm_recv.rdv = rdv; + req->comm_recv.dst_buff = dst_buff; + req->comm_recv.dst_buff_size = dst_buff_size; + req->comm_recv.match_fun = match_fun; + req->comm_recv.data = data; + req->comm_recv.timeout = timeout; + + SIMIX_request_push(); + } +} + smx_action_t SIMIX_req_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 *), void *data) { - smx_req_t req = SIMIX_req_mine(); + xbt_assert(rdv, "No rendez-vous point defined for irecv"); - xbt_assert0(rdv, "No rendez-vous point defined for isend"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_COMM_IRECV; req->comm_irecv.rdv = rdv; @@ -646,12 +799,19 @@ smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_bu void SIMIX_req_comm_destroy(smx_action_t comm) { + xbt_assert(comm, "Invalid parameter"); + + /* FIXME remove this request type: comms are auto-destroyed now, + * but what happens with unfinished comms? */ + + /* smx_req_t req = SIMIX_req_mine(); req->call = REQ_COMM_DESTROY; req->comm_destroy.comm = comm; SIMIX_request_push(); + */ } void SIMIX_req_comm_cancel(smx_action_t comm) @@ -690,6 +850,8 @@ int SIMIX_req_comm_testany(xbt_dynar_t comms) void SIMIX_req_comm_wait(smx_action_t comm, double timeout) { + xbt_assert(isfinite(timeout), "timeout is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_COMM_WAIT; @@ -778,50 +940,6 @@ void *SIMIX_req_comm_get_dst_data(smx_action_t comm) return req->comm_get_dst_data.result; } -void *SIMIX_req_comm_get_src_buff(smx_action_t comm) -{ - smx_req_t req = SIMIX_req_mine(); - - req->call = REQ_COMM_GET_SRC_BUFF; - req->comm_get_src_buff.comm = comm; - - SIMIX_request_push(); - return req->comm_get_src_buff.result; -} - -void *SIMIX_req_comm_get_dst_buff(smx_action_t comm) -{ - smx_req_t req = SIMIX_req_mine(); - - req->call = REQ_COMM_GET_DST_BUFF; - req->comm_get_dst_buff.comm = comm; - - SIMIX_request_push(); - return req->comm_get_dst_buff.result; -} - -size_t SIMIX_req_comm_get_src_buff_size(smx_action_t comm) -{ - smx_req_t req = SIMIX_req_mine(); - - req->call = REQ_COMM_GET_SRC_BUFF_SIZE; - req->comm_get_src_buff_size.comm = comm; - - SIMIX_request_push(); - return req->comm_get_src_buff_size.result; -} - -size_t SIMIX_req_comm_get_dst_buff_size(smx_action_t comm) -{ - smx_req_t req = SIMIX_req_mine(); - - req->call = REQ_COMM_GET_DST_BUFF_SIZE; - req->comm_get_dst_buff_size.comm = comm; - - SIMIX_request_push(); - return req->comm_get_dst_buff_size.result; -} - smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm) { smx_req_t req = SIMIX_req_mine(); @@ -954,6 +1072,8 @@ void SIMIX_req_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout) { + xbt_assert(isfinite(timeout), "timeout is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_COND_WAIT_TIMEOUT; @@ -1029,6 +1149,8 @@ void SIMIX_req_sem_acquire(smx_sem_t sem) void SIMIX_req_sem_acquire_timeout(smx_sem_t sem, double timeout) { + xbt_assert(isfinite(timeout), "timeout is not finite!"); + smx_req_t req = SIMIX_req_mine(); req->call = REQ_SEM_ACQUIRE_TIMEOUT;