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 = simcall_comm_isend(rdv, task_size, rate,
764 src_buff, src_buff_size, match_fun, NULL, data, 0);
765 simcall_comm_wait(comm, timeout);
768 simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
769 match_fun, data, timeout);
774 * \ingroup simix_comm_management
776 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
777 void *src_buff, size_t src_buff_size,
778 int (*match_fun)(void *, void *, smx_action_t),
779 void (*clean_fun)(void *),
783 /* checking for infinite values */
784 xbt_assert(isfinite(task_size), "task_size is not finite!");
785 xbt_assert(isfinite(rate), "rate is not finite!");
787 xbt_assert(rdv, "No rendez-vous point defined for isend");
789 return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
790 src_buff_size, match_fun,
791 clean_fun, data, detached);
794 * \ingroup simix_comm_management
796 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
797 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
799 xbt_assert(isfinite(timeout), "timeout is not finite!");
800 xbt_assert(rdv, "No rendez-vous point defined for recv");
802 if (MC_is_active()) {
803 /* the model-checker wants two separate simcalls */
804 smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
806 simcall_comm_wait(comm, timeout);
809 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
810 match_fun, data, timeout);
814 * \ingroup simix_comm_management
816 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
817 int (*match_fun)(void *, void *, smx_action_t), void *data)
819 xbt_assert(rdv, "No rendez-vous point defined for irecv");
821 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
827 * \ingroup simix_comm_management
829 void simcall_comm_recv_bounded(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
830 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout, double rate)
832 xbt_assert(isfinite(timeout), "timeout is not finite!");
833 xbt_assert(rdv, "No rendez-vous point defined for recv");
835 if (MC_is_active()) {
836 /* the model-checker wants two separate simcalls */
837 smx_action_t comm = simcall_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
838 match_fun, data, rate);
839 simcall_comm_wait(comm, timeout);
842 simcall_BODY_comm_recv_bounded(rdv, dst_buff, dst_buff_size,
843 match_fun, data, timeout, rate);
847 * \ingroup simix_comm_management
849 smx_action_t simcall_comm_irecv_bounded(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
850 int (*match_fun)(void *, void *, smx_action_t), void *data, double rate)
852 xbt_assert(rdv, "No rendez-vous point defined for irecv");
854 return simcall_BODY_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
855 match_fun, data, rate);
860 * \ingroup simix_comm_management
862 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
863 int (*match_fun)(void *, void *, smx_action_t), void *data)
865 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
867 return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
870 void simcall_comm_destroy(smx_action_t comm)
872 xbt_assert(comm, "Invalid parameter");
874 /* FIXME remove this simcall type: comms are auto-destroyed now */
877 smx_simcall_t simcall = simcall_mine();
879 simcall->call = SIMCALL_COMM_DESTROY;
880 simcall->comm_destroy.comm = comm;
882 SIMIX_simcall_push(simcall->issuer);
887 * \ingroup simix_comm_management
889 void simcall_comm_cancel(smx_action_t comm)
891 simcall_BODY_comm_cancel(comm);
895 * \ingroup simix_comm_management
897 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
899 return simcall_BODY_comm_waitany(comms);
903 * \ingroup simix_comm_management
905 int simcall_comm_testany(xbt_dynar_t comms)
907 if (xbt_dynar_is_empty(comms))
909 return simcall_BODY_comm_testany(comms);
913 * \ingroup simix_comm_management
915 void simcall_comm_wait(smx_action_t comm, double timeout)
917 xbt_assert(isfinite(timeout), "timeout is not finite!");
918 simcall_BODY_comm_wait(comm, timeout);
923 * \brief Set the category of an action.
925 * This functions changes the category only. It calls a surf function.
926 * \param execution The execution action
927 * \param category The tracing category
929 void simcall_set_category(smx_action_t action, const char *category)
931 if (category == NULL) {
934 simcall_BODY_set_category(action, category);
939 * \ingroup simix_comm_management
942 int simcall_comm_test(smx_action_t comm)
944 return simcall_BODY_comm_test(comm);
948 * \ingroup simix_comm_management
951 double simcall_comm_get_remains(smx_action_t comm)
953 return simcall_BODY_comm_get_remains(comm);
957 * \ingroup simix_comm_management
960 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
962 return simcall_BODY_comm_get_state(comm);
966 * \ingroup simix_comm_management
969 void *simcall_comm_get_src_data(smx_action_t comm)
971 return simcall_BODY_comm_get_src_data(comm);
975 * \ingroup simix_comm_management
978 void *simcall_comm_get_dst_data(smx_action_t comm)
980 return simcall_BODY_comm_get_dst_data(comm);
984 * \ingroup simix_comm_management
987 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
989 return simcall_BODY_comm_get_src_proc(comm);
993 * \ingroup simix_comm_management
996 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
998 return simcall_BODY_comm_get_dst_proc(comm);
1001 #ifdef HAVE_LATENCY_BOUND_TRACKING
1002 int simcall_comm_is_latency_bounded(smx_action_t comm)
1004 return simcall_BODY_comm_is_latency_bounded(comm);
1009 * \ingroup simix_synchro_management
1012 smx_mutex_t simcall_mutex_init(void)
1015 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
1018 return simcall_BODY_mutex_init();
1022 * \ingroup simix_synchro_management
1025 void simcall_mutex_destroy(smx_mutex_t mutex)
1027 simcall_BODY_mutex_destroy(mutex);
1031 * \ingroup simix_synchro_management
1034 void simcall_mutex_lock(smx_mutex_t mutex)
1036 simcall_BODY_mutex_lock(mutex);
1040 * \ingroup simix_synchro_management
1043 int simcall_mutex_trylock(smx_mutex_t mutex)
1045 return simcall_BODY_mutex_trylock(mutex);
1049 * \ingroup simix_synchro_management
1052 void simcall_mutex_unlock(smx_mutex_t mutex)
1054 simcall_BODY_mutex_unlock(mutex);
1058 * \ingroup simix_synchro_management
1061 smx_cond_t simcall_cond_init(void)
1063 return simcall_BODY_cond_init();
1067 * \ingroup simix_synchro_management
1070 void simcall_cond_destroy(smx_cond_t cond)
1072 simcall_BODY_cond_destroy(cond);
1076 * \ingroup simix_synchro_management
1079 void simcall_cond_signal(smx_cond_t cond)
1081 simcall_BODY_cond_signal(cond);
1085 * \ingroup simix_synchro_management
1088 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1090 simcall_BODY_cond_wait(cond, mutex);
1094 * \ingroup simix_synchro_management
1097 void simcall_cond_wait_timeout(smx_cond_t cond,
1101 xbt_assert(isfinite(timeout), "timeout is not finite!");
1102 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1106 * \ingroup simix_synchro_management
1109 void simcall_cond_broadcast(smx_cond_t cond)
1111 simcall_BODY_cond_broadcast(cond);
1115 * \ingroup simix_synchro_management
1118 smx_sem_t simcall_sem_init(int capacity)
1120 return simcall_BODY_sem_init(capacity);
1124 * \ingroup simix_synchro_management
1127 void simcall_sem_destroy(smx_sem_t sem)
1129 simcall_sem_destroy(sem);
1133 * \ingroup simix_synchro_management
1136 void simcall_sem_release(smx_sem_t sem)
1138 simcall_BODY_sem_release(sem);
1142 * \ingroup simix_synchro_management
1145 int simcall_sem_would_block(smx_sem_t sem)
1147 return simcall_BODY_sem_would_block(sem);
1151 * \ingroup simix_synchro_management
1154 void simcall_sem_acquire(smx_sem_t sem)
1156 simcall_BODY_sem_acquire(sem);
1160 * \ingroup simix_synchro_management
1163 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1165 xbt_assert(isfinite(timeout), "timeout is not finite!");
1166 simcall_BODY_sem_acquire_timeout(sem, timeout);
1170 * \ingroup simix_synchro_management
1173 int simcall_sem_get_capacity(smx_sem_t sem)
1175 return simcall_BODY_sem_get_capacity(sem);
1179 * \ingroup simix_file_management
1180 * \brief Returns the user data associated to a file.
1182 * \param fd A simix file
1183 * \return the user data of this file
1185 void* simcall_file_get_data(smx_file_t fd)
1187 return simcall_BODY_file_get_data(fd);
1191 * \ingroup simix_file_management
1192 * \brief Sets the user data associated to a file.
1194 * \param fd A SIMIX file
1195 * \param data The user data to set
1197 void simcall_file_set_data(smx_file_t fd, void *data)
1199 simcall_file_set_data(fd, data);
1203 * \ingroup simix_file_management
1206 size_t simcall_file_read(size_t size, smx_file_t fd)
1208 return simcall_BODY_file_read(size, fd);
1212 * \ingroup simix_file_management
1215 size_t simcall_file_write(size_t size, smx_file_t fd)
1217 return simcall_BODY_file_write(size, fd);
1221 * \ingroup simix_file_management
1224 smx_file_t simcall_file_open(const char* mount, const char* path)
1226 return simcall_BODY_file_open(mount, path);
1230 * \ingroup simix_file_management
1233 int simcall_file_close(smx_file_t fd)
1235 return simcall_BODY_file_close(fd);
1239 * \ingroup simix_file_management
1242 int simcall_file_unlink(smx_file_t fd)
1244 return simcall_BODY_file_unlink(fd);
1248 * \ingroup simix_file_management
1251 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1253 return simcall_BODY_file_ls(mount, path);
1256 * \ingroup simix_file_management
1259 size_t simcall_file_get_size (smx_file_t fd){
1260 return simcall_BODY_file_get_size(fd);
1264 * \ingroup simix_file_management
1267 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1269 return simcall_BODY_file_get_info(fd);
1273 * \ingroup simix_storage_management
1274 * \brief Returns the free space size on a given storage element.
1275 * \param storage name
1276 * \return Return the free space size on a given storage element (as size_t)
1278 size_t simcall_storage_get_free_size (const char* name){
1279 return simcall_BODY_storage_get_free_size(name);
1283 * \ingroup simix_storage_management
1284 * \brief Returns the used space size on a given storage element.
1285 * \param storage name
1286 * \return Return the used space size on a given storage element (as size_t)
1288 size_t simcall_storage_get_used_size (const char* name){
1289 return simcall_BODY_storage_get_used_size(name);
1293 * \ingroup simix_storage_management
1294 * \brief Returns the list of storages mounted on an host.
1295 * \param host A SIMIX host
1296 * \return a dynar containing all storages mounted on the host
1298 xbt_dynar_t simcall_host_get_storage_list(smx_host_t host)
1300 return simcall_BODY_host_get_storage_list(host);
1304 * \ingroup simix_storage_management
1305 * \brief Returns a dict of the properties assigned to a storage element.
1307 * \param storage A storage element
1308 * \return The properties of this storage element
1310 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1312 return simcall_BODY_storage_get_properties(storage);
1316 * \ingroup simix_storage_management
1317 * \brief Returns a dict containing the content of a storage element.
1319 * \param storage A storage element
1320 * \return The content of this storage element as a dict (full path file => size)
1322 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1324 return simcall_BODY_storage_get_content(storage);
1329 void *simcall_mc_snapshot(void)
1331 return simcall_BODY_mc_snapshot();
1334 int simcall_mc_compare_snapshots(void *s1, void *s2){
1335 return simcall_BODY_mc_compare_snapshots(s1, s2);
1338 int simcall_mc_random(int min, int max)
1340 return simcall_BODY_mc_random(min, max);
1344 #endif /* HAVE_MC */
1346 /* ****************************************************************************************** */
1347 /* TUTORIAL: New API */
1348 /* All functions for simcall */
1349 /* ****************************************************************************************** */
1350 int simcall_new_api_fct(const char* param1, double param2){
1351 smx_simcall_t simcall = SIMIX_simcall_mine();
1352 simcall->call = SIMCALL_NEW_API_INIT;
1353 simcall->new_api.param1 = param1;
1354 simcall->new_api.param2 = param2;
1356 SIMIX_simcall_push(simcall->issuer);
1357 return simcall->new_api.result;
1360 /* ************************************************************************** */
1362 /** @brief returns a printable string representing a simcall */
1363 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1364 return simcall_names[kind];