2 #include "xbt/sysdep.h"
5 /** \defgroup msg_gos_functions MSG Operating System Functions
6 * \brief This section describes the functions that can be used
7 * by an agent for handling some task.
10 static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task,
19 /** \ingroup msg_gos_functions
20 * \brief Listen on a channel and wait for receiving a task.
22 * It takes two parameters.
23 * \param task a memory location for storing a #m_task_t. It will
24 hold a task when this function will return. Thus \a task should not
25 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
26 those two condition does not hold, there will be a warning message.
27 * \param channel the channel on which the agent should be
28 listening. This value has to be >=0 and < than the maximal
29 number of channels fixed with MSG_set_channel_number().
30 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
31 * if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
33 MSG_error_t MSG_task_get(m_task_t * task,
36 return MSG_task_get_with_time_out(task, channel, -1);
39 /** \ingroup msg_gos_functions
40 * \brief Listen on a channel and wait for receiving a task with a timeout.
42 * It takes three parameters.
43 * \param task a memory location for storing a #m_task_t. It will
44 hold a task when this function will return. Thus \a task should not
45 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
46 those two condition does not hold, there will be a warning message.
47 * \param channel the channel on which the agent should be
48 listening. This value has to be >=0 and < than the maximal
49 number of channels fixed with MSG_set_channel_number().
50 * \param max_duration the maximum time to wait for a task before giving
51 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
52 will not be modified and will still be
53 equal to \c NULL when returning.
54 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
55 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
57 MSG_error_t MSG_task_get_with_time_out(m_task_t * task,
61 return __MSG_task_get_with_time_out_from_host(task, channel, max_duration, NULL);
64 /** \ingroup msg_gos_functions
65 * \brief Listen on \a channel and waits for receiving a task from \a host.
67 * It takes three parameters.
68 * \param task a memory location for storing a #m_task_t. It will
69 hold a task when this function will return. Thus \a task should not
70 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
71 those two condition does not hold, there will be a warning message.
72 * \param channel the channel on which the agent should be
73 listening. This value has to be >=0 and < than the maximal
74 number of channels fixed with MSG_set_channel_number().
75 * \param host the host that is to be watched.
76 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
77 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
79 MSG_error_t MSG_task_get_from_host(m_task_t * task, int channel,
82 return __MSG_task_get_with_time_out_from_host(task, channel, -1, host);
85 /** \ingroup msg_gos_functions
86 * \brief Test whether there is a pending communication on a channel.
88 * It takes one parameter.
89 * \param channel the channel on which the agent should be
90 listening. This value has to be >=0 and < than the maximal
91 number of channels fixed with MSG_set_channel_number().
92 * \return 1 if there is a pending communication and 0 otherwise
94 int MSG_task_Iprobe(m_channel_t channel)
99 /** \ingroup msg_gos_functions
100 * \brief Test whether there is a pending communication on a channel, and who sent it.
102 * It takes one parameter.
103 * \param channel the channel on which the agent should be
104 listening. This value has to be >=0 and < than the maximal
105 number of channels fixed with MSG_set_channel_number().
106 * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
108 int MSG_task_probe_from(m_channel_t channel)
113 /** \ingroup msg_gos_functions
114 * \brief Wait for at most \a max_duration second for a task reception
115 on \a channel. *\a PID is updated with the PID of the first process
116 that triggered this event if any.
118 * It takes three parameters:
119 * \param channel the channel on which the agent should be
120 listening. This value has to be >=0 and < than the maximal.
121 number of channels fixed with MSG_set_channel_number().
122 * \param PID a memory location for storing an int.
123 * \param max_duration the maximum time to wait for a task before
124 giving up. In the case of a reception, *\a PID will be updated
125 with the PID of the first process to send a task.
126 * \return #MSG_HOST_FAILURE if the host is shut down in the meantime
127 and #MSG_OK otherwise.
129 MSG_error_t MSG_channel_select_from(m_channel_t channel, double max_duration,
136 /** \ingroup msg_gos_functions
138 * \brief Return the number of tasks waiting to be received on a \a
139 channel and sent by \a host.
141 * It takes two parameters.
142 * \param channel the channel on which the agent should be
143 listening. This value has to be >=0 and < than the maximal
144 number of channels fixed with MSG_set_channel_number().
145 * \param host the host that is to be watched.
146 * \return the number of tasks waiting to be received on \a channel
149 int MSG_task_probe_from_host(int channel, m_host_t host)
154 /** \ingroup msg_gos_functions \brief Put a task on a channel of an
155 * host (with a timeout on the waiting of the destination host) and
156 * waits for the end of the transmission.
158 * This function is used for describing the behavior of an agent. It
159 * takes four parameter.
160 * \param task a #m_task_t to send on another location. This task
161 will not be usable anymore when the function will return. There is
162 no automatic task duplication and you have to save your parameters
163 before calling this function. Tasks are unique and once it has been
164 sent to another location, you should not access it anymore. You do
165 not need to call MSG_task_destroy() but to avoid using, as an
166 effect of inattention, this task anymore, you definitely should
167 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
168 can be transfered iff it has been correctly created with
170 * \param dest the destination of the message
171 * \param channel the channel on which the agent should put this
172 task. This value has to be >=0 and < than the maximal number of
173 channels fixed with MSG_set_channel_number().
174 * \param max_duration the maximum time to wait for a task before giving
175 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
177 * \return #MSG_FATAL if \a task is not properly initialized and
178 #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
179 this function was called was shut down. Returns
180 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
181 (network failure, dest failure, timeout...)
183 MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
184 m_channel_t channel, double max_duration)
188 /** \ingroup msg_gos_functions
189 * \brief Put a task on a channel of an host and waits for the end of the
192 * This function is used for describing the behavior of an agent. It
193 * takes three parameter.
194 * \param task a #m_task_t to send on another location. This task
195 will not be usable anymore when the function will return. There is
196 no automatic task duplication and you have to save your parameters
197 before calling this function. Tasks are unique and once it has been
198 sent to another location, you should not access it anymore. You do
199 not need to call MSG_task_destroy() but to avoid using, as an
200 effect of inattention, this task anymore, you definitely should
201 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
202 can be transfered iff it has been correctly created with
204 * \param dest the destination of the message
205 * \param channel the channel on which the agent should put this
206 task. This value has to be >=0 and < than the maximal number of
207 channels fixed with MSG_set_channel_number().
208 * \return #MSG_FATAL if \a task is not properly initialized and
209 * #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
210 * this function was called was shut down. Returns
211 * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
212 * (network failure, dest failure)
214 MSG_error_t MSG_task_put(m_task_t task,
215 m_host_t dest, m_channel_t channel)
217 return MSG_task_put_with_timeout(task, dest, channel, -1.0);
220 /** \ingroup msg_gos_functions
221 * \brief Does exactly the same as MSG_task_put but with a bounded transmition
226 MSG_error_t MSG_task_put_bounded(m_task_t task,
227 m_host_t dest, m_channel_t channel,
230 MSG_error_t res = MSG_OK;
231 task->simdata->rate=max_rate;
232 res = MSG_task_put(task, dest, channel);
236 /** \ingroup msg_gos_functions
237 * \brief Executes a task and waits for its termination.
239 * This function is used for describing the behavior of an agent. It
240 * takes only one parameter.
241 * \param task a #m_task_t to execute on the location on which the
243 * \return #MSG_FATAL if \a task is not properly initialized and
246 MSG_error_t MSG_task_execute(m_task_t task)
251 void __MSG_task_execute(m_process_t process, m_task_t task)
256 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task)
260 /** \ingroup m_task_management
261 * \brief Creates a new #m_task_t (a parallel one....).
263 * A constructor for #m_task_t taking six arguments and returning the
264 corresponding object.
265 * \param name a name for the object. It is for user-level information
267 * \param host_nb the number of hosts implied in the parallel task.
268 * \param host_list an array of \p host_nb m_host_t.
269 * \param computation_amount an array of \p host_nb
270 doubles. computation_amount[i] is the total number of operations
271 that have to be performed on host_list[i].
272 * \param communication_amount an array of \p host_nb* \p host_nb doubles.
273 * \param data a pointer to any data may want to attach to the new
274 object. It is for user-level information and can be NULL. It can
275 be retrieved with the function \ref MSG_task_get_data.
277 * \return The new corresponding object.
279 m_task_t MSG_parallel_task_create(const char *name,
281 const m_host_t *host_list,
282 double *computation_amount,
283 double *communication_amount,
286 m_task_t task = xbt_new0(s_m_task_t,1);
291 static void __MSG_parallel_task_execute(m_process_t process, m_task_t task)
296 MSG_error_t MSG_parallel_task_execute(m_task_t task)
298 m_process_t process = MSG_process_self();
301 DEBUG0("Computing on a tons of guys");
303 __MSG_parallel_task_execute(process, task);
305 if(task->simdata->compute)
306 res = __MSG_wait_for_computation(process,task);
314 /** \ingroup msg_gos_functions
315 * \brief Sleep for the specified number of seconds
317 * Makes the current process sleep until \a time seconds have elapsed.
319 * \param nb_sec a number of second
321 MSG_error_t MSG_process_sleep(double nb_sec)
326 /** \ingroup msg_gos_functions
327 * \brief Return the number of MSG tasks currently running on
328 * the host of the current running process.
330 static int MSG_get_msgload(void)
335 /** \ingroup msg_gos_functions
337 * \brief Return the last value returned by a MSG function (except
340 MSG_error_t MSG_get_errno(void)
342 return PROCESS_GET_ERRNO();