1 /* Copyright (c) 2004-2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/simix/smx_private.h" /* MSG_task_listen looks inside the rdv directly. Not clean. */
7 #include "msg_private.h"
10 #include "xbt/sysdep.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
13 "Logging specific to MSG (gos)");
15 /** \ingroup msg_task_usage
16 * \brief Executes a task and waits for its termination.
18 * This function is used for describing the behavior of a process. It takes only one parameter.
19 * \param task a #msg_task_t to execute on the location on which the process is running.
20 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
22 msg_error_t MSG_task_execute(msg_task_t task)
24 /* TODO: add this to other locations */
25 msg_host_t host = MSG_process_get_host(MSG_process_self());
26 MSG_host_add_task(host, task);
28 msg_error_t ret = MSG_parallel_task_execute(task);
30 MSG_host_del_task(host, task);
35 /** \ingroup msg_task_usage
36 * \brief Executes a parallel task and waits for its termination.
38 * \param task a #msg_task_t to execute on the location on which the process is running.
40 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
41 * or #MSG_HOST_FAILURE otherwise
43 msg_error_t MSG_parallel_task_execute(msg_task_t task)
46 simdata_task_t simdata = task->simdata;
47 msg_process_t self = SIMIX_process_self();
48 simdata_process_t p_simdata = (simdata_process_t) SIMIX_process_self_get_data(self);
49 e_smx_state_t comp_state;
50 msg_error_t status = MSG_OK;
52 TRACE_msg_task_execute_start(task);
54 xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
55 "This task is executed somewhere else. Go fix your code! %d", task->simdata->isused!=NULL);
57 XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
59 if (simdata->flops_amount == 0 && !simdata->host_nb) {
60 TRACE_msg_task_execute_end(task);
65 if (msg_global->debug_multiple_use)
66 MSG_BT(simdata->isused, "Using Backtrace");
68 simdata->isused = (void*)1;
70 if (simdata->host_nb > 0) {
71 simdata->compute = simcall_execution_parallel_start(task->name, simdata->host_nb,simdata->host_list,
72 simdata->flops_parallel_amount, simdata->bytes_parallel_amount,
74 XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
76 unsigned long affinity_mask =
77 (unsigned long)(uintptr_t) xbt_dict_get_or_null_ext(simdata->affinity_mask_db, (char *) p_simdata->m_host,
79 XBT_DEBUG("execute %s@%s with affinity(0x%04lx)",
80 MSG_task_get_name(task), MSG_host_get_name(p_simdata->m_host), affinity_mask);
82 simdata->compute = simcall_execution_start(task->name, simdata->flops_amount, simdata->priority,
83 simdata->bound, affinity_mask);
85 simcall_set_category(simdata->compute, task->category);
86 p_simdata->waiting_action = simdata->compute;
87 comp_state = simcall_execution_wait(simdata->compute);
89 p_simdata->waiting_action = NULL;
91 if (msg_global->debug_multiple_use && simdata->isused!=0)
92 xbt_ex_free(*(xbt_ex_t*)simdata->isused);
95 XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (int)comp_state);
100 status = MSG_TASK_CANCELED;
103 status = MSG_HOST_FAILURE;
110 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
111 simdata->flops_amount = 0.0;
112 simdata->comm = NULL;
113 simdata->compute = NULL;
114 TRACE_msg_task_execute_end(task);
119 /** \ingroup msg_task_usage
120 * \brief Sleep for the specified number of seconds
122 * Makes the current process sleep until \a time seconds have elapsed.
124 * \param nb_sec a number of second
126 msg_error_t MSG_process_sleep(double nb_sec)
129 msg_error_t status = MSG_OK;
130 /*msg_process_t proc = MSG_process_self();*/
132 TRACE_msg_process_sleep_in(MSG_process_self());
135 simcall_process_sleep(nb_sec);
138 switch (e.category) {
140 XBT_DEBUG("According to the JAVA API, a sleep call should only deal with HostFailureException, WTF here ?");
141 // adsein: MSG_TASK_CANCELED is assigned when someone kills the process that made the sleep, this is not
142 // correct. For instance, when the node is turned off, the error should be MSG_HOST_FAILURE, which is by the way
143 // and according to the JAVA document, the only exception that can be triggered by MSG_Process_sleep call.
144 // To avoid possible impacts in the code, I just raised a host_failure exception for the moment in the JAVA code
145 // and did not change anythings at the C level.
146 // See comment in the jmsg_process.c file, function JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cls, jlong jmillis, jint jnanos)
147 status = MSG_TASK_CANCELED;
155 TRACE_msg_process_sleep_out(MSG_process_self());
159 /** \ingroup msg_task_usage
160 * \brief Receives a task from a mailbox.
162 * This is a blocking function, the execution flow will be blocked until the task is received. See #MSG_task_irecv
163 * for receiving tasks asynchronously.
165 * \param task a memory location for storing a #msg_task_t.
166 * \param alias name of the mailbox to receive the task from
169 * #MSG_OK if the task was successfully received,
170 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
172 msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
174 return MSG_task_receive_with_timeout(task, alias, -1);
177 /** \ingroup msg_task_usage
178 * \brief Receives a task from a mailbox at a given rate.
180 * \param task a memory location for storing a #msg_task_t.
181 * \param alias name of the mailbox to receive the task from
182 * \param rate limit the reception to rate bandwidth
185 * #MSG_OK if the task was successfully received,
186 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
188 msg_error_t MSG_task_receive_bounded(msg_task_t * task, const char *alias, double rate)
190 return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
193 /** \ingroup msg_task_usage
194 * \brief Receives a task from a mailbox with a given timeout.
196 * This is a blocking function with a timeout, the execution flow will be blocked until the task is received or the
197 * timeout is achieved. See #MSG_task_irecv for receiving tasks asynchronously. You can provide a -1 timeout
198 * to obtain an infinite timeout.
200 * \param task a memory location for storing a #msg_task_t.
201 * \param alias name of the mailbox to receive the task from
202 * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
205 * #MSG_OK if the task was successfully received,
206 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
208 msg_error_t MSG_task_receive_with_timeout(msg_task_t * task, const char *alias, double timeout)
210 return MSG_task_receive_ext(task, alias, timeout, NULL);
213 /** \ingroup msg_task_usage
214 * \brief Receives a task from a mailbox with a given timeout and at a given rate.
216 * \param task a memory location for storing a #msg_task_t.
217 * \param alias name of the mailbox to receive the task from
218 * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
219 * \param rate limit the reception to rate bandwidth
222 * #MSG_OK if the task was successfully received,
223 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
225 msg_error_t MSG_task_receive_with_timeout_bounded(msg_task_t * task, const char *alias, double timeout,double rate)
227 return MSG_task_receive_ext_bounded(task, alias, timeout, NULL, rate);
230 /** \ingroup msg_task_usage
231 * \brief Receives a task from a mailbox from a specific host with a given timeout.
233 * This is a blocking function with a timeout, the execution flow will be blocked until the task is received or the
234 * timeout is achieved. See #MSG_task_irecv for receiving tasks asynchronously. You can provide a -1 timeout
235 * to obtain an infinite timeout.
237 * \param task a memory location for storing a #msg_task_t.
238 * \param alias name of the mailbox to receive the task from
239 * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
240 * \param host a #msg_host_t host from where the task was sent
243 * #MSG_OK if the task was successfully received,
244 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
246 msg_error_t MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout, msg_host_t host)
249 msg_error_t ret = MSG_OK;
250 XBT_DEBUG("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'", alias);
252 ret = MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task, host, timeout);
255 switch (e.category) {
256 case cancel_error: /* may be thrown by MSG_mailbox_get_by_alias */
257 ret = MSG_HOST_FAILURE;
267 /** \ingroup msg_task_usage
268 * \brief Receives a task from a mailbox from a specific host with a given timeout and at a given rate.
270 * \param task a memory location for storing a #msg_task_t.
271 * \param alias name of the mailbox to receive the task from
272 * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
273 * \param host a #msg_host_t host from where the task was sent
274 * \param rate limit the reception to rate bandwidth
277 * #MSG_OK if the task was successfully received,
278 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
280 msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, double timeout, msg_host_t host,
283 XBT_DEBUG("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'", alias);
284 return MSG_mailbox_get_task_ext_bounded(MSG_mailbox_get_by_alias(alias), task, host, timeout, rate);
287 /* Internal function used to factorize code between MSG_task_isend_with_matching() and MSG_task_dsend(). */
288 static XBT_INLINE msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *alias,
289 int (*match_fun)(void*,void*, smx_synchro_t),
290 void *match_data, void_f_pvoid_t cleanup, int detached)
292 simdata_task_t t_simdata = NULL;
293 msg_process_t process = MSG_process_self();
294 msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
295 int call_end = TRACE_msg_task_put_start(task);
297 /* Prepare the task to send */
298 t_simdata = task->simdata;
299 t_simdata->sender = process;
300 t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
302 if (t_simdata->isused != 0) {
303 if (msg_global->debug_multiple_use){
304 XBT_ERROR("This task is already used in there:");
305 xbt_backtrace_display((xbt_ex_t*) t_simdata->isused);
306 XBT_ERROR("And you try to reuse it from here:");
307 xbt_backtrace_display_current();
309 xbt_assert(t_simdata->isused == 0,
310 "This task is still being used somewhere else. You cannot send it now. Go fix your code!"
311 "(use --cfg=msg/debug_multiple_use:on to get the backtrace of the other process)");
315 if (msg_global->debug_multiple_use)
316 MSG_BT(t_simdata->isused, "Using Backtrace");
318 t_simdata->isused = (void*)1;
319 t_simdata->comm = NULL;
320 msg_global->sent_msg++;
322 /* Send it by calling SIMIX network layer */
323 smx_synchro_t act = simcall_comm_isend(SIMIX_process_self(), mailbox, t_simdata->bytes_amount, t_simdata->rate,
324 task, sizeof(void *), match_fun, cleanup, NULL, match_data,detached);
325 t_simdata->comm = act; /* FIXME: is the field t_simdata->comm still useful? */
331 comm = xbt_new0(s_msg_comm_t, 1);
332 comm->task_sent = task;
333 comm->task_received = NULL;
334 comm->status = MSG_OK;
338 if (TRACE_is_enabled())
339 simcall_set_category(act, task->category);
341 TRACE_msg_task_put_end();
346 /** \ingroup msg_task_usage
347 * \brief Sends a task on a mailbox.
349 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
351 * \param task a #msg_task_t to send on another location.
352 * \param alias name of the mailbox to sent the task to
353 * \return the msg_comm_t communication created
355 msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
357 return MSG_task_isend_internal(task, alias, NULL, NULL, NULL, 0);
360 /** \ingroup msg_task_usage
361 * \brief Sends a task on a mailbox with a maximum rate
363 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication. The maxrate
364 * parameter allows the application to limit the bandwidth utilization of network links when sending the task.
366 * \param task a #msg_task_t to send on another location.
367 * \param alias name of the mailbox to sent the task to
368 * \param maxrate the maximum communication rate for sending this task .
369 * \return the msg_comm_t communication created
371 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char *alias, double maxrate)
373 task->simdata->rate = maxrate;
374 return MSG_task_isend_internal(task, alias, NULL, NULL, NULL, 0);
377 /** \ingroup msg_task_usage
378 * \brief Sends a task on a mailbox, with support for matching requests
380 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
382 * \param task a #msg_task_t to send on another location.
383 * \param alias name of the mailbox to sent the task to
384 * \param match_fun boolean function which parameters are:
385 * - match_data_provided_here
386 * - match_data_provided_by_other_side_if_any
387 * - the_smx_synchro_describing_the_other_side
388 * \param match_data user provided data passed to match_fun
389 * \return the msg_comm_t communication created
391 msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char *alias,
392 int (*match_fun)(void*, void*, smx_synchro_t), void *match_data)
394 return MSG_task_isend_internal(task, alias, match_fun, match_data, NULL, 0);
397 /** \ingroup msg_task_usage
398 * \brief Sends a task on a mailbox.
400 * This is a non blocking detached send function.
401 * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
402 * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
403 * usual. More details on this can be obtained on
404 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
405 * in the SimGrid-user mailing list archive.
407 * \param task a #msg_task_t to send on another location.
408 * \param alias name of the mailbox to sent the task to
409 * \param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy
410 * (if NULL, no function will be called)
412 void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
414 MSG_task_isend_internal(task, alias, NULL, NULL, cleanup, 1);
417 /** \ingroup msg_task_usage
418 * \brief Sends a task on a mailbox with a maximal rate.
420 * This is a non blocking detached send function.
421 * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
422 * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
423 * usual. More details on this can be obtained on
424 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
425 * in the SimGrid-user mailing list archive.
427 * \param task a #msg_task_t to send on another location.
428 * \param alias name of the mailbox to sent the task to
429 * \param cleanup a function to destroy the task if the
430 * communication fails, e.g. MSG_task_destroy
431 * (if NULL, no function will be called)
432 * \param maxrate the maximum communication rate for sending this task
435 void MSG_task_dsend_bounded(msg_task_t task, const char *alias, void_f_pvoid_t cleanup, double maxrate)
437 task->simdata->rate = maxrate;
438 MSG_task_dsend(task, alias, cleanup);
441 /** \ingroup msg_task_usage
442 * \brief Starts listening for receiving a task from an asynchronous communication.
444 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
446 * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
447 * \param name of the mailbox to receive the task on
448 * \return the msg_comm_t communication created
450 msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
452 return MSG_task_irecv_bounded(task, name, -1.0);
455 /** \ingroup msg_task_usage
456 * \brief Starts listening for receiving a task from an asynchronous communication at a given rate.
458 * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
459 * \param name of the mailbox to receive the task on
460 * \param rate limit the bandwidth to the given rate
461 * \return the msg_comm_t communication created
463 msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rate)
465 smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
467 /* FIXME: these functions are not traceable */
469 xbt_assert(task, "Null pointer for the task storage");
472 XBT_CRITICAL("MSG_task_irecv() was asked to write in a non empty task struct.");
474 /* Try to receive it by calling SIMIX network layer */
475 msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
476 comm->task_sent = NULL;
477 comm->task_received = task;
478 comm->status = MSG_OK;
479 comm->s_comm = simcall_comm_irecv(MSG_process_self(), rdv, task, NULL, NULL, NULL, NULL, rate);
484 /** \ingroup msg_task_usage
485 * \brief Checks whether a communication is done, and if yes, finalizes it.
486 * \param comm the communication to test
487 * \return TRUE if the communication is finished
488 * (but it may have failed, use MSG_comm_get_status() to know its status)
489 * or FALSE if the communication is not finished yet
490 * If the status is FALSE, don't forget to use MSG_process_sleep() after the test.
492 int MSG_comm_test(msg_comm_t comm)
498 finished = simcall_comm_test(comm->s_comm);
500 if (finished && comm->task_received != NULL) {
501 /* I am the receiver */
502 if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
503 xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
504 (*comm->task_received)->simdata->isused = 0;
508 switch (e.category) {
510 comm->status = MSG_TRANSFER_FAILURE;
514 comm->status = MSG_TIMEOUT;
526 /** \ingroup msg_task_usage
527 * \brief This function checks if a communication is finished.
528 * \param comms a vector of communications
529 * \return the position of the finished communication if any
530 * (but it may have failed, use MSG_comm_get_status() to know its status),
531 * or -1 if none is finished
533 int MSG_comm_testany(xbt_dynar_t comms)
536 int finished_index = -1;
538 /* create the equivalent dynar with SIMIX objects */
539 xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_synchro_t), NULL);
542 xbt_dynar_foreach(comms, cursor, comm) {
543 xbt_dynar_push(s_comms, &comm->s_comm);
546 msg_error_t status = MSG_OK;
548 finished_index = simcall_comm_testany(s_comms);
551 switch (e.category) {
553 finished_index = e.value;
554 status = MSG_TRANSFER_FAILURE;
557 finished_index = e.value;
558 status = MSG_TIMEOUT;
565 xbt_dynar_free(&s_comms);
567 if (finished_index != -1) {
568 comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
569 /* the communication is finished */
570 comm->status = status;
572 if (status == MSG_OK && comm->task_received != NULL) {
573 /* I am the receiver */
574 if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
575 xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
576 (*comm->task_received)->simdata->isused = 0;
580 return finished_index;
583 /** \ingroup msg_task_usage
584 * \brief Destroys a communication.
585 * \param comm the communication to destroy.
587 void MSG_comm_destroy(msg_comm_t comm)
592 /** \ingroup msg_task_usage
593 * \brief Wait for the completion of a communication.
595 * It takes two parameters.
596 * \param comm the communication to wait.
597 * \param timeout Wait until the communication terminates or the timeout occurs.
598 * You can provide a -1 timeout to obtain an infinite timeout.
599 * \return msg_error_t
601 msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
605 simcall_comm_wait(comm->s_comm, timeout);
607 if (comm->task_received != NULL) {
608 /* I am the receiver */
609 if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
610 xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
611 (*comm->task_received)->simdata->isused = 0;
614 /* FIXME: these functions are not traceable */
617 switch (e.category) {
619 comm->status = MSG_TRANSFER_FAILURE;
622 comm->status = MSG_TIMEOUT;
633 /** \ingroup msg_task_usage
634 * \brief This function is called by a sender and permit to wait for each communication
636 * \param comm a vector of communication
637 * \param nb_elem is the size of the comm vector
638 * \param timeout for each call of MSG_comm_wait
640 void MSG_comm_waitall(msg_comm_t * comm, int nb_elem, double timeout)
643 for (i = 0; i < nb_elem; i++) {
644 MSG_comm_wait(comm[i], timeout);
648 /** \ingroup msg_task_usage
649 * \brief This function waits for the first communication finished in a list.
650 * \param comms a vector of communications
651 * \return the position of the first finished communication
652 * (but it may have failed, use MSG_comm_get_status() to know its status)
654 int MSG_comm_waitany(xbt_dynar_t comms)
657 int finished_index = -1;
659 /* create the equivalent dynar with SIMIX objects */
660 xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_synchro_t), NULL);
663 xbt_dynar_foreach(comms, cursor, comm) {
664 xbt_dynar_push(s_comms, &comm->s_comm);
667 msg_error_t status = MSG_OK;
669 finished_index = simcall_comm_waitany(s_comms);
672 switch (e.category) {
674 finished_index = e.value;
675 status = MSG_TRANSFER_FAILURE;
678 finished_index = e.value;
679 status = MSG_TIMEOUT;
687 xbt_assert(finished_index != -1, "WaitAny returned -1");
688 xbt_dynar_free(&s_comms);
690 comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
691 /* the communication is finished */
692 comm->status = status;
694 if (comm->task_received != NULL) {
695 /* I am the receiver */
696 if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
697 xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
698 (*comm->task_received)->simdata->isused = 0;
701 return finished_index;
705 * \ingroup msg_task_usage
706 * \brief Returns the error (if any) that occured during a finished communication.
707 * \param comm a finished communication
708 * \return the status of the communication, or #MSG_OK if no error occured
709 * during the communication
711 msg_error_t MSG_comm_get_status(msg_comm_t comm) {
716 /** \ingroup msg_task_usage
717 * \brief Get a task (#msg_task_t) from a communication
719 * \param comm the communication where to get the task
720 * \return the task from the communication
722 msg_task_t MSG_comm_get_task(msg_comm_t comm)
724 xbt_assert(comm, "Invalid parameter");
726 return comm->task_received ? *comm->task_received : comm->task_sent;
730 * \brief This function is called by SIMIX in kernel mode to copy the data of a comm.
731 * \param comm the comm
732 * \param buff the data copied
733 * \param buff_size size of the buffer
735 void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size) {
737 SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
739 // notify the user callback if any
740 if (msg_global->task_copy_callback) {
741 msg_task_t task = (msg_task_t) buff;
742 msg_global->task_copy_callback(task, simcall_comm_get_src_proc(comm), simcall_comm_get_dst_proc(comm));
746 /** \ingroup msg_task_usage
747 * \brief Sends a task to a mailbox
749 * This is a blocking function, the execution flow will be blocked until the task is sent (and received on the other
750 * side if #MSG_task_receive is used).
751 * See #MSG_task_isend for sending tasks asynchronously.
753 * \param task the task to be sent
754 * \param alias the mailbox name to where the task is sent
756 * \return Returns #MSG_OK if the task was successfully sent,
757 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
759 msg_error_t MSG_task_send(msg_task_t task, const char *alias)
761 XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
762 return MSG_task_send_with_timeout(task, alias, -1);
765 /** \ingroup msg_task_usage
766 * \brief Sends a task to a mailbox with a maximum rate
768 * This is a blocking function, the execution flow will be blocked until the task is sent. The maxrate parameter allows
769 * the application to limit the bandwidth utilization of network links when sending the task.
771 * \param task the task to be sent
772 * \param alias the mailbox name to where the task is sent
773 * \param maxrate the maximum communication rate for sending this task
775 * \return Returns #MSG_OK if the task was successfully sent,
776 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
778 msg_error_t MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
780 task->simdata->rate = maxrate;
781 return MSG_task_send(task, alias);
784 /** \ingroup msg_task_usage
785 * \brief Sends a task to a mailbox with a timeout
787 * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
789 * \param task the task to be sent
790 * \param alias the mailbox name to where the task is sent
791 * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
793 * \return Returns #MSG_OK if the task was successfully sent,
794 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
796 msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, double timeout)
798 return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), task, timeout);
801 /** \ingroup msg_task_usage
802 * \brief Sends a task to a mailbox with a timeout and with a maximum rate
804 * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
806 * \param task the task to be sent
807 * \param alias the mailbox name to where the task is sent
808 * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
809 * \param maxrate the maximum communication rate for sending this task
811 * \return Returns #MSG_OK if the task was successfully sent,
812 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
814 msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias, double timeout, double maxrate)
816 task->simdata->rate = maxrate;
817 return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), task, timeout);
820 /** \ingroup msg_task_usage
821 * \brief Check if there is a communication going on in a mailbox.
823 * \param alias the name of the mailbox to be considered
825 * \return Returns 1 if there is a communication, 0 otherwise
827 int MSG_task_listen(const char *alias)
829 smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias);
830 return !MSG_mailbox_is_empty(rdv) || (rdv->permanent_receiver && xbt_fifo_size(rdv->done_comm_fifo)!=0);
833 /** \ingroup msg_task_usage
834 * \brief Check the number of communication actions of a given host pending in a mailbox.
836 * \param alias the name of the mailbox to be considered
837 * \param host the host to check for communication
839 * \return Returns the number of pending communication actions of the host in the given mailbox, 0 if there is no
840 * pending communication actions.
842 int MSG_task_listen_from_host(const char *alias, msg_host_t host)
844 return MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias(alias), host);
847 /** \ingroup msg_task_usage
848 * \brief Look if there is a communication on a mailbox and return the PID of the sender process.
850 * \param alias the name of the mailbox to be considered
852 * \return Returns the PID of sender process,
853 * -1 if there is no communication in the mailbox.
855 int MSG_task_listen_from(const char *alias)
859 if (NULL == (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
862 return MSG_process_get_PID(task->simdata->sender);
865 /** \ingroup msg_task_usage
866 * \brief Sets the tracing category of a task.
868 * This function should be called after the creation of a MSG task, to define the category of that task. The
869 * first parameter task must contain a task that was created with the function #MSG_task_create. The second
870 * parameter category must contain a category that was previously declared with the function #TRACE_category
871 * (or with #TRACE_category_with_color).
873 * See \ref tracing for details on how to trace the (categorized) resource utilization.
875 * \param task the task that is going to be categorized
876 * \param category the name of the category to be associated to the task
878 * \see MSG_task_get_category, TRACE_category, TRACE_category_with_color
880 void MSG_task_set_category (msg_task_t task, const char *category)
882 TRACE_msg_set_task_category (task, category);
885 /** \ingroup msg_task_usage
887 * \brief Gets the current tracing category of a task.
889 * \param task the task to be considered
891 * \see MSG_task_set_category
893 * \return Returns the name of the tracing category of the given task, NULL otherwise
895 const char *MSG_task_get_category (msg_task_t task)
897 return task->category;
901 * \brief Returns the value of a given AS or router property
903 * \param asr the name of a router or AS
904 * \param name a property name
905 * \return value of a property (or NULL if property not set)
907 const char *MSG_as_router_get_property_value(const char* asr, const char *name)
909 return (char*) xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name);
913 * \brief Returns a xbt_dict_t consisting of the list of properties assigned to
916 * \param asr the name of a router or AS
917 * \return a dict containing the properties
919 xbt_dict_t MSG_as_router_get_properties(const char* asr)
921 return (simcall_asr_get_properties(asr));
925 * \brief Change the value of a given AS or router
927 * \param asr the name of a router or AS
928 * \param name a property name
929 * \param value what to change the property to
930 * \param free_ctn the freeing function to use to kill the value on need
932 void MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn) {
933 xbt_dict_set(MSG_as_router_get_properties(asr), name, value,free_ctn);