1 /* smx_user.c - public interface to simix */
3 /* Copyright (c) 2010-2013. The SimGrid Team.
4 All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "smx_private.h"
12 #include <math.h> /* isfinite() */
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
16 /* generate strings from the enumeration values */
17 static const char* simcall_names[] = {
18 SIMCALL_LIST(SIMCALL_STRING_TYPE, SIMCALL_SEP_COMMA)
19 [SIMCALL_NONE] = "NONE"
22 SIMCALL_LIST(SIMCALL_FUNC, SIMCALL_SEP_NOTHING)
25 * \ingroup simix_host_management
26 * \brief Returns a host given its name.
28 * \param name The name of the host to get
29 * \return The corresponding host
31 smx_host_t simcall_host_get_by_name(const char *name)
33 return simcall_BODY_host_get_by_name(name);
37 * \ingroup simix_host_management
38 * \brief Returns the name of a host.
40 * \param host A SIMIX host
41 * \return The name of this host
43 const char* simcall_host_get_name(smx_host_t host)
45 return simcall_BODY_host_get_name(host);
49 * \ingroup simix_host_management
50 * \brief Returns a dict of the properties assigned to a host.
53 * \return The properties of this host
55 xbt_dict_t simcall_host_get_properties(smx_host_t host)
57 return simcall_BODY_host_get_properties(host);
61 * \ingroup simix_host_management
62 * \brief Returns a dict of the properties assigned to a router or AS.
64 * \param name The name of the router or AS
65 * \return The properties
67 xbt_dict_t simcall_asr_get_properties(const char *name)
69 return simcall_BODY_asr_get_properties(name);
74 * \ingroup simix_host_management
75 * \brief Returns the speed of the processor.
77 * The speed returned does not take into account the current load on the machine.
78 * \param host A SIMIX host
79 * \return The speed of this host (in Mflop/s)
81 double simcall_host_get_speed(smx_host_t host)
83 return simcall_BODY_host_get_speed(host);
87 * \ingroup simix_host_management
88 * \brief Returns the number of core of the processor.
90 * \param host A SIMIX host
91 * \return The number of core
93 int simcall_host_get_core(smx_host_t host)
95 return simcall_BODY_host_get_core(host);
99 * \ingroup simix_host_management
100 * \brief Returns the list of processes attached to the host.
102 * \param host A SIMIX host
103 * \return the swag of attached processes
105 xbt_swag_t simcall_host_get_process_list(smx_host_t host)
107 return simcall_BODY_host_get_process_list(host);
112 * \ingroup simix_host_management
113 * \brief Returns the available speed of the processor.
115 * \return Speed currently available (in Mflop/s)
117 double simcall_host_get_available_speed(smx_host_t host)
119 return simcall_BODY_host_get_available_speed(host);
123 * \ingroup simix_host_management
124 * \brief Returns the state of a host.
126 * Two states are possible: 1 if the host is active or 0 if it has crashed.
127 * \param host A SIMIX host
128 * \return 1 if the host is available, 0 otherwise
130 int simcall_host_get_state(smx_host_t host)
132 return simcall_BODY_host_get_state(host);
136 * \ingroup simix_host_management
137 * \brief Returns the user data associated to a host.
139 * \param host SIMIX host
140 * \return the user data of this host
142 void* simcall_host_get_data(smx_host_t host)
144 return simcall_BODY_host_get_data(host);
148 * \ingroup simix_host_management
149 * \brief Sets the user data associated to a host.
151 * The host must not have previous user data associated to it.
152 * \param host A SIMIX host
153 * \param data The user data to set
155 void simcall_host_set_data(smx_host_t host, void *data)
157 simcall_host_set_data(host, data);
161 * \ingroup simix_host_management
162 * \brief Returns the power peak of a host.
164 * \param host A SIMIX host
165 * \return the current power peak value (double)
167 double simcall_host_get_current_power_peak(smx_host_t host)
169 return simcall_BODY_host_get_current_power_peak(host);
173 * \ingroup simix_host_management
174 * \brief Returns one power peak (in flops/s) of a host at a given pstate
176 * \param host A SIMIX host
177 * \param pstate_index pstate to test
178 * \return the current power peak value (double) for pstate_index
180 double simcall_host_get_power_peak_at(smx_host_t host, int pstate_index)
182 return simcall_BODY_host_get_power_peak_at(host, pstate_index);
186 * \ingroup simix_host_management
187 * \brief Returns the number of power states for a host.
189 * \param host A SIMIX host
190 * \return the number of power states
192 int simcall_host_get_nb_pstates(smx_host_t host)
194 return simcall_BODY_host_get_nb_pstates(host);
198 * \ingroup simix_host_management
199 * \brief Sets a new power peak for a host.
201 * \param host A SIMIX host
202 * \param pstate_index The pstate to which the CPU power will be set
205 void simcall_host_set_power_peak_at(smx_host_t host, int pstate_index)
207 simcall_BODY_host_set_power_peak_at(host, pstate_index);
211 * \ingroup simix_host_management
212 * \brief Returns the total energy consumed by the host (in Joules)
214 * \param host A SIMIX host
215 * \return the energy consumed by the host (double)
217 double simcall_host_get_consumed_energy(smx_host_t host)
219 return simcall_BODY_host_get_consumed_energy(host);
224 * \ingroup simix_host_management
225 * \brief Creates an action that executes some computation of an host.
227 * This function creates a SURF action and allocates the data necessary
228 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
230 * \param name Name of the execution action to create
231 * \param host SIMIX host where the action will be executed
232 * \param computation_amount amount Computation amount (in bytes)
233 * \param priority computation priority
234 * \return A new SIMIX execution action
236 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
237 double computation_amount,
240 /* checking for infinite values */
241 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
242 xbt_assert(isfinite(priority), "priority is not finite!");
244 return simcall_BODY_host_execute(name, host, computation_amount, priority);
248 * \ingroup simix_host_management
249 * \brief Creates an action that may involve parallel computation on
250 * several hosts and communication between them.
252 * \param name Name of the execution action to create
253 * \param host_nb Number of hosts where the action will be executed
254 * \param host_list Array (of size host_nb) of hosts where the action will be executed
255 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
256 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
257 * amount between each pair of hosts
258 * \param amount the SURF action amount
259 * \param rate the SURF action rate
260 * \return A new SIMIX execution action
262 smx_action_t simcall_host_parallel_execute(const char *name,
264 smx_host_t *host_list,
265 double *computation_amount,
266 double *communication_amount,
271 /* checking for infinite values */
272 for (i = 0 ; i < host_nb ; ++i) {
273 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
274 for (j = 0 ; j < host_nb ; ++j) {
275 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
276 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
280 xbt_assert(isfinite(amount), "amount is not finite!");
281 xbt_assert(isfinite(rate), "rate is not finite!");
283 return simcall_BODY_host_parallel_execute(name, host_nb, host_list,
285 communication_amount,
291 * \ingroup simix_host_management
292 * \brief Destroys an execution action.
294 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
295 * \param execution The execution action to destroy
297 void simcall_host_execution_destroy(smx_action_t execution)
299 simcall_BODY_host_execution_destroy(execution);
303 * \ingroup simix_host_management
304 * \brief Cancels an execution action.
306 * This functions stops the execution. It calls a surf function.
307 * \param execution The execution action to cancel
309 void simcall_host_execution_cancel(smx_action_t execution)
311 simcall_BODY_host_execution_cancel(execution);
315 * \ingroup simix_host_management
316 * \brief Returns how much of an execution action remains to be done.
318 * \param execution The execution action
319 * \return The remaining amount
321 double simcall_host_execution_get_remains(smx_action_t execution)
323 return simcall_BODY_host_execution_get_remains(execution);
327 * \ingroup simix_host_management
328 * \brief Returns the state of an execution action.
330 * \param execution The execution action
333 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
335 return simcall_BODY_host_execution_get_state(execution);
339 * \ingroup simix_host_management
340 * \brief Changes the priority of an execution action.
342 * This functions changes the priority only. It calls a surf function.
343 * \param execution The execution action
344 * \param priority The new priority
346 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
348 /* checking for infinite values */
349 xbt_assert(isfinite(priority), "priority is not finite!");
351 simcall_BODY_host_execution_set_priority(execution, priority);
355 * \ingroup simix_host_management
356 * \brief Waits for the completion of an execution action and destroy it.
358 * \param execution The execution action
360 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
362 return simcall_BODY_host_execution_wait(execution);
366 * \ingroup simix_process_management
367 * \brief Creates and runs a new SIMIX process.
369 * The structure and the corresponding thread are created and put in the list of ready processes.
371 * \param process the process created will be stored in this pointer
372 * \param name a name for the process. It is for user-level information and can be NULL.
373 * \param code the main function of the process
374 * \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.
375 * It can be retrieved with the function \ref simcall_process_get_data.
376 * \param hostname name of the host where the new agent is executed.
377 * \param kill_time time when the process is killed
378 * \param argc first argument passed to \a code
379 * \param argv second argument passed to \a code
380 * \param properties the properties of the process
381 * \param auto_restart either it is autorestarting or not.
383 void simcall_process_create(smx_process_t *process, const char *name,
384 xbt_main_func_t code,
386 const char *hostname,
388 int argc, char **argv,
389 xbt_dict_t properties,
392 simcall_BODY_process_create(process, name, code, data, hostname,
393 kill_time, argc, argv, properties,
398 * \ingroup simix_process_management
399 * \brief Kills a SIMIX process.
401 * This function simply kills a process.
403 * \param process poor victim
405 void simcall_process_kill(smx_process_t process)
407 simcall_BODY_process_kill(process);
411 * \ingroup simix_process_management
412 * \brief Kills all SIMIX processes.
414 void simcall_process_killall(int reset_pid)
416 simcall_BODY_process_killall(reset_pid);
420 * \ingroup simix_process_management
421 * \brief Cleans up a SIMIX process.
422 * \param process poor victim (must have already been killed)
424 void simcall_process_cleanup(smx_process_t process)
426 simcall_BODY_process_cleanup(process);
430 * \ingroup simix_process_management
431 * \brief Migrates an agent to another location.
433 * This function changes the value of the host on which \a process is running.
435 * \param process the process to migrate
436 * \param dest name of the new host
438 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
440 simcall_BODY_process_change_host(process, dest);
444 * \ingroup simix_process_management
445 * \brief Suspends a process.
447 * This function suspends the process by suspending the action
448 * it was waiting for completion.
450 * \param process a SIMIX process
452 void simcall_process_suspend(smx_process_t process)
454 xbt_assert(process, "Invalid parameters");
456 simcall_BODY_process_suspend(process);
460 * \ingroup simix_process_management
461 * \brief Resumes a suspended process.
463 * This function resumes a suspended process by resuming the action
464 * it was waiting for completion.
466 * \param process a SIMIX process
468 void simcall_process_resume(smx_process_t process)
470 simcall_BODY_process_resume(process);
474 * \ingroup simix_process_management
475 * \brief Returns the amount of SIMIX processes in the system
477 * Maestro internal process is not counted, only user code processes are
479 int simcall_process_count(void)
481 return simcall_BODY_process_count();
485 * \ingroup simix_process_management
486 * \brief Return the PID of a #smx_process_t.
487 * \param process a SIMIX process
488 * \return the PID of this process
490 int simcall_process_get_PID(smx_process_t process)
492 if (process == SIMIX_process_self()) {
493 /* avoid a simcall if this function is called by the process itself */
494 return SIMIX_process_get_PID(process);
497 return simcall_BODY_process_get_PID(process);
501 * \ingroup simix_process_management
502 * \brief Return the parent PID of a #smx_process_t.
503 * \param process a SIMIX process
504 * \return the PID of this process parenrt
506 int simcall_process_get_PPID(smx_process_t process)
508 if (process == SIMIX_process_self()) {
509 /* avoid a simcall if this function is called by the process itself */
510 return SIMIX_process_get_PPID(process);
513 return simcall_BODY_process_get_PPID(process);
517 * \ingroup simix_process_management
518 * \brief Return the user data of a #smx_process_t.
519 * \param process a SIMIX process
520 * \return the user data of this process
522 void* simcall_process_get_data(smx_process_t process)
524 if (process == SIMIX_process_self()) {
525 /* avoid a simcall if this function is called by the process itself */
526 return SIMIX_process_get_data(process);
529 return simcall_BODY_process_get_data(process);
533 * \ingroup simix_process_management
534 * \brief Set the user data of a #smx_process_t.
536 * This functions sets the user data associated to \a process.
537 * \param process SIMIX process
538 * \param data User data
540 void simcall_process_set_data(smx_process_t process, void *data)
542 if (process == SIMIX_process_self()) {
543 /* avoid a simcall if this function is called by the process itself */
544 SIMIX_process_self_set_data(process, data);
547 simcall_BODY_process_set_data(process, data);
552 * \ingroup simix_process_management
553 * \brief Set the kill time of a process.
554 * \param process a process
555 * \param kill_time a double
557 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
560 if (kill_time > SIMIX_get_clock()) {
561 if (simix_global->kill_process_function) {
562 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
563 sg_host_name(process->smx_host));
564 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
570 * \ingroup simix_process_management
571 * \brief Return the location on which an agent is running.
573 * This functions returns the smx_host_t corresponding to the location on which
574 * \a process is running.
575 * \param process SIMIX process
578 smx_host_t simcall_process_get_host(smx_process_t process)
580 return simcall_BODY_process_get_host(process);
584 * \ingroup simix_process_management
585 * \brief Return the name of an agent.
587 * This functions checks whether \a process is a valid pointer or not and return its name.
588 * \param process SIMIX process
589 * \return The process name
591 const char* simcall_process_get_name(smx_process_t process)
593 if (process == SIMIX_process_self()) {
594 /* avoid a simcall if this function is called by the process itself */
595 return process->name;
597 return simcall_BODY_process_get_name(process);
601 * \ingroup simix_process_management
602 * \brief Returns true if the process is suspended .
604 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
605 * \param process SIMIX process
606 * \return 1, if the process is suspended, else 0.
608 int simcall_process_is_suspended(smx_process_t process)
610 return simcall_BODY_process_is_suspended(process);
614 * \ingroup simix_process_management
615 * \brief Return the properties
617 * This functions returns the properties associated with this process
619 xbt_dict_t simcall_process_get_properties(smx_process_t process)
621 return simcall_BODY_process_get_properties(process);
624 * \ingroup simix_process_management
625 * \brief Add an on_exit function
626 * Add an on_exit function which will be executed when the process exits/is killed.
628 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
630 simcall_BODY_process_on_exit(process, fun, data);
633 * \ingroup simix_process_management
634 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
635 * Will restart the process when the host comes back up if auto_restart is set to 1.
638 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
640 simcall_BODY_process_auto_restart_set(process, auto_restart);
644 * \ingroup simix_process_management
645 * \brief Restarts the process, killing it and starting it again from scratch.
647 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
649 return simcall_BODY_process_restart(process);
652 * \ingroup simix_process_management
653 * \brief Creates a new sleep SIMIX action.
655 * This function creates a SURF action and allocates the data necessary
656 * to create the SIMIX action. It can raise a host_error exception if the
657 * host crashed. The default SIMIX name of the action is "sleep".
659 * \param duration Time duration of the sleep.
660 * \return A result telling whether the sleep was successful
662 e_smx_state_t simcall_process_sleep(double duration)
664 /* checking for infinite values */
665 xbt_assert(isfinite(duration), "duration is not finite!");
666 return simcall_BODY_process_sleep(duration);
670 * \ingroup simix_rdv_management
671 * \brief Creates a new rendez-vous point
672 * \param name The name of the rendez-vous point
673 * \return The created rendez-vous point
675 smx_rdv_t simcall_rdv_create(const char *name)
677 return simcall_BODY_rdv_create(name);
682 * \ingroup simix_rdv_management
683 * \brief Destroy a rendez-vous point
684 * \param rdv The rendez-vous point to destroy
686 void simcall_rdv_destroy(smx_rdv_t rdv)
688 simcall_BODY_rdv_destroy(rdv);
691 * \ingroup simix_rdv_management
692 * \brief Returns a rendez-vous point knowing its name
694 smx_rdv_t simcall_rdv_get_by_name(const char *name)
696 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
698 /* FIXME: this is a horrible loss of performance, so we hack it out by
699 * skipping the simcall (for now). It works in parallel, it won't work on
700 * distributed but probably we will change MSG for that. */
703 smx_simcall_t simcall = simcall_mine();
704 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
705 simcall->rdv_get_by_name.name = name;
706 SIMIX_simcall_push(simcall->issuer);
707 return simcall->rdv_get_by_name.result;*/
709 return SIMIX_rdv_get_by_name(name);
713 * \ingroup simix_rdv_management
714 * \brief Counts the number of communication actions of a given host pending
715 * on a rendez-vous point.
716 * \param rdv The rendez-vous point
717 * \param host The host to be counted
718 * \return The number of comm actions pending in the rdv
720 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
722 return simcall_BODY_rdv_comm_count_by_host(rdv, host);
726 * \ingroup simix_rdv_management
727 * \brief returns the communication at the head of the rendez-vous
728 * \param rdv The rendez-vous point
729 * \return The communication or NULL if empty
731 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
733 return simcall_BODY_rdv_get_head(rdv);
736 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
738 simcall_BODY_rdv_set_receiver(rdv, process);
741 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
743 return simcall_BODY_rdv_get_receiver(rdv);
747 * \ingroup simix_comm_management
749 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
750 void *src_buff, size_t src_buff_size,
751 int (*match_fun)(void *, void *, smx_action_t), void *data,
754 /* checking for infinite values */
755 xbt_assert(isfinite(task_size), "task_size is not finite!");
756 xbt_assert(isfinite(rate), "rate is not finite!");
757 xbt_assert(isfinite(timeout), "timeout is not finite!");
759 xbt_assert(rdv, "No rendez-vous point defined for send");
761 if (MC_is_active()) {
762 /* the model-checker wants two separate simcalls */
763 smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
764 comm = simcall_comm_isend(rdv, task_size, rate,
765 src_buff, src_buff_size, match_fun, NULL, data, 0);
766 simcall_comm_wait(comm, timeout);
770 simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
771 match_fun, data, timeout);
776 * \ingroup simix_comm_management
778 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
779 void *src_buff, size_t src_buff_size,
780 int (*match_fun)(void *, void *, smx_action_t),
781 void (*clean_fun)(void *),
785 /* checking for infinite values */
786 xbt_assert(isfinite(task_size), "task_size is not finite!");
787 xbt_assert(isfinite(rate), "rate is not finite!");
789 xbt_assert(rdv, "No rendez-vous point defined for isend");
791 return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
792 src_buff_size, match_fun,
793 clean_fun, data, detached);
796 * \ingroup simix_comm_management
798 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
799 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
801 xbt_assert(isfinite(timeout), "timeout is not finite!");
802 xbt_assert(rdv, "No rendez-vous point defined for recv");
804 if (MC_is_active()) {
805 /* the model-checker wants two separate simcalls */
806 smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
807 comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
809 simcall_comm_wait(comm, timeout);
813 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
814 match_fun, data, timeout);
818 * \ingroup simix_comm_management
820 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
821 int (*match_fun)(void *, void *, smx_action_t), void *data)
823 xbt_assert(rdv, "No rendez-vous point defined for irecv");
825 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
831 * \ingroup simix_comm_management
833 void simcall_comm_recv_bounded(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
834 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout, double rate)
836 xbt_assert(isfinite(timeout), "timeout is not finite!");
837 xbt_assert(rdv, "No rendez-vous point defined for recv");
839 if (MC_is_active()) {
840 /* the model-checker wants two separate simcalls */
841 smx_action_t comm = simcall_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
842 match_fun, data, rate);
843 simcall_comm_wait(comm, timeout);
846 simcall_BODY_comm_recv_bounded(rdv, dst_buff, dst_buff_size,
847 match_fun, data, timeout, rate);
851 * \ingroup simix_comm_management
853 smx_action_t simcall_comm_irecv_bounded(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
854 int (*match_fun)(void *, void *, smx_action_t), void *data, double rate)
856 xbt_assert(rdv, "No rendez-vous point defined for irecv");
858 return simcall_BODY_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
859 match_fun, data, rate);
864 * \ingroup simix_comm_management
866 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
867 int (*match_fun)(void *, void *, smx_action_t), void *data)
869 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
871 return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
874 void simcall_comm_destroy(smx_action_t comm)
876 xbt_assert(comm, "Invalid parameter");
878 /* FIXME remove this simcall type: comms are auto-destroyed now */
881 smx_simcall_t simcall = simcall_mine();
883 simcall->call = SIMCALL_COMM_DESTROY;
884 simcall->comm_destroy.comm = comm;
886 SIMIX_simcall_push(simcall->issuer);
891 * \ingroup simix_comm_management
893 void simcall_comm_cancel(smx_action_t comm)
895 simcall_BODY_comm_cancel(comm);
899 * \ingroup simix_comm_management
901 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
903 return simcall_BODY_comm_waitany(comms);
907 * \ingroup simix_comm_management
909 int simcall_comm_testany(xbt_dynar_t comms)
911 if (xbt_dynar_is_empty(comms))
913 return simcall_BODY_comm_testany(comms);
917 * \ingroup simix_comm_management
919 void simcall_comm_wait(smx_action_t comm, double timeout)
921 xbt_assert(isfinite(timeout), "timeout is not finite!");
922 simcall_BODY_comm_wait(comm, timeout);
927 * \brief Set the category of an action.
929 * This functions changes the category only. It calls a surf function.
930 * \param execution The execution action
931 * \param category The tracing category
933 void simcall_set_category(smx_action_t action, const char *category)
935 if (category == NULL) {
938 simcall_BODY_set_category(action, category);
943 * \ingroup simix_comm_management
946 int simcall_comm_test(smx_action_t comm)
948 return simcall_BODY_comm_test(comm);
952 * \ingroup simix_comm_management
955 double simcall_comm_get_remains(smx_action_t comm)
957 return simcall_BODY_comm_get_remains(comm);
961 * \ingroup simix_comm_management
964 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
966 return simcall_BODY_comm_get_state(comm);
970 * \ingroup simix_comm_management
973 void *simcall_comm_get_src_data(smx_action_t comm)
975 return simcall_BODY_comm_get_src_data(comm);
979 * \ingroup simix_comm_management
982 void *simcall_comm_get_dst_data(smx_action_t comm)
984 return simcall_BODY_comm_get_dst_data(comm);
988 * \ingroup simix_comm_management
991 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
993 return simcall_BODY_comm_get_src_proc(comm);
997 * \ingroup simix_comm_management
1000 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1002 return simcall_BODY_comm_get_dst_proc(comm);
1005 #ifdef HAVE_LATENCY_BOUND_TRACKING
1006 int simcall_comm_is_latency_bounded(smx_action_t comm)
1008 return simcall_BODY_comm_is_latency_bounded(comm);
1013 * \ingroup simix_synchro_management
1016 smx_mutex_t simcall_mutex_init(void)
1019 fprintf(stderr,"You must run MSG_init before using MSG\n"); // We can't use xbt_die since we may get there before the initialization
1022 return simcall_BODY_mutex_init();
1026 * \ingroup simix_synchro_management
1029 void simcall_mutex_destroy(smx_mutex_t mutex)
1031 simcall_BODY_mutex_destroy(mutex);
1035 * \ingroup simix_synchro_management
1038 void simcall_mutex_lock(smx_mutex_t mutex)
1040 simcall_BODY_mutex_lock(mutex);
1044 * \ingroup simix_synchro_management
1047 int simcall_mutex_trylock(smx_mutex_t mutex)
1049 return simcall_BODY_mutex_trylock(mutex);
1053 * \ingroup simix_synchro_management
1056 void simcall_mutex_unlock(smx_mutex_t mutex)
1058 simcall_BODY_mutex_unlock(mutex);
1062 * \ingroup simix_synchro_management
1065 smx_cond_t simcall_cond_init(void)
1067 return simcall_BODY_cond_init();
1071 * \ingroup simix_synchro_management
1074 void simcall_cond_destroy(smx_cond_t cond)
1076 simcall_BODY_cond_destroy(cond);
1080 * \ingroup simix_synchro_management
1083 void simcall_cond_signal(smx_cond_t cond)
1085 simcall_BODY_cond_signal(cond);
1089 * \ingroup simix_synchro_management
1092 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1094 simcall_BODY_cond_wait(cond, mutex);
1098 * \ingroup simix_synchro_management
1101 void simcall_cond_wait_timeout(smx_cond_t cond,
1105 xbt_assert(isfinite(timeout), "timeout is not finite!");
1106 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1110 * \ingroup simix_synchro_management
1113 void simcall_cond_broadcast(smx_cond_t cond)
1115 simcall_BODY_cond_broadcast(cond);
1119 * \ingroup simix_synchro_management
1122 smx_sem_t simcall_sem_init(int capacity)
1124 return simcall_BODY_sem_init(capacity);
1128 * \ingroup simix_synchro_management
1131 void simcall_sem_destroy(smx_sem_t sem)
1133 simcall_sem_destroy(sem);
1137 * \ingroup simix_synchro_management
1140 void simcall_sem_release(smx_sem_t sem)
1142 simcall_BODY_sem_release(sem);
1146 * \ingroup simix_synchro_management
1149 int simcall_sem_would_block(smx_sem_t sem)
1151 return simcall_BODY_sem_would_block(sem);
1155 * \ingroup simix_synchro_management
1158 void simcall_sem_acquire(smx_sem_t sem)
1160 simcall_BODY_sem_acquire(sem);
1164 * \ingroup simix_synchro_management
1167 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1169 xbt_assert(isfinite(timeout), "timeout is not finite!");
1170 simcall_BODY_sem_acquire_timeout(sem, timeout);
1174 * \ingroup simix_synchro_management
1177 int simcall_sem_get_capacity(smx_sem_t sem)
1179 return simcall_BODY_sem_get_capacity(sem);
1183 * \ingroup simix_file_management
1184 * \brief Returns the user data associated to a file.
1186 * \param fd A simix file
1187 * \return the user data of this file
1189 void* simcall_file_get_data(smx_file_t fd)
1191 return simcall_BODY_file_get_data(fd);
1195 * \ingroup simix_file_management
1196 * \brief Sets the user data associated to a file.
1198 * \param fd A SIMIX file
1199 * \param data The user data to set
1201 void simcall_file_set_data(smx_file_t fd, void *data)
1203 simcall_file_set_data(fd, data);
1207 * \ingroup simix_file_management
1210 sg_storage_size_t simcall_file_read(smx_file_t fd, sg_storage_size_t size)
1212 return simcall_BODY_file_read(fd, size);
1216 * \ingroup simix_file_management
1219 sg_storage_size_t simcall_file_write(smx_file_t fd, sg_storage_size_t size)
1221 return simcall_BODY_file_write(fd, size);
1225 * \ingroup simix_file_management
1228 smx_file_t simcall_file_open(const char* mount, const char* path)
1230 return simcall_BODY_file_open(mount, path);
1234 * \ingroup simix_file_management
1237 int simcall_file_close(smx_file_t fd)
1239 return simcall_BODY_file_close(fd);
1243 * \ingroup simix_file_management
1246 int simcall_file_unlink(smx_file_t fd)
1248 return simcall_BODY_file_unlink(fd);
1252 * \ingroup simix_file_management
1255 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1257 return simcall_BODY_file_ls(mount, path);
1260 * \ingroup simix_file_management
1263 sg_storage_size_t simcall_file_get_size (smx_file_t fd){
1264 return simcall_BODY_file_get_size(fd);
1268 * \ingroup simix_file_management
1271 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1273 return simcall_BODY_file_get_info(fd);
1277 * \ingroup simix_file_management
1280 void simcall_file_rename(smx_file_t fd, const char* new_name)
1282 return simcall_BODY_file_rename(fd, new_name);
1286 * \ingroup simix_storage_management
1287 * \brief Returns the free space size on a given storage element.
1288 * \param storage name
1289 * \return Return the free space size on a given storage element (as sg_storage_size_t)
1291 sg_storage_size_t simcall_storage_get_free_size (const char* name){
1292 return simcall_BODY_storage_get_free_size(name);
1296 * \ingroup simix_storage_management
1297 * \brief Returns the used space size on a given storage element.
1298 * \param storage name
1299 * \return Return the used space size on a given storage element (as sg_storage_size_t)
1301 sg_storage_size_t simcall_storage_get_used_size (const char* name){
1302 return simcall_BODY_storage_get_used_size(name);
1306 * \ingroup simix_storage_management
1307 * \brief Returns the list of storages mounted on an host.
1308 * \param host A SIMIX host
1309 * \return a dict containing all storages mounted on the host
1311 xbt_dict_t simcall_host_get_storage_list(smx_host_t host)
1313 return simcall_BODY_host_get_storage_list(host);
1317 * \ingroup simix_storage_management
1318 * \brief Returns a dict of the properties assigned to a storage element.
1320 * \param storage A storage element
1321 * \return The properties of this storage element
1323 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1325 return simcall_BODY_storage_get_properties(storage);
1329 * \ingroup simix_storage_management
1330 * \brief Returns a dict containing the content of a storage element.
1332 * \param storage A storage element
1333 * \return The content of this storage element as a dict (full path file => size)
1335 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1337 return simcall_BODY_storage_get_content(storage);
1342 void *simcall_mc_snapshot(void)
1344 return simcall_BODY_mc_snapshot();
1347 int simcall_mc_compare_snapshots(void *s1, void *s2){
1348 return simcall_BODY_mc_compare_snapshots(s1, s2);
1351 int simcall_mc_random(int min, int max)
1353 return simcall_BODY_mc_random(min, max);
1357 #endif /* HAVE_MC */
1359 /* ****************************************************************************************** */
1360 /* TUTORIAL: New API */
1361 /* All functions for simcall */
1362 /* ****************************************************************************************** */
1363 int simcall_new_api_fct(const char* param1, double param2){
1364 smx_simcall_t simcall = SIMIX_simcall_mine();
1365 simcall->call = SIMCALL_NEW_API_INIT;
1366 simcall->new_api.param1 = param1;
1367 simcall->new_api.param2 = param2;
1369 SIMIX_simcall_push(simcall->issuer);
1370 return simcall->new_api.result;
1373 /* ************************************************************************** */
1375 /** @brief returns a printable string representing a simcall */
1376 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1377 return simcall_names[kind];