From: mquinson Date: Mon, 10 Nov 2008 13:43:47 +0000 (+0000) Subject: Kill MSG_mailbox_put, which were not meant to be a public symbol anyway, add MSG_get_... X-Git-Tag: v3.3~113 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3ce8957cfe6f904f244fdd79731800f0c61e50b0 Kill MSG_mailbox_put, which were not meant to be a public symbol anyway, add MSG_get_sent_msg() to retrieve the amount of messages exchanged during the simulation, plus a whole load of automatic reindent from eclipse (sorry for the noise) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6008 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/msg/msg.h b/include/msg/msg.h index 4fe9c1d18e..28bbc28776 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -28,6 +28,8 @@ XBT_PUBLIC(void) MSG_launch_application(const char *file); XBT_PUBLIC(void) MSG_paje_output(const char *filename); XBT_PUBLIC(double) MSG_get_clock(void); +XBT_PUBLIC(unsigned long int) MSG_get_sent_msg(void); + /************************** Host handling ***********************************/ XBT_PUBLIC(MSG_error_t) MSG_host_set_data(m_host_t host, void *data); @@ -87,7 +89,7 @@ XBT_PUBLIC(int) MSG_process_is_suspended(m_process_t process); XBT_PUBLIC(m_task_t) MSG_task_create(const char *name, double compute_duration, double message_size, void *data); -XBT_PUBLIC(m_task_t) MSG_parallel_task_create(const char *name, +XBT_PUBLIC(m_task_t) MSG_parallel_task_create(const char *name, int host_nb, const m_host_t *host_list, double *computation_amount, @@ -103,20 +105,20 @@ XBT_PUBLIC(MSG_error_t) MSG_task_destroy(m_task_t task); XBT_PUBLIC(MSG_error_t) MSG_task_get(m_task_t * task, m_channel_t channel); XBT_PUBLIC(MSG_error_t) MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel, double max_duration); -XBT_PUBLIC(MSG_error_t) MSG_task_get_from_host(m_task_t * task, int channel, +XBT_PUBLIC(MSG_error_t) MSG_task_get_from_host(m_task_t * task, int channel, m_host_t host); -MSG_error_t +MSG_error_t MSG_task_receive_from_host(m_task_t * task, const char* alias, m_host_t host); -XBT_PUBLIC(MSG_error_t) MSG_task_get_ext(m_task_t * task, int channel, +XBT_PUBLIC(MSG_error_t) MSG_task_get_ext(m_task_t * task, int channel, double max_duration, m_host_t host); -XBT_PUBLIC(MSG_error_t) MSG_task_put(m_task_t task, m_host_t dest, +XBT_PUBLIC(MSG_error_t) MSG_task_put(m_task_t task, m_host_t dest, m_channel_t channel); XBT_PUBLIC(MSG_error_t) MSG_task_put_bounded(m_task_t task, m_host_t dest, m_channel_t channel, double max_rate); -XBT_PUBLIC(MSG_error_t) MSG_task_put_with_timeout(m_task_t task, m_host_t dest, +XBT_PUBLIC(MSG_error_t) MSG_task_put_with_timeout(m_task_t task, m_host_t dest, m_channel_t channel, double max_duration); XBT_PUBLIC(MSG_error_t) MSG_task_execute(m_task_t task); XBT_PUBLIC(MSG_error_t) MSG_parallel_task_execute(m_task_t task); @@ -136,31 +138,31 @@ XBT_PUBLIC(double) MSG_task_get_remaining_communication(m_task_t task); XBT_PUBLIC(double) MSG_task_get_data_size(m_task_t task); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_task_receive_ext(m_task_t* task, const char* alias, double timeout, m_host_t host); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_task_receive_with_timeout(m_task_t * task, const char* alias, double timeout); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_task_receive(m_task_t * task, const char* alias); -XBT_PUBLIC(int) +XBT_PUBLIC(int) MSG_task_listen(const char* alias); -XBT_PUBLIC(int) +XBT_PUBLIC(int) MSG_task_listen_from_host(const char* alias, m_host_t host); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_alias_select_from(const char* alias, double timeout, int* PID); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_task_send_with_timeout(m_task_t task, const char* alias, double timeout); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_task_send(m_task_t task,const char* alias); -XBT_PUBLIC(MSG_error_t) +XBT_PUBLIC(MSG_error_t) MSG_task_send_bounded(m_task_t task, const char* alias, double rate); XBT_PUBLIC(int) diff --git a/src/msg/global.c b/src/msg/global.c index d9d1719568..090574b722 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -22,7 +22,7 @@ MSG_Global_t msg_global = NULL; /** \defgroup msg_simulation MSG simulation Functions * \brief This section describes the functions you need to know to - * set up a simulation. You should have a look at \ref MSG_examples + * set up a simulation. You should have a look at \ref MSG_examples * to have an overview of their usage. */ /** @addtogroup msg_simulation @@ -57,7 +57,7 @@ void MSG_global_init(int *argc, char **argv) XBT_LOG_CONNECT(msg_kernel, msg); XBT_LOG_CONNECT(msg_mailbox, msg); XBT_LOG_CONNECT(msg_process, msg); - + SIMIX_global_init(argc, argv); msg_global = xbt_new0(s_MSG_Global_t, 1); @@ -66,6 +66,7 @@ void MSG_global_init(int *argc, char **argv) msg_global->process_list = xbt_fifo_new(); msg_global->max_channel = 0; msg_global->PID = 1; + msg_global->sent_msg = 0; /* initialization of the mailbox module */ MSG_mailbox_mod_init(); @@ -91,7 +92,7 @@ void MSG_paje_output(const char *filename) */ /** @addtogroup m_channel_management * \htmlonly \endhtmlonly - * + * * * For convenience, the simulator provides the notion of channel * that is close to the tag notion in MPI. A channel is not a @@ -124,7 +125,7 @@ MSG_error_t MSG_set_channel_number(int number) /** \ingroup m_channel_management * \brief Return the number of channel in the simulation. * - * This function has to be called once the number of channel is fixed. I can't + * This function has to be called once the number of channel is fixed. I can't figure out a reason why anyone would like to call this function but nevermind. * \return the number of channel in the simulation. */ @@ -251,7 +252,7 @@ MSG_error_t MSG_clean(void) SIMIX_clean(); - + return MSG_OK; } @@ -264,3 +265,7 @@ double MSG_get_clock(void) { return SIMIX_get_clock(); } + +unsigned long int MSG_get_sent_msg() { + return msg_global->sent_msg; +} diff --git a/src/msg/gos.c b/src/msg/gos.c index 8d5cf00b4b..0eb23d7e97 100644 --- a/src/msg/gos.c +++ b/src/msg/gos.c @@ -21,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg, * \brief Return the last value returned by a MSG function (except * MSG_get_errno...). */ -MSG_error_t +MSG_error_t MSG_get_errno(void) { return PROCESS_GET_ERRNO(); @@ -37,33 +37,33 @@ MSG_get_errno(void) * \return #MSG_FATAL if \a task is not properly initialized and * #MSG_OK otherwise. */ -MSG_error_t +MSG_error_t MSG_task_execute(m_task_t task) { simdata_task_t simdata = NULL; m_process_t self = MSG_process_self(); CHECK_HOST(); - + simdata = task->simdata; xbt_assert0((!simdata->compute) && (task->simdata->refcount == 1),"This task is executed somewhere else. Go fix your code!"); - + DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); - + simdata->refcount ++; SIMIX_mutex_lock(simdata->mutex); simdata->compute = SIMIX_action_execute(SIMIX_host_self(), task->name, simdata->computation_amount); SIMIX_action_set_priority(simdata->compute, simdata->priority); - + self->simdata->waiting_task = task; SIMIX_register_action_to_condition(simdata->compute, simdata->cond); SIMIX_cond_wait(simdata->cond, simdata->mutex); SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond); self->simdata->waiting_task = NULL; - + SIMIX_mutex_unlock(simdata->mutex); simdata->refcount --; - - if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) + + if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ SIMIX_action_destroy(task->simdata->compute); @@ -71,16 +71,16 @@ MSG_task_execute(m_task_t task) simdata->comm = NULL; simdata->compute = NULL; MSG_RETURN(MSG_OK); - } - else if(SIMIX_host_get_state(SIMIX_host_self()) == 0) + } + else if(SIMIX_host_get_state(SIMIX_host_self()) == 0) { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ SIMIX_action_destroy(task->simdata->compute); simdata->comm = NULL; simdata->compute = NULL; MSG_RETURN(MSG_HOST_FAILURE); - } - else + } + else { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ SIMIX_action_destroy(task->simdata->compute); @@ -93,7 +93,7 @@ MSG_task_execute(m_task_t task) /** \ingroup m_task_management * \brief Creates a new #m_task_t (a parallel one....). * - * A constructor for #m_task_t taking six arguments and returning the + * A constructor for #m_task_t taking six arguments and returning the corresponding object. * \param name a name for the object. It is for user-level information and can be NULL. @@ -109,18 +109,18 @@ MSG_task_execute(m_task_t task) * \see m_task_t * \return The new corresponding object. */ -m_task_t +m_task_t MSG_parallel_task_create(const char *name,int host_nb, const m_host_t * host_list, double *computation_amount, double *communication_amount, void *data) { int i; simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1); m_task_t task = xbt_new0(s_m_task_t, 1); task->simdata = simdata; - + /* Task structure */ task->name = xbt_strdup(name); task->data = data; - + /* Simulator Data */ simdata->computation_amount = 0; simdata->message_size = 0; @@ -133,50 +133,50 @@ MSG_parallel_task_create(const char *name,int host_nb, const m_host_t * host_lis simdata->sender = NULL; simdata->receiver = NULL; simdata->source = NULL; - + simdata->host_nb = host_nb; simdata->host_list = xbt_new0(smx_host_t, host_nb); simdata->comp_amount = computation_amount; simdata->comm_amount = communication_amount; - + for (i = 0; i < host_nb; i++) simdata->host_list[i] = host_list[i]->simdata->smx_host; - + return task; } -MSG_error_t +MSG_error_t MSG_parallel_task_execute(m_task_t task) { simdata_task_t simdata = NULL; m_process_t self = MSG_process_self(); CHECK_HOST(); - + simdata = task->simdata; - + xbt_assert0((!simdata->compute) && (task->simdata->refcount == 1),"This task is executed somewhere else. Go fix your code!"); - + xbt_assert0(simdata->host_nb,"This is not a parallel task. Go to hell."); - + DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); - + simdata->refcount ++; - + SIMIX_mutex_lock(simdata->mutex); simdata->compute = SIMIX_action_parallel_execute(task->name, simdata->host_nb, simdata->host_list, simdata->comp_amount, simdata->comm_amount, 1.0, -1.0); - + self->simdata->waiting_task = task; SIMIX_register_action_to_condition(simdata->compute, simdata->cond); SIMIX_cond_wait(simdata->cond, simdata->mutex); SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond); self->simdata->waiting_task = NULL; - - + + SIMIX_mutex_unlock(simdata->mutex); simdata->refcount --; - - if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) + + if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ SIMIX_action_destroy(task->simdata->compute); @@ -184,16 +184,16 @@ MSG_parallel_task_execute(m_task_t task) simdata->comm = NULL; simdata->compute = NULL; MSG_RETURN(MSG_OK); - } - else if(SIMIX_host_get_state(SIMIX_host_self()) == 0) + } + else if(SIMIX_host_get_state(SIMIX_host_self()) == 0) { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ SIMIX_action_destroy(task->simdata->compute); simdata->comm = NULL; simdata->compute = NULL; MSG_RETURN(MSG_HOST_FAILURE); - } - else + } + else { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ SIMIX_action_destroy(task->simdata->compute); @@ -212,46 +212,46 @@ MSG_parallel_task_execute(m_task_t task) * * \param nb_sec a number of second */ -MSG_error_t +MSG_error_t MSG_process_sleep(double nb_sec) { smx_action_t act_sleep; m_process_t proc = MSG_process_self(); smx_mutex_t mutex; smx_cond_t cond; - + /* create action to sleep */ act_sleep = SIMIX_action_sleep(SIMIX_process_get_host(proc->simdata->s_process), nb_sec); - + mutex = SIMIX_mutex_init(); SIMIX_mutex_lock(mutex); - + /* create conditional and register action to it */ cond = SIMIX_cond_init(); - + SIMIX_register_action_to_condition(act_sleep, cond); SIMIX_cond_wait(cond, mutex); SIMIX_unregister_action_to_condition(act_sleep, cond); SIMIX_mutex_unlock(mutex); - + /* remove variables */ SIMIX_cond_destroy(cond); SIMIX_mutex_destroy(mutex); - - if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) + + if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { - if (SIMIX_host_get_state(SIMIX_host_self()) == SURF_CPU_OFF) + if (SIMIX_host_get_state(SIMIX_host_self()) == SURF_CPU_OFF) { SIMIX_action_destroy(act_sleep); MSG_RETURN(MSG_HOST_FAILURE); } - } - else + } + else { SIMIX_action_destroy(act_sleep); MSG_RETURN(MSG_HOST_FAILURE); } - + MSG_RETURN(MSG_OK); } @@ -259,7 +259,7 @@ MSG_process_sleep(double nb_sec) * \brief Return the number of MSG tasks currently running on * the host of the current running process. */ -static int +static int MSG_get_msgload(void) { xbt_die("not implemented yet"); @@ -283,7 +283,7 @@ MSG_get_msgload(void) * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING if \a *task is not equal to \c NULL, and #MSG_OK otherwise. */ -MSG_error_t +MSG_error_t MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host) { return MSG_task_get_ext(task, channel, -1, host); @@ -303,7 +303,7 @@ MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host) * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING * if \a *task is not equal to \c NULL, and #MSG_OK otherwise. */ -MSG_error_t +MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel) { return MSG_task_get_with_timeout(task, channel, -1); @@ -321,13 +321,13 @@ MSG_task_get(m_task_t * task, m_channel_t channel) listening. This value has to be >=0 and < than the maximal number of channels fixed with MSG_set_channel_number(). * \param max_duration the maximum time to wait for a task before giving - up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task + up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task will not be modified and will still be - equal to \c NULL when returning. + equal to \c NULL when returning. * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING if \a *task is not equal to \c NULL, and #MSG_OK otherwise. */ -MSG_error_t +MSG_error_t MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel, double max_duration) { return MSG_task_get_ext(task, channel, max_duration, NULL); @@ -338,33 +338,33 @@ MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel, double max_durat * by an agent for handling some task. */ -MSG_error_t +MSG_error_t MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout,m_host_t host) { xbt_assert1((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d",channel); - + return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel(MSG_host_self(), channel), task, host, timeout); } -MSG_error_t +MSG_error_t MSG_task_receive_from_host(m_task_t * task, const char* alias, m_host_t host) { return MSG_task_receive_ext(task, alias, -1, host); } -MSG_error_t +MSG_error_t MSG_task_receive(m_task_t * task, const char* alias) { - return MSG_task_receive_with_timeout(task, alias, -1); + return MSG_task_receive_with_timeout(task, alias, -1); } -MSG_error_t +MSG_error_t MSG_task_receive_with_timeout(m_task_t * task, const char* alias, double timeout) { - return MSG_task_receive_ext(task, alias, timeout, NULL); + return MSG_task_receive_ext(task, alias, timeout, NULL); } -MSG_error_t +MSG_error_t MSG_task_receive_ext(m_task_t* task, const char* alias, double timeout, m_host_t host) { return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task, host, timeout); @@ -397,14 +397,14 @@ MSG_task_receive_ext(m_task_t* task, const char* alias, double timeout, m_host_t * #MSG_TRANSFER_FAILURE if the transfer could not be properly done * (network failure, dest failure) */ -MSG_error_t +MSG_error_t MSG_task_put(m_task_t task, m_host_t dest, m_channel_t channel) { return MSG_task_put_with_timeout(task, dest, channel, -1.0); } /** \ingroup msg_gos_functions - * \brief Does exactly the same as MSG_task_put but with a bounded transmition + * \brief Does exactly the same as MSG_task_put but with a bounded transmition * rate. * * \sa MSG_task_put @@ -437,48 +437,48 @@ MSG_task_put_bounded(m_task_t task, m_host_t dest, m_channel_t channel, double m task. This value has to be >=0 and < than the maximal number of channels fixed with MSG_set_channel_number(). * \param timeout the maximum time to wait for a task before giving - up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task - will not be modified + up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task + will not be modified * \return #MSG_FATAL if \a task is not properly initialized and #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which this function was called was shut down. Returns #MSG_TRANSFER_FAILURE if the transfer could not be properly done (network failure, dest failure, timeout...) */ -MSG_error_t +MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest, m_channel_t channel, double timeout) { xbt_assert1((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d", channel); - + return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel(dest, channel), task, timeout); } -MSG_error_t +MSG_error_t MSG_task_send(m_task_t task,const char* alias) { return MSG_task_send_with_timeout(task, alias, -1); } -MSG_error_t +MSG_error_t MSG_task_send_bounded(m_task_t task, const char* alias, double maxrate) { task->simdata->rate = maxrate; return MSG_task_send(task, alias); } - -MSG_error_t + +MSG_error_t MSG_task_send_with_timeout(m_task_t task, const char* alias, double timeout) { return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), task, timeout); } -int +int MSG_task_listen(const char* alias) { CHECK_HOST(); - + return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias)); } @@ -491,13 +491,13 @@ MSG_task_listen(const char* alias) number of channels fixed with MSG_set_channel_number(). * \return 1 if there is a pending communication and 0 otherwise */ -int +int MSG_task_Iprobe(m_channel_t channel) { xbt_assert1((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d", channel); - + CHECK_HOST(); - + return !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel(MSG_host_self(), channel)); } @@ -514,23 +514,23 @@ MSG_task_Iprobe(m_channel_t channel) * \return the number of tasks waiting to be received on \a channel and sent by \a host. */ -int +int MSG_task_probe_from_host(int channel, m_host_t host) { xbt_assert1((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d", channel); - + CHECK_HOST(); - - return MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel(MSG_host_self(), channel),host); - + + return MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel(MSG_host_self(), channel),host); + } -int +int MSG_task_listen_from_host(const char* alias, m_host_t host) { CHECK_HOST(); - - return MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias(alias),host); + + return MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias(alias),host); } /** \ingroup msg_gos_functions @@ -542,13 +542,13 @@ MSG_task_listen_from_host(const char* alias, m_host_t host) number of channels fixed with MSG_set_channel_number(). * \return -1 if there is no pending communication and the PID of the process who sent it otherwise */ -int +int MSG_task_probe_from(m_channel_t channel) { m_task_t task; CHECK_HOST(); - + xbt_assert1((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d", channel); if(NULL == (task = MSG_mailbox_get_head(MSG_mailbox_get_by_channel(MSG_host_self(), channel)))) @@ -572,8 +572,8 @@ MSG_task_listen_from(const char* alias) /** \ingroup msg_gos_functions * \brief Wait for at most \a max_duration second for a task reception - on \a channel. - + on \a channel. + * \a PID is updated with the PID of the first process that triggered this event if any. * * It takes three parameters: @@ -587,7 +587,7 @@ MSG_task_listen_from(const char* alias) * \return #MSG_HOST_FAILURE if the host is shut down in the meantime and #MSG_OK otherwise. */ -MSG_error_t +MSG_error_t MSG_channel_select_from(m_channel_t channel,double timeout, int *PID) { m_host_t h = NULL; @@ -596,81 +596,81 @@ MSG_channel_select_from(m_channel_t channel,double timeout, int *PID) int first_time = 1; smx_cond_t cond; msg_mailbox_t mailbox; - + xbt_assert1((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d",channel); - - if(PID) + + if(PID) { *PID = -1; } - - if (timeout == 0.0) + + if (timeout == 0.0) { *PID = MSG_task_probe_from(channel); MSG_RETURN(MSG_OK); - } - else + } + else { CHECK_HOST(); h = MSG_host_self(); h_simdata = h->simdata; - - mailbox = MSG_mailbox_get_by_channel(MSG_host_self(), channel); - + + mailbox = MSG_mailbox_get_by_channel(MSG_host_self(), channel); + while(MSG_mailbox_is_empty(mailbox)) { - if(timeout > 0) + if(timeout > 0) { - if (!first_time) + if (!first_time) { MSG_RETURN(MSG_OK); } } - + SIMIX_mutex_lock(h_simdata->mutex); - + xbt_assert1(!MSG_mailbox_get_cond(mailbox),"A process is already blocked on this channel %d",channel); - + cond = SIMIX_cond_init(); - + MSG_mailbox_set_cond(mailbox, cond); - - if (timeout > 0) + + if (timeout > 0) { SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout); - } - else + } + else { SIMIX_cond_wait(cond, h_simdata->mutex); } - + SIMIX_cond_destroy(cond); SIMIX_mutex_unlock(h_simdata->mutex); - - if (SIMIX_host_get_state(h_simdata->smx_host) == 0) + + if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { MSG_RETURN(MSG_HOST_FAILURE); } - + MSG_mailbox_set_cond(mailbox,NULL); first_time = 0; } - + if(NULL == (t = MSG_mailbox_get_head(mailbox))) MSG_RETURN(MSG_OK); - - - if (PID) + + + if (PID) { *PID = MSG_process_get_PID(t->simdata->sender); } - + MSG_RETURN(MSG_OK); } } -MSG_error_t +MSG_error_t MSG_alias_select_from(const char* alias, double timeout, int* PID) { m_host_t h = NULL; @@ -679,75 +679,75 @@ MSG_alias_select_from(const char* alias, double timeout, int* PID) int first_time = 1; smx_cond_t cond; msg_mailbox_t mailbox; - - if (PID) + + if (PID) { *PID = -1; } - - if(timeout == 0.0) + + if(timeout == 0.0) { *PID = MSG_task_listen_from(alias); MSG_RETURN(MSG_OK); - } - else + } + else { CHECK_HOST(); h = MSG_host_self(); h_simdata = h->simdata; - + DEBUG2("Probing on alias %s (%s)", alias, h->name); - - mailbox = MSG_mailbox_get_by_alias(alias); - + + mailbox = MSG_mailbox_get_by_alias(alias); + while(MSG_mailbox_is_empty(mailbox)) { - if(timeout > 0) + if(timeout > 0) { - if (!first_time) + if (!first_time) { MSG_RETURN(MSG_OK); } } - + SIMIX_mutex_lock(h_simdata->mutex); - + xbt_assert1(!MSG_mailbox_get_cond(mailbox),"A process is already blocked on this alias %s",alias); - + cond = SIMIX_cond_init(); - + MSG_mailbox_set_cond(mailbox, cond); - - if (timeout > 0) + + if (timeout > 0) { SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout); - } - else + } + else { SIMIX_cond_wait(cond, h_simdata->mutex); } - + SIMIX_cond_destroy(cond); SIMIX_mutex_unlock(h_simdata->mutex); - - if (SIMIX_host_get_state(h_simdata->smx_host) == 0) + + if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { MSG_RETURN(MSG_HOST_FAILURE); } - + MSG_mailbox_set_cond(mailbox,NULL); first_time = 0; } - + if(NULL == (t = MSG_mailbox_get_head(mailbox))) MSG_RETURN(MSG_OK); - - - if (PID) + + + if (PID) { *PID = MSG_process_get_PID(t->simdata->sender); } - + MSG_RETURN(MSG_OK); } } @@ -755,4 +755,4 @@ MSG_alias_select_from(const char* alias, double timeout, int* PID) - + diff --git a/src/msg/m_process.c b/src/msg/m_process.c index 79aef14891..c168bbf1f4 100644 --- a/src/msg/m_process.c +++ b/src/msg/m_process.c @@ -21,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_process, msg, */ /** @addtogroup m_process_management * \htmlonly \endhtmlonly - * + * * We need to simulate many independent scheduling decisions, so * the concept of process is at the heart of the * simulator. A process may be defined as a code, with @@ -58,7 +58,7 @@ void *_MSG_process_create_from_SIMIX(const char *name, /** \ingroup m_process_management * \brief Creates and runs a new #m_process_t. * - * Does exactly the same as #MSG_process_create_with_arguments but without + * Does exactly the same as #MSG_process_create_with_arguments but without providing standard arguments (\a argc, \a argv, \a start_time, \a kill_time). * \sa MSG_process_create_with_arguments */ @@ -73,7 +73,7 @@ m_process_t MSG_process_create(const char *name, /** \ingroup m_process_management * \brief Creates and runs a new #m_process_t. - * A constructor for #m_process_t taking four arguments and returning the + * A constructor for #m_process_t taking four arguments and returning the * corresponding object. The structure (and the corresponding thread) is * created, and put in the list of ready process. * \param name a name for the object. It is for user-level information @@ -100,14 +100,14 @@ m_process_t MSG_process_create_with_arguments(const char *name, void *data, m_host_t host, int argc, char **argv) { - return MSG_process_create_with_environment(name, code, data, host, + return MSG_process_create_with_environment(name, code, data, host, argc,argv,NULL); } /** \ingroup m_process_management * \brief Creates and runs a new #m_process_t. - * A constructor for #m_process_t taking four arguments and returning the + * A constructor for #m_process_t taking four arguments and returning the * corresponding object. The structure (and the corresponding thread) is * created, and put in the list of ready process. * \param name a name for the object. It is for user-level information @@ -217,7 +217,7 @@ MSG_error_t MSG_process_change_host(m_host_t host) /** \ingroup m_process_management * \brief Return the user data of a #m_process_t. * - * This function checks whether \a process is a valid pointer or not + * This function checks whether \a process is a valid pointer or not and return the user data associated to \a process if it is possible. */ void *MSG_process_get_data(m_process_t process) @@ -230,7 +230,7 @@ void *MSG_process_get_data(m_process_t process) /** \ingroup m_process_management * \brief Set the user data of a #m_process_t. * - * This function checks whether \a process is a valid pointer or not + * This function checks whether \a process is a valid pointer or not and set the user data associated to \a process if it is possible. */ MSG_error_t MSG_process_set_data(m_process_t process, void *data) @@ -246,8 +246,8 @@ MSG_error_t MSG_process_set_data(m_process_t process, void *data) /** \ingroup m_process_management * \brief Return the location on which an agent is running. * - * This function checks whether \a process is a valid pointer or not - and return the m_host_t corresponding to the location on which \a + * This function checks whether \a process is a valid pointer or not + and return the m_host_t corresponding to the location on which \a process is running. */ m_host_t MSG_process_get_host(m_process_t process) @@ -262,8 +262,8 @@ m_host_t MSG_process_get_host(m_process_t process) * * \brief Return a #m_process_t given its PID. * - * This function search in the list of all the created m_process_t for a m_process_t - whose PID is equal to \a PID. If no host is found, \c NULL is returned. + * This function search in the list of all the created m_process_t for a m_process_t + whose PID is equal to \a PID. If no host is found, \c NULL is returned. Note that the PID are uniq in the whole simulation, not only on a given host. */ m_process_t MSG_process_from_PID(int PID) @@ -281,12 +281,12 @@ m_process_t MSG_process_from_PID(int PID) /** \ingroup m_process_management * \brief Returns the process ID of \a process. * - * This function checks whether \a process is a valid pointer or not + * This function checks whether \a process is a valid pointer or not and return its PID (or 0 in case of problem). */ int MSG_process_get_PID(m_process_t process) { - /* Do not raise an exception here: this function is used in the logs, + /* Do not raise an exception here: this function is used in the logs, and it will be called back by the exception handling stuff */ if (process == NULL || process->simdata == NULL) return 0; @@ -297,8 +297,8 @@ int MSG_process_get_PID(m_process_t process) /** \ingroup m_process_management * \brief Returns the process ID of the parent of \a process. * - * This function checks whether \a process is a valid pointer or not - and return its PID. Returns -1 if the agent has not been created by + * This function checks whether \a process is a valid pointer or not + and return its PID. Returns -1 if the agent has not been created by another agent. */ int MSG_process_get_PPID(m_process_t process) @@ -312,7 +312,7 @@ int MSG_process_get_PPID(m_process_t process) /** \ingroup m_process_management * \brief Return the name of an agent. * - * This function checks whether \a process is a valid pointer or not + * This function checks whether \a process is a valid pointer or not and return its name. */ const char *MSG_process_get_name(m_process_t process) diff --git a/src/msg/mailbox.h b/src/msg/mailbox.h index 89fbf09fc4..bceaa98ef0 100644 --- a/src/msg/mailbox.h +++ b/src/msg/mailbox.h @@ -24,7 +24,7 @@ void MSG_mailbox_mod_exit(void); * by the parameter alias and add it in the global dictionary. * * \param alias The alias of the mailbox to create. - * + * * \return The newly created mailbox. */ XBT_PUBLIC(msg_mailbox_t) @@ -38,7 +38,7 @@ MSG_mailbox_new(const char *alias); * this type of mailbox is associated with a channel. * * \param alias The alias of the mailbox to create. - * + * * \return The newly created mailbox. */ msg_mailbox_t @@ -81,7 +81,7 @@ MSG_mailbox_get_by_alias(const char *alias); * * \return The mailbox of the specified host associated the channel * specified as parameter. - * + * */ XBT_PUBLIC(msg_mailbox_t) MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel); @@ -160,16 +160,6 @@ MSG_mailbox_set_hostname(msg_mailbox_t mailbox, const char *hostname); XBT_PUBLIC(int) MSG_mailbox_is_empty(msg_mailbox_t mailbox); -/*! \brief MSG_mailbox_put - put a task in a mailbox. - * - * The MSG_mailbox_put puts a task in a specified mailbox. - * - * \param mailbox The mailbox where put the task. - * \param task The task to put in the mailbox. - */ -XBT_PUBLIC(void) -MSG_mailbox_put(msg_mailbox_t mailbox, m_task_t task); - /*! \brief MSG_mailbox_remove - remove a task from a mailbox. * * The MSG_mailbox_remove removes a task from a specified mailbox. @@ -220,7 +210,7 @@ MSG_mailbox_pop_head(msg_mailbox_t mailbox); XBT_PUBLIC(m_task_t) MSG_mailbox_get_first_host_task(msg_mailbox_t mailbox, m_host_t host); -/*! \brief MSG_mailbox_get_count_host_waiting_tasks - Return the number of tasks +/*! \brief MSG_mailbox_get_count_host_waiting_tasks - Return the number of tasks waiting to be received in a mailbox and sent by a host. * * \param mailbox The mailbox concerned by the operation. diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index 53e1bbf4eb..3454104229 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -51,11 +51,6 @@ void MSG_mailbox_free(void *mailbox) free(_mailbox); } -void MSG_mailbox_put(msg_mailbox_t mailbox, m_task_t task) -{ - xbt_fifo_push(mailbox->tasks, task); -} - smx_cond_t MSG_mailbox_get_cond(msg_mailbox_t mailbox) { return mailbox->cond; @@ -332,6 +327,7 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, task_simdata->refcount ++; local_host = ((simdata_process_t) process->simdata)->m_host; + msg_global->sent_msg++; /* get the host name containing the mailbox */ hostname = MSG_mailbox_get_hostname(mailbox); @@ -350,7 +346,7 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, SIMIX_mutex_lock(remote_host->simdata->mutex); /* put the task in the mailbox */ - MSG_mailbox_put(mailbox, task); + xbt_fifo_push(mailbox->tasks, task); if ((cond = MSG_mailbox_get_cond(mailbox))) { DEBUG0("Somebody is listening. Let's wake him up!"); diff --git a/src/msg/private.h b/src/msg/private.h index 9f95cee8ce..f72dd97e3e 100644 --- a/src/msg/private.h +++ b/src/msg/private.h @@ -1,12 +1,12 @@ /* $Id$ */ - + /* Copyright (c) 2002-2007 Arnaud Legrand. */ /* Copyright (c) 2007 Bruno Donassolo. */ /* 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. */ - + #ifndef METASIMGRID_PRIVATE_H #define METASIMGRID_PRIVATE_H @@ -34,7 +34,7 @@ typedef struct s_msg_mailbox char* hostname; /* the name of the host containing the mailbox */ }s_msg_mailbox_t; -typedef struct simdata_host +typedef struct simdata_host { smx_host_t smx_host; /* SURF modeling */ struct s_msg_mailbox** mailboxes; /* mailboxes to store msg tasks of of the host */ @@ -48,7 +48,7 @@ typedef struct simdata_task { smx_action_t comm; /* SURF modeling of communication */ double message_size; /* Data size */ double computation_amount; /* Computation size */ - smx_cond_t cond; + smx_cond_t cond; smx_mutex_t mutex; /* Task mutex */ m_process_t sender; m_process_t receiver; @@ -95,12 +95,13 @@ typedef struct MSG_Global { int max_channel; int PID; int session; + unsigned long int sent_msg; /* Total amount of messages sent during the simulation */ } s_MSG_Global_t, *MSG_Global_t; /*extern MSG_Global_t msg_global;*/ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; - + /*************************************************************/ #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)