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 _ISO_C99_SOURCE /* isfinite() */
9 #include <math.h> /* isfinite() */
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
17 static const char* request_names[] = {
18 #undef SIMIX_REQ_ENUM_ELEMENT
19 #define SIMIX_REQ_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
21 #undef SIMIX_REQ_ENUM_ELEMENT
25 * \brief Returns a host given its name.
27 * \param name The name of the host to get
28 * \return The corresponding host
30 smx_host_t SIMIX_req_host_get_by_name(const char *name)
32 smx_req_t req = SIMIX_req_mine();
34 req->call = REQ_HOST_GET_BY_NAME;
35 req->host_get_by_name.name = name;
37 return req->host_get_by_name.result;
41 * \brief Returns the name of a host.
43 * \param host A SIMIX host
44 * \return The name of this host
46 const char* SIMIX_req_host_get_name(smx_host_t host)
48 smx_req_t req = SIMIX_req_mine();
50 req->call = REQ_HOST_GET_NAME;
51 req->host_get_name.host = host;
53 return req->host_get_name.result;
57 * \brief Returns a dict of the properties assigned to a host.
60 * \return The properties of this host
62 xbt_dict_t SIMIX_req_host_get_properties(smx_host_t host)
64 smx_req_t req = SIMIX_req_mine();
66 req->call = REQ_HOST_GET_PROPERTIES;
67 req->host_get_properties.host = host;
69 return req->host_get_properties.result;
73 * \brief Returns the speed of the processor.
75 * The speed returned does not take into account the current load on the machine.
76 * \param host A SIMIX host
77 * \return The speed of this host (in Mflop/s)
79 double SIMIX_req_host_get_speed(smx_host_t host)
81 smx_req_t req = SIMIX_req_mine();
83 req->call = REQ_HOST_GET_SPEED;
84 req->host_get_speed.host = host;
86 return req->host_get_speed.result;
90 * \brief Returns the available speed of the processor.
92 * \return Speed currently available (in Mflop/s)
94 double SIMIX_req_host_get_available_speed(smx_host_t host)
96 smx_req_t req = SIMIX_req_mine();
98 req->call = REQ_HOST_GET_AVAILABLE_SPEED;
99 req->host_get_available_speed.host = host;
100 SIMIX_request_push();
101 return req->host_get_available_speed.result;
105 * \brief Returns the state of a host.
107 * Two states are possible: 1 if the host is active or 0 if it has crashed.
108 * \param host A SIMIX host
109 * \return 1 if the host is available, 0 otherwise
111 int SIMIX_req_host_get_state(smx_host_t host)
113 smx_req_t req = SIMIX_req_mine();
115 req->call = REQ_HOST_GET_STATE;
116 req->host_get_state.host = host;
117 SIMIX_request_push();
118 return req->host_get_state.result;
122 * \brief Returns the user data associated to a host.
124 * \param host SIMIX host
125 * \return the user data of this host
127 void* SIMIX_req_host_get_data(smx_host_t host)
129 smx_req_t req = SIMIX_req_mine();
131 req->call = REQ_HOST_GET_DATA;
132 req->host_get_data.host = host;
133 SIMIX_request_push();
134 return req->host_get_data.result;
138 * \brief Sets the user data associated to a host.
140 * The host must not have previous user data associated to it.
141 * \param A host SIMIX host
142 * \param data The user data to set
144 void SIMIX_req_host_set_data(smx_host_t host, void *data)
146 smx_req_t req = SIMIX_req_mine();
148 req->call = REQ_HOST_SET_DATA;
149 req->host_set_data.host = host;
150 req->host_set_data.data = data;
151 SIMIX_request_push();
154 /** \brief Creates an action that executes some computation of an host.
156 * This function creates a SURF action and allocates the data necessary
157 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
159 * \param name Name of the execution action to create
160 * \param host SIMIX host where the action will be executed
161 * \param amount Computation amount (in bytes)
162 * \return A new SIMIX execution action
164 smx_action_t SIMIX_req_host_execute(const char *name, smx_host_t host,
165 double computation_amount,
168 /* checking for infinite values */
169 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
170 xbt_assert(isfinite(priority), "priority is not finite!");
172 smx_req_t req = SIMIX_req_mine();
174 req->call = REQ_HOST_EXECUTE;
175 req->host_execute.name = name;
176 req->host_execute.host = host;
177 req->host_execute.computation_amount = computation_amount;
178 req->host_execute.priority = priority;
179 SIMIX_request_push();
180 return req->host_execute.result;
183 /** \brief Creates an action that may involve parallel computation on
184 * several hosts and communication between them.
186 * \param name Name of the execution action to create
187 * \param host_nb Number of hosts where the action will be executed
188 * \param host_list Array (of size host_nb) of hosts where the action will be executed
189 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
190 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
191 * amount between each pair of hosts
192 * \param amount the SURF action amount
193 * \param rate the SURF action rate
194 * \return A new SIMIX execution action
196 smx_action_t SIMIX_req_host_parallel_execute(const char *name,
198 smx_host_t *host_list,
199 double *computation_amount,
200 double *communication_amount,
205 /* checking for infinite values */
206 for (i = 0 ; i < host_nb ; ++i) {
207 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
208 for (j = 0 ; j < host_nb ; ++j) {
209 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
210 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
214 xbt_assert(isfinite(amount), "amount is not finite!");
215 xbt_assert(isfinite(rate), "rate is not finite!");
217 smx_req_t req = SIMIX_req_mine();
219 req->call = REQ_HOST_PARALLEL_EXECUTE;
220 req->host_parallel_execute.name = name;
221 req->host_parallel_execute.host_nb = host_nb;
222 req->host_parallel_execute.host_list = host_list;
223 req->host_parallel_execute.computation_amount = computation_amount;
224 req->host_parallel_execute.communication_amount = communication_amount;
225 req->host_parallel_execute.amount = amount;
226 req->host_parallel_execute.rate = rate;
227 SIMIX_request_push();
228 return req->host_parallel_execute.result;
232 * \brief Destroys an execution action.
234 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
235 * \param action The execution action to destroy
237 void SIMIX_req_host_execution_destroy(smx_action_t execution)
239 smx_req_t req = SIMIX_req_mine();
241 req->call = REQ_HOST_EXECUTION_DESTROY;
242 req->host_execution_destroy.execution = execution;
243 SIMIX_request_push();
247 * \brief Cancels an execution action.
249 * This functions stops the execution. It calls a surf function.
250 * \param action The execution action to cancel
252 void SIMIX_req_host_execution_cancel(smx_action_t execution)
254 smx_req_t req = SIMIX_req_mine();
256 req->call = REQ_HOST_EXECUTION_CANCEL;
257 req->host_execution_cancel.execution = execution;
258 SIMIX_request_push();
262 * \brief Returns how much of an execution action remains to be done.
264 * \param Action The execution action
265 * \return The remaining amount
267 double SIMIX_req_host_execution_get_remains(smx_action_t execution)
269 smx_req_t req = SIMIX_req_mine();
271 req->call = REQ_HOST_EXECUTION_GET_REMAINS;
272 req->host_execution_get_remains.execution = execution;
273 SIMIX_request_push();
274 return req->host_execution_get_remains.result;
278 * \brief Returns the state of an execution action.
280 * \param execution The execution action
283 e_smx_state_t SIMIX_req_host_execution_get_state(smx_action_t execution)
285 smx_req_t req = SIMIX_req_mine();
287 req->call = REQ_HOST_EXECUTION_GET_STATE;
288 req->host_execution_get_state.execution = execution;
289 SIMIX_request_push();
290 return req->host_execution_get_state.result;
294 * \brief Changes the priority of an execution action.
296 * This functions changes the priority only. It calls a surf function.
297 * \param execution The execution action
298 * \param priority The new priority
300 void SIMIX_req_host_execution_set_priority(smx_action_t execution, double priority)
302 /* checking for infinite values */
303 xbt_assert(isfinite(priority), "priority is not finite!");
305 smx_req_t req = SIMIX_req_mine();
307 req->call = REQ_HOST_EXECUTION_SET_PRIORITY;
308 req->host_execution_set_priority.execution = execution;
309 req->host_execution_set_priority.priority = priority;
310 SIMIX_request_push();
314 * \brief Waits for the completion of an execution action and destroy it.
316 * \param execution The execution action
318 e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution)
320 smx_req_t req = SIMIX_req_mine();
322 req->call = REQ_HOST_EXECUTION_WAIT;
323 req->host_execution_wait.execution = execution;
324 SIMIX_request_push();
325 return req->host_execution_wait.result;
329 * \brief Creates and runs a new SIMIX process.
331 * The structure and the corresponding thread are created and put in the list of ready processes.
333 * \param process the process created will be stored in this pointer
334 * \param name a name for the process. It is for user-level information and can be NULL.
335 * \param code the main function of the process
336 * \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.
337 * It can be retrieved with the function \ref SIMIX_req_process_get_data.
338 * \param hostname name of the host where the new agent is executed.
339 * \param argc first argument passed to \a code
340 * \param argv second argument passed to \a code
341 * \param properties the properties of the process
343 void SIMIX_req_process_create(smx_process_t *process, const char *name,
344 xbt_main_func_t code,
346 const char *hostname,
347 int argc, char **argv,
348 xbt_dict_t properties)
350 smx_req_t req = SIMIX_req_mine();
352 req->call = REQ_PROCESS_CREATE;
353 req->process_create.process = process;
354 req->process_create.name = name;
355 req->process_create.code = code;
356 req->process_create.data = data;
357 req->process_create.hostname = hostname;
358 req->process_create.argc = argc;
359 req->process_create.argv = argv;
360 req->process_create.properties = properties;
361 SIMIX_request_push();
364 /** \brief Kills a SIMIX process.
366 * This function simply kills a process.
368 * \param process poor victim
370 void SIMIX_req_process_kill(smx_process_t process)
372 smx_req_t req = SIMIX_req_mine();
374 req->call = REQ_PROCESS_KILL;
375 req->process_kill.process = process;
376 SIMIX_request_push();
379 /** \brief Kills all SIMIX processes.
381 void SIMIX_req_process_killall(void)
383 smx_req_t req = SIMIX_req_mine();
385 req->call = REQ_PROCESS_KILLALL;
386 SIMIX_request_push();
389 /** \brief Cleans up a SIMIX process.
390 * \param process poor victim (must have already been killed)
392 void SIMIX_req_process_cleanup(smx_process_t process)
394 smx_req_t req = SIMIX_req_mine();
396 req->call = REQ_PROCESS_CLEANUP;
397 req->process_cleanup.process = process;
398 SIMIX_request_push();
402 * \brief Migrates an agent to another location.
404 * This function changes the value of the host on which \a process is running.
406 * \param process the process to migrate
407 * \param source name of the previous host
408 * \param dest name of the new host
410 void SIMIX_req_process_change_host(smx_process_t process, smx_host_t dest)
412 smx_req_t req = SIMIX_req_mine();
414 req->call = REQ_PROCESS_CHANGE_HOST;
415 req->process_change_host.process = process;
416 req->process_change_host.dest = dest;
417 SIMIX_request_push();
421 * \brief Suspends a process.
423 * This function suspends the process by suspending the action
424 * it was waiting for completion.
426 * \param process a SIMIX process
428 void SIMIX_req_process_suspend(smx_process_t process)
430 xbt_assert(process, "Invalid parameters");
432 smx_req_t req = SIMIX_req_mine();
434 req->call = REQ_PROCESS_SUSPEND;
435 req->process_suspend.process = process;
436 SIMIX_request_push();
440 * \brief Resumes a suspended process.
442 * This function resumes a suspended process by resuming the action
443 * it was waiting for completion.
445 * \param process a SIMIX process
447 void SIMIX_req_process_resume(smx_process_t process)
449 smx_req_t req = SIMIX_req_mine();
451 req->call = REQ_PROCESS_RESUME;
452 req->process_resume.process = process;
453 SIMIX_request_push();
457 * \brief Returns the amount of SIMIX processes in the system
459 * Maestro internal process is not counted, only user code processes are
461 int SIMIX_req_process_count(void)
463 smx_req_t req = SIMIX_req_mine();
465 req->call = REQ_PROCESS_COUNT;
466 SIMIX_request_push();
467 return req->process_count.result;
471 * \brief Return the user data of a #smx_process_t.
473 * This functions checks whether \a process is a valid pointer or not and return the user data associated to \a process if it is possible.
474 * \param process SIMIX process
475 * \return A void pointer to the user data
477 void* SIMIX_req_process_get_data(smx_process_t process)
479 if (process == SIMIX_process_self()) {
480 /* avoid a request if this function is called by the process itself */
481 return SIMIX_process_self_get_data();
484 smx_req_t req = SIMIX_req_mine();
486 req->call = REQ_PROCESS_GET_DATA;
487 req->process_get_data.process = process;
488 SIMIX_request_push();
489 return req->process_get_data.result;
493 * \brief Set the user data of a #m_process_t.
495 * 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.
496 * \param process SIMIX process
497 * \param data User data
499 void SIMIX_req_process_set_data(smx_process_t process, void *data)
501 if (process == SIMIX_process_self()) {
502 /* avoid a request if this function is called by the process itself */
503 SIMIX_process_self_set_data(data);
507 smx_req_t req = SIMIX_req_mine();
509 req->call = REQ_PROCESS_SET_DATA;
510 req->process_set_data.process = process;
511 req->process_set_data.data = data;
512 SIMIX_request_push();
517 * \brief Return the location on which an agent is running.
519 * 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.
520 * \param process SIMIX process
523 smx_host_t SIMIX_req_process_get_host(smx_process_t process)
525 smx_req_t req = SIMIX_req_mine();
527 req->call = REQ_PROCESS_GET_HOST;
528 req->process_get_host.process = process;
529 SIMIX_request_push();
530 return req->process_get_host.result;
534 * \brief Return the name of an agent.
536 * This functions checks whether \a process is a valid pointer or not and return its name.
537 * \param process SIMIX process
538 * \return The process name
540 const char* SIMIX_req_process_get_name(smx_process_t process)
542 if (process == SIMIX_process_self()) {
543 /* avoid a request if this function is called by the process itself */
544 return process->name;
547 smx_req_t req = SIMIX_req_mine();
549 req->call = REQ_PROCESS_GET_NAME;
550 req->process_get_name.process = process;
551 SIMIX_request_push();
552 return req->process_get_name.result;
556 * \brief Returns true if the process is suspended .
558 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
559 * \param process SIMIX process
560 * \return 1, if the process is suspended, else 0.
562 int SIMIX_req_process_is_suspended(smx_process_t process)
564 smx_req_t req = SIMIX_req_mine();
566 req->call = REQ_PROCESS_IS_SUSPENDED;
567 req->process_is_suspended.process = process;
568 SIMIX_request_push();
569 return req->process_is_suspended.result;
572 /** \ingroup m_process_management
573 * \brief Return the properties
575 * This functions returns the properties associated with this process
577 xbt_dict_t SIMIX_req_process_get_properties(smx_process_t process)
579 smx_req_t req = SIMIX_req_mine();
581 req->call = REQ_PROCESS_GET_PROPERTIES;
582 req->process_get_properties.process = process;
583 SIMIX_request_push();
584 return req->process_get_properties.result;
587 /** \brief Creates a new sleep SIMIX action.
589 * This function creates a SURF action and allocates the data necessary
590 * to create the SIMIX action. It can raise a host_error exception if the
591 * host crashed. The default SIMIX name of the action is "sleep".
593 * \param duration Time duration of the sleep.
594 * \return A result telling whether the sleep was successful
596 e_smx_state_t SIMIX_req_process_sleep(double duration)
598 /* checking for infinite values */
599 xbt_assert(isfinite(duration), "duration is not finite!");
601 smx_req_t req = SIMIX_req_mine();
603 req->call = REQ_PROCESS_SLEEP;
604 req->process_sleep.duration = duration;
605 SIMIX_request_push();
606 return req->process_sleep.result;
610 * \brief Creates a new rendez-vous point
611 * \param name The name of the rendez-vous point
612 * \return The created rendez-vous point
614 smx_rdv_t SIMIX_req_rdv_create(const char *name)
616 smx_req_t req = SIMIX_req_mine();
618 req->call = REQ_RDV_CREATE;
619 req->rdv_create.name = name;
621 SIMIX_request_push();
622 return req->rdv_create.result;
627 * \brief Destroy a rendez-vous point
628 * \param name The rendez-vous point to destroy
630 void SIMIX_req_rdv_destroy(smx_rdv_t rdv)
632 smx_req_t req = SIMIX_req_mine();
634 req->call = REQ_RDV_DESTROY;
635 req->rdv_destroy.rdv = rdv;
637 SIMIX_request_push();
640 smx_rdv_t SIMIX_req_rdv_get_by_name(const char *name)
642 xbt_assert(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)");
644 /* FIXME: this is a horrible lost of performance, so we hack it out by
645 * skipping the request (for now). It won't work on distributed but
646 * probably we will change MSG for that. */
648 smx_req_t req = SIMIX_req_mine();
649 req->call = REQ_RDV_GEY_BY_NAME;
650 req->rdv_get_by_name.name = name;
651 SIMIX_request_push();
652 return req->rdv_get_by_name.result;*/
654 return SIMIX_rdv_get_by_name(name);
658 * \brief counts the number of communication requests of a given host pending
659 * on a rendez-vous point
660 * \param rdv The rendez-vous point
661 * \param host The host to be counted
662 * \return The number of comm request pending in the rdv
664 int SIMIX_req_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
666 smx_req_t req = SIMIX_req_mine();
668 req->call = REQ_RDV_COMM_COUNT_BY_HOST;
669 req->rdv_comm_count_by_host.rdv = rdv;
670 req->rdv_comm_count_by_host.host = host;
672 SIMIX_request_push();
673 return req->rdv_comm_count_by_host.result;
677 * \brief returns the communication at the head of the rendez-vous
678 * \param rdv The rendez-vous point
679 * \return The communication or NULL if empty
681 smx_action_t SIMIX_req_rdv_get_head(smx_rdv_t rdv)
683 smx_req_t req = SIMIX_req_mine();
685 req->call = REQ_RDV_GET_HEAD;
686 req->rdv_get_head.rdv = rdv;
688 SIMIX_request_push();
689 return req->rdv_get_head.result;
692 void SIMIX_req_comm_send(smx_rdv_t rdv, double task_size, double rate,
693 void *src_buff, size_t src_buff_size,
694 int (*match_fun)(void *, void *), void *data,
697 /* checking for infinite values */
698 xbt_assert(isfinite(task_size), "task_size is not finite!");
699 xbt_assert(isfinite(rate), "rate is not finite!");
700 xbt_assert(isfinite(timeout), "timeout is not finite!");
702 xbt_assert(rdv, "No rendez-vous point defined for send");
705 /* the model-checker wants two separate requests */
706 smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate,
707 src_buff, src_buff_size, match_fun, data, 0);
708 SIMIX_req_comm_wait(comm, timeout);
711 smx_req_t req = SIMIX_req_mine();
713 req->call = REQ_COMM_SEND;
714 req->comm_send.rdv = rdv;
715 req->comm_send.task_size = task_size;
716 req->comm_send.rate = rate;
717 req->comm_send.src_buff = src_buff;
718 req->comm_send.src_buff_size = src_buff_size;
719 req->comm_send.match_fun = match_fun;
720 req->comm_send.data = data;
721 req->comm_send.timeout = timeout;
723 SIMIX_request_push();
727 smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
728 void *src_buff, size_t src_buff_size,
729 int (*match_fun)(void *, void *), void *data,
732 /* checking for infinite values */
733 xbt_assert(isfinite(task_size), "task_size is not finite!");
734 xbt_assert(isfinite(rate), "rate is not finite!");
736 xbt_assert(rdv, "No rendez-vous point defined for isend");
738 smx_req_t req = SIMIX_req_mine();
740 req->call = REQ_COMM_ISEND;
741 req->comm_isend.rdv = rdv;
742 req->comm_isend.task_size = task_size;
743 req->comm_isend.rate = rate;
744 req->comm_isend.src_buff = src_buff;
745 req->comm_isend.src_buff_size = src_buff_size;
746 req->comm_isend.match_fun = match_fun;
747 req->comm_isend.data = data;
748 req->comm_isend.detached = detached;
750 SIMIX_request_push();
751 return req->comm_isend.result;
754 void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
755 int (*match_fun)(void *, void *), void *data, double timeout)
757 xbt_assert(isfinite(timeout), "timeout is not finite!");
758 xbt_assert(rdv, "No rendez-vous point defined for recv");
761 /* the model-checker wants two separate requests */
762 smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size,
764 SIMIX_req_comm_wait(comm, timeout);
767 smx_req_t req = SIMIX_req_mine();
769 req->call = REQ_COMM_RECV;
770 req->comm_recv.rdv = rdv;
771 req->comm_recv.dst_buff = dst_buff;
772 req->comm_recv.dst_buff_size = dst_buff_size;
773 req->comm_recv.match_fun = match_fun;
774 req->comm_recv.data = data;
775 req->comm_recv.timeout = timeout;
777 SIMIX_request_push();
781 smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
782 int (*match_fun)(void *, void *), void *data)
784 xbt_assert(rdv, "No rendez-vous point defined for irecv");
786 smx_req_t req = SIMIX_req_mine();
788 req->call = REQ_COMM_IRECV;
789 req->comm_irecv.rdv = rdv;
790 req->comm_irecv.dst_buff = dst_buff;
791 req->comm_irecv.dst_buff_size = dst_buff_size;
792 req->comm_irecv.match_fun = match_fun;
793 req->comm_irecv.data = data;
795 SIMIX_request_push();
796 return req->comm_irecv.result;
799 void SIMIX_req_comm_destroy(smx_action_t comm)
801 xbt_assert(comm, "Invalid parameter");
803 /* FIXME remove this request type: comms are auto-destroyed now,
804 * but what happens with unfinished comms? */
807 smx_req_t req = SIMIX_req_mine();
809 req->call = REQ_COMM_DESTROY;
810 req->comm_destroy.comm = comm;
812 SIMIX_request_push();
816 void SIMIX_req_comm_cancel(smx_action_t comm)
818 smx_req_t req = SIMIX_req_mine();
820 req->call = REQ_COMM_CANCEL;
821 req->comm_cancel.comm = comm;
823 SIMIX_request_push();
826 unsigned int SIMIX_req_comm_waitany(xbt_dynar_t comms)
828 smx_req_t req = SIMIX_req_mine();
830 req->call = REQ_COMM_WAITANY;
831 req->comm_waitany.comms = comms;
833 SIMIX_request_push();
834 return req->comm_waitany.result;
837 int SIMIX_req_comm_testany(xbt_dynar_t comms)
839 smx_req_t req = SIMIX_req_mine();
840 if (xbt_dynar_length(comms)==0)
843 req->call = REQ_COMM_TESTANY;
844 req->comm_testany.comms = comms;
846 SIMIX_request_push();
847 return req->comm_testany.result;
850 void SIMIX_req_comm_wait(smx_action_t comm, double timeout)
852 xbt_assert(isfinite(timeout), "timeout is not finite!");
854 smx_req_t req = SIMIX_req_mine();
856 req->call = REQ_COMM_WAIT;
857 req->comm_wait.comm = comm;
858 req->comm_wait.timeout = timeout;
860 SIMIX_request_push();
865 * \brief Set the category of an action.
867 * This functions changes the category only. It calls a surf function.
868 * \param execution The execution action
869 * \param category The tracing category
871 void SIMIX_req_set_category(smx_action_t action, const char *category)
873 if (category == NULL) {
877 smx_req_t req = SIMIX_req_mine();
879 req->call = REQ_SET_CATEGORY;
880 req->set_category.action = action;
881 req->set_category.category = category;
883 SIMIX_request_push();
887 int SIMIX_req_comm_test(smx_action_t comm)
889 smx_req_t req = SIMIX_req_mine();
891 req->call = REQ_COMM_TEST;
892 req->comm_test.comm = comm;
894 SIMIX_request_push();
895 return req->comm_test.result;
898 double SIMIX_req_comm_get_remains(smx_action_t comm)
900 smx_req_t req = SIMIX_req_mine();
902 req->call = REQ_COMM_GET_REMAINS;
903 req->comm_get_remains.comm = comm;
905 SIMIX_request_push();
906 return req->comm_get_remains.result;
909 e_smx_state_t SIMIX_req_comm_get_state(smx_action_t comm)
911 smx_req_t req = SIMIX_req_mine();
913 req->call = REQ_COMM_GET_STATE;
914 req->comm_get_state.comm = comm;
916 SIMIX_request_push();
917 return req->comm_get_state.result;
920 void *SIMIX_req_comm_get_src_data(smx_action_t comm)
922 smx_req_t req = SIMIX_req_mine();
924 req->call = REQ_COMM_GET_SRC_DATA;
925 req->comm_get_src_data.comm = comm;
927 SIMIX_request_push();
928 return req->comm_get_src_data.result;
931 void *SIMIX_req_comm_get_dst_data(smx_action_t comm)
933 smx_req_t req = SIMIX_req_mine();
935 req->call = REQ_COMM_GET_DST_DATA;
936 req->comm_get_dst_data.comm = comm;
938 SIMIX_request_push();
939 return req->comm_get_dst_data.result;
942 smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm)
944 smx_req_t req = SIMIX_req_mine();
946 req->call = REQ_COMM_GET_SRC_PROC;
947 req->comm_get_src_proc.comm = comm;
949 SIMIX_request_push();
950 return req->comm_get_src_proc.result;
953 smx_process_t SIMIX_req_comm_get_dst_proc(smx_action_t comm)
955 smx_req_t req = SIMIX_req_mine();
957 req->call = REQ_COMM_GET_DST_PROC;
958 req->comm_get_dst_proc.comm = comm;
960 SIMIX_request_push();
961 return req->comm_get_dst_proc.result;
964 #ifdef HAVE_LATENCY_BOUND_TRACKING
965 int SIMIX_req_comm_is_latency_bounded(smx_action_t comm)
967 smx_req_t req = SIMIX_req_mine();
969 req->call = REQ_COMM_IS_LATENCY_BOUNDED;
970 req->comm_is_latency_bounded.comm = comm;
972 SIMIX_request_push();
973 return req->comm_is_latency_bounded.result;
977 smx_mutex_t SIMIX_req_mutex_init(void)
979 smx_req_t req = SIMIX_req_mine();
981 req->call = REQ_MUTEX_INIT;
983 SIMIX_request_push();
984 return req->mutex_init.result;
987 void SIMIX_req_mutex_destroy(smx_mutex_t mutex)
989 smx_req_t req = SIMIX_req_mine();
991 req->call = REQ_MUTEX_DESTROY;
992 req->mutex_destroy.mutex = mutex;
994 SIMIX_request_push();
997 void SIMIX_req_mutex_lock(smx_mutex_t mutex)
999 smx_req_t req = SIMIX_req_mine();
1001 req->call = REQ_MUTEX_LOCK;
1002 req->mutex_lock.mutex = mutex;
1004 SIMIX_request_push();
1007 int SIMIX_req_mutex_trylock(smx_mutex_t mutex)
1009 smx_req_t req = SIMIX_req_mine();
1011 req->call = REQ_MUTEX_TRYLOCK;
1012 req->mutex_trylock.mutex = mutex;
1014 SIMIX_request_push();
1015 return req->mutex_trylock.result;
1018 void SIMIX_req_mutex_unlock(smx_mutex_t mutex)
1020 smx_req_t req = SIMIX_req_mine();
1022 req->call = REQ_MUTEX_UNLOCK;
1023 req->mutex_unlock.mutex = mutex;
1025 SIMIX_request_push();
1029 smx_cond_t SIMIX_req_cond_init(void)
1031 smx_req_t req = SIMIX_req_mine();
1033 req->call = REQ_COND_INIT;
1035 SIMIX_request_push();
1036 return req->cond_init.result;
1039 void SIMIX_req_cond_destroy(smx_cond_t cond)
1041 smx_req_t req = SIMIX_req_mine();
1043 req->call = REQ_COND_DESTROY;
1044 req->cond_destroy.cond = cond;
1046 SIMIX_request_push();
1049 void SIMIX_req_cond_signal(smx_cond_t cond)
1051 smx_req_t req = SIMIX_req_mine();
1053 req->call = REQ_COND_SIGNAL;
1054 req->cond_signal.cond = cond;
1056 SIMIX_request_push();
1059 void SIMIX_req_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1061 smx_req_t req = SIMIX_req_mine();
1063 req->call = REQ_COND_WAIT;
1064 req->cond_wait.cond = cond;
1065 req->cond_wait.mutex = mutex;
1067 SIMIX_request_push();
1070 void SIMIX_req_cond_wait_timeout(smx_cond_t cond,
1074 xbt_assert(isfinite(timeout), "timeout is not finite!");
1076 smx_req_t req = SIMIX_req_mine();
1078 req->call = REQ_COND_WAIT_TIMEOUT;
1079 req->cond_wait_timeout.cond = cond;
1080 req->cond_wait_timeout.mutex = mutex;
1081 req->cond_wait_timeout.timeout = timeout;
1083 SIMIX_request_push();
1086 void SIMIX_req_cond_broadcast(smx_cond_t cond)
1088 smx_req_t req = SIMIX_req_mine();
1090 req->call = REQ_COND_BROADCAST;
1091 req->cond_broadcast.cond = cond;
1093 SIMIX_request_push();
1097 smx_sem_t SIMIX_req_sem_init(int capacity)
1099 smx_req_t req = SIMIX_req_mine();
1101 req->call = REQ_SEM_INIT;
1102 req->sem_init.capacity = capacity;
1104 SIMIX_request_push();
1105 return req->sem_init.result;
1108 void SIMIX_req_sem_destroy(smx_sem_t sem)
1110 smx_req_t req = SIMIX_req_mine();
1112 req->call = REQ_SEM_DESTROY;
1113 req->sem_destroy.sem = sem;
1115 SIMIX_request_push();
1118 void SIMIX_req_sem_release(smx_sem_t sem)
1120 smx_req_t req = SIMIX_req_mine();
1122 req->call = REQ_SEM_RELEASE;
1123 req->sem_release.sem = sem;
1125 SIMIX_request_push();
1128 int SIMIX_req_sem_would_block(smx_sem_t sem)
1130 smx_req_t req = SIMIX_req_mine();
1132 req->call = REQ_SEM_WOULD_BLOCK;
1133 req->sem_would_block.sem = sem;
1135 SIMIX_request_push();
1136 return req->sem_would_block.result;
1139 void SIMIX_req_sem_acquire(smx_sem_t sem)
1141 smx_req_t req = SIMIX_req_mine();
1143 req->call = REQ_SEM_ACQUIRE;
1144 req->sem_acquire.sem = sem;
1146 SIMIX_request_push();
1149 void SIMIX_req_sem_acquire_timeout(smx_sem_t sem, double timeout)
1151 xbt_assert(isfinite(timeout), "timeout is not finite!");
1153 smx_req_t req = SIMIX_req_mine();
1155 req->call = REQ_SEM_ACQUIRE_TIMEOUT;
1156 req->sem_acquire_timeout.sem = sem;
1157 req->sem_acquire_timeout.timeout = timeout;
1159 SIMIX_request_push();
1162 int SIMIX_req_sem_get_capacity(smx_sem_t sem)
1164 smx_req_t req = SIMIX_req_mine();
1166 req->call = REQ_SEM_GET_CAPACITY;
1167 req->sem_get_capacity.sem = sem;
1169 SIMIX_request_push();
1170 return req->sem_get_capacity.result;
1172 /* ************************************************************************** */
1174 /** @brief returns a printable string representing the request kind */
1175 const char *SIMIX_request_name(int kind) {
1176 return request_names[kind];