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,
16 xbt_die("not implemented yet");
20 /** \ingroup msg_gos_functions
21 * \brief Listen on a channel and wait for receiving a task.
23 * It takes two parameters.
24 * \param task a memory location for storing a #m_task_t. It will
25 hold a task when this function will return. Thus \a task should not
26 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
27 those two condition does not hold, there will be a warning message.
28 * \param channel the channel on which the agent should be
29 listening. This value has to be >=0 and < than the maximal
30 number of channels fixed with MSG_set_channel_number().
31 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
32 * if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
34 MSG_error_t MSG_task_get(m_task_t * task,
37 return MSG_task_get_with_time_out(task, channel, -1);
40 /** \ingroup msg_gos_functions
41 * \brief Listen on a channel and wait for receiving a task with a timeout.
43 * It takes three parameters.
44 * \param task a memory location for storing a #m_task_t. It will
45 hold a task when this function will return. Thus \a task should not
46 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
47 those two condition does not hold, there will be a warning message.
48 * \param channel the channel on which the agent should be
49 listening. This value has to be >=0 and < than the maximal
50 number of channels fixed with MSG_set_channel_number().
51 * \param max_duration the maximum time to wait for a task before giving
52 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
53 will not be modified and will still be
54 equal to \c NULL when returning.
55 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
56 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
58 MSG_error_t MSG_task_get_with_time_out(m_task_t * task,
62 return __MSG_task_get_with_time_out_from_host(task, channel, max_duration, NULL);
65 /** \ingroup msg_gos_functions
66 * \brief Listen on \a channel and waits for receiving a task from \a host.
68 * It takes three parameters.
69 * \param task a memory location for storing a #m_task_t. It will
70 hold a task when this function will return. Thus \a task should not
71 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
72 those two condition does not hold, there will be a warning message.
73 * \param channel the channel on which the agent should be
74 listening. This value has to be >=0 and < than the maximal
75 number of channels fixed with MSG_set_channel_number().
76 * \param host the host that is to be watched.
77 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
78 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
80 MSG_error_t MSG_task_get_from_host(m_task_t * task, int channel,
83 return __MSG_task_get_with_time_out_from_host(task, channel, -1, host);
86 /** \ingroup msg_gos_functions
87 * \brief Test whether there is a pending communication on a channel.
89 * It takes one parameter.
90 * \param channel the channel on which the agent should be
91 listening. This value has to be >=0 and < than the maximal
92 number of channels fixed with MSG_set_channel_number().
93 * \return 1 if there is a pending communication and 0 otherwise
95 int MSG_task_Iprobe(m_channel_t channel)
97 xbt_die("not implemented yet");
101 /** \ingroup msg_gos_functions
102 * \brief Test whether there is a pending communication on a channel, and who sent it.
104 * It takes one parameter.
105 * \param channel the channel on which the agent should be
106 listening. This value has to be >=0 and < than the maximal
107 number of channels fixed with MSG_set_channel_number().
108 * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
110 int MSG_task_probe_from(m_channel_t channel)
112 xbt_die("not implemented yet");
116 /** \ingroup msg_gos_functions
117 * \brief Wait for at most \a max_duration second for a task reception
118 on \a channel. *\a PID is updated with the PID of the first process
119 that triggered this event if any.
121 * It takes three parameters:
122 * \param channel the channel on which the agent should be
123 listening. This value has to be >=0 and < than the maximal.
124 number of channels fixed with MSG_set_channel_number().
125 * \param PID a memory location for storing an int.
126 * \param max_duration the maximum time to wait for a task before
127 giving up. In the case of a reception, *\a PID will be updated
128 with the PID of the first process to send a task.
129 * \return #MSG_HOST_FAILURE if the host is shut down in the meantime
130 and #MSG_OK otherwise.
132 MSG_error_t MSG_channel_select_from(m_channel_t channel, double max_duration,
135 xbt_die("not implemented yet");
140 /** \ingroup msg_gos_functions
142 * \brief Return the number of tasks waiting to be received on a \a
143 channel and sent by \a host.
145 * It takes two parameters.
146 * \param channel the channel on which the agent should be
147 listening. This value has to be >=0 and < than the maximal
148 number of channels fixed with MSG_set_channel_number().
149 * \param host the host that is to be watched.
150 * \return the number of tasks waiting to be received on \a channel
153 int MSG_task_probe_from_host(int channel, m_host_t host)
155 xbt_die("not implemented yet");
159 /** \ingroup msg_gos_functions \brief Put a task on a channel of an
160 * host (with a timeout on the waiting of the destination host) and
161 * waits for the end of the transmission.
163 * This function is used for describing the behavior of an agent. It
164 * takes four parameter.
165 * \param task a #m_task_t to send on another location. This task
166 will not be usable anymore when the function will return. There is
167 no automatic task duplication and you have to save your parameters
168 before calling this function. Tasks are unique and once it has been
169 sent to another location, you should not access it anymore. You do
170 not need to call MSG_task_destroy() but to avoid using, as an
171 effect of inattention, this task anymore, you definitely should
172 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
173 can be transfered iff it has been correctly created with
175 * \param dest the destination of the message
176 * \param channel the channel on which the agent should put this
177 task. This value has to be >=0 and < than the maximal number of
178 channels fixed with MSG_set_channel_number().
179 * \param max_duration the maximum time to wait for a task before giving
180 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
182 * \return #MSG_FATAL if \a task is not properly initialized and
183 #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
184 this function was called was shut down. Returns
185 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
186 (network failure, dest failure, timeout...)
188 MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
189 m_channel_t channel, double max_duration)
191 xbt_die("not implemented yet");
194 /** \ingroup msg_gos_functions
195 * \brief Put a task on a channel of an host and waits for the end of the
198 * This function is used for describing the behavior of an agent. It
199 * takes three parameter.
200 * \param task a #m_task_t to send on another location. This task
201 will not be usable anymore when the function will return. There is
202 no automatic task duplication and you have to save your parameters
203 before calling this function. Tasks are unique and once it has been
204 sent to another location, you should not access it anymore. You do
205 not need to call MSG_task_destroy() but to avoid using, as an
206 effect of inattention, this task anymore, you definitely should
207 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
208 can be transfered iff it has been correctly created with
210 * \param dest the destination of the message
211 * \param channel the channel on which the agent should put this
212 task. This value has to be >=0 and < than the maximal number of
213 channels fixed with MSG_set_channel_number().
214 * \return #MSG_FATAL if \a task is not properly initialized and
215 * #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
216 * this function was called was shut down. Returns
217 * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
218 * (network failure, dest failure)
220 MSG_error_t MSG_task_put(m_task_t task,
221 m_host_t dest, m_channel_t channel)
223 return MSG_task_put_with_timeout(task, dest, channel, -1.0);
226 /** \ingroup msg_gos_functions
227 * \brief Does exactly the same as MSG_task_put but with a bounded transmition
232 MSG_error_t MSG_task_put_bounded(m_task_t task,
233 m_host_t dest, m_channel_t channel,
236 MSG_error_t res = MSG_OK;
237 task->simdata->rate=max_rate;
238 res = MSG_task_put(task, dest, channel);
242 /** \ingroup msg_gos_functions
243 * \brief Executes a task and waits for its termination.
245 * This function is used for describing the behavior of an agent. It
246 * takes only one parameter.
247 * \param task a #m_task_t to execute on the location on which the
249 * \return #MSG_FATAL if \a task is not properly initialized and
252 MSG_error_t MSG_task_execute(m_task_t task)
257 void __MSG_task_execute(m_process_t process, m_task_t task)
262 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task)
266 /** \ingroup m_task_management
267 * \brief Creates a new #m_task_t (a parallel one....).
269 * A constructor for #m_task_t taking six arguments and returning the
270 corresponding object.
271 * \param name a name for the object. It is for user-level information
273 * \param host_nb the number of hosts implied in the parallel task.
274 * \param host_list an array of \p host_nb m_host_t.
275 * \param computation_amount an array of \p host_nb
276 doubles. computation_amount[i] is the total number of operations
277 that have to be performed on host_list[i].
278 * \param communication_amount an array of \p host_nb* \p host_nb doubles.
279 * \param data a pointer to any data may want to attach to the new
280 object. It is for user-level information and can be NULL. It can
281 be retrieved with the function \ref MSG_task_get_data.
283 * \return The new corresponding object.
285 m_task_t MSG_parallel_task_create(const char *name,
287 const m_host_t *host_list,
288 double *computation_amount,
289 double *communication_amount,
292 m_task_t task = xbt_new0(s_m_task_t,1);
293 xbt_die("not implemented yet");
298 static void __MSG_parallel_task_execute(m_process_t process, m_task_t task)
303 MSG_error_t MSG_parallel_task_execute(m_task_t task)
306 xbt_die("not implemented yet");
311 /** \ingroup msg_gos_functions
312 * \brief Sleep for the specified number of seconds
314 * Makes the current process sleep until \a time seconds have elapsed.
316 * \param nb_sec a number of second
318 MSG_error_t MSG_process_sleep(double nb_sec)
320 smx_action_t act_sleep;
321 m_process_t proc = MSG_process_self();
324 /* create action to sleep */
325 act_sleep = SIMIX_action_sleep(SIMIX_process_get_host(proc->simdata->smx_process),nb_sec);
327 mutex = SIMIX_mutex_init();
328 SIMIX_mutex_lock(mutex);
329 /* create conditional and register action to it */
330 cond = SIMIX_cond_init();
332 SIMIX_register_condition_to_action(act_sleep, cond);
333 SIMIX_register_action_to_condition(act_sleep, cond);
334 SIMIX_cond_wait(cond,mutex);
335 SIMIX_mutex_unlock(mutex);
337 /* remove variables */
338 SIMIX_action_destroy(act_sleep);
339 SIMIX_cond_destroy(cond);
340 SIMIX_mutex_destroy(mutex);
345 /** \ingroup msg_gos_functions
346 * \brief Return the number of MSG tasks currently running on
347 * the host of the current running process.
349 static int MSG_get_msgload(void)
351 xbt_die("not implemented yet");
355 /** \ingroup msg_gos_functions
357 * \brief Return the last value returned by a MSG function (except
360 MSG_error_t MSG_get_errno(void)
362 return PROCESS_GET_ERRNO();