1 /* smx_user.c - public interface to simix */
3 /* Copyright (c) 2010, 2011. Da SimGrid team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 # define _SVID_SOURCE /* strdup() */
10 #ifndef _ISOC99_SOURCE
11 # define _ISOC99_SOURCE /* isfinite() */
13 #ifndef _ISO_C99_SOURCE
14 # define _ISO_C99_SOURCE /* isfinite() */
16 #include <math.h> /* isfinite() */
18 #include "smx_private.h"
22 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
24 static const char* simcall_names[] = {
25 #undef SIMCALL_ENUM_ELEMENT
26 #define SIMCALL_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
28 #undef SIMCALL_ENUM_ELEMENT
32 * \ingroup simix_host_management
33 * \brief Returns a host given its name.
35 * \param name The name of the host to get
36 * \return The corresponding host
38 smx_host_t simcall_host_get_by_name(const char *name)
40 smx_simcall_t simcall = SIMIX_simcall_mine();
42 simcall->call = SIMCALL_HOST_GET_BY_NAME;
43 simcall->host_get_by_name.name = name;
44 SIMIX_simcall_push(simcall->issuer);
45 return simcall->host_get_by_name.result;
49 * \ingroup simix_host_management
50 * \brief Returns the name of a host.
52 * \param host A SIMIX host
53 * \return The name of this host
55 const char* simcall_host_get_name(smx_host_t host)
57 smx_simcall_t simcall = SIMIX_simcall_mine();
59 simcall->call = SIMCALL_HOST_GET_NAME;
60 simcall->host_get_name.host = host;
61 SIMIX_simcall_push(simcall->issuer);
62 return simcall->host_get_name.result;
66 * \ingroup simix_host_management
67 * \brief Returns a dict of the properties assigned to a host.
70 * \return The properties of this host
72 xbt_dict_t simcall_host_get_properties(smx_host_t host)
74 smx_simcall_t simcall = SIMIX_simcall_mine();
76 simcall->call = SIMCALL_HOST_GET_PROPERTIES;
77 simcall->host_get_properties.host = host;
78 SIMIX_simcall_push(simcall->issuer);
79 return simcall->host_get_properties.result;
83 * \ingroup simix_host_management
84 * \brief Returns the speed of the processor.
86 * The speed returned does not take into account the current load on the machine.
87 * \param host A SIMIX host
88 * \return The speed of this host (in Mflop/s)
90 double simcall_host_get_speed(smx_host_t host)
92 smx_simcall_t simcall = SIMIX_simcall_mine();
94 simcall->call = SIMCALL_HOST_GET_SPEED;
95 simcall->host_get_speed.host = host;
96 SIMIX_simcall_push(simcall->issuer);
97 return simcall->host_get_speed.result;
101 * \ingroup simix_host_management
102 * \brief Returns the available speed of the processor.
104 * \return Speed currently available (in Mflop/s)
106 double simcall_host_get_available_speed(smx_host_t host)
108 smx_simcall_t simcall = SIMIX_simcall_mine();
110 simcall->call = SIMCALL_HOST_GET_AVAILABLE_SPEED;
111 simcall->host_get_available_speed.host = host;
112 SIMIX_simcall_push(simcall->issuer);
113 return simcall->host_get_available_speed.result;
117 * \ingroup simix_host_management
118 * \brief Returns the state of a host.
120 * Two states are possible: 1 if the host is active or 0 if it has crashed.
121 * \param host A SIMIX host
122 * \return 1 if the host is available, 0 otherwise
124 int simcall_host_get_state(smx_host_t host)
126 smx_simcall_t simcall = SIMIX_simcall_mine();
128 simcall->call = SIMCALL_HOST_GET_STATE;
129 simcall->host_get_state.host = host;
130 SIMIX_simcall_push(simcall->issuer);
131 return simcall->host_get_state.result;
135 * \ingroup simix_host_management
136 * \brief Returns the user data associated to a host.
138 * \param host SIMIX host
139 * \return the user data of this host
141 void* simcall_host_get_data(smx_host_t host)
143 smx_simcall_t simcall = SIMIX_simcall_mine();
145 simcall->call = SIMCALL_HOST_GET_DATA;
146 simcall->host_get_data.host = host;
147 SIMIX_simcall_push(simcall->issuer);
148 return simcall->host_get_data.result;
152 * \ingroup simix_host_management
153 * \brief Sets the user data associated to a host.
155 * The host must not have previous user data associated to it.
156 * \param host A SIMIX host
157 * \param data The user data to set
159 void simcall_host_set_data(smx_host_t host, void *data)
161 smx_simcall_t simcall = SIMIX_simcall_mine();
163 simcall->call = SIMCALL_HOST_SET_DATA;
164 simcall->host_set_data.host = host;
165 simcall->host_set_data.data = data;
166 SIMIX_simcall_push(simcall->issuer);
170 * \ingroup simix_host_management
171 * \brief Creates an action that executes some computation of an host.
173 * This function creates a SURF action and allocates the data necessary
174 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
176 * \param name Name of the execution action to create
177 * \param host SIMIX host where the action will be executed
178 * \param computation_amount amount Computation amount (in bytes)
179 * \param priority computation priority
180 * \return A new SIMIX execution action
182 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
183 double computation_amount,
186 /* checking for infinite values */
187 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
188 xbt_assert(isfinite(priority), "priority is not finite!");
190 smx_simcall_t simcall = SIMIX_simcall_mine();
192 simcall->call = SIMCALL_HOST_EXECUTE;
193 simcall->host_execute.name = name;
194 simcall->host_execute.host = host;
195 simcall->host_execute.computation_amount = computation_amount;
196 simcall->host_execute.priority = priority;
197 SIMIX_simcall_push(simcall->issuer);
198 return simcall->host_execute.result;
202 * \ingroup simix_host_management
203 * \brief Creates an action that may involve parallel computation on
204 * several hosts and communication between them.
206 * \param name Name of the execution action to create
207 * \param host_nb Number of hosts where the action will be executed
208 * \param host_list Array (of size host_nb) of hosts where the action will be executed
209 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
210 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
211 * amount between each pair of hosts
212 * \param amount the SURF action amount
213 * \param rate the SURF action rate
214 * \return A new SIMIX execution action
216 smx_action_t simcall_host_parallel_execute(const char *name,
218 smx_host_t *host_list,
219 double *computation_amount,
220 double *communication_amount,
225 /* checking for infinite values */
226 for (i = 0 ; i < host_nb ; ++i) {
227 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
228 for (j = 0 ; j < host_nb ; ++j) {
229 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
230 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
234 xbt_assert(isfinite(amount), "amount is not finite!");
235 xbt_assert(isfinite(rate), "rate is not finite!");
237 smx_simcall_t simcall = SIMIX_simcall_mine();
239 simcall->call = SIMCALL_HOST_PARALLEL_EXECUTE;
240 simcall->host_parallel_execute.name = name;
241 simcall->host_parallel_execute.host_nb = host_nb;
242 simcall->host_parallel_execute.host_list = host_list;
243 simcall->host_parallel_execute.computation_amount = computation_amount;
244 simcall->host_parallel_execute.communication_amount = communication_amount;
245 simcall->host_parallel_execute.amount = amount;
246 simcall->host_parallel_execute.rate = rate;
247 SIMIX_simcall_push(simcall->issuer);
248 return simcall->host_parallel_execute.result;
252 * \ingroup simix_host_management
253 * \brief Destroys an execution action.
255 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
256 * \param execution The execution action to destroy
258 void simcall_host_execution_destroy(smx_action_t execution)
260 smx_simcall_t simcall = SIMIX_simcall_mine();
262 simcall->call = SIMCALL_HOST_EXECUTION_DESTROY;
263 simcall->host_execution_destroy.execution = execution;
264 SIMIX_simcall_push(simcall->issuer);
268 * \ingroup simix_host_management
269 * \brief Cancels an execution action.
271 * This functions stops the execution. It calls a surf function.
272 * \param execution The execution action to cancel
274 void simcall_host_execution_cancel(smx_action_t execution)
276 smx_simcall_t simcall = SIMIX_simcall_mine();
278 simcall->call = SIMCALL_HOST_EXECUTION_CANCEL;
279 simcall->host_execution_cancel.execution = execution;
280 SIMIX_simcall_push(simcall->issuer);
284 * \ingroup simix_host_management
285 * \brief Returns how much of an execution action remains to be done.
287 * \param execution The execution action
288 * \return The remaining amount
290 double simcall_host_execution_get_remains(smx_action_t execution)
292 smx_simcall_t simcall = SIMIX_simcall_mine();
294 simcall->call = SIMCALL_HOST_EXECUTION_GET_REMAINS;
295 simcall->host_execution_get_remains.execution = execution;
296 SIMIX_simcall_push(simcall->issuer);
297 return simcall->host_execution_get_remains.result;
301 * \ingroup simix_host_management
302 * \brief Returns the state of an execution action.
304 * \param execution The execution action
307 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
309 smx_simcall_t simcall = SIMIX_simcall_mine();
311 simcall->call = SIMCALL_HOST_EXECUTION_GET_STATE;
312 simcall->host_execution_get_state.execution = execution;
313 SIMIX_simcall_push(simcall->issuer);
314 return simcall->host_execution_get_state.result;
318 * \ingroup simix_host_management
319 * \brief Changes the priority of an execution action.
321 * This functions changes the priority only. It calls a surf function.
322 * \param execution The execution action
323 * \param priority The new priority
325 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
327 /* checking for infinite values */
328 xbt_assert(isfinite(priority), "priority is not finite!");
330 smx_simcall_t simcall = SIMIX_simcall_mine();
332 simcall->call = SIMCALL_HOST_EXECUTION_SET_PRIORITY;
333 simcall->host_execution_set_priority.execution = execution;
334 simcall->host_execution_set_priority.priority = priority;
335 SIMIX_simcall_push(simcall->issuer);
339 * \ingroup simix_host_management
340 * \brief Waits for the completion of an execution action and destroy it.
342 * \param execution The execution action
344 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
346 smx_simcall_t simcall = SIMIX_simcall_mine();
348 simcall->call = SIMCALL_HOST_EXECUTION_WAIT;
349 simcall->host_execution_wait.execution = execution;
350 SIMIX_simcall_push(simcall->issuer);
351 return simcall->host_execution_wait.result;
355 * \ingroup simix_process_management
356 * \brief Creates and runs a new SIMIX process.
358 * The structure and the corresponding thread are created and put in the list of ready processes.
360 * \param process the process created will be stored in this pointer
361 * \param name a name for the process. It is for user-level information and can be NULL.
362 * \param code the main function of the process
363 * \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.
364 * It can be retrieved with the function \ref simcall_process_get_data.
365 * \param hostname name of the host where the new agent is executed.
366 * \param kill_time time when the process is killed
367 * \param argc first argument passed to \a code
368 * \param argv second argument passed to \a code
369 * \param properties the properties of the process
370 * \param auto_restart either it is autorestarting or not.
372 void simcall_process_create(smx_process_t *process, const char *name,
373 xbt_main_func_t code,
375 const char *hostname,
377 int argc, char **argv,
378 xbt_dict_t properties,
381 smx_simcall_t simcall = SIMIX_simcall_mine();
383 simcall->call = SIMCALL_PROCESS_CREATE;
384 simcall->process_create.process = process;
385 simcall->process_create.name = name;
386 simcall->process_create.code = code;
387 simcall->process_create.data = data;
388 simcall->process_create.hostname = hostname;
389 simcall->process_create.kill_time = kill_time;
390 simcall->process_create.argc = argc;
391 simcall->process_create.argv = argv;
392 simcall->process_create.properties = properties;
393 simcall->process_create.auto_restart = auto_restart;
394 SIMIX_simcall_push(simcall->issuer);
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 smx_simcall_t simcall = SIMIX_simcall_mine();
409 simcall->call = SIMCALL_PROCESS_KILL;
410 simcall->process_kill.process = process;
411 SIMIX_simcall_push(simcall->issuer);
415 * \ingroup simix_process_management
416 * \brief Kills all SIMIX processes.
418 void simcall_process_killall(void)
420 smx_simcall_t simcall = SIMIX_simcall_mine();
422 simcall->call = SIMCALL_PROCESS_KILLALL;
423 SIMIX_simcall_push(simcall->issuer);
427 * \ingroup simix_process_management
428 * \brief Cleans up a SIMIX process.
429 * \param process poor victim (must have already been killed)
431 void simcall_process_cleanup(smx_process_t process)
433 smx_simcall_t simcall = SIMIX_simcall_mine();
435 simcall->call = SIMCALL_PROCESS_CLEANUP;
436 simcall->process_cleanup.process = process;
437 SIMIX_simcall_push(simcall->issuer);
441 * \ingroup simix_process_management
442 * \brief Migrates an agent to another location.
444 * This function changes the value of the host on which \a process is running.
446 * \param process the process to migrate
447 * \param dest name of the new host
449 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
451 smx_simcall_t simcall = SIMIX_simcall_mine();
453 simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
454 simcall->process_change_host.process = process;
455 simcall->process_change_host.dest = dest;
456 SIMIX_simcall_push(simcall->issuer);
460 * \ingroup simix_process_management
461 * \brief Suspends a process.
463 * This function suspends the process by suspending the action
464 * it was waiting for completion.
466 * \param process a SIMIX process
468 void simcall_process_suspend(smx_process_t process)
470 xbt_assert(process, "Invalid parameters");
472 smx_simcall_t simcall = SIMIX_simcall_mine();
474 simcall->call = SIMCALL_PROCESS_SUSPEND;
475 simcall->process_suspend.process = process;
476 SIMIX_simcall_push(simcall->issuer);
480 * \ingroup simix_process_management
481 * \brief Resumes a suspended process.
483 * This function resumes a suspended process by resuming the action
484 * it was waiting for completion.
486 * \param process a SIMIX process
488 void simcall_process_resume(smx_process_t process)
490 smx_simcall_t simcall = SIMIX_simcall_mine();
492 simcall->call = SIMCALL_PROCESS_RESUME;
493 simcall->process_resume.process = process;
494 SIMIX_simcall_push(simcall->issuer);
498 * \ingroup simix_process_management
499 * \brief Returns the amount of SIMIX processes in the system
501 * Maestro internal process is not counted, only user code processes are
503 int simcall_process_count(void)
505 smx_simcall_t simcall = SIMIX_simcall_mine();
507 simcall->call = SIMCALL_PROCESS_COUNT;
508 SIMIX_simcall_push(simcall->issuer);
509 return simcall->process_count.result;
513 * \ingroup simix_process_management
514 * \brief Return the user data of a #smx_process_t.
515 * \param process a SIMIX process
516 * \return the user data of this process
518 void* simcall_process_get_data(smx_process_t process)
520 if (process == SIMIX_process_self()) {
521 /* avoid a simcall if this function is called by the process itself */
522 return SIMIX_process_get_data(process);
525 smx_simcall_t simcall = SIMIX_simcall_mine();
527 simcall->call = SIMCALL_PROCESS_GET_DATA;
528 simcall->process_get_data.process = process;
529 SIMIX_simcall_push(simcall->issuer);
530 return simcall->process_get_data.result;
534 * \ingroup simix_process_management
535 * \brief Set the user data of a #smx_process_t.
537 * This functions sets the user data associated to \a process.
538 * \param process SIMIX process
539 * \param data User data
541 void simcall_process_set_data(smx_process_t process, void *data)
543 if (process == SIMIX_process_self()) {
544 /* avoid a simcall if this function is called by the process itself */
545 SIMIX_process_self_set_data(process, data);
549 smx_simcall_t simcall = SIMIX_simcall_mine();
551 simcall->call = SIMCALL_PROCESS_SET_DATA;
552 simcall->process_set_data.process = process;
553 simcall->process_set_data.data = data;
554 SIMIX_simcall_push(simcall->issuer);
559 * \ingroup simix_process_management
560 * \brief Set the kill time of a process.
561 * \param process a process
562 * \param kill_time a double
564 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
567 if (kill_time > SIMIX_get_clock()) {
568 if (simix_global->kill_process_function) {
569 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
570 process->smx_host->name);
571 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
577 * \ingroup simix_process_management
578 * \brief Return the location on which an agent is running.
580 * This functions returns the smx_host_t corresponding to the location on which
581 * \a process is running.
582 * \param process SIMIX process
585 smx_host_t simcall_process_get_host(smx_process_t process)
587 smx_simcall_t simcall = SIMIX_simcall_mine();
589 simcall->call = SIMCALL_PROCESS_GET_HOST;
590 simcall->process_get_host.process = process;
591 SIMIX_simcall_push(simcall->issuer);
592 return simcall->process_get_host.result;
596 * \ingroup simix_process_management
597 * \brief Return the name of an agent.
599 * This functions checks whether \a process is a valid pointer or not and return its name.
600 * \param process SIMIX process
601 * \return The process name
603 const char* simcall_process_get_name(smx_process_t process)
605 if (process == SIMIX_process_self()) {
606 /* avoid a simcall if this function is called by the process itself */
607 return process->name;
610 smx_simcall_t simcall = SIMIX_simcall_mine();
612 simcall->call = SIMCALL_PROCESS_GET_NAME;
613 simcall->process_get_name.process = process;
614 SIMIX_simcall_push(simcall->issuer);
615 return simcall->process_get_name.result;
619 * \ingroup simix_process_management
620 * \brief Returns true if the process is suspended .
622 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
623 * \param process SIMIX process
624 * \return 1, if the process is suspended, else 0.
626 int simcall_process_is_suspended(smx_process_t process)
628 smx_simcall_t simcall = SIMIX_simcall_mine();
630 simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
631 simcall->process_is_suspended.process = process;
632 SIMIX_simcall_push(simcall->issuer);
633 return simcall->process_is_suspended.result;
637 * \ingroup simix_process_management
638 * \brief Return the properties
640 * This functions returns the properties associated with this process
642 xbt_dict_t simcall_process_get_properties(smx_process_t process)
644 smx_simcall_t simcall = SIMIX_simcall_mine();
646 simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
647 simcall->process_get_properties.process = process;
648 SIMIX_simcall_push(simcall->issuer);
649 return simcall->process_get_properties.result;
652 * \ingroup simix_process_management
653 * \brief Add an on_exit function
654 * Add an on_exit function which will be executed when the process exits/is killed.
656 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
658 smx_simcall_t simcall = SIMIX_simcall_mine();
660 simcall->call = SIMCALL_PROCESS_ON_EXIT;
661 simcall->process_on_exit.process = process;
662 simcall->process_on_exit.fun = fun;
663 simcall->process_on_exit.data = data;
665 SIMIX_simcall_push(simcall->issuer);
668 * \ingroup simix_process_management
669 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
670 * Will restart the process when the host comes back up if auto_restart is set to 1.
673 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
675 smx_simcall_t simcall = SIMIX_simcall_mine();
677 simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET;
678 simcall->process_auto_restart.process = process;
679 simcall->process_auto_restart.auto_restart = auto_restart;
681 SIMIX_simcall_push(simcall->issuer);
684 * \ingroup simix_process_management
685 * \brief Restarts the process, killing it and starting it again from scratch.
687 XBT_PUBLIC(void) simcall_process_restart(smx_process_t process)
689 smx_simcall_t simcall = SIMIX_simcall_mine();
691 simcall->call = SIMCALL_PROCESS_RESTART;
692 simcall->process_restart.process = process;
694 SIMIX_simcall_push(simcall->issuer);
697 * \ingroup simix_process_management
698 * \brief Creates a new sleep SIMIX action.
700 * This function creates a SURF action and allocates the data necessary
701 * to create the SIMIX action. It can raise a host_error exception if the
702 * host crashed. The default SIMIX name of the action is "sleep".
704 * \param duration Time duration of the sleep.
705 * \return A result telling whether the sleep was successful
707 e_smx_state_t simcall_process_sleep(double duration)
709 /* checking for infinite values */
710 xbt_assert(isfinite(duration), "duration is not finite!");
712 smx_simcall_t simcall = SIMIX_simcall_mine();
714 simcall->call = SIMCALL_PROCESS_SLEEP;
715 simcall->process_sleep.duration = duration;
716 SIMIX_simcall_push(simcall->issuer);
717 return simcall->process_sleep.result;
721 * \ingroup simix_rdv_management
722 * \brief Creates a new rendez-vous point
723 * \param name The name of the rendez-vous point
724 * \return The created rendez-vous point
726 smx_rdv_t simcall_rdv_create(const char *name)
728 smx_simcall_t simcall = SIMIX_simcall_mine();
730 simcall->call = SIMCALL_RDV_CREATE;
731 simcall->rdv_create.name = name;
733 SIMIX_simcall_push(simcall->issuer);
734 return simcall->rdv_create.result;
739 * \ingroup simix_rdv_management
740 * \brief Destroy a rendez-vous point
741 * \param rdv The rendez-vous point to destroy
743 void simcall_rdv_destroy(smx_rdv_t rdv)
745 smx_simcall_t simcall = SIMIX_simcall_mine();
747 simcall->call = SIMCALL_RDV_DESTROY;
748 simcall->rdv_destroy.rdv = rdv;
750 SIMIX_simcall_push(simcall->issuer);
753 * \ingroup simix_rdv_management
754 * \brief Returns a rendez-vous point knowing its name
756 smx_rdv_t simcall_rdv_get_by_name(const char *name)
758 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
760 /* FIXME: this is a horrible lost of performance, so we hack it out by
761 * skipping the simcall (for now). It works in parallel, it won't work on
762 * distributed but probably we will change MSG for that. */
765 smx_simcall_t simcall = simcall_mine();
766 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
767 simcall->rdv_get_by_name.name = name;
768 SIMIX_simcall_push(simcall->issuer);
769 return simcall->rdv_get_by_name.result;*/
771 return SIMIX_rdv_get_by_name(name);
775 * \ingroup simix_rdv_management
776 * \brief Counts the number of communication actions of a given host pending
777 * on a rendez-vous point.
778 * \param rdv The rendez-vous point
779 * \param host The host to be counted
780 * \return The number of comm actions pending in the rdv
782 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
784 smx_simcall_t simcall = SIMIX_simcall_mine();
786 simcall->call = SIMCALL_RDV_COMM_COUNT_BY_HOST;
787 simcall->rdv_comm_count_by_host.rdv = rdv;
788 simcall->rdv_comm_count_by_host.host = host;
790 SIMIX_simcall_push(simcall->issuer);
791 return simcall->rdv_comm_count_by_host.result;
795 * \ingroup simix_rdv_management
796 * \brief returns the communication at the head of the rendez-vous
797 * \param rdv The rendez-vous point
798 * \return The communication or NULL if empty
800 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
802 smx_simcall_t simcall = SIMIX_simcall_mine();
804 simcall->call = SIMCALL_RDV_GET_HEAD;
805 simcall->rdv_get_head.rdv = rdv;
807 SIMIX_simcall_push(simcall->issuer);
808 return simcall->rdv_get_head.result;
811 * \ingroup simix_comm_management
813 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
814 void *src_buff, size_t src_buff_size,
815 int (*match_fun)(void *, void *, smx_action_t), void *data,
818 /* checking for infinite values */
819 xbt_assert(isfinite(task_size), "task_size is not finite!");
820 xbt_assert(isfinite(rate), "rate is not finite!");
821 xbt_assert(isfinite(timeout), "timeout is not finite!");
823 xbt_assert(rdv, "No rendez-vous point defined for send");
826 /* the model-checker wants two separate simcalls */
827 smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
828 src_buff, src_buff_size, match_fun, NULL, data, 0);
829 simcall_comm_wait(comm, timeout);
832 smx_simcall_t simcall = SIMIX_simcall_mine();
834 simcall->call = SIMCALL_COMM_SEND;
835 simcall->comm_send.rdv = rdv;
836 simcall->comm_send.task_size = task_size;
837 simcall->comm_send.rate = rate;
838 simcall->comm_send.src_buff = src_buff;
839 simcall->comm_send.src_buff_size = src_buff_size;
840 simcall->comm_send.match_fun = match_fun;
841 simcall->comm_send.data = data;
842 simcall->comm_send.timeout = timeout;
844 SIMIX_simcall_push(simcall->issuer);
848 * \ingroup simix_comm_management
850 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
851 void *src_buff, size_t src_buff_size,
852 int (*match_fun)(void *, void *, smx_action_t),
853 void (*clean_fun)(void *),
857 /* checking for infinite values */
858 xbt_assert(isfinite(task_size), "task_size is not finite!");
859 xbt_assert(isfinite(rate), "rate is not finite!");
861 xbt_assert(rdv, "No rendez-vous point defined for isend");
863 smx_simcall_t simcall = SIMIX_simcall_mine();
865 simcall->call = SIMCALL_COMM_ISEND;
866 simcall->comm_isend.rdv = rdv;
867 simcall->comm_isend.task_size = task_size;
868 simcall->comm_isend.rate = rate;
869 simcall->comm_isend.src_buff = src_buff;
870 simcall->comm_isend.src_buff_size = src_buff_size;
871 simcall->comm_isend.match_fun = match_fun;
872 simcall->comm_isend.clean_fun = clean_fun;
873 simcall->comm_isend.data = data;
874 simcall->comm_isend.detached = detached;
876 SIMIX_simcall_push(simcall->issuer);
877 return simcall->comm_isend.result;
880 * \ingroup simix_comm_management
882 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
883 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
885 xbt_assert(isfinite(timeout), "timeout is not finite!");
886 xbt_assert(rdv, "No rendez-vous point defined for recv");
889 /* the model-checker wants two separate simcalls */
890 smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
892 simcall_comm_wait(comm, timeout);
895 smx_simcall_t simcall = SIMIX_simcall_mine();
897 simcall->call = SIMCALL_COMM_RECV;
898 simcall->comm_recv.rdv = rdv;
899 simcall->comm_recv.dst_buff = dst_buff;
900 simcall->comm_recv.dst_buff_size = dst_buff_size;
901 simcall->comm_recv.match_fun = match_fun;
902 simcall->comm_recv.data = data;
903 simcall->comm_recv.timeout = timeout;
905 SIMIX_simcall_push(simcall->issuer);
909 * \ingroup simix_comm_management
911 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
912 int (*match_fun)(void *, void *, smx_action_t), void *data)
914 xbt_assert(rdv, "No rendez-vous point defined for irecv");
916 smx_simcall_t simcall = SIMIX_simcall_mine();
918 simcall->call = SIMCALL_COMM_IRECV;
919 simcall->comm_irecv.rdv = rdv;
920 simcall->comm_irecv.dst_buff = dst_buff;
921 simcall->comm_irecv.dst_buff_size = dst_buff_size;
922 simcall->comm_irecv.match_fun = match_fun;
923 simcall->comm_irecv.data = data;
925 SIMIX_simcall_push(simcall->issuer);
926 return simcall->comm_irecv.result;
928 void simcall_comm_destroy(smx_action_t comm)
930 xbt_assert(comm, "Invalid parameter");
932 /* FIXME remove this simcall type: comms are auto-destroyed now */
935 smx_simcall_t simcall = simcall_mine();
937 simcall->call = SIMCALL_COMM_DESTROY;
938 simcall->comm_destroy.comm = comm;
940 SIMIX_simcall_push(simcall->issuer);
944 * \ingroup simix_comm_management
946 void simcall_comm_cancel(smx_action_t comm)
948 smx_simcall_t simcall = SIMIX_simcall_mine();
950 simcall->call = SIMCALL_COMM_CANCEL;
951 simcall->comm_cancel.comm = comm;
953 SIMIX_simcall_push(simcall->issuer);
956 * \ingroup simix_comm_management
958 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
960 smx_simcall_t simcall = SIMIX_simcall_mine();
962 simcall->call = SIMCALL_COMM_WAITANY;
963 simcall->comm_waitany.comms = comms;
965 SIMIX_simcall_push(simcall->issuer);
966 return simcall->comm_waitany.result;
969 * \ingroup simix_comm_management
971 int simcall_comm_testany(xbt_dynar_t comms)
973 smx_simcall_t simcall = SIMIX_simcall_mine();
974 if (xbt_dynar_is_empty(comms))
977 simcall->call = SIMCALL_COMM_TESTANY;
978 simcall->comm_testany.comms = comms;
980 SIMIX_simcall_push(simcall->issuer);
981 return simcall->comm_testany.result;
984 * \ingroup simix_comm_management
986 void simcall_comm_wait(smx_action_t comm, double timeout)
988 xbt_assert(isfinite(timeout), "timeout is not finite!");
990 smx_simcall_t simcall = SIMIX_simcall_mine();
992 simcall->call = SIMCALL_COMM_WAIT;
993 simcall->comm_wait.comm = comm;
994 simcall->comm_wait.timeout = timeout;
996 SIMIX_simcall_push(simcall->issuer);
1001 * \brief Set the category of an action.
1003 * This functions changes the category only. It calls a surf function.
1004 * \param execution The execution action
1005 * \param category The tracing category
1007 void simcall_set_category(smx_action_t action, const char *category)
1009 if (category == NULL) {
1013 smx_simcall_t simcall = SIMIX_simcall_mine();
1015 simcall->call = SIMCALL_SET_CATEGORY;
1016 simcall->set_category.action = action;
1017 simcall->set_category.category = category;
1019 SIMIX_simcall_push(simcall->issuer);
1023 * \ingroup simix_comm_management
1026 int simcall_comm_test(smx_action_t comm)
1028 smx_simcall_t simcall = SIMIX_simcall_mine();
1030 simcall->call = SIMCALL_COMM_TEST;
1031 simcall->comm_test.comm = comm;
1033 SIMIX_simcall_push(simcall->issuer);
1034 return simcall->comm_test.result;
1037 * \ingroup simix_comm_management
1040 double simcall_comm_get_remains(smx_action_t comm)
1042 smx_simcall_t simcall = SIMIX_simcall_mine();
1044 simcall->call = SIMCALL_COMM_GET_REMAINS;
1045 simcall->comm_get_remains.comm = comm;
1047 SIMIX_simcall_push(simcall->issuer);
1048 return simcall->comm_get_remains.result;
1051 * \ingroup simix_comm_management
1054 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1056 smx_simcall_t simcall = SIMIX_simcall_mine();
1058 simcall->call = SIMCALL_COMM_GET_STATE;
1059 simcall->comm_get_state.comm = comm;
1061 SIMIX_simcall_push(simcall->issuer);
1062 return simcall->comm_get_state.result;
1065 * \ingroup simix_comm_management
1068 void *simcall_comm_get_src_data(smx_action_t comm)
1070 smx_simcall_t simcall = SIMIX_simcall_mine();
1072 simcall->call = SIMCALL_COMM_GET_SRC_DATA;
1073 simcall->comm_get_src_data.comm = comm;
1075 SIMIX_simcall_push(simcall->issuer);
1076 return simcall->comm_get_src_data.result;
1079 * \ingroup simix_comm_management
1082 void *simcall_comm_get_dst_data(smx_action_t comm)
1084 smx_simcall_t simcall = SIMIX_simcall_mine();
1086 simcall->call = SIMCALL_COMM_GET_DST_DATA;
1087 simcall->comm_get_dst_data.comm = comm;
1089 SIMIX_simcall_push(simcall->issuer);
1090 return simcall->comm_get_dst_data.result;
1093 * \ingroup simix_comm_management
1096 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1098 smx_simcall_t simcall = SIMIX_simcall_mine();
1100 simcall->call = SIMCALL_COMM_GET_SRC_PROC;
1101 simcall->comm_get_src_proc.comm = comm;
1103 SIMIX_simcall_push(simcall->issuer);
1104 return simcall->comm_get_src_proc.result;
1107 * \ingroup simix_comm_management
1110 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1112 smx_simcall_t simcall = SIMIX_simcall_mine();
1114 simcall->call = SIMCALL_COMM_GET_DST_PROC;
1115 simcall->comm_get_dst_proc.comm = comm;
1117 SIMIX_simcall_push(simcall->issuer);
1118 return simcall->comm_get_dst_proc.result;
1121 #ifdef HAVE_LATENCY_BOUND_TRACKING
1122 int simcall_comm_is_latency_bounded(smx_action_t comm)
1124 smx_simcall_t simcall = SIMIX_simcall_mine();
1126 simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
1127 simcall->comm_is_latency_bounded.comm = comm;
1129 SIMIX_simcall_push(simcall->issuer);
1130 return simcall->comm_is_latency_bounded.result;
1134 * \ingroup simix_synchro_management
1137 smx_mutex_t simcall_mutex_init(void)
1140 fprintf(stderr,"You must run MSG_init or gras_init before using MSG or GRAS\n"); // I would have loved using xbt_die but I can't since it is not initialized yet... :)
1143 smx_simcall_t simcall = SIMIX_simcall_mine();
1145 simcall->call = SIMCALL_MUTEX_INIT;
1147 SIMIX_simcall_push(simcall->issuer);
1148 return simcall->mutex_init.result;
1151 * \ingroup simix_synchro_management
1154 void simcall_mutex_destroy(smx_mutex_t mutex)
1156 smx_simcall_t simcall = SIMIX_simcall_mine();
1158 simcall->call = SIMCALL_MUTEX_DESTROY;
1159 simcall->mutex_destroy.mutex = mutex;
1161 SIMIX_simcall_push(simcall->issuer);
1164 * \ingroup simix_synchro_management
1167 void simcall_mutex_lock(smx_mutex_t mutex)
1169 smx_simcall_t simcall = SIMIX_simcall_mine();
1171 simcall->call = SIMCALL_MUTEX_LOCK;
1172 simcall->mutex_lock.mutex = mutex;
1174 SIMIX_simcall_push(simcall->issuer);
1177 * \ingroup simix_synchro_management
1180 int simcall_mutex_trylock(smx_mutex_t mutex)
1182 smx_simcall_t simcall = SIMIX_simcall_mine();
1184 simcall->call = SIMCALL_MUTEX_TRYLOCK;
1185 simcall->mutex_trylock.mutex = mutex;
1187 SIMIX_simcall_push(simcall->issuer);
1188 return simcall->mutex_trylock.result;
1191 * \ingroup simix_synchro_management
1194 void simcall_mutex_unlock(smx_mutex_t mutex)
1196 smx_simcall_t simcall = SIMIX_simcall_mine();
1198 simcall->call = SIMCALL_MUTEX_UNLOCK;
1199 simcall->mutex_unlock.mutex = mutex;
1201 SIMIX_simcall_push(simcall->issuer);
1204 * \ingroup simix_synchro_management
1207 smx_cond_t simcall_cond_init(void)
1209 smx_simcall_t simcall = SIMIX_simcall_mine();
1211 simcall->call = SIMCALL_COND_INIT;
1213 SIMIX_simcall_push(simcall->issuer);
1214 return simcall->cond_init.result;
1217 * \ingroup simix_synchro_management
1220 void simcall_cond_destroy(smx_cond_t cond)
1222 smx_simcall_t simcall = SIMIX_simcall_mine();
1224 simcall->call = SIMCALL_COND_DESTROY;
1225 simcall->cond_destroy.cond = cond;
1227 SIMIX_simcall_push(simcall->issuer);
1230 * \ingroup simix_synchro_management
1233 void simcall_cond_signal(smx_cond_t cond)
1235 smx_simcall_t simcall = SIMIX_simcall_mine();
1237 simcall->call = SIMCALL_COND_SIGNAL;
1238 simcall->cond_signal.cond = cond;
1240 SIMIX_simcall_push(simcall->issuer);
1243 * \ingroup simix_synchro_management
1246 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1248 smx_simcall_t simcall = SIMIX_simcall_mine();
1250 simcall->call = SIMCALL_COND_WAIT;
1251 simcall->cond_wait.cond = cond;
1252 simcall->cond_wait.mutex = mutex;
1254 SIMIX_simcall_push(simcall->issuer);
1257 * \ingroup simix_synchro_management
1260 void simcall_cond_wait_timeout(smx_cond_t cond,
1264 xbt_assert(isfinite(timeout), "timeout is not finite!");
1266 smx_simcall_t simcall = SIMIX_simcall_mine();
1268 simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1269 simcall->cond_wait_timeout.cond = cond;
1270 simcall->cond_wait_timeout.mutex = mutex;
1271 simcall->cond_wait_timeout.timeout = timeout;
1273 SIMIX_simcall_push(simcall->issuer);
1276 * \ingroup simix_synchro_management
1279 void simcall_cond_broadcast(smx_cond_t cond)
1281 smx_simcall_t simcall = SIMIX_simcall_mine();
1283 simcall->call = SIMCALL_COND_BROADCAST;
1284 simcall->cond_broadcast.cond = cond;
1286 SIMIX_simcall_push(simcall->issuer);
1289 * \ingroup simix_synchro_management
1292 smx_sem_t simcall_sem_init(int capacity)
1294 smx_simcall_t simcall = SIMIX_simcall_mine();
1296 simcall->call = SIMCALL_SEM_INIT;
1297 simcall->sem_init.capacity = capacity;
1299 SIMIX_simcall_push(simcall->issuer);
1300 return simcall->sem_init.result;
1303 * \ingroup simix_synchro_management
1306 void simcall_sem_destroy(smx_sem_t sem)
1308 smx_simcall_t simcall = SIMIX_simcall_mine();
1310 simcall->call = SIMCALL_SEM_DESTROY;
1311 simcall->sem_destroy.sem = sem;
1313 SIMIX_simcall_push(simcall->issuer);
1316 * \ingroup simix_synchro_management
1319 void simcall_sem_release(smx_sem_t sem)
1321 smx_simcall_t simcall = SIMIX_simcall_mine();
1323 simcall->call = SIMCALL_SEM_RELEASE;
1324 simcall->sem_release.sem = sem;
1326 SIMIX_simcall_push(simcall->issuer);
1329 * \ingroup simix_synchro_management
1332 int simcall_sem_would_block(smx_sem_t sem)
1334 smx_simcall_t simcall = SIMIX_simcall_mine();
1336 simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1337 simcall->sem_would_block.sem = sem;
1339 SIMIX_simcall_push(simcall->issuer);
1340 return simcall->sem_would_block.result;
1343 * \ingroup simix_synchro_management
1346 void simcall_sem_acquire(smx_sem_t sem)
1348 smx_simcall_t simcall = SIMIX_simcall_mine();
1350 simcall->call = SIMCALL_SEM_ACQUIRE;
1351 simcall->sem_acquire.sem = sem;
1353 SIMIX_simcall_push(simcall->issuer);
1356 * \ingroup simix_synchro_management
1359 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1361 xbt_assert(isfinite(timeout), "timeout is not finite!");
1363 smx_simcall_t simcall = SIMIX_simcall_mine();
1365 simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1366 simcall->sem_acquire_timeout.sem = sem;
1367 simcall->sem_acquire_timeout.timeout = timeout;
1369 SIMIX_simcall_push(simcall->issuer);
1372 * \ingroup simix_synchro_management
1375 int simcall_sem_get_capacity(smx_sem_t sem)
1377 smx_simcall_t simcall = SIMIX_simcall_mine();
1379 simcall->call = SIMCALL_SEM_GET_CAPACITY;
1380 simcall->sem_get_capacity.sem = sem;
1382 SIMIX_simcall_push(simcall->issuer);
1383 return simcall->sem_get_capacity.result;
1386 * \ingroup simix_file_management
1389 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1391 smx_simcall_t simcall = SIMIX_simcall_mine();
1393 simcall->call = SIMCALL_FILE_READ;
1394 simcall->file_read.ptr = ptr;
1395 simcall->file_read.size = size;
1396 simcall->file_read.nmemb = nmemb;
1397 simcall->file_read.stream = stream;
1398 SIMIX_simcall_push(simcall->issuer);
1400 return simcall->file_read.result;
1403 * \ingroup simix_file_management
1406 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1408 smx_simcall_t simcall = SIMIX_simcall_mine();
1410 simcall->call = SIMCALL_FILE_WRITE;
1411 simcall->file_write.ptr = ptr;
1412 simcall->file_write.size = size;
1413 simcall->file_write.nmemb = nmemb;
1414 simcall->file_write.stream = stream;
1415 SIMIX_simcall_push(simcall->issuer);
1417 return simcall->file_write.result;
1420 * \ingroup simix_file_management
1423 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1425 smx_simcall_t simcall = SIMIX_simcall_mine();
1427 simcall->call = SIMCALL_FILE_OPEN;
1428 simcall->file_open.mount = mount;
1429 simcall->file_open.path = path;
1430 simcall->file_open.mode = mode;
1431 SIMIX_simcall_push(simcall->issuer);
1433 return simcall->file_open.result;
1436 * \ingroup simix_file_management
1439 int simcall_file_close(smx_file_t fp)
1441 smx_simcall_t simcall = SIMIX_simcall_mine();
1443 simcall->call = SIMCALL_FILE_CLOSE;
1444 simcall->file_close.fp = fp;
1445 SIMIX_simcall_push(simcall->issuer);
1447 return simcall->file_close.result;
1450 * \ingroup simix_file_management
1453 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1455 smx_simcall_t simcall = SIMIX_simcall_mine();
1456 simcall->call = SIMCALL_FILE_STAT;
1457 simcall->file_stat.fd = fd;
1459 SIMIX_simcall_push(simcall->issuer);
1461 *buf = simcall->file_stat.buf;
1463 return simcall->file_stat.result;
1466 /* ************************************************************************** */
1468 /** @brief returns a printable string representing a simcall */
1469 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1470 return simcall_names[kind];