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() */
22 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
24 static const char* request_names[] = {
25 #undef SIMIX_REQ_ENUM_ELEMENT
26 #define SIMIX_REQ_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
28 #undef SIMIX_REQ_ENUM_ELEMENT
32 * \brief Returns a host given its name.
34 * \param name The name of the host to get
35 * \return The corresponding host
37 smx_host_t SIMIX_req_host_get_by_name(const char *name)
39 smx_req_t req = SIMIX_req_mine();
41 req->call = REQ_HOST_GET_BY_NAME;
42 req->host_get_by_name.name = name;
43 SIMIX_request_push(req->issuer);
44 return req->host_get_by_name.result;
48 * \brief Returns the name of a host.
50 * \param host A SIMIX host
51 * \return The name of this host
53 const char* SIMIX_req_host_get_name(smx_host_t host)
55 smx_req_t req = SIMIX_req_mine();
57 req->call = REQ_HOST_GET_NAME;
58 req->host_get_name.host = host;
59 SIMIX_request_push(req->issuer);
60 return req->host_get_name.result;
64 * \brief Returns a dict of the properties assigned to a host.
67 * \return The properties of this host
69 xbt_dict_t SIMIX_req_host_get_properties(smx_host_t host)
71 smx_req_t req = SIMIX_req_mine();
73 req->call = REQ_HOST_GET_PROPERTIES;
74 req->host_get_properties.host = host;
75 SIMIX_request_push(req->issuer);
76 return req->host_get_properties.result;
80 * \brief Returns the speed of the processor.
82 * The speed returned does not take into account the current load on the machine.
83 * \param host A SIMIX host
84 * \return The speed of this host (in Mflop/s)
86 double SIMIX_req_host_get_speed(smx_host_t host)
88 smx_req_t req = SIMIX_req_mine();
90 req->call = REQ_HOST_GET_SPEED;
91 req->host_get_speed.host = host;
92 SIMIX_request_push(req->issuer);
93 return req->host_get_speed.result;
97 * \brief Returns the available speed of the processor.
99 * \return Speed currently available (in Mflop/s)
101 double SIMIX_req_host_get_available_speed(smx_host_t host)
103 smx_req_t req = SIMIX_req_mine();
105 req->call = REQ_HOST_GET_AVAILABLE_SPEED;
106 req->host_get_available_speed.host = host;
107 SIMIX_request_push(req->issuer);
108 return req->host_get_available_speed.result;
112 * \brief Returns the state of a host.
114 * Two states are possible: 1 if the host is active or 0 if it has crashed.
115 * \param host A SIMIX host
116 * \return 1 if the host is available, 0 otherwise
118 int SIMIX_req_host_get_state(smx_host_t host)
120 smx_req_t req = SIMIX_req_mine();
122 req->call = REQ_HOST_GET_STATE;
123 req->host_get_state.host = host;
124 SIMIX_request_push(req->issuer);
125 return req->host_get_state.result;
129 * \brief Returns the user data associated to a host.
131 * \param host SIMIX host
132 * \return the user data of this host
134 void* SIMIX_req_host_get_data(smx_host_t host)
136 smx_req_t req = SIMIX_req_mine();
138 req->call = REQ_HOST_GET_DATA;
139 req->host_get_data.host = host;
140 SIMIX_request_push(req->issuer);
141 return req->host_get_data.result;
145 * \brief Sets the user data associated to a host.
147 * The host must not have previous user data associated to it.
148 * \param A host SIMIX host
149 * \param data The user data to set
151 void SIMIX_req_host_set_data(smx_host_t host, void *data)
153 smx_req_t req = SIMIX_req_mine();
155 req->call = REQ_HOST_SET_DATA;
156 req->host_set_data.host = host;
157 req->host_set_data.data = data;
158 SIMIX_request_push(req->issuer);
161 /** \brief Creates an action that executes some computation of an host.
163 * This function creates a SURF action and allocates the data necessary
164 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
166 * \param name Name of the execution action to create
167 * \param host SIMIX host where the action will be executed
168 * \param amount Computation amount (in bytes)
169 * \return A new SIMIX execution action
171 smx_action_t SIMIX_req_host_execute(const char *name, smx_host_t host,
172 double computation_amount,
175 /* checking for infinite values */
176 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
177 xbt_assert(isfinite(priority), "priority is not finite!");
179 smx_req_t req = SIMIX_req_mine();
181 req->call = REQ_HOST_EXECUTE;
182 req->host_execute.name = name;
183 req->host_execute.host = host;
184 req->host_execute.computation_amount = computation_amount;
185 req->host_execute.priority = priority;
186 SIMIX_request_push(req->issuer);
187 return req->host_execute.result;
190 /** \brief Creates an action that may involve parallel computation on
191 * several hosts and communication between them.
193 * \param name Name of the execution action to create
194 * \param host_nb Number of hosts where the action will be executed
195 * \param host_list Array (of size host_nb) of hosts where the action will be executed
196 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
197 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
198 * amount between each pair of hosts
199 * \param amount the SURF action amount
200 * \param rate the SURF action rate
201 * \return A new SIMIX execution action
203 smx_action_t SIMIX_req_host_parallel_execute(const char *name,
205 smx_host_t *host_list,
206 double *computation_amount,
207 double *communication_amount,
212 /* checking for infinite values */
213 for (i = 0 ; i < host_nb ; ++i) {
214 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
215 for (j = 0 ; j < host_nb ; ++j) {
216 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
217 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
221 xbt_assert(isfinite(amount), "amount is not finite!");
222 xbt_assert(isfinite(rate), "rate is not finite!");
224 smx_req_t req = SIMIX_req_mine();
226 req->call = REQ_HOST_PARALLEL_EXECUTE;
227 req->host_parallel_execute.name = name;
228 req->host_parallel_execute.host_nb = host_nb;
229 req->host_parallel_execute.host_list = host_list;
230 req->host_parallel_execute.computation_amount = computation_amount;
231 req->host_parallel_execute.communication_amount = communication_amount;
232 req->host_parallel_execute.amount = amount;
233 req->host_parallel_execute.rate = rate;
234 SIMIX_request_push(req->issuer);
235 return req->host_parallel_execute.result;
239 * \brief Destroys an execution action.
241 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
242 * \param action The execution action to destroy
244 void SIMIX_req_host_execution_destroy(smx_action_t execution)
246 smx_req_t req = SIMIX_req_mine();
248 req->call = REQ_HOST_EXECUTION_DESTROY;
249 req->host_execution_destroy.execution = execution;
250 SIMIX_request_push(req->issuer);
254 * \brief Cancels an execution action.
256 * This functions stops the execution. It calls a surf function.
257 * \param action The execution action to cancel
259 void SIMIX_req_host_execution_cancel(smx_action_t execution)
261 smx_req_t req = SIMIX_req_mine();
263 req->call = REQ_HOST_EXECUTION_CANCEL;
264 req->host_execution_cancel.execution = execution;
265 SIMIX_request_push(req->issuer);
269 * \brief Returns how much of an execution action remains to be done.
271 * \param Action The execution action
272 * \return The remaining amount
274 double SIMIX_req_host_execution_get_remains(smx_action_t execution)
276 smx_req_t req = SIMIX_req_mine();
278 req->call = REQ_HOST_EXECUTION_GET_REMAINS;
279 req->host_execution_get_remains.execution = execution;
280 SIMIX_request_push(req->issuer);
281 return req->host_execution_get_remains.result;
285 * \brief Returns the state of an execution action.
287 * \param execution The execution action
290 e_smx_state_t SIMIX_req_host_execution_get_state(smx_action_t execution)
292 smx_req_t req = SIMIX_req_mine();
294 req->call = REQ_HOST_EXECUTION_GET_STATE;
295 req->host_execution_get_state.execution = execution;
296 SIMIX_request_push(req->issuer);
297 return req->host_execution_get_state.result;
301 * \brief Changes the priority of an execution action.
303 * This functions changes the priority only. It calls a surf function.
304 * \param execution The execution action
305 * \param priority The new priority
307 void SIMIX_req_host_execution_set_priority(smx_action_t execution, double priority)
309 /* checking for infinite values */
310 xbt_assert(isfinite(priority), "priority is not finite!");
312 smx_req_t req = SIMIX_req_mine();
314 req->call = REQ_HOST_EXECUTION_SET_PRIORITY;
315 req->host_execution_set_priority.execution = execution;
316 req->host_execution_set_priority.priority = priority;
317 SIMIX_request_push(req->issuer);
321 * \brief Waits for the completion of an execution action and destroy it.
323 * \param execution The execution action
325 e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution)
327 smx_req_t req = SIMIX_req_mine();
329 req->call = REQ_HOST_EXECUTION_WAIT;
330 req->host_execution_wait.execution = execution;
331 SIMIX_request_push(req->issuer);
332 return req->host_execution_wait.result;
336 * \brief Creates and runs a new SIMIX process.
338 * The structure and the corresponding thread are created and put in the list of ready processes.
340 * \param process the process created will be stored in this pointer
341 * \param name a name for the process. It is for user-level information and can be NULL.
342 * \param code the main function of the process
343 * \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.
344 * It can be retrieved with the function \ref SIMIX_req_process_get_data.
345 * \param hostname name of the host where the new agent is executed.
346 * \param argc first argument passed to \a code
347 * \param argv second argument passed to \a code
348 * \param properties the properties of the process
350 void SIMIX_req_process_create(smx_process_t *process, const char *name,
351 xbt_main_func_t code,
353 const char *hostname,
354 int argc, char **argv,
355 xbt_dict_t properties)
357 smx_req_t req = SIMIX_req_mine();
359 req->call = REQ_PROCESS_CREATE;
360 req->process_create.process = process;
361 req->process_create.name = name;
362 req->process_create.code = code;
363 req->process_create.data = data;
364 req->process_create.hostname = hostname;
365 req->process_create.argc = argc;
366 req->process_create.argv = argv;
367 req->process_create.properties = properties;
368 SIMIX_request_push(req->issuer);
371 /** \brief Kills a SIMIX process.
373 * This function simply kills a process.
375 * \param process poor victim
377 void SIMIX_req_process_kill(smx_process_t process)
379 smx_req_t req = SIMIX_req_mine();
381 req->call = REQ_PROCESS_KILL;
382 req->process_kill.process = process;
383 SIMIX_request_push(req->issuer);
386 /** \brief Kills all SIMIX processes.
388 void SIMIX_req_process_killall(void)
390 smx_req_t req = SIMIX_req_mine();
392 req->call = REQ_PROCESS_KILLALL;
393 SIMIX_request_push(req->issuer);
396 /** \brief Cleans up a SIMIX process.
397 * \param process poor victim (must have already been killed)
399 void SIMIX_req_process_cleanup(smx_process_t process)
401 smx_req_t req = SIMIX_req_mine();
403 req->call = REQ_PROCESS_CLEANUP;
404 req->process_cleanup.process = process;
405 SIMIX_request_push(req->issuer);
409 * \brief Migrates an agent to another location.
411 * This function changes the value of the host on which \a process is running.
413 * \param process the process to migrate
414 * \param source name of the previous host
415 * \param dest name of the new host
417 void SIMIX_req_process_change_host(smx_process_t process, smx_host_t dest)
419 smx_req_t req = SIMIX_req_mine();
421 req->call = REQ_PROCESS_CHANGE_HOST;
422 req->process_change_host.process = process;
423 req->process_change_host.dest = dest;
424 SIMIX_request_push(req->issuer);
428 * \brief Suspends a process.
430 * This function suspends the process by suspending the action
431 * it was waiting for completion.
433 * \param process a SIMIX process
435 void SIMIX_req_process_suspend(smx_process_t process)
437 xbt_assert(process, "Invalid parameters");
439 smx_req_t req = SIMIX_req_mine();
441 req->call = REQ_PROCESS_SUSPEND;
442 req->process_suspend.process = process;
443 SIMIX_request_push(req->issuer);
447 * \brief Resumes a suspended process.
449 * This function resumes a suspended process by resuming the action
450 * it was waiting for completion.
452 * \param process a SIMIX process
454 void SIMIX_req_process_resume(smx_process_t process)
456 smx_req_t req = SIMIX_req_mine();
458 req->call = REQ_PROCESS_RESUME;
459 req->process_resume.process = process;
460 SIMIX_request_push(req->issuer);
464 * \brief Returns the amount of SIMIX processes in the system
466 * Maestro internal process is not counted, only user code processes are
468 int SIMIX_req_process_count(void)
470 smx_req_t req = SIMIX_req_mine();
472 req->call = REQ_PROCESS_COUNT;
473 SIMIX_request_push(req->issuer);
474 return req->process_count.result;
478 * \brief Return the user data of a #smx_process_t.
479 * \param process a SIMIX process
480 * \return the user data of this process
482 void* SIMIX_req_process_get_data(smx_process_t process)
484 if (process == SIMIX_process_self()) {
485 /* avoid a request if this function is called by the process itself */
486 return SIMIX_process_get_data(process);
489 smx_req_t req = SIMIX_req_mine();
491 req->call = REQ_PROCESS_GET_DATA;
492 req->process_get_data.process = process;
493 SIMIX_request_push(req->issuer);
494 return req->process_get_data.result;
498 * \brief Set the user data of a #m_process_t.
500 * This functions checks whether \a process is a valid pointer or not and set the user data associated to \a process if it is possible.
501 * \param process SIMIX process
502 * \param data User data
504 void SIMIX_req_process_set_data(smx_process_t process, void *data)
506 if (process == SIMIX_process_self()) {
507 /* avoid a request if this function is called by the process itself */
508 SIMIX_process_self_set_data(process, data);
512 smx_req_t req = SIMIX_req_mine();
514 req->call = REQ_PROCESS_SET_DATA;
515 req->process_set_data.process = process;
516 req->process_set_data.data = data;
517 SIMIX_request_push(req->issuer);
522 * \brief Return the location on which an agent is running.
524 * This functions checks whether \a process is a valid pointer or not and return the m_host_t corresponding to the location on which \a process is running.
525 * \param process SIMIX process
528 smx_host_t SIMIX_req_process_get_host(smx_process_t process)
530 smx_req_t req = SIMIX_req_mine();
532 req->call = REQ_PROCESS_GET_HOST;
533 req->process_get_host.process = process;
534 SIMIX_request_push(req->issuer);
535 return req->process_get_host.result;
539 * \brief Return the name of an agent.
541 * This functions checks whether \a process is a valid pointer or not and return its name.
542 * \param process SIMIX process
543 * \return The process name
545 const char* SIMIX_req_process_get_name(smx_process_t process)
547 if (process == SIMIX_process_self()) {
548 /* avoid a request if this function is called by the process itself */
549 return process->name;
552 smx_req_t req = SIMIX_req_mine();
554 req->call = REQ_PROCESS_GET_NAME;
555 req->process_get_name.process = process;
556 SIMIX_request_push(req->issuer);
557 return req->process_get_name.result;
561 * \brief Returns true if the process is suspended .
563 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
564 * \param process SIMIX process
565 * \return 1, if the process is suspended, else 0.
567 int SIMIX_req_process_is_suspended(smx_process_t process)
569 smx_req_t req = SIMIX_req_mine();
571 req->call = REQ_PROCESS_IS_SUSPENDED;
572 req->process_is_suspended.process = process;
573 SIMIX_request_push(req->issuer);
574 return req->process_is_suspended.result;
577 /** \ingroup m_process_management
578 * \brief Return the properties
580 * This functions returns the properties associated with this process
582 xbt_dict_t SIMIX_req_process_get_properties(smx_process_t process)
584 smx_req_t req = SIMIX_req_mine();
586 req->call = REQ_PROCESS_GET_PROPERTIES;
587 req->process_get_properties.process = process;
588 SIMIX_request_push(req->issuer);
589 return req->process_get_properties.result;
592 /** \brief Creates a new sleep SIMIX action.
594 * This function creates a SURF action and allocates the data necessary
595 * to create the SIMIX action. It can raise a host_error exception if the
596 * host crashed. The default SIMIX name of the action is "sleep".
598 * \param duration Time duration of the sleep.
599 * \return A result telling whether the sleep was successful
601 e_smx_state_t SIMIX_req_process_sleep(double duration)
603 /* checking for infinite values */
604 xbt_assert(isfinite(duration), "duration is not finite!");
606 smx_req_t req = SIMIX_req_mine();
608 req->call = REQ_PROCESS_SLEEP;
609 req->process_sleep.duration = duration;
610 SIMIX_request_push(req->issuer);
611 return req->process_sleep.result;
615 * \brief Creates a new rendez-vous point
616 * \param name The name of the rendez-vous point
617 * \return The created rendez-vous point
619 smx_rdv_t SIMIX_req_rdv_create(const char *name)
621 smx_req_t req = SIMIX_req_mine();
623 req->call = REQ_RDV_CREATE;
624 req->rdv_create.name = name;
626 SIMIX_request_push(req->issuer);
627 return req->rdv_create.result;
632 * \brief Destroy a rendez-vous point
633 * \param name The rendez-vous point to destroy
635 void SIMIX_req_rdv_destroy(smx_rdv_t rdv)
637 smx_req_t req = SIMIX_req_mine();
639 req->call = REQ_RDV_DESTROY;
640 req->rdv_destroy.rdv = rdv;
642 SIMIX_request_push(req->issuer);
645 smx_rdv_t SIMIX_req_rdv_get_by_name(const char *name)
647 xbt_assert(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)");
649 /* FIXME: this is a horrible lost of performance, so we hack it out by
650 * skipping the request (for now). It won't work on distributed but
651 * probably we will change MSG for that. */
653 smx_req_t req = SIMIX_req_mine();
654 req->call = REQ_RDV_GEY_BY_NAME;
655 req->rdv_get_by_name.name = name;
656 SIMIX_request_push(req->issuer);
657 return req->rdv_get_by_name.result;*/
659 return SIMIX_rdv_get_by_name(name);
663 * \brief counts the number of communication requests of a given host pending
664 * on a rendez-vous point
665 * \param rdv The rendez-vous point
666 * \param host The host to be counted
667 * \return The number of comm request pending in the rdv
669 int SIMIX_req_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
671 smx_req_t req = SIMIX_req_mine();
673 req->call = REQ_RDV_COMM_COUNT_BY_HOST;
674 req->rdv_comm_count_by_host.rdv = rdv;
675 req->rdv_comm_count_by_host.host = host;
677 SIMIX_request_push(req->issuer);
678 return req->rdv_comm_count_by_host.result;
682 * \brief returns the communication at the head of the rendez-vous
683 * \param rdv The rendez-vous point
684 * \return The communication or NULL if empty
686 smx_action_t SIMIX_req_rdv_get_head(smx_rdv_t rdv)
688 smx_req_t req = SIMIX_req_mine();
690 req->call = REQ_RDV_GET_HEAD;
691 req->rdv_get_head.rdv = rdv;
693 SIMIX_request_push(req->issuer);
694 return req->rdv_get_head.result;
697 void SIMIX_req_comm_send(smx_rdv_t rdv, double task_size, double rate,
698 void *src_buff, size_t src_buff_size,
699 int (*match_fun)(void *, void *), void *data,
702 /* checking for infinite values */
703 xbt_assert(isfinite(task_size), "task_size is not finite!");
704 xbt_assert(isfinite(rate), "rate is not finite!");
705 xbt_assert(isfinite(timeout), "timeout is not finite!");
707 xbt_assert(rdv, "No rendez-vous point defined for send");
710 /* the model-checker wants two separate requests */
711 smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate,
712 src_buff, src_buff_size, match_fun, data, 0);
713 SIMIX_req_comm_wait(comm, timeout);
716 smx_req_t req = SIMIX_req_mine();
718 req->call = REQ_COMM_SEND;
719 req->comm_send.rdv = rdv;
720 req->comm_send.task_size = task_size;
721 req->comm_send.rate = rate;
722 req->comm_send.src_buff = src_buff;
723 req->comm_send.src_buff_size = src_buff_size;
724 req->comm_send.match_fun = match_fun;
725 req->comm_send.data = data;
726 req->comm_send.timeout = timeout;
728 SIMIX_request_push(req->issuer);
732 smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
733 void *src_buff, size_t src_buff_size,
734 int (*match_fun)(void *, void *), void *data,
737 /* checking for infinite values */
738 xbt_assert(isfinite(task_size), "task_size is not finite!");
739 xbt_assert(isfinite(rate), "rate is not finite!");
741 xbt_assert(rdv, "No rendez-vous point defined for isend");
743 smx_req_t req = SIMIX_req_mine();
745 req->call = REQ_COMM_ISEND;
746 req->comm_isend.rdv = rdv;
747 req->comm_isend.task_size = task_size;
748 req->comm_isend.rate = rate;
749 req->comm_isend.src_buff = src_buff;
750 req->comm_isend.src_buff_size = src_buff_size;
751 req->comm_isend.match_fun = match_fun;
752 req->comm_isend.data = data;
753 req->comm_isend.detached = detached;
755 SIMIX_request_push(req->issuer);
756 return req->comm_isend.result;
759 void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
760 int (*match_fun)(void *, void *), void *data, double timeout)
762 xbt_assert(isfinite(timeout), "timeout is not finite!");
763 xbt_assert(rdv, "No rendez-vous point defined for recv");
766 /* the model-checker wants two separate requests */
767 smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size,
769 SIMIX_req_comm_wait(comm, timeout);
772 smx_req_t req = SIMIX_req_mine();
774 req->call = REQ_COMM_RECV;
775 req->comm_recv.rdv = rdv;
776 req->comm_recv.dst_buff = dst_buff;
777 req->comm_recv.dst_buff_size = dst_buff_size;
778 req->comm_recv.match_fun = match_fun;
779 req->comm_recv.data = data;
780 req->comm_recv.timeout = timeout;
782 SIMIX_request_push(req->issuer);
786 smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
787 int (*match_fun)(void *, void *), void *data)
789 xbt_assert(rdv, "No rendez-vous point defined for irecv");
791 smx_req_t req = SIMIX_req_mine();
793 req->call = REQ_COMM_IRECV;
794 req->comm_irecv.rdv = rdv;
795 req->comm_irecv.dst_buff = dst_buff;
796 req->comm_irecv.dst_buff_size = dst_buff_size;
797 req->comm_irecv.match_fun = match_fun;
798 req->comm_irecv.data = data;
800 SIMIX_request_push(req->issuer);
801 return req->comm_irecv.result;
804 void SIMIX_req_comm_destroy(smx_action_t comm)
806 xbt_assert(comm, "Invalid parameter");
808 /* FIXME remove this request type: comms are auto-destroyed now */
811 smx_req_t req = SIMIX_req_mine();
813 req->call = REQ_COMM_DESTROY;
814 req->comm_destroy.comm = comm;
816 SIMIX_request_push(req->issuer);
820 void SIMIX_req_comm_cancel(smx_action_t comm)
822 smx_req_t req = SIMIX_req_mine();
824 req->call = REQ_COMM_CANCEL;
825 req->comm_cancel.comm = comm;
827 SIMIX_request_push(req->issuer);
830 unsigned int SIMIX_req_comm_waitany(xbt_dynar_t comms)
832 smx_req_t req = SIMIX_req_mine();
834 req->call = REQ_COMM_WAITANY;
835 req->comm_waitany.comms = comms;
837 SIMIX_request_push(req->issuer);
838 return req->comm_waitany.result;
841 int SIMIX_req_comm_testany(xbt_dynar_t comms)
843 smx_req_t req = SIMIX_req_mine();
844 if (xbt_dynar_is_empty(comms))
847 req->call = REQ_COMM_TESTANY;
848 req->comm_testany.comms = comms;
850 SIMIX_request_push(req->issuer);
851 return req->comm_testany.result;
854 void SIMIX_req_comm_wait(smx_action_t comm, double timeout)
856 xbt_assert(isfinite(timeout), "timeout is not finite!");
858 smx_req_t req = SIMIX_req_mine();
860 req->call = REQ_COMM_WAIT;
861 req->comm_wait.comm = comm;
862 req->comm_wait.timeout = timeout;
864 SIMIX_request_push(req->issuer);
869 * \brief Set the category of an action.
871 * This functions changes the category only. It calls a surf function.
872 * \param execution The execution action
873 * \param category The tracing category
875 void SIMIX_req_set_category(smx_action_t action, const char *category)
877 if (category == NULL) {
881 smx_req_t req = SIMIX_req_mine();
883 req->call = REQ_SET_CATEGORY;
884 req->set_category.action = action;
885 req->set_category.category = category;
887 SIMIX_request_push(req->issuer);
891 int SIMIX_req_comm_test(smx_action_t comm)
893 smx_req_t req = SIMIX_req_mine();
895 req->call = REQ_COMM_TEST;
896 req->comm_test.comm = comm;
898 SIMIX_request_push(req->issuer);
899 return req->comm_test.result;
902 double SIMIX_req_comm_get_remains(smx_action_t comm)
904 smx_req_t req = SIMIX_req_mine();
906 req->call = REQ_COMM_GET_REMAINS;
907 req->comm_get_remains.comm = comm;
909 SIMIX_request_push(req->issuer);
910 return req->comm_get_remains.result;
913 e_smx_state_t SIMIX_req_comm_get_state(smx_action_t comm)
915 smx_req_t req = SIMIX_req_mine();
917 req->call = REQ_COMM_GET_STATE;
918 req->comm_get_state.comm = comm;
920 SIMIX_request_push(req->issuer);
921 return req->comm_get_state.result;
924 void *SIMIX_req_comm_get_src_data(smx_action_t comm)
926 smx_req_t req = SIMIX_req_mine();
928 req->call = REQ_COMM_GET_SRC_DATA;
929 req->comm_get_src_data.comm = comm;
931 SIMIX_request_push(req->issuer);
932 return req->comm_get_src_data.result;
935 void *SIMIX_req_comm_get_dst_data(smx_action_t comm)
937 smx_req_t req = SIMIX_req_mine();
939 req->call = REQ_COMM_GET_DST_DATA;
940 req->comm_get_dst_data.comm = comm;
942 SIMIX_request_push(req->issuer);
943 return req->comm_get_dst_data.result;
946 smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm)
948 smx_req_t req = SIMIX_req_mine();
950 req->call = REQ_COMM_GET_SRC_PROC;
951 req->comm_get_src_proc.comm = comm;
953 SIMIX_request_push(req->issuer);
954 return req->comm_get_src_proc.result;
957 smx_process_t SIMIX_req_comm_get_dst_proc(smx_action_t comm)
959 smx_req_t req = SIMIX_req_mine();
961 req->call = REQ_COMM_GET_DST_PROC;
962 req->comm_get_dst_proc.comm = comm;
964 SIMIX_request_push(req->issuer);
965 return req->comm_get_dst_proc.result;
968 #ifdef HAVE_LATENCY_BOUND_TRACKING
969 int SIMIX_req_comm_is_latency_bounded(smx_action_t comm)
971 smx_req_t req = SIMIX_req_mine();
973 req->call = REQ_COMM_IS_LATENCY_BOUNDED;
974 req->comm_is_latency_bounded.comm = comm;
976 SIMIX_request_push(req->issuer);
977 return req->comm_is_latency_bounded.result;
981 smx_mutex_t SIMIX_req_mutex_init(void)
983 smx_req_t req = SIMIX_req_mine();
985 req->call = REQ_MUTEX_INIT;
987 SIMIX_request_push(req->issuer);
988 return req->mutex_init.result;
991 void SIMIX_req_mutex_destroy(smx_mutex_t mutex)
993 smx_req_t req = SIMIX_req_mine();
995 req->call = REQ_MUTEX_DESTROY;
996 req->mutex_destroy.mutex = mutex;
998 SIMIX_request_push(req->issuer);
1001 void SIMIX_req_mutex_lock(smx_mutex_t mutex)
1003 smx_req_t req = SIMIX_req_mine();
1005 req->call = REQ_MUTEX_LOCK;
1006 req->mutex_lock.mutex = mutex;
1008 SIMIX_request_push(req->issuer);
1011 int SIMIX_req_mutex_trylock(smx_mutex_t mutex)
1013 smx_req_t req = SIMIX_req_mine();
1015 req->call = REQ_MUTEX_TRYLOCK;
1016 req->mutex_trylock.mutex = mutex;
1018 SIMIX_request_push(req->issuer);
1019 return req->mutex_trylock.result;
1022 void SIMIX_req_mutex_unlock(smx_mutex_t mutex)
1024 smx_req_t req = SIMIX_req_mine();
1026 req->call = REQ_MUTEX_UNLOCK;
1027 req->mutex_unlock.mutex = mutex;
1029 SIMIX_request_push(req->issuer);
1033 smx_cond_t SIMIX_req_cond_init(void)
1035 smx_req_t req = SIMIX_req_mine();
1037 req->call = REQ_COND_INIT;
1039 SIMIX_request_push(req->issuer);
1040 return req->cond_init.result;
1043 void SIMIX_req_cond_destroy(smx_cond_t cond)
1045 smx_req_t req = SIMIX_req_mine();
1047 req->call = REQ_COND_DESTROY;
1048 req->cond_destroy.cond = cond;
1050 SIMIX_request_push(req->issuer);
1053 void SIMIX_req_cond_signal(smx_cond_t cond)
1055 smx_req_t req = SIMIX_req_mine();
1057 req->call = REQ_COND_SIGNAL;
1058 req->cond_signal.cond = cond;
1060 SIMIX_request_push(req->issuer);
1063 void SIMIX_req_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1065 smx_req_t req = SIMIX_req_mine();
1067 req->call = REQ_COND_WAIT;
1068 req->cond_wait.cond = cond;
1069 req->cond_wait.mutex = mutex;
1071 SIMIX_request_push(req->issuer);
1074 void SIMIX_req_cond_wait_timeout(smx_cond_t cond,
1078 xbt_assert(isfinite(timeout), "timeout is not finite!");
1080 smx_req_t req = SIMIX_req_mine();
1082 req->call = REQ_COND_WAIT_TIMEOUT;
1083 req->cond_wait_timeout.cond = cond;
1084 req->cond_wait_timeout.mutex = mutex;
1085 req->cond_wait_timeout.timeout = timeout;
1087 SIMIX_request_push(req->issuer);
1090 void SIMIX_req_cond_broadcast(smx_cond_t cond)
1092 smx_req_t req = SIMIX_req_mine();
1094 req->call = REQ_COND_BROADCAST;
1095 req->cond_broadcast.cond = cond;
1097 SIMIX_request_push(req->issuer);
1101 smx_sem_t SIMIX_req_sem_init(int capacity)
1103 smx_req_t req = SIMIX_req_mine();
1105 req->call = REQ_SEM_INIT;
1106 req->sem_init.capacity = capacity;
1108 SIMIX_request_push(req->issuer);
1109 return req->sem_init.result;
1112 void SIMIX_req_sem_destroy(smx_sem_t sem)
1114 smx_req_t req = SIMIX_req_mine();
1116 req->call = REQ_SEM_DESTROY;
1117 req->sem_destroy.sem = sem;
1119 SIMIX_request_push(req->issuer);
1122 void SIMIX_req_sem_release(smx_sem_t sem)
1124 smx_req_t req = SIMIX_req_mine();
1126 req->call = REQ_SEM_RELEASE;
1127 req->sem_release.sem = sem;
1129 SIMIX_request_push(req->issuer);
1132 int SIMIX_req_sem_would_block(smx_sem_t sem)
1134 smx_req_t req = SIMIX_req_mine();
1136 req->call = REQ_SEM_WOULD_BLOCK;
1137 req->sem_would_block.sem = sem;
1139 SIMIX_request_push(req->issuer);
1140 return req->sem_would_block.result;
1143 void SIMIX_req_sem_acquire(smx_sem_t sem)
1145 smx_req_t req = SIMIX_req_mine();
1147 req->call = REQ_SEM_ACQUIRE;
1148 req->sem_acquire.sem = sem;
1150 SIMIX_request_push(req->issuer);
1153 void SIMIX_req_sem_acquire_timeout(smx_sem_t sem, double timeout)
1155 xbt_assert(isfinite(timeout), "timeout is not finite!");
1157 smx_req_t req = SIMIX_req_mine();
1159 req->call = REQ_SEM_ACQUIRE_TIMEOUT;
1160 req->sem_acquire_timeout.sem = sem;
1161 req->sem_acquire_timeout.timeout = timeout;
1163 SIMIX_request_push(req->issuer);
1166 int SIMIX_req_sem_get_capacity(smx_sem_t sem)
1168 smx_req_t req = SIMIX_req_mine();
1170 req->call = REQ_SEM_GET_CAPACITY;
1171 req->sem_get_capacity.sem = sem;
1173 SIMIX_request_push(req->issuer);
1174 return req->sem_get_capacity.result;
1176 /* ************************************************************************** */
1178 /** @brief returns a printable string representing the request kind */
1179 const char *SIMIX_request_name(int kind) {
1180 return request_names[kind];